Class BaseJdbcBatchableDao<T extends net.solarnetwork.dao.Entity<K>,K>

java.lang.Object
org.springframework.dao.support.DaoSupport
org.springframework.jdbc.core.support.JdbcDaoSupport
net.solarnetwork.node.dao.jdbc.AbstractJdbcDao<T>
net.solarnetwork.node.dao.jdbc.BaseJdbcGenericDao<T,K>
net.solarnetwork.node.dao.jdbc.BaseJdbcBatchableDao<T,K>
Type Parameters:
T - the type of domain object this DAO supports
K - the primary key type
All Implemented Interfaces:
net.solarnetwork.dao.BatchableDao<T>, net.solarnetwork.dao.GenericDao<T,K>, JdbcDao, org.springframework.beans.factory.InitializingBean

public abstract class BaseJdbcBatchableDao<T extends net.solarnetwork.dao.Entity<K>,K> extends BaseJdbcGenericDao<T,K> implements net.solarnetwork.dao.BatchableDao<T>
Base class for BatchableDao implementations.
Since:
1.29
Version:
1.0
Author:
matt
  • Constructor Details

    • BaseJdbcBatchableDao

      public BaseJdbcBatchableDao(Class<? extends T> objectType, Class<? extends K> keyType, org.springframework.jdbc.core.RowMapper<T> rowMapper)
      Constructor.
      Parameters:
      objectType - the entity type
      keyType - the key type
      rowMapper - a mapper to use when mapping entity query result rows to entity objects
      Throws:
      IllegalArgumentException - if any parameter is null
    • BaseJdbcBatchableDao

      public BaseJdbcBatchableDao(Class<? extends T> objectType, Class<? extends K> keyType, org.springframework.jdbc.core.RowMapper<T> rowMapper, String tableNameTemplate, String entityName, int version)
      Init with an an entity name and table version, deriving various names based on conventions.
      Parameters:
      objectType - the entity type
      keyType - the key type
      rowMapper - a mapper to use when mapping entity query result rows to entity objects
      tableNameTemplate - a template with a %s parameter for the SQL table name
      entityName - The entity name to use. This name forms the basis of the default SQL resource prefix, table name, tables version query, and SQL init resource.
      version - the tables version, to manage DDL migrations
  • Method Details

    • getBatchJdbcStatement

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

      protected void prepareBatchStatement(net.solarnetwork.dao.BatchableDao.BatchOptions options, Connection con, PreparedStatement queryStmt) throws SQLException
      Prepare the batch statement.

      This implementation does nothing. Extending classes might need to set parameters.

      Parameters:
      options - the batch options
      con - the SQL connection
      queryStmt - the SQL statement
      Throws:
      SQLException - if any SQL error occurs
    • getBatchRowEntity

      protected abstract T getBatchRowEntity(net.solarnetwork.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.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.dao.BatchableDao.BatchResult batchProcess(net.solarnetwork.dao.BatchableDao.BatchCallback<T> callback, net.solarnetwork.dao.BatchableDao.BatchOptions options)
      Specified by:
      batchProcess in interface net.solarnetwork.dao.BatchableDao<T extends net.solarnetwork.dao.Entity<K>>
    • 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.
      Overrides:
      getSqlForUpdateSuffix in class AbstractJdbcDao<T extends net.solarnetwork.dao.Entity<K>>
      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.

      Overrides:
      setSqlForUpdateSuffix in class AbstractJdbcDao<T extends net.solarnetwork.dao.Entity<K>>
      Parameters:
      sqlForUpdateSuffix - the suffix to set
      Since:
      1.4