Class BulkLoadingDaoSupport.BulkLoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable>
- Type Parameters:
T- the entity typePK- the primary key type
- All Implemented Interfaces:
AutoCloseable,BulkLoadingDao.LoadingContext<T,PK>
- Enclosing class:
BulkLoadingDaoSupport
This class implements the majority of a bulk loading context. Extending
classes must override
doLoad(Entity, PreparedStatement, long) to
perform the actual loading of an entity.
-
Constructor Summary
ConstructorsConstructorDescriptionBulkLoadingContext(BulkLoadingDao.LoadingOptions options, BulkLoadingDao.LoadingExceptionHandler<T, PK> exceptionHandler) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close any temporary resources.voidcommit()Commit the current transaction.voidCreate a checkpoint that can be rolled back to.protected abstract booleandoLoad(T entity, PreparedStatement stmt, long index) longGet the count of entities committed thus far using this context.Get the entity that was last passed to theBulkLoadingDao.LoadingContext.load(Entity)method.longGet the count of entities loaded thus far using this context.Get the loading options used to create the context.final voidLoad an entity.voidrollback()Discard the entities loaded within the current transaction.
-
Constructor Details
-
BulkLoadingContext
public BulkLoadingContext(BulkLoadingDao.LoadingOptions options, BulkLoadingDao.LoadingExceptionHandler<T, PK> exceptionHandler) throws SQLException- Throws:
SQLException
-
-
Method Details
-
getOptions
Description copied from interface:BulkLoadingDao.LoadingContextGet the loading options used to create the context.- Specified by:
getOptionsin interfaceBulkLoadingDao.LoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable> - Returns:
- the loading options
-
getLoadedCount
public long getLoadedCount()Description copied from interface:BulkLoadingDao.LoadingContextGet the count of entities loaded thus far using this context.If
BulkLoadingDao.LoadingContext.rollback()is called, this value will reset back to the count of currently committed entities.- Specified by:
getLoadedCountin interfaceBulkLoadingDao.LoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable> - Returns:
- the loaded count
-
getCommittedCount
public long getCommittedCount()Description copied from interface:BulkLoadingDao.LoadingContextGet the count of entities committed thus far using this context.How this value increments depends on the
BulkLoadingDao.LoadingTransactionModedefined in the options that were used to create this context:BulkLoadingDao.LoadingTransactionMode.NoTransaction- This count will match
BulkLoadingDao.LoadingContext.getLoadedCount()and increment as each entity is loaded. BulkLoadingDao.LoadingTransactionMode.BatchTransactions- This count will increment only after each batch of loaded entity
have been committed, and thus can lag behind
BulkLoadingDao.LoadingContext.getLoadedCount(). BulkLoadingDao.LoadingTransactionMode.TransactionCheckpoints- This count will only increment after calls to
BulkLoadingDao.LoadingContext.createCheckpoint()are made. IfBulkLoadingDao.LoadingContext.rollback()is called, this count will reset back to the count at the previous timeBulkLoadingDao.LoadingContext.createCheckpoint()was called. BulkLoadingDao.LoadingTransactionMode.SingleTransaction- This count will remain at 0 until
BulkLoadingDao.LoadingContext.commit()is called, at which point it will matchBulkLoadingDao.LoadingContext.getLoadedCount().
- Specified by:
getCommittedCountin interfaceBulkLoadingDao.LoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable> - Returns:
- the committed entity count
-
getLastLoadedEntity
Description copied from interface:BulkLoadingDao.LoadingContextGet the entity that was last passed to theBulkLoadingDao.LoadingContext.load(Entity)method.- Specified by:
getLastLoadedEntityin interfaceBulkLoadingDao.LoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable> - Returns:
- the last loaded entity
-
load
Description copied from interface:BulkLoadingDao.LoadingContextLoad an entity.- Specified by:
loadin interfaceBulkLoadingDao.LoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable> - Parameters:
entity- the entity to load
-
doLoad
- Throws:
SQLException
-
createCheckpoint
public void createCheckpoint()Description copied from interface:BulkLoadingDao.LoadingContextCreate a checkpoint that can be rolled back to.The
BulkLoadingDao.LoadingTransactionMode.TransactionCheckpointsmode must have been set in the options used to create this context.- Specified by:
createCheckpointin interfaceBulkLoadingDao.LoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable>
-
commit
public void commit()Description copied from interface:BulkLoadingDao.LoadingContextCommit the current transaction.The nature of the current transaction depends on the transaction mode set in the options used to create this context:
TransactionCheckpointsorSingleTransaction- All entities loaded via
BulkLoadingDao.LoadingContext.load(Entity)are committed. BatchTransactions- The entities loaded via
BulkLoadingDao.LoadingContext.load(Entity)since the last automatic batch commit are committed.
- Specified by:
commitin interfaceBulkLoadingDao.LoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable>
-
rollback
public void rollback()Description copied from interface:BulkLoadingDao.LoadingContextDiscard the entities loaded within the current transaction.The nature of the current transaction depends on the transaction mode set in the options used to create this context:
SingleTransaction- All entities loaded are discarded.
TransactionCheckpoints- All entities loaded via
BulkLoadingDao.LoadingContext.load(Entity)since the last call toBulkLoadingDao.LoadingContext.createCheckpoint()are discarded. BatchTransactions- The entities loaded via
BulkLoadingDao.LoadingContext.load(Entity)since the last automatic batch commit are discarded.
- Specified by:
rollbackin interfaceBulkLoadingDao.LoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable>
-
close
public void close()Description copied from interface:BulkLoadingDao.LoadingContextClose any temporary resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceBulkLoadingDao.LoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable>
-