Package net.solarnetwork.node.dao.jdbc
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 supportsK- 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
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.solarnetwork.dao.BatchableDao
net.solarnetwork.dao.BatchableDao.BatchCallback<T extends Object>, net.solarnetwork.dao.BatchableDao.BatchCallbackResult, net.solarnetwork.dao.BatchableDao.BatchOptions, net.solarnetwork.dao.BatchableDao.BatchResultNested classes/interfaces inherited from interface net.solarnetwork.dao.GenericDao
net.solarnetwork.dao.GenericDao.EntityEventType, net.solarnetwork.dao.GenericDao.StandardSortKey -
Field Summary
Fields inherited from class net.solarnetwork.node.dao.jdbc.BaseJdbcGenericDao
INIT_SQL_FORMAT, ORDER_BY, SQL_DELETE_BY_PK, SQL_FIND_ALL, SQL_GET_BY_PK, SQL_GET_TABLES_VERSION_FORMAT, SQL_INSERT, SQL_RESOURCE_PREFIX, SQL_UPDATE, UTC_CALENDARFields inherited from class net.solarnetwork.node.dao.jdbc.AbstractJdbcDao
logFields inherited from class org.springframework.dao.support.DaoSupport
loggerFields inherited from interface net.solarnetwork.dao.GenericDao
ENTITY_EVENT_ENTITY_ID_PROPERTY, ENTITY_EVENT_ENTITY_PROPERTY, ENTITY_EVENT_TOPIC_TEMPLATE, SORT_BY_CREATED_ASCENDING, SORT_BY_CREATED_DESCENDING, SORT_BY_CREATED_ID_ASCENDING, SORT_BY_CREATED_ID_DESCENDING, SORT_BY_ID_ASCENDING, SORT_BY_ID_DESCENDING -
Constructor Summary
ConstructorsConstructorDescriptionBaseJdbcBatchableDao(Class<? extends T> objectType, Class<? extends K> keyType, org.springframework.jdbc.core.RowMapper<T> rowMapper) Constructor.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. -
Method Summary
Modifier and TypeMethodDescriptionnet.solarnetwork.dao.BatchableDao.BatchResultbatchProcess(net.solarnetwork.dao.BatchableDao.BatchCallback<T> callback, net.solarnetwork.dao.BatchableDao.BatchOptions options) protected abstract StringgetBatchJdbcStatement(net.solarnetwork.dao.BatchableDao.BatchOptions options) Get the SQL statement to use for batch processing.protected abstract TgetBatchRowEntity(net.solarnetwork.dao.BatchableDao.BatchOptions options, ResultSet resultSet, int rowCount) Get an entity from the current row in a ResultSet for batch processing.Set a SQL fragment to append to SQL statements where an updatable result set is desired.org.springframework.transaction.support.TransactionTemplateGet the transaction template.protected voidprepareBatchStatement(net.solarnetwork.dao.BatchableDao.BatchOptions options, Connection con, PreparedStatement queryStmt) Prepare the batch statement.voidsetSqlForUpdateSuffix(String sqlForUpdateSuffix) Set a SQL fragment to append to SQL statements where an updatable result set is desired.voidsetTransactionTemplate(org.springframework.transaction.support.TransactionTemplate transactionTemplate) Set the transaction template.protected abstract voidupdateBatchRowEntity(net.solarnetwork.dao.BatchableDao.BatchOptions options, ResultSet resultSet, int rowCount, T entity) Update the current row in a ResulSet for batch processing.Methods inherited from class net.solarnetwork.node.dao.jdbc.BaseJdbcGenericDao
applySqlOrderClauses, delete, findFirst, get, getAll, getInstantColumn, getKeyType, getObjectType, getRowMapper, getUuidColumns, postEntityEvent, primaryKeyArguments, querySql, save, setInstantParameter, setUuidParameters, sqlOrderClause, sqlOrderClausesMethods inherited from class net.solarnetwork.node.dao.jdbc.AbstractJdbcDao
getBatchSqlResource, getEventAdmin, getInitSqlResource, getMessageSource, getSchemaName, getSqlGetTablesVersion, getSqlResource, getSqlResource, getSqlResourcePrefix, getTableName, getTableNames, getTablesVersion, init, insertDomainObject, isUseAutogeneratedKeys, postEvent, schemaExists, setEventAdmin, setInitSqlResource, setMessageSource, setSchemaName, setSqlGetTablesVersion, setSqlResourcePrefix, setStoreStatementValues, setTableName, setTablesVersion, setUpdateStatementValues, setUseAutogeneratedKeys, storeDomainObject, storeDomainObjectWithoutAutogeneratedKeys, tableExists, updateDomainObject, upgradeTablesVersion, verifyDatabaseExistsMethods 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, initDaoMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.dao.GenericDao
entityEventTopic
-
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 typekeyType- the key typerowMapper- 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 typekeyType- the key typerowMapper- a mapper to use when mapping entity query result rows to entity objectstableNameTemplate- a template with a%sparameter for the SQL table nameentityName- 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 optionscon- the SQL connectionqueryStmt- 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 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.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.dao.BatchableDao.BatchResult batchProcess(net.solarnetwork.dao.BatchableDao.BatchCallback<T> callback, net.solarnetwork.dao.BatchableDao.BatchOptions options) -
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.- Overrides:
getSqlForUpdateSuffixin classAbstractJdbcDao<T extends net.solarnetwork.dao.Entity<K>>- 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.
- Overrides:
setSqlForUpdateSuffixin classAbstractJdbcDao<T extends net.solarnetwork.dao.Entity<K>>- Parameters:
sqlForUpdateSuffix- the suffix to set- Since:
- 1.4
-