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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The query property for a filter (search criteria) object.
    static final org.apache.ibatis.session.RowBounds
    A RowBounds instance that returns at most the first row.
    protected final org.slf4j.Logger
    A class-level logger.
    static final String
    The query property for any custom sort descriptors that are provided.

    Fields inherited from class org.springframework.dao.support.DaoSupport

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Long
    executeCountQuery(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> E
    selectFirst(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 Long
    selectLong(String statement, Object parameters)
    Execute a SELECT query that returns a single long value.
    void
    setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory)
     

    Methods inherited from class org.mybatis.spring.support.SqlSessionDaoSupport

    checkDaoConfig, createSqlSessionTemplate, getSqlSession, getSqlSessionFactory, getSqlSessionTemplate, setSqlSessionTemplate

    Methods inherited from class org.springframework.dao.support.DaoSupport

    afterPropertiesSet, initDao

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FIRST_ROW

      public static final org.apache.ibatis.session.RowBounds FIRST_ROW
      A RowBounds instance that returns at most the first row.
    • FILTER_PROPERTY

      public static final String FILTER_PROPERTY
      The query property for a filter (search criteria) object.
      See Also:
    • SORT_DESCRIPTORS_PROPERTY

      public static final String SORT_DESCRIPTORS_PROPERTY
      The query property for any custom sort descriptors that are provided.
      See Also:
    • log

      protected final org.slf4j.Logger log
      A class-level logger.
  • Constructor Details

    • BaseMyBatisDao

      public BaseMyBatisDao()
  • Method Details

    • setSqlSessionFactory

      public void setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory)
      Overrides:
      setSqlSessionFactory in class org.mybatis.spring.support.SqlSessionDaoSupport
    • selectFirst

      protected final <E> E selectFirst(String statement, Object parameters)
      Select the first available result from a query. This is similar to SqlSession.selectOne(String, Object) except that the FIRST_ROW bounds is passed to the database.
      Type Parameters:
      E - the result type
      Parameters:
      statement - the name of the SQL statement to execute
      parameters - 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 execute
      parameters - any parameters to pass to the statement
      offset - a result offset, or null for no offset
      max - the maximum number of results, or null for no maximum
      Returns:
      the first result, or null if none matched the query
    • selectLong

      protected Long selectLong(String statement, Object parameters)
      Execute a SELECT query that returns a single long value.
      Parameters:
      statement - the name of the SQL statement to execute
      parameters - any parameters to pass to the statement
      Returns:
      the result as a long, or null
      Since:
      1.1
    • executeCountQuery

      protected Long executeCountQuery(String countQueryName, Map<String,?> sqlProps)
      Execute a count query for a filter.

      If the query throws an IllegalArgumentException this method assumes that means the query name was not found, and will simply return null.

      Parameters:
      countQueryName - the query name
      sqlProps - the SQL properties
      Returns:
      the count
      Since:
      1.3
    • selectFiltered

      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.
      Type Parameters:
      M - the match type
      K - the match key type
      F - the filter type
      Parameters:
      query - the query name
      filter - the filter
      Returns:
      the results
      Since:
      1.3
      See Also:
    • selectFiltered

      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.
      Type Parameters:
      M - the match type
      K - the match key type
      F - the filter type
      Parameters:
      query - the query name
      filter - the filter
      sorts - the sort descriptors
      offset - the starting result offset
      max - the maximum number of results
      Returns:
      the results
      Since:
      1.3
      See Also:
    • selectFiltered

      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.
      Type Parameters:
      M - the match type
      K - the match key type
      F - the filter type
      Parameters:
      query - the query name
      filter - the filter
      sorts - the sort descriptors
      offset - the starting result offset
      max - the maximum number of results
      propertyProcessor - 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, 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.

      The following steps are taken:

      1. Create a SQL parameters map with a BaseMyBatisGenericDaoSupport.FILTER_PROPERTY key and f value.
      2. If filter implements SortCriteria and provides sort descriptors, those will be set as the SQL parameter BaseMyBatisGenericDaoSupport.SORT_DESCRIPTORS_PROPERTY. Otherwise the sorts argument will be set.
      3. If propertyProcessor is not null invoke that.
      4. If filter implements PaginationCriteria and provides pagination values, those will be used in preference to the offset and max method arguments.
      5. If max is not null, and if filter implements OptimizedQueryCriteria and does not disable a total results count, then call executeCountQuery(String, Map)
      6. Call selectList(String, Object, Integer, Integer)
      7. Create a result object, or if resultsFactory provided then call FilterResultsFactory.createFilterResults(Object, Map, Iterable, Long, Integer, Integer) and return the result.
      Type Parameters:
      M - the match type
      K - the match key type
      F - the filter type
      Parameters:
      query - the query name
      filter - the filter
      sorts - the sort descriptors
      offset - the starting result offset
      max - the maximum number of results
      propertyProcessor - an optional property process to adjust the SQL properties
      resultsFactory - an optional factory for creating filter results objects
      Returns:
      the results
      Since:
      1.3