Class BaseMyBatisGenericDaoSupport<T extends net.solarnetwork.dao.Entity<K>,K>
java.lang.Object
org.springframework.dao.support.DaoSupport
org.mybatis.spring.support.SqlSessionDaoSupport
net.solarnetwork.central.dao.mybatis.support.BaseMyBatisDao
net.solarnetwork.central.dao.mybatis.support.BaseMyBatisGenericDaoSupport<T,K>
- All Implemented Interfaces:
net.solarnetwork.dao.GenericDao<T,,K> org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
BaseMyBatisFilterableDaoSupport
public abstract class BaseMyBatisGenericDaoSupport<T extends net.solarnetwork.dao.Entity<K>,K>
extends BaseMyBatisDao
implements net.solarnetwork.dao.GenericDao<T,K>
Base implementation of
GenericDao using MyBatis via
SqlSessionDaoSupport.- Since:
- 2.1
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.solarnetwork.dao.GenericDao
net.solarnetwork.dao.GenericDao.EntityEventType, net.solarnetwork.dao.GenericDao.StandardSortKey -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe query name used for updates inGenericDao.delete(Entity).static final intError code to report that a named query was not found.static final StringThe query property for a filter (search criteria) object.static final StringThe query name used for inserts inGenericDao.save(Entity).static final StringThe query name used forGenericDao.getAll(List).static final StringThe query name used forGenericDao.get(Object).static final StringThe query property for any custom sort descriptors that are provided.static final StringThe query name used for updates inGenericDao.save(Entity).Fields inherited from class net.solarnetwork.central.dao.mybatis.support.BaseMyBatisDao
FIRST_ROW, logFields inherited from class org.springframework.dao.support.DaoSupport
loggerFields inherited from interface net.solarnetwork.dao.GenericDao
ENTITY_EVENT_ENTITY_ID_PROPERTY, ENTITY_EVENT_ENTITY_PROPERTY, ENTITY_EVENT_TOPIC_TEMPLATE, SORT_BY_CREATED_ASCENDING, SORT_BY_CREATED_DESCENDING, SORT_BY_CREATED_ID_ASCENDING, SORT_BY_CREATED_ID_DESCENDING, SORT_BY_ID_ASCENDING, SORT_BY_ID_DESCENDING -
Constructor Summary
ConstructorsConstructorDescriptionBaseMyBatisGenericDaoSupport(Class<? extends T> objectType, Class<? extends K> keyType) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidGet the query name to delete an entity.Get the query name to insert an entity.Get the primary key type.protected intgetLastUpdateCount(int count) Get the last updated count, supporting batch operations.Get the main domain object type.Get the query name to query for all entities.Get the query name to query by primary key.Get the query name to update an entity.protected inthandleDelete(K id) Delete an entity based on its primary key.protected KhandleInsert(T entity) Process the insert of a persisted entity.protected KhandleUpdate(T entity) Process the update of a persisted entity.protected booleanTell if entities used assigned primary keys.protected voidpreprocessInsert(T entity) Process a new unsaved entity for persisting.protected KsaveWithAssignedPrimaryKey(T entity) Save an entity that uses an assigned primary key.voidSet the query name to delete an entity.voidSet the query name to insert an entity.voidsetQueryForAll(String queryForAll) Set the query name to query for all entities.voidsetQueryForId(String queryForId) Set the query name to query by primary key.voidSet the query name to update an entity.Methods inherited from class net.solarnetwork.central.dao.mybatis.support.BaseMyBatisDao
executeCountQuery, selectFiltered, selectFiltered, selectFiltered, selectFiltered, selectFirst, selectList, selectLong, setSqlSessionFactoryMethods inherited from class org.mybatis.spring.support.SqlSessionDaoSupport
checkDaoConfig, createSqlSessionTemplate, getSqlSession, getSqlSessionFactory, getSqlSessionTemplate, setSqlSessionTemplateMethods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDaoMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.dao.GenericDao
entityEventTopic, entityKey
-
Field Details
-
ERROR_CODE_INVALID_QUERY
public static final int ERROR_CODE_INVALID_QUERYError code to report that a named query was not found.- See Also:
-
QUERY_FOR_ID
The query name used forGenericDao.get(Object).- See Also:
-
QUERY_FOR_ALL
The query name used forGenericDao.getAll(List).- See Also:
-
INSERT_OBJECT
The query name used for inserts inGenericDao.save(Entity).- See Also:
-
UPDATE_OBJECT
The query name used for updates inGenericDao.save(Entity).- See Also:
-
DELETE_OBJECT
The query name used for updates inGenericDao.delete(Entity).- See Also:
-
SORT_DESCRIPTORS_PROPERTY
The query property for any custom sort descriptors that are provided.- See Also:
-
FILTER_PROPERTY
The query property for a filter (search criteria) object.- See Also:
-
-
Constructor Details
-
BaseMyBatisGenericDaoSupport
Constructor.- Parameters:
objectType- the entity typekeyType- the key type- Throws:
IllegalArgumentException- if any parameter is null
-
-
Method Details
-
getObjectType
Get the main domain object type. -
getKeyType
Get the primary key type.- Returns:
- the key type, never null
-
get
-
getAll
-
save
-
saveWithAssignedPrimaryKey
Save an entity that uses an assigned primary key.This method is called by
#save(Entity)whenisAssignedPrimaryKeys()returns true.- Parameters:
entity- the entity to save- Returns:
- the primary key
-
getLastUpdateCount
protected int getLastUpdateCount(int count) Get the last updated count, supporting batch operations.- Parameters:
count- the last returned count from callingSqlSession#update()- Returns:
- the count, extracted from batch updates if necessary
-
delete
-
handleDelete
Delete an entity based on its primary key.This method is called from
delete(Entity).- Parameters:
id- the primary key of the entity to delete- Returns:
- the number of deleted rows
-
preprocessInsert
Process a new unsaved entity for persisting.This implementation will set the value of a writable
createdbean property of the datum instance to the current time ifEntity.getCreated()is null. Extending classes may want to extend or modify this behavior.- Parameters:
entity- the entity to be persisted
-
handleUpdate
Process the update of a persisted entity.This implementation merely calls
SqlSession.update(String, Object)using thegetUpdate()SqlMap.- Parameters:
entity- the datum to update- Returns:
Identity.getId()
-
handleInsert
Process the insert of a persisted entity.This implementation calls
SqlSession.insert(String, Object)using thegetInsert()SqlMap.- Parameters:
entity- the datum to insert- Returns:
- the result of the insert statement
-
isAssignedPrimaryKeys
protected boolean isAssignedPrimaryKeys()Tell if entities used assigned primary keys.This method returns false. Extending classes can override to change the setting.
- Returns:
- true if entities use assigned primary keys, or false if keys are generated by the database
-
getQueryForId
Get the query name to query by primary key.- Returns:
- the query name; defaults to
QUERY_FOR_ID
-
setQueryForId
Set the query name to query by primary key.- Parameters:
queryForId- the query name to set
-
getQueryForAll
Get the query name to query for all entities.- Returns:
- the query name; defaults to
QUERY_FOR_ALL
-
setQueryForAll
Set the query name to query for all entities.- Parameters:
queryForAll- the query name to set
-
getInsert
Get the query name to insert an entity.- Returns:
- the query name; defaults to
INSERT_OBJECT
-
setInsert
Set the query name to insert an entity.- Parameters:
insert- the query name to set
-
setUpdate
Set the query name to update an entity.- Parameters:
update- the query name to set
-
getUpdate
Get the query name to update an entity.- Returns:
- the query name; defaults to
UPDATE_OBJECT
-
getDelete
Get the query name to delete an entity.- Returns:
- the query name; defaults to
DELETE_OBJECT
-
setDelete
Set the query name to delete an entity.- Parameters:
delete- the delete to set
-