R
- record typeT
- execute return typepublic abstract class ActiveOperation<R extends ActiveRecord<? super R>,T>
extends java.lang.Object
operate()
on an active table. Used by ActiveTable
for thread-safe and transaction based operation for a table (and any cascaded tables).
A database transaction will only be used if Connection.getAutoCommit()
returns false.Constructor and Description |
---|
ActiveOperation(ActiveTable<R> activeTable,
java.lang.String exceptionMessage)
Constructs for a table and fail message.
|
Modifier and Type | Method and Description |
---|---|
protected void |
attach(java.util.Collection<R> records)
Attaches a collection of active record to the active database used by this operation with
ActiveRecord.attach(ActiveDatabase) . |
protected void |
attach(R record)
Attaches an active record to the active database used by this operation with
ActiveRecord.attach(ActiveDatabase) . |
protected void |
close()
Cleans up any used resources.
|
T |
execute()
Executes
operate() within a try/catch and transaction. |
protected OperationDatabase |
getOperationDatabase()
Gets the database used in
execute() . |
protected Table<R> |
getTable()
Gets the table used in
execute() . |
boolean |
isLocalTransaction()
Reports type of transaction used.
|
protected abstract T |
operate()
Invoked by
execute() to perform the operation. |
public ActiveOperation(ActiveTable<R> activeTable, java.lang.String exceptionMessage)
activeTable
- table to operate uponexceptionMessage
- exception message for ActiveException
if operation failspublic T execute() throws ActiveException
operate()
within a try/catch and transaction. If operate()
throws an exception, then transaction is rolled back.operate()
ActiveException
- if errorpublic boolean isLocalTransaction()
execute()
is in progress.execute()
protected abstract T operate() throws java.lang.Exception
execute()
to perform the operation. Subclasses must implement.java.lang.Exception
- if errorprotected OperationDatabase getOperationDatabase()
execute()
. Database is closed when
the transaction is closed.protected Table<R> getTable()
execute()
. Table is obtained with
OperationDatabase.getTable(Class)
.protected void attach(R record)
ActiveRecord.attach(ActiveDatabase)
.record
- active record to be attachedprotected void attach(java.util.Collection<R> records)
ActiveRecord.attach(ActiveDatabase)
.records
- active records to be attachedprotected void close() throws ActiveException
isLocalTransaction()
is true. Otherwise JDBC connection will
be closed when transaction completes.ActiveException
- if error