Package com.github.ddth.dao.jdbc
Class GenericMultiBoJdbcDao
- java.lang.Object
-
- com.github.ddth.dao.BaseDao
-
- com.github.ddth.dao.jdbc.BaseJdbcDao
-
- com.github.ddth.dao.jdbc.GenericMultiBoJdbcDao
-
- All Implemented Interfaces:
IGenericMultiBoDao
,IJdbcHelper
,java.lang.AutoCloseable
public class GenericMultiBoJdbcDao extends BaseJdbcDao implements IGenericMultiBoDao
Generic implementation ofIGenericMultiBoDao
- Since:
- 0.9.0
- Author:
- Thanh Nguyen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GenericMultiBoJdbcDao.DelegateDaoNotFound
Thrown when the delegate DAO is not found.
-
Field Summary
-
Fields inherited from interface com.github.ddth.dao.jdbc.IJdbcHelper
DEFAULT_DATASOURCE
-
-
Constructor Summary
Constructors Constructor Description GenericMultiBoJdbcDao()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> GenericMultiBoJdbcDao
addDelegateDao(java.lang.Class<T> clazz, IGenericBoDao<T> dao)
Add a delegate dao to mapping list.<T> GenericMultiBoJdbcDao
addDelegateDao(java.lang.String className, IGenericBoDao<T> dao)
Add a delegate dao to mapping list.<T> DaoResult
create(java.lang.Class<T> clazz, T bo)
Create/Persist a new BO to storage.<T> DaoResult
createOrUpdate(java.lang.Class<T> clazz, T bo)
Create a new BO or update an existing one.<T> DaoResult
delete(java.lang.Class<T> clazz, T bo)
Delete an existing BO from storage.<T> T
get(java.lang.Class<T> clazz, BoId id)
Fetch an existing BO from storage by id.<T> T[]
get(java.lang.Class<T> clazz, BoId... idList)
Fetch list of existing BOs from storage by id.<T> java.util.stream.Stream<T>
getAll(java.lang.Class<T> clazz)
Fetch all existing BOs from storage and return the result as a stream.<T> java.util.stream.Stream<T>
getAllSorted(java.lang.Class<T> clazz)
Fetch all existing BOs from storage, sorted by primary key(s) and return the result as a stream.protected <T> IGenericBoDao<T>
lookupDelegateDao(java.lang.Class<T> clazz)
Lookup the delegate dao.GenericMultiBoJdbcDao
setDelegateDaos(java.util.Map<?,IGenericBoDao<?>> daoMappings)
Set delegate dao mappings.<T> DaoResult
update(java.lang.Class<T> clazz, T bo)
Update an existing BO.<T> DaoResult
updateOrCreate(java.lang.Class<T> clazz, T bo)
Update an existing BO or create a new one.-
Methods inherited from class com.github.ddth.dao.jdbc.BaseJdbcDao
commitTransaction, execute, execute, execute, execute, executeSelect, executeSelect, executeSelect, executeSelect, executeSelect, executeSelect, executeSelect, executeSelect, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectAsStream, executeSelectOne, executeSelectOne, executeSelectOne, executeSelectOne, executeSelectOne, executeSelectOne, executeSelectOne, executeSelectOne, getConnection, getConnection, getConnection, getConnection, getJdbcHelper, returnConnection, rollbackTransaction, setJdbcHelper, startTransaction
-
Methods inherited from class com.github.ddth.dao.BaseDao
addProfiling, clearProfiling, close, destroy, getCache, getCacheFactory, getFromCache, getFromCache, getProfiling, init, isCacheEnabled, isCacheItemsExpireAfterWrite, putToCache, putToCache, putToCache, removeFromCache, setCacheFactory, setCacheItemsExpireAfterWrite, startProfiling
-
-
-
-
Method Detail
-
lookupDelegateDao
protected <T> IGenericBoDao<T> lookupDelegateDao(java.lang.Class<T> clazz) throws GenericMultiBoJdbcDao.DelegateDaoNotFound
Lookup the delegate dao.- Parameters:
clazz
-- Returns:
- Throws:
GenericMultiBoJdbcDao.DelegateDaoNotFound
-
addDelegateDao
public <T> GenericMultiBoJdbcDao addDelegateDao(java.lang.Class<T> clazz, IGenericBoDao<T> dao)
Add a delegate dao to mapping list.- Parameters:
clazz
-dao
-- Returns:
-
addDelegateDao
public <T> GenericMultiBoJdbcDao addDelegateDao(java.lang.String className, IGenericBoDao<T> dao) throws java.lang.ClassNotFoundException
Add a delegate dao to mapping list.- Parameters:
className
-dao
-- Returns:
- Throws:
java.lang.ClassNotFoundException
-
setDelegateDaos
public GenericMultiBoJdbcDao setDelegateDaos(java.util.Map<?,IGenericBoDao<?>> daoMappings) throws java.lang.ClassNotFoundException
Set delegate dao mappings.- Parameters:
daoMappings
-- Returns:
- Throws:
java.lang.ClassNotFoundException
-
create
public <T> DaoResult create(java.lang.Class<T> clazz, T bo) throws DaoException
Create/Persist a new BO to storage.- Specified by:
create
in interfaceIGenericMultiBoDao
- Returns:
- Throws:
DaoException
-
delete
public <T> DaoResult delete(java.lang.Class<T> clazz, T bo) throws DaoException
Delete an existing BO from storage.- Specified by:
delete
in interfaceIGenericMultiBoDao
- Returns:
- Throws:
DaoException
-
get
public <T> T get(java.lang.Class<T> clazz, BoId id) throws DaoException
Fetch an existing BO from storage by id.- Specified by:
get
in interfaceIGenericMultiBoDao
- Returns:
- Throws:
DaoException
-
get
public <T> T[] get(java.lang.Class<T> clazz, BoId... idList) throws DaoException
Fetch list of existing BOs from storage by id.- Specified by:
get
in interfaceIGenericMultiBoDao
- Returns:
- Throws:
DaoException
-
getAll
public <T> java.util.stream.Stream<T> getAll(java.lang.Class<T> clazz) throws DaoException
Fetch all existing BOs from storage and return the result as a stream.- Specified by:
getAll
in interfaceIGenericMultiBoDao
- Returns:
- Throws:
DaoException
-
getAllSorted
public <T> java.util.stream.Stream<T> getAllSorted(java.lang.Class<T> clazz) throws DaoException
Fetch all existing BOs from storage, sorted by primary key(s) and return the result as a stream.- Specified by:
getAllSorted
in interfaceIGenericMultiBoDao
- Returns:
- Throws:
DaoException
-
update
public <T> DaoResult update(java.lang.Class<T> clazz, T bo) throws DaoException
Update an existing BO.- Specified by:
update
in interfaceIGenericMultiBoDao
- Returns:
- Throws:
DaoException
-
createOrUpdate
public <T> DaoResult createOrUpdate(java.lang.Class<T> clazz, T bo) throws DaoException
Create a new BO or update an existing one.- Specified by:
createOrUpdate
in interfaceIGenericMultiBoDao
- Returns:
- Throws:
DaoException
-
updateOrCreate
public <T> DaoResult updateOrCreate(java.lang.Class<T> clazz, T bo) throws DaoException
Update an existing BO or create a new one.- Specified by:
updateOrCreate
in interfaceIGenericMultiBoDao
- Returns:
- Throws:
DaoException
-
-