R
- class type which contains members for columns of a row in a tablepublic abstract class ModifyOperation<R> extends SqlOperation<R>
Constructor and Description |
---|
ModifyOperation(Table<R> table)
Constructs for a table.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Cleans up after operation is no longer needed.
|
void |
execute()
Executes operation for all row parameters using current prepared statement.
|
int[] |
getModifyCounts()
Gets the number of rows that were modified.
|
java.util.Collection<R> |
getRows()
Gets the rows that will be modified.
|
int |
getRowsAffected()
Gets the number of rows affected from most recent invocation of
execute() . |
boolean |
isBatch()
Gets batch mode.
|
int |
modify(java.lang.Object... parameters)
Modifies row(s) with sql parameters as Objects.
|
int |
modify(R row)
Modifies one row.
|
int |
modifyAll(java.util.Collection<R> rows)
Modifies a collection of rows.
|
protected abstract void |
notifyCacheModified(R row)
Delegates to
Cache.inserted(Object) , Cache.updated(Object) ,
Cache.deleted(Object) based upon the subclass operation. |
protected abstract boolean |
notifyCacheModify(R row)
Delegates to
Cache.insert(Object) , Cache.update(Object) ,
Cache.delete(Object) based upon the subclass operation. |
protected void |
postExecute(R row)
Invoked after JDBC execute.
|
protected void |
postExecuteCascade(R row)
Invoked after JDBC execute.
|
protected void |
preExecute(R row)
Invoked prior to JDBC execute.
|
protected void |
preExecuteCascade(R row)
Invoked prior to JDBC execute.
|
void |
setBatch(boolean batch)
Sets batch mode.
|
void |
setParameters(java.lang.Object... parameters)
Allows modification of table data using objects instead from row objects.
|
void |
setRow(R row)
Sets parameters from a row object.
|
void |
setRows(java.util.Collection<R> rows)
Sets parameters from rows in a collection.
|
void |
setRows(java.util.Map<?,R> rows)
Sets parameters from rows in a map.
|
void |
setRows(R[] rows)
Sets parameters from rows in an array.
|
protected void |
setRowsAffected(int rowsAffected) |
cancel, cascade, closeCascades, closeStatement, createRowField, getBaseSql, getCascadeDepth, getConnection, getCustomSql, getNamedParameterMap, getNextParameter, getOperationTime, getParameter, getParameters, getPreparedSql, getPreparedStatement, getQueryTimeout, getRequiredCascades, getSql, getTable, getTargetTable, getTimingId, getWhereAnnotation, getWhereConditionName, getWhereTranslator, initOperationTime, isCached, isCascade, isCascading, isIncludeIdentityColumns, isPrimaryKey, isReadOnly, isRequiredCascade, isTimings, logTimings, prepare, prepareCascades, prepareCascades, prepareCheck, prepareStatement, setBaseSql, setCached, setCascade, setCascadeDepth, setCustomSql, setIncludeIdentityColumns, setNamedParameterMap, setNextParameter, setParameter, setQueryTimeout, setReadOnly, setRequiredCascades, setTimingId, setTimings, setWhere, setWhereTranslator, writeColumns, writeParameter, writeParameters, writeWhere
public ModifyOperation(Table<R> table) throws OperationException
table
- modify this tableOperationException
- if errorpublic void setRow(R row)
setParameters(Object...)
.row
- get parameter values from this row objectpublic void setRows(R[] rows)
rows
- row objects to modifypublic void setRows(java.util.Collection<R> rows)
Collection
of rows.rows
- row objects to modifypublic void setRows(java.util.Map<?,R> rows)
Map
of rows.rows
- row objects to modifypublic java.util.Collection<R> getRows()
Collection
so this method will get the row(s) regardless of setter
method that was used.setParameters(Object...)
was usedpublic void setParameters(java.lang.Object... parameters)
setRow(Object)
, setRows(Collection)
, or setRows(Map)
instead. preExecute(Object)
and postExecute(Object)
will not be invoked
if this method is used.setParameters
in class SqlOperation<R>
parameters
- values to set in PreparedStatement
for modify operationpublic boolean isBatch()
Statement.executeBatch()
public void setBatch(boolean batch)
execute()
to insert/update/delete rows using
JDBC batch mode. Batch mode does not support identity columns. Auto commit must
be off for batch mode. preExecute(Object)
is invoked prior to batch add and
postExecute(Object)
is invoked after batch execute.
Since version 4.1, cascades are performed for batch mode.
Batch modifications are not cached. So when batch is true and table is cached, then
table cache is flushed prior to executing batch modifications to avoid inconsistencies in
cache. Database.flush()
may be required if batched rows affect foreign key
relationships.
batch
- true to use JDBC batching for execute()
Statement.executeBatch()
public void execute() throws OperationException
getRowsAffected()
will return the sum of all rows affected.execute
in class SqlOperation<R>
OperationException
- if errorBatchException
- for batch operations if EXECUTE_FAILED is returnedBatchException
- for batch operations if SUCCESS_NO_INFO is returned and cascading is neededReadOnlyException
- if row or table is read onlypublic void close() throws OperationException
CascadeOperation
objects. This method should
be invoked when operation is no longer needed for proper JDBC clean up.close
in interface java.lang.AutoCloseable
close
in class SqlOperation<R>
OperationException
- if errorpublic int getRowsAffected()
execute()
.execute()
public int[] getModifyCounts()
getRows()
if not null or 1 if SqlOperation.getParameters()
is not null. The
value of each array element is determined by one of the following:
PreparedStatement.executeUpdate()
for each row in getRows()
Statement.executeBatch()
if isBatch()
is truePreparedStatement.executeUpdate()
if SqlOperation.getParameters()
is not nullStatement.SUCCESS_NO_INFO
for some databasespublic int modify(R row) throws OperationException
Since this class implements AutoCloseable
, you may see resource leak
sing when you use this method. You can ignore it, add a suppress annotation,
explicitly close, or close with a try-with-resources statement. Closing an operation
more than once will not cause problems since the close methods are idempotent.
row
- row to use for parametersgetRowsAffected()
OperationException
- if errorpublic int modifyAll(java.util.Collection<R> rows) throws OperationException
Since this class implements AutoCloseable
, you may see resource leak
warning when you use this method. You can ignore it, add a suppress annotation,
explicitly close, or close with a try-with-resources statement. Closing an operation
more than once will not cause problems since the close methods are idempotent.
rows
- collection of rows to use as parametersgetRowsAffected()
OperationException
- if errorpublic int modify(java.lang.Object... parameters) throws OperationException
Since this class implements AutoCloseable
, you may see resource leak
warning when you use this method. You can ignore it, add a suppress annotation,
explicitly close, or close with a try-with-resources statement. Closing an operation
more than once will not cause problems since the close methods are idempotent.
parameters
- operation parameters as objects (see setParameters(Object...)
)OperationException
- if errorprotected void preExecute(R row) throws OperationException
setParameters(Object...)
is used since no row is available.row
- row for JDBC executeOperationException
- if errorprotected void postExecute(R row) throws OperationException
setParameters(Object...)
is used since no row is available.row
- row for JDBC executeOperationException
- if errorprotected void preExecuteCascade(R row) throws OperationException
row
- row for JDBC executeOperationException
- if errorInsertCascade.post()
,
UpdateCascade.post()
,
SaveCascade.post()
,
DeleteCascade.post()
protected void postExecuteCascade(R row) throws OperationException
row
- row for JDBC executeOperationException
- if errorInsertCascade.post()
,
UpdateCascade.post()
,
SaveCascade.post()
,
DeleteCascade.post()
protected void setRowsAffected(int rowsAffected)
protected abstract boolean notifyCacheModify(R row) throws OperationException
Cache.insert(Object)
, Cache.update(Object)
,
Cache.delete(Object)
based upon the subclass operation.row
- row to be modifiedOperationException
- if errorprotected abstract void notifyCacheModified(R row) throws OperationException
Cache.inserted(Object)
, Cache.updated(Object)
,
Cache.deleted(Object)
based upon the subclass operation.row
- that was modified in databaseOperationException
- if error