All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gu.sql2java.CacheManager Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
package gu.sql2java;

import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import gu.sql2java.exception.DaoException;
import gu.sql2java.exception.ObjectRetrievalException;
import gu.sql2java.exception.RuntimeDaoException;

/**
 * cache implementation for BaseTableManager
* @author guyadong */ class CacheManager extends BaseTableManager { /** instance of {@link TableCache} */ private final TableCache cache; CacheManager(String tablename,UpdateStrategy updateStrategy,Long maximumSize, Long duration, TimeUnit unit) { super(tablename); cache = new TableCache<>(metaData,updateStrategy,maximumSize,duration,unit); cache.registerListener(); } CacheManager(String tablename){ this(tablename, null, null, null, null); } /** * create a instance of DeviceCacheManager and assign to {@link #instance} if {@code instance} is not initialized.
* otherwise return {@code instance}. * @param tablename * @param updateStrategy cache update strategy,{@link Constant#DEFAULT_STRATEGY} be used if {@code null} * @param maximumSize maximum capacity of cache ,{@link Constant#DEFAULT_CACHE_MAXIMUMSIZE } be used if {@code null} or <=0,see also {@link CacheBuilder#maximumSize(long)} * @param duration cache data expired time,{@link Constant#DEFAULT_DURATION} be used if {@code null} or <=0,see also {@link CacheBuilder#expireAfterAccess(long, TimeUnit)} * @param unit time unit for {@code duration},{@link Constant#DEFAULT_TIME_UNIT} be used if {@code null},see also {@link CacheBuilder#expireAfterAccess(long, TimeUnit)} */ static synchronized final TableManager makeCacheInstance( String tablename, UpdateStrategy updateStrategy, long maximumSize, long duration, TimeUnit unit){ CacheManager manager = new CacheManager(tablename,updateStrategy,maximumSize,duration,unit); return TableManagerDecorator.makeInterfaceInstance(manager); } @Override protected BaseBean doLoadByPrimaryKeyChecked(Object ...keys)throws RuntimeDaoException,ObjectRetrievalException{ return cache.getBean(keys); } @Override protected boolean doExistsPrimaryKey(Object ...keys)throws RuntimeDaoException{ return null != cache.getBeanUnchecked(keys); } @Override protected int actionOnResultSet(ResultSet rs, int[] fieldList, int startRow, int numRows, Action action) throws DaoException{ if(null == fieldList || fieldList.length == 0){ action = cache.wrap(action); } return super.actionOnResultSet(rs, fieldList, startRow, numRows, action); } @Override protected BaseBean doLoadUniqueByIndex(String indexName,Object ...indexValues)throws RuntimeDaoException{ return cache.getBeanByIndexUnchecked(indexName, indexValues); } @Override protected BaseBean doLoadUniqueByIndexChecked(String indexName,Object ...indexValues)throws ObjectRetrievalException{ return cache.getBeanByIndex(indexName, indexValues); } @Override protected Map> getForeignKeyDeleteListeners(){ return cache.getManager().getForeignKeyDeleteListeners(); } @Override public ListenerContainer getListenerContainer() { return cache.getManager().getListenerContainer(); } @Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("CacheManager [cache="); builder.append(cache); builder.append("]"); return builder.toString(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy