Package net.solarnetwork.node.dao.jdbc
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
FieldsFields inherited from class org.springframework.dao.support.DaoSupport
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionnet.solarnetwork.node.dao.BatchableDao.BatchResultbatchProcess(net.solarnetwork.node.dao.BatchableDao.BatchCallback<T> callback, net.solarnetwork.node.dao.BatchableDao.BatchOptions options) protected abstract StringgetBatchJdbcStatement(net.solarnetwork.node.dao.BatchableDao.BatchOptions options) Get the SQL statement to use for batch processing.protected abstract TgetBatchRowEntity(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 StringgetSqlResource(String classPathResource) Load a classpath SQL resource into a string.protected StringgetSqlResource(org.springframework.core.io.Resource resource) Load a SQL resource into a String.Get a SQL resource prefix.org.springframework.transaction.support.TransactionTemplateGet the transaction template.voidsetSqlForUpdateSuffix(String sqlForUpdateSuffix) Set a SQL fragment to append to SQL statements where an updatable result set is desired.voidsetSqlResourcePrefix(String sqlResourcePrefix) Set a SQL resource prefix.voidsetTransactionTemplate(org.springframework.transaction.support.TransactionTemplate transactionTemplate) Set the transaction template.protected abstract voidupdateBatchRowEntity(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, setJdbcTemplateMethods inherited from class org.springframework.dao.support.DaoSupport
afterPropertiesSet, initDao
-
Field Details
-
log
protected final org.slf4j.Logger logA 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 optionsresultSet- the current ResultSet, positioned on the next rowrowCount- 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 optionsresultSet- the current ResultSet, positioned on the next rowrowCount- 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:
batchProcessin interfacenet.solarnetwork.node.dao.BatchableDao<T>
-
getSqlResource
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
Load a SQL resource into a String.- Parameters:
resource- the SQL resource to load- Returns:
- the SQL
- Since:
- 1.5
- See Also:
-
getBatchSqlResource
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
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
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
Get a SQL resource prefix.- Returns:
- the prefix
- Since:
- 1.5
-
setSqlResourcePrefix
Set a SQL resource prefix.- Parameters:
sqlResourcePrefix- the prefix to set- Since:
- 1.5
-