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,
boolean identity)
Constructs to update by primary key or insert if update fails.
|
SaveOperation(Table<R> table,
boolean identity,
java.lang.String whereConditionName)
Constructs to update by where condition 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 by updating all row(s) using
UpdateOperation . |
int[] |
getModifyCounts()
For each row saved, gets modify counts either from
ModifyOperation.getModifyCounts()
if row was updated or from ModifyOperation.getModifyCounts() if row was inserted. |
void |
notifyCacheModified(R row)
Delegates to
Cache.inserted(Object) , Cache.updated(Object) ,
Cache.deleted(Object) based upon the subclass operation. |
protected 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.
|
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, 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, prepareCheck, prepareStatement, setBaseSql, setCascadeDepth, setCustomSql, setIncludeIdentityColumns, setNamedParameterMap, setNextParameter, setParameter, setQueryTimeout, setReadOnly, setRequiredCascades, setTimingId, setTimings, setWhere, setWhereTranslator, writeColumns, writeParameter, writeParameters, writeWhere
public SaveOperation(Table<R> table) throws OperationException
table
- update/insert to this tableOperationException
- if errorpublic SaveOperation(Table<R> table, boolean identity) throws OperationException
This constructor is equivalent to SaveOperation(Table, boolean, "primaryKey"). Use this constructor when you want identity columns to be inserted without using autogenerated keys (use false for identity parameter).
table
- update/insert to this tableidentity
- true to insert using autogenerated keys for identity columns;
false to insert identity columns as without generating keyOperationException
- 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 SaveOperation(Table<R> table, boolean identity, java.lang.String whereConditionName) throws OperationException
Use this constructor when you want identity columns to be inserted without using autogenerated keys (use false for identity parameter).
table
- update/insert to this tableidentity
- true to insert using autogenerated keys for identity columns;
false to insert identity columns as without generating keywhereConditionName
- 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 int[] getModifyCounts()
ModifyOperation.getModifyCounts()
if row was updated or from ModifyOperation.getModifyCounts()
if row was inserted.getModifyCounts
in class ModifyOperation<R>
public 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
UpdateOperation
. For all rows
that are not updated, uses InsertOperation
to insert them.execute
in class ModifyOperation<R>
OperationException
- if errorBatchException
- for batch operations if EXECUTE_FAILED is returnedBatchException
- for batch operations if SUCCESS_NO_INFO is returned and cascading is neededBatchException
- for batch operations if SUCCESS_NO_INFO is returned for updateprotected 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
- if errorInsertCascade.post()
,
UpdateCascade.post()
,
SaveCascade.post()
,
DeleteCascade.post()
protected void postExecuteCascade(R row) throws OperationException
postExecuteCascade
in class ModifyOperation<R>
row
- row for JDBC executeOperationException
- if errorInsertCascade.post()
,
UpdateCascade.post()
,
SaveCascade.post()
,
DeleteCascade.post()
protected boolean notifyCacheModify(R row) throws OperationException
Cache.insert(Object)
, Cache.update(Object)
,
Cache.delete(Object)
based upon the subclass operation.notifyCacheModify
in class ModifyOperation<R>
row
- row to be modifiedOperationException
- if errorpublic void notifyCacheModified(R row) throws OperationException
Cache.inserted(Object)
, Cache.updated(Object)
,
Cache.deleted(Object)
based upon the subclass operation.notifyCacheModified
in class ModifyOperation<R>
row
- that was modified in databaseOperationException
- if error