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.
|
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, createTargetField, getBaseSql, getConnection, getCustomSql, getNamedParameterMap, getNextParameter, getOperationTime, getParameter, getParameters, getPreparedSql, getPreparedStatement, getQueryTimeout, getRequiredCascades, getSql, getTable, getTargetTable, getTargetTable, getTimingId, getWhereAnnotation, getWhereConditionName, getWhereTranslator, initOperationTime, isAutoGeneratedKeys, isCached, isCascade, isCascading, isIncludeIdentityColumns, isPrimaryKey, isReadOnly, isRequiredCascade, isTimings, logTimings, prepare, prepareCascades, prepareCascades, prepareCheck, setAutoGeneratedKeys, setBaseSql, setCached, setCascade, 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 or cascades. Auto commit must
be off for batch mode. preExecute(Object)
is invoked prior to batch add and
postExecute(Object)
is invoked after batch execute.
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 errorpublic 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 modify(R row) throws OperationException
row
- row to use for parametersgetRowsAffected()
OperationException
- if errorpublic int modifyAll(java.util.Collection<R> rows) throws OperationException
rows
- collection of rows to use as parametersgetRowsAffected()
OperationException
- if errorpublic int modify(java.lang.Object... parameters) throws OperationException
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
InsertCascade.post()
,
UpdateCascade.post()
,
SaveCascade.post()
,
DeleteCascade.post()
protected void postExecuteCascade(R row) throws OperationException
row
- row for JDBC executeOperationException
InsertCascade.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
protected 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