Class BaseMyBatisDao
java.lang.Object
org.springframework.dao.support.DaoSupport
org.mybatis.spring.support.SqlSessionDaoSupport
net.solarnetwork.central.dao.mybatis.support.BaseMyBatisDao
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
BaseMyBatisGenericDao,BaseMyBatisGenericDaoSupport,MyBatisNetworkAssociationDao,MyBatisVersionedMessageDao
public abstract class BaseMyBatisDao
extends org.mybatis.spring.support.SqlSessionDaoSupport
Base DAO support for MyBatis implementations
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe query property for a filter (search criteria) object.static final org.apache.ibatis.session.RowBoundsA RowBounds instance that returns at most the first row.protected final org.slf4j.LoggerA class-level logger.static final StringThe query property for any custom sort descriptors that are provided.Fields inherited from class org.springframework.dao.support.DaoSupport
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected LongexecuteCountQuery(String countQueryName, Map<String, ?> sqlProps) Execute a count query for a filter.protected <M extends net.solarnetwork.domain.Identity<K>,K, F>
net.solarnetwork.dao.FilterResults<M, K> selectFiltered(String query, F filter) Perform a filter search using standardized semantics.protected <M extends net.solarnetwork.domain.Identity<K>,K, F>
net.solarnetwork.dao.FilterResults<M, K> selectFiltered(String query, F filter, List<net.solarnetwork.domain.SortDescriptor> sorts, Integer offset, Integer max) Perform a filter search using standardized semantics.protected <M extends net.solarnetwork.domain.Identity<K>,K, F>
net.solarnetwork.dao.FilterResults<M, K> selectFiltered(String query, F filter, List<net.solarnetwork.domain.SortDescriptor> sorts, Integer offset, Integer max, BiConsumer<F, Map<String, Object>> propertyProcessor) Perform a filter search using standardized semantics.protected <M extends net.solarnetwork.domain.Identity<K>,K, F>
net.solarnetwork.dao.FilterResults<M, K> selectFiltered(String query, F filter, List<net.solarnetwork.domain.SortDescriptor> sorts, Integer offset, Integer max, BiConsumer<F, Map<String, Object>> propertyProcessor, FilterResultsFactory<M, K, F> resultsFactory) Perform a filter search using standardized semantics.protected final <E> EselectFirst(String statement, Object parameters) Select the first available result from a query.protected final <E> List<E> selectList(String statement, Object parameters, Integer offset, Integer max) Select a list with optional support for row bounds.protected LongselectLong(String statement, Object parameters) Execute aSELECTquery that returns a single long value.voidsetSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory) Methods inherited from class org.mybatis.spring.support.SqlSessionDaoSupport
checkDaoConfig, createSqlSessionTemplate, getSqlSession, getSqlSessionFactory, getSqlSessionTemplate, setSqlSessionTemplateMethods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
-
Field Details
-
FIRST_ROW
public static final org.apache.ibatis.session.RowBounds FIRST_ROWA RowBounds instance that returns at most the first row. -
FILTER_PROPERTY
The query property for a filter (search criteria) object.- See Also:
-
SORT_DESCRIPTORS_PROPERTY
The query property for any custom sort descriptors that are provided.- See Also:
-
log
protected final org.slf4j.Logger logA class-level logger.
-
-
Constructor Details
-
BaseMyBatisDao
public BaseMyBatisDao()
-
-
Method Details
-
setSqlSessionFactory
public void setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory) - Overrides:
setSqlSessionFactoryin classorg.mybatis.spring.support.SqlSessionDaoSupport
-
selectFirst
Select the first available result from a query. This is similar toSqlSession.selectOne(String, Object)except that theFIRST_ROWbounds is passed to the database.- Type Parameters:
E- the result type- Parameters:
statement- the name of the SQL statement to executeparameters- any parameters to pass to the statement- Returns:
- the first result, or null if none matched the query
-
selectList
protected final <E> List<E> selectList(String statement, Object parameters, Integer offset, Integer max) Select a list with optional support for row bounds.- Type Parameters:
E- the result type- Parameters:
statement- the name of the SQL statement to executeparameters- any parameters to pass to the statementoffset- a result offset, or null for no offsetmax- the maximum number of results, or null for no maximum- Returns:
- the first result, or null if none matched the query
-
selectLong
Execute aSELECTquery that returns a single long value.- Parameters:
statement- the name of the SQL statement to executeparameters- any parameters to pass to the statement- Returns:
- the result as a long, or null
- Since:
- 1.1
-
executeCountQuery
Execute a count query for a filter.If the query throws an
IllegalArgumentExceptionthis method assumes that means the query name was not found, and will simply return null.- Parameters:
countQueryName- the query namesqlProps- the SQL properties- Returns:
- the count
- Since:
- 1.3
-
selectFiltered
protected <M extends net.solarnetwork.domain.Identity<K>,K, net.solarnetwork.dao.FilterResults<M,F> K> selectFiltered(String query, F filter) Perform a filter search using standardized semantics.- Type Parameters:
M- the match typeK- the match key typeF- the filter type- Parameters:
query- the query namefilter- the filter- Returns:
- the results
- Since:
- 1.3
- See Also:
-
selectFiltered
protected <M extends net.solarnetwork.domain.Identity<K>,K, net.solarnetwork.dao.FilterResults<M,F> K> selectFiltered(String query, F filter, List<net.solarnetwork.domain.SortDescriptor> sorts, Integer offset, Integer max) Perform a filter search using standardized semantics.- Type Parameters:
M- the match typeK- the match key typeF- the filter type- Parameters:
query- the query namefilter- the filtersorts- the sort descriptorsoffset- the starting result offsetmax- the maximum number of results- Returns:
- the results
- Since:
- 1.3
- See Also:
-
selectFiltered
protected <M extends net.solarnetwork.domain.Identity<K>,K, net.solarnetwork.dao.FilterResults<M,F> K> selectFiltered(String query, F filter, List<net.solarnetwork.domain.SortDescriptor> sorts, Integer offset, Integer max, BiConsumer<F, Map<String, Object>> propertyProcessor) Perform a filter search using standardized semantics.- Type Parameters:
M- the match typeK- the match key typeF- the filter type- Parameters:
query- the query namefilter- the filtersorts- the sort descriptorsoffset- the starting result offsetmax- the maximum number of resultspropertyProcessor- an optional property process to adjust the SQL properties- Returns:
- the results
- Since:
- 1.3
- See Also:
-
selectFiltered
protected <M extends net.solarnetwork.domain.Identity<K>,K, net.solarnetwork.dao.FilterResults<M,F> K> selectFiltered(String query, F filter, List<net.solarnetwork.domain.SortDescriptor> sorts, Integer offset, Integer max, BiConsumer<F, Map<String, Object>> propertyProcessor, FilterResultsFactory<M, K, F> resultsFactory) Perform a filter search using standardized semantics.The following steps are taken:
- Create a SQL parameters map with a
BaseMyBatisGenericDaoSupport.FILTER_PROPERTYkey andfvalue. - If
filterimplementsSortCriteriaand provides sort descriptors, those will be set as the SQL parameterBaseMyBatisGenericDaoSupport.SORT_DESCRIPTORS_PROPERTY. Otherwise thesortsargument will be set. - If
propertyProcessoris not null invoke that. - If
filterimplementsPaginationCriteriaand provides pagination values, those will be used in preference to theoffsetandmaxmethod arguments. - If
maxis not null, and if filter implementsOptimizedQueryCriteriaand does not disable a total results count, then callexecuteCountQuery(String, Map) - Call
selectList(String, Object, Integer, Integer) - Create a result object, or if
resultsFactoryprovided then callFilterResultsFactory.createFilterResults(Object, Map, Iterable, Long, Integer, Integer)and return the result.
- Type Parameters:
M- the match typeK- the match key typeF- the filter type- Parameters:
query- the query namefilter- the filtersorts- the sort descriptorsoffset- the starting result offsetmax- the maximum number of resultspropertyProcessor- an optional property process to adjust the SQL propertiesresultsFactory- an optional factory for creating filter results objects- Returns:
- the results
- Since:
- 1.3
- Create a SQL parameters map with a
-