Example usage for org.apache.ibatis.cache Cache putObject

List of usage examples for org.apache.ibatis.cache Cache putObject

Introduction

In this page you can find the example usage for org.apache.ibatis.cache Cache putObject.

Prototype

void putObject(Object key, Object value);

Source Link

Usage

From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.PaginationInterceptor.java

License:Apache License

private Integer getCount(String sql, Executor executor, MappedStatement ms, RowBounds rowBounds,
        BoundSql boundSql, Object parameter, Dialect dialect) throws SQLException {
    Integer count = 0;/*from w  w w  . ja  v a2s. c  o  m*/
    Cache cache = ms.getCache();
    if (cache != null && ms.isUseCache() && ms.getConfiguration().isCacheEnabled()) {
        CacheKey cacheKey = executor.createCacheKey(ms, parameter, rowBounds, boundSql);
        count = (Integer) cache.getObject(cacheKey);
        if (count == null) {
            count = SqlHelper.getCount(sql, ms, executor.getTransaction(), parameter, boundSql, dialect);
            cache.putObject(cacheKey, count);
        }
    } else {
        count = SqlHelper.getCount(sql, ms, executor.getTransaction(), parameter, boundSql, dialect);
    }
    return count;
}

From source file:org.mybatis.caches.hazelcast.BaseHazelcastTestCase.java

License:Apache License

@Test
public void shouldDemonstrateHowAllObjectsAreKept() {
    Cache cache = newCache();
    for (int i = 0; i < 100000; i++) {
        cache.putObject(i, i);
        assertEquals(i, cache.getObject(i));
    }/* w ww.  j ava 2  s . c o  m*/
    assertEquals(100000, cache.getSize());
}

From source file:org.mybatis.caches.hazelcast.BaseHazelcastTestCase.java

License:Apache License

@Test
public void shouldDemonstrateCopiesAreEqual() {
    Cache cache = newCache();
    for (int i = 0; i < 1000; i++) {
        cache.putObject(i, i);
        assertEquals(i, cache.getObject(i));
    }/*from w  ww.j a  va 2 s  . c o  m*/
}

From source file:org.mybatis.caches.hazelcast.BaseHazelcastTestCase.java

License:Apache License

@Test
public void shouldRemoveItemOnDemand() {
    Cache cache = newCache();
    cache.putObject(0, 0);
    assertNotNull(cache.getObject(0));/*from   w  w w .  j  av  a  2 s  .  co  m*/
    cache.removeObject(0);
    assertNull(cache.getObject(0));
}

From source file:org.mybatis.caches.hazelcast.BaseHazelcastTestCase.java

License:Apache License

@Test
public void shouldFlushAllItemsOnDemand() {
    Cache cache = newCache();
    for (int i = 0; i < 5; i++) {
        cache.putObject(i, i);
    }//  w  ww  . j a v a  2s.c om
    assertNotNull(cache.getObject(0));
    assertNotNull(cache.getObject(4));
    cache.clear();
    assertNull(cache.getObject(0));
    assertNull(cache.getObject(4));
}

From source file:plum.mybatis.PaginationExecutor.java

License:Apache License

@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler,
        CacheKey cacheKey, BoundSql boundSql) throws SQLException {

    final List<E> rows = executor.query(ms, parameter, rowBounds, resultHandler);
    Pager total = PaginationInterceptor.getTotal();
    try {//from w  w w  . j  av  a  2  s  . co m
        if (total != null) {
            final PageList<E> result = new PageList<E>(rows, total);
            // if the current of the executor is for CachingExecutor
            final Cache cache = ms.getCache();
            System.out.println(cache);
            // Determine whether the current query cache.
            if (executor.getClass().isAssignableFrom(CachingExecutor.class) && cache != null) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("cache executor the cache's kye  is " + cacheKey);
                }

                cache.putObject(cacheKey, result);
            }
            return result;
        } else {
            return rows;
        }
    } finally {
        PaginationInterceptor.clean();
    }
}

From source file:plum.mybatis.PaginationExecutor.java

License:Apache License

@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler)
        throws SQLException {

    final List<E> rows = executor.query(ms, parameter, rowBounds, resultHandler);
    Pager total = PaginationInterceptor.getTotal();
    try {//from   w  w  w. j  av  a  2s  .  co m
        if (total != null) {
            final PageList<E> result = new PageList<E>(rows, total);
            // if the current of the executor is for CachingExecutor
            final Cache cache = ms.getCache();
            System.out.println(cache);
            // Determine whether the current query cache.
            if (executor.getClass().isAssignableFrom(CachingExecutor.class) && cache != null) {
                BoundSql boundSql = ms.getBoundSql(parameter);
                final CacheKey cacheKey = createCacheKey(ms, parameter, rowBounds, boundSql);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("cache executor the cache's kye  is " + cacheKey);
                }

                cache.putObject(cacheKey, result);
            }
            return result;
        } else {
            return rows;
        }
    } finally {
        PaginationInterceptor.clean();
    }

}