R
- class type which contains members for columns of a row in a tablepublic class SaveOperation<R> extends ModifyOperation<R>
Cascade.saves()
, OneToManyCascade.saves()
, or OneToOneCascade.saves()
.
Inserts and updates are performed by class members of type InsertOperation
and UpdateOperation
. Since most of the work is delegated to InsertOperation
and UpdateOperation
, not all methods of base class ModifyOperation
are
used. All of the methods in SaveOperation may be safely overridden but some subclass methods
may not be used.
Constructor and Description |
---|
SaveOperation(Table<R> table)
Constructs to update by primary key or insert if update fails.
|
SaveOperation(Table<R> table,
java.lang.String whereConditionName)
Constructs to update by where condition or insert if update fails.
|
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.
|
void |
notifyCacheModified(R row)
|
protected boolean |
notifyCacheModify(R row)
|
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.
|
protected java.util.List<CascadeOperation<R,?>> |
prepareCascades(java.lang.reflect.Field field)
Creates save cascade operations based upon the save annotations for field.
|
int |
save(java.lang.Object... parameters)
Saves rows based upon parameters.
|
int |
save(R row)
Saves a row.
|
int |
saveAll(java.util.Collection<R> rows)
Saves all rows in collection.
|
void |
setBatch(boolean batch)
Sets batch state for internal insert and update operations.
|
void |
setCached(boolean cached)
Sets cached enabled state for internal insert and update operations.
|
void |
setCascade(boolean cascade)
Sets cascade state for internal insert and update operations.
|
getRows, getRowsAffected, isBatch, modify, modify, modifyAll, setParameters, setRow, setRows, setRows, setRows, setRowsAffected
cancel, cascade, closeCascades, closeStatement, createTargetField, getBaseSql, getConnection, getCustomSql, getNamedParameterMap, getNextParameter, getOperationTime, getParameter, getParameters, getPreparedSql, getPreparedStatement, getQueryTimeout, getRequiredCascades, getSql, getTable, getTargetTable, getTimingId, getWhereAnnotation, getWhereConditionName, getWhereTranslator, getWhereTranslator2, initOperationTime, isAutoGeneratedKeys, isCached, isCascade, isCascading, isIncludeIdentityColumns, isPrimaryKey, isReadOnly, isRequiredCascade, isTimings, logTimings, prepare, prepareCascades, prepareCheck, setAutoGeneratedKeys, setBaseSql, setCustomSql, setIncludeIdentityColumns, setNamedParameterMap, setNextParameter, setParameter, setQueryTimeout, setReadOnly, setRequiredCascades, setTimingId, setTimings, setWhere, setWhereTranslator, setWhereTranslator2, writeColumns, writeParameter, writeParameters, writeWhere
public SaveOperation(Table<R> table) throws OperationException
table
- update/insert to this tableOperationException
- if errorpublic SaveOperation(Table<R> table, java.lang.String whereConditionName) throws OperationException
table
- update/insert to this tablewhereConditionName
- name of where condition to use for update ("primaryKey" to update
by primary key; empty string to update all rows in table)OperationException
- if errorpublic void close() throws OperationException
ModifyOperation
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 ModifyOperation<R>
OperationException
- if errorpublic void setBatch(boolean batch)
setBatch
in class ModifyOperation<R>
batch
- true for batch saveStatement.executeBatch()
public void setCached(boolean cached)
setCached
in class SqlOperation<R>
cached
- true to enable cache; false to turn off cachingpublic void setCascade(boolean cascade)
setCascade
in class SqlOperation<R>
cascade
- true to allow cascades to occur; false for no cascadingpublic int save(R row) throws OperationException
ModifyOperation.modify(Object)
.row
- row to use for parametersModifyOperation.getRowsAffected()
OperationException
- if errorpublic int saveAll(java.util.Collection<R> rows) throws OperationException
ModifyOperation.modifyAll(Collection)
.rows
- collection of rows to use as parametersModifyOperation.getRowsAffected()
OperationException
- if errorpublic int save(java.lang.Object... parameters) throws OperationException
ModifyOperation.modify(Object...)
.parameters
- operation parameters as objects (see ModifyOperation.setParameters(Object...)
)OperationException
- if errorpublic void execute() throws OperationException
ModifyOperation
ModifyOperation.getRowsAffected()
will return the sum of all rows affected.execute
in class ModifyOperation<R>
OperationException
- if errorprotected java.util.List<CascadeOperation<R,?>> prepareCascades(java.lang.reflect.Field field) throws OperationException
prepareCascades
in class SqlOperation<R>
field
- annotation is for this field of row class ROperationException
- if errorprotected void preExecute(R row) throws OperationException
ModifyOperation.setParameters(Object...)
is used since no row is available.preExecute
in class ModifyOperation<R>
row
- row for JDBC executeOperationException
- if errorprotected void postExecute(R row) throws OperationException
ModifyOperation.setParameters(Object...)
is used since no row is available.postExecute
in class ModifyOperation<R>
row
- row for JDBC executeOperationException
- if errorprotected void preExecuteCascade(R row) throws OperationException
preExecuteCascade
in class ModifyOperation<R>
row
- row for JDBC executeOperationException
InsertCascade.post()
,
UpdateCascade.post()
,
SaveCascade.post()
,
DeleteCascade.post()
protected void postExecuteCascade(R row) throws OperationException
postExecuteCascade
in class ModifyOperation<R>
row
- row for JDBC executeOperationException
InsertCascade.post()
,
UpdateCascade.post()
,
SaveCascade.post()
,
DeleteCascade.post()
protected boolean notifyCacheModify(R row) throws OperationException
notifyCacheModify
in class ModifyOperation<R>
row
- ignoredOperationException
public void notifyCacheModified(R row) throws OperationException
notifyCacheModified
in class ModifyOperation<R>
row
- ignoredOperationException