Package net.solarnetwork.central.dao
Interface BulkLoadingDao.LoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable>
- Type Parameters:
T- the entity typePK- the primary key type
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
BulkLoadingDaoSupport.BulkLoadingContext
- Enclosing interface:
BulkLoadingDao<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable>
public static interface BulkLoadingDao.LoadingContext<T extends net.solarnetwork.dao.Entity<PK>,PK extends Serializable>
extends AutoCloseable
API for a bulk loading operational context.
This is the main API used to perform the bulk loading operation.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close any temporary resources.voidcommit()Commit the current transaction.voidCreate a checkpoint that can be rolled back to.longGet the count of entities committed thus far using this context.Get the entity that was last passed to theload(Entity)method.longGet the count of entities loaded thus far using this context.Get the loading options used to create the context.voidLoad an entity.voidrollback()Discard the entities loaded within the current transaction.
-
Method Details
-
getOptions
BulkLoadingDao.LoadingOptions getOptions()Get the loading options used to create the context.- Returns:
- the loading options
-
load
Load an entity.- Parameters:
entity- the entity to load
-
getLoadedCount
long getLoadedCount()Get the count of entities loaded thus far using this context.If
rollback()is called, this value will reset back to the count of currently committed entities.- Returns:
- the loaded count
-
getCommittedCount
long getCommittedCount()Get 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
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
getLoadedCount(). BulkLoadingDao.LoadingTransactionMode.TransactionCheckpoints- This count will only increment after calls to
createCheckpoint()are made. Ifrollback()is called, this count will reset back to the count at the previous timecreateCheckpoint()was called. BulkLoadingDao.LoadingTransactionMode.SingleTransaction- This count will remain at 0 until
commit()is called, at which point it will matchgetLoadedCount().
- Returns:
- the committed entity count
-
getLastLoadedEntity
T getLastLoadedEntity()Get the entity that was last passed to theload(Entity)method.- Returns:
- the last loaded entity
-
createCheckpoint
void createCheckpoint()Create a checkpoint that can be rolled back to.The
BulkLoadingDao.LoadingTransactionMode.TransactionCheckpointsmode must have been set in the options used to create this context. -
commit
void commit()Commit 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
load(Entity)are committed. BatchTransactions- The entities loaded via
load(Entity)since the last automatic batch commit are committed.
-
rollback
void rollback()Discard 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
load(Entity)since the last call tocreateCheckpoint()are discarded. BatchTransactions- The entities loaded via
load(Entity)since the last automatic batch commit are discarded.
-
close
void close()Close any temporary resources.- Specified by:
closein interfaceAutoCloseable
-