Package com.github.ddth.dao
Class BaseDao
- java.lang.Object
-
- com.github.ddth.dao.BaseDao
-
- All Implemented Interfaces:
java.lang.AutoCloseable
- Direct Known Subclasses:
BaseJdbcDao
,BaseNoSqlDao
public abstract class BaseDao extends java.lang.Object implements java.lang.AutoCloseable
Base class for application DAOs.- Since:
- 0.1.0
- Author:
- Thanh Nguyen
-
-
Constructor Summary
Constructors Constructor Description BaseDao()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ProfilingRecord
addProfiling(long execTimeMs, java.lang.String command, long durationMs)
Adds a new profiling record.static void
clearProfiling()
Clears profiling data.void
close()
void
destroy()
Destroy method.protected com.github.ddth.cacheadapter.ICache
getCache(java.lang.String cacheName)
protected com.github.ddth.cacheadapter.ICacheFactory
getCacheFactory()
Cache factory used to cache DAO data.protected java.lang.Object
getFromCache(java.lang.String cacheName, java.lang.String key)
Get an entry from cache.protected <T> T
getFromCache(java.lang.String cacheName, java.lang.String key, java.lang.Class<T> clazz)
Get an entry from cache.static ProfilingRecord[]
getProfiling()
Gets current profiling data.BaseDao
init()
Initializing method.protected boolean
isCacheEnabled()
boolean
isCacheItemsExpireAfterWrite()
Check if cache items, by default, expire after write or read/access.protected void
putToCache(java.lang.String cacheName, java.lang.String key, java.lang.Object value)
Put an entry to cache, with default TTL.protected void
putToCache(java.lang.String cacheName, java.lang.String key, java.lang.Object value, long ttlSeconds)
Put an entry to cache, with specific TTL.protected void
putToCache(java.lang.String cacheName, java.lang.String key, java.lang.Object value, long expireAfterWriteSeconds, long expireAfterAccessSeconds)
Put an entry to cache, with specificexpireAfterWriteSeconds/expireAfterAccessSeconds
.protected void
removeFromCache(java.lang.String cacheName, java.lang.String key)
Remove an entry from cache.BaseDao
setCacheFactory(com.github.ddth.cacheadapter.ICacheFactory cacheFactory)
Cache factory used to cache DAO data.void
setCacheItemsExpireAfterWrite(boolean cacheItemsExpireAfterWrite)
Set if cache items, by default, expire after write or read/access.static void
startProfiling()
Initializes profiling data.
-
-
-
Method Detail
-
startProfiling
public static void startProfiling()
Initializes profiling data.
-
clearProfiling
public static void clearProfiling()
Clears profiling data.
-
getProfiling
public static ProfilingRecord[] getProfiling()
Gets current profiling data.- Returns:
-
addProfiling
public static ProfilingRecord addProfiling(long execTimeMs, java.lang.String command, long durationMs)
Adds a new profiling record.- Parameters:
execTimeMs
-command
-- Returns:
-
init
public BaseDao init()
Initializing method.- Returns:
-
destroy
public void destroy()
Destroy method.
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Since:
- 0.8.5
-
getCacheFactory
protected com.github.ddth.cacheadapter.ICacheFactory getCacheFactory()
Cache factory used to cache DAO data.- Returns:
-
setCacheFactory
public BaseDao setCacheFactory(com.github.ddth.cacheadapter.ICacheFactory cacheFactory)
Cache factory used to cache DAO data.- Parameters:
cacheFactory
-- Returns:
-
isCacheEnabled
protected boolean isCacheEnabled()
-
getCache
protected com.github.ddth.cacheadapter.ICache getCache(java.lang.String cacheName)
-
isCacheItemsExpireAfterWrite
public boolean isCacheItemsExpireAfterWrite()
Check if cache items, by default, expire after write or read/access.- Returns:
-
setCacheItemsExpireAfterWrite
public void setCacheItemsExpireAfterWrite(boolean cacheItemsExpireAfterWrite)
Set if cache items, by default, expire after write or read/access.- Parameters:
cacheItemsExpireAfterWrite
-
-
removeFromCache
protected void removeFromCache(java.lang.String cacheName, java.lang.String key)
Remove an entry from cache.- Parameters:
cacheName
-key
-
-
putToCache
protected void putToCache(java.lang.String cacheName, java.lang.String key, java.lang.Object value)
Put an entry to cache, with default TTL.- Parameters:
cacheName
-key
-value
-
-
putToCache
protected void putToCache(java.lang.String cacheName, java.lang.String key, java.lang.Object value, long ttlSeconds)
Put an entry to cache, with specific TTL.- Parameters:
cacheName
-key
-value
-ttlSeconds
-
-
putToCache
protected void putToCache(java.lang.String cacheName, java.lang.String key, java.lang.Object value, long expireAfterWriteSeconds, long expireAfterAccessSeconds)
Put an entry to cache, with specificexpireAfterWriteSeconds/expireAfterAccessSeconds
.- Parameters:
cacheName
-key
-value
-expireAfterWriteSeconds
-expireAfterAccessSeconds
-
-
getFromCache
protected java.lang.Object getFromCache(java.lang.String cacheName, java.lang.String key)
Get an entry from cache.- Parameters:
cacheName
-key
-- Returns:
-
getFromCache
protected <T> T getFromCache(java.lang.String cacheName, java.lang.String key, java.lang.Class<T> clazz)
Get an entry from cache.Note: if the object from cache is not assignable to clazz,
null
is returned.- Parameters:
cacheName
-key
-clazz
-- Returns:
-
-