Class AbstractBatchableJdbcDao<T>

java.lang.Object
org.springframework.dao.support.DaoSupport
org.springframework.jdbc.core.support.JdbcDaoSupport
net.solarnetwork.node.dao.jdbc.AbstractBatchableJdbcDao<T>
Type Parameters:
T - the type of domain object this DAO supports
All Implemented Interfaces:
net.solarnetwork.node.dao.BatchableDao<T>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
JdbcSettingDao

public abstract class AbstractBatchableJdbcDao<T> extends org.springframework.jdbc.core.support.JdbcDaoSupport implements net.solarnetwork.node.dao.BatchableDao<T>
Base class for BatchableDao implementations.
Version:
1.5
Author:
matt
  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.solarnetwork.node.dao.BatchableDao

    net.solarnetwork.node.dao.BatchableDao.BatchCallback<T extends Object>, net.solarnetwork.node.dao.BatchableDao.BatchCallbackResult, net.solarnetwork.node.dao.BatchableDao.BatchOptions, net.solarnetwork.node.dao.BatchableDao.BatchResult
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final org.slf4j.Logger
    A class-level logger.

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

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    net.solarnetwork.node.dao.BatchableDao.BatchResult
    batchProcess(net.solarnetwork.node.dao.BatchableDao.BatchCallback<T> callback, net.solarnetwork.node.dao.BatchableDao.BatchOptions options)
     
    protected abstract String
    getBatchJdbcStatement(net.solarnetwork.node.dao.BatchableDao.BatchOptions options)
    Get the SQL statement to use for batch processing.
    protected abstract T
    getBatchRowEntity(net.solarnetwork.node.dao.BatchableDao.BatchOptions options, ResultSet resultSet, int rowCount)
    Get an entity from the current row in a ResultSet for batch processing.
    protected String[]
    getBatchSqlResource(org.springframework.core.io.Resource sqlResource)
    Get batch SQL statements, split into multiple statements on the ; character.
    Set a SQL fragment to append to SQL statements where an updatable result set is desired.
    protected String
    getSqlResource(String classPathResource)
    Load a classpath SQL resource into a string.
    protected String
    getSqlResource(org.springframework.core.io.Resource resource)
    Load a SQL resource into a String.
    Get a SQL resource prefix.
    org.springframework.transaction.support.TransactionTemplate
    Get the transaction template.
    void
    setSqlForUpdateSuffix(String sqlForUpdateSuffix)
    Set a SQL fragment to append to SQL statements where an updatable result set is desired.
    void
    setSqlResourcePrefix(String sqlResourcePrefix)
    Set a SQL resource prefix.
    void
    setTransactionTemplate(org.springframework.transaction.support.TransactionTemplate transactionTemplate)
    Set the transaction template.
    protected abstract void
    updateBatchRowEntity(net.solarnetwork.node.dao.BatchableDao.BatchOptions options, ResultSet resultSet, int rowCount, T entity)
    Update the current row in a ResulSet for batch processing.

    Methods inherited from class org.springframework.jdbc.core.support.JdbcDaoSupport

    checkDaoConfig, createJdbcTemplate, getConnection, getDataSource, getExceptionTranslator, getJdbcTemplate, initTemplateConfig, releaseConnection, setDataSource, setJdbcTemplate

    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

    • log

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

    • AbstractBatchableJdbcDao

      public AbstractBatchableJdbcDao()
  • Method Details

    • getBatchJdbcStatement

      protected abstract String getBatchJdbcStatement(net.solarnetwork.node.dao.BatchableDao.BatchOptions options)
      Get the SQL statement to use for batch processing.
      Parameters:
      options - the requested batch options
      Returns:
      the SQL query
    • getBatchRowEntity

      protected abstract T getBatchRowEntity(net.solarnetwork.node.dao.BatchableDao.BatchOptions options, ResultSet resultSet, int rowCount) throws SQLException
      Get an entity from the current row in a ResultSet for batch processing.
      Parameters:
      options - the requested batch options
      resultSet - the current ResultSet, positioned on the next row
      rowCount - the current count of rows processed (1-based)
      Returns:
      the entity
      Throws:
      SQLException - if any SQL error occurs
    • updateBatchRowEntity

      protected abstract void updateBatchRowEntity(net.solarnetwork.node.dao.BatchableDao.BatchOptions options, ResultSet resultSet, int rowCount, T entity) throws SQLException
      Update the current row in a ResulSet for batch processing.

      The ResultSet.updateRow() method should not be called within this method.

      Parameters:
      options - the requested batch options
      resultSet - the current ResultSet, positioned on the next row
      rowCount - the current count of rows processed (1-based)
      entity - the entity data to update
      Throws:
      SQLException - if any SQL error occurs
    • batchProcess

      public net.solarnetwork.node.dao.BatchableDao.BatchResult batchProcess(net.solarnetwork.node.dao.BatchableDao.BatchCallback<T> callback, net.solarnetwork.node.dao.BatchableDao.BatchOptions options)
      Specified by:
      batchProcess in interface net.solarnetwork.node.dao.BatchableDao<T>
    • getSqlResource

      protected String getSqlResource(String classPathResource)
      Load a classpath SQL resource into a string.
      Parameters:
      classPathResource - the classpath resource to load as a SQL string
      Returns:
      the SQL
      Since:
      1.5
      See Also:
    • getSqlResource

      protected String getSqlResource(org.springframework.core.io.Resource resource)
      Load a SQL resource into a String.
      Parameters:
      resource - the SQL resource to load
      Returns:
      the SQL
      Since:
      1.5
      See Also:
    • getBatchSqlResource

      protected String[] getBatchSqlResource(org.springframework.core.io.Resource sqlResource)
      Get batch SQL statements, split into multiple statements on the ; character.
      Parameters:
      sqlResource - the SQL resource to load
      Returns:
      split SQL
      Since:
      1.5
      See Also:
    • getTransactionTemplate

      public org.springframework.transaction.support.TransactionTemplate getTransactionTemplate()
      Get the transaction template.
      Returns:
      the template
    • setTransactionTemplate

      public void setTransactionTemplate(org.springframework.transaction.support.TransactionTemplate transactionTemplate)
      Set the transaction template.
      Parameters:
      transactionTemplate - the template to set
    • getSqlForUpdateSuffix

      public String getSqlForUpdateSuffix()
      Set a SQL fragment to append to SQL statements where an updatable result set is desired.
      Returns:
      the SQL suffix, or null if not desired
      Since:
      1.4
    • setSqlForUpdateSuffix

      public void setSqlForUpdateSuffix(String sqlForUpdateSuffix)
      Set a SQL fragment to append to SQL statements where an updatable result set is desired.

      This defaults to FOR UPDATE. Note a space must be included at the beginning. Set to null to disable.

      Parameters:
      sqlForUpdateSuffix - the suffix to set
      Since:
      1.4
    • getSqlResourcePrefix

      public String getSqlResourcePrefix()
      Get a SQL resource prefix.
      Returns:
      the prefix
      Since:
      1.5
    • setSqlResourcePrefix

      public void setSqlResourcePrefix(String sqlResourcePrefix)
      Set a SQL resource prefix.
      Parameters:
      sqlResourcePrefix - the prefix to set
      Since:
      1.5