org.sormula.operation
Class ModifyOperation<R>

java.lang.Object
  extended by org.sormula.operation.SqlOperation<R>
      extended by org.sormula.operation.ModifyOperation<R>
Type Parameters:
R - class type which contains members for columns of a row in a table
Direct Known Subclasses:
DeleteOperation, InsertOperation, SaveOperation, UpdateOperation

public abstract class ModifyOperation<R>
extends SqlOperation<R>

Base class for operations that modify database.

Since:
1.0
Author:
Jeff Miller

Constructor Summary
ModifyOperation(Table<R> table)
          Constructs for a table.
 
Method Summary
 void close()
          Cleans up after operation is no longer needed.
 void execute()
          Executes operation for all row parameters using current prepared statement.
 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 parametes as Objects
 int modify(R row)
          Modifies one row.
 int modifyAll(java.util.Collection<R> rows)
          Modifies a collection of rows.
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)
           
 
Methods inherited from class org.sormula.operation.SqlOperation
cancel, cascade, closeCascades, closeStatement, createTargetField, getBaseSql, getConnection, getCustomSql, getNextParameter, getOperationTime, getParameters, getPreparedSql, getPreparedStatement, getQueryTimeout, getSql, getTable, getTargetTable, getTimingId, getWhereConditionName, getWhereTranslator, initOperationTime, isAutoGeneratedKeys, isIncludeIdentityColumns, isReadOnly, isTimings, logTimings, prepare, prepareCascades, prepareCascades, prepareCheck, prepareColumns, prepareParameters, prepareWhere, setAutoGeneratedKeys, setBaseSql, setCustomSql, setIncludeIdentityColumns, setNextParameter, setQueryTimeout, setReadOnly, setTimingId, setTimings, setWhere, setWhereTranslator, writeColumns, writeParameter, writeParameters, writeWhere
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModifyOperation

public ModifyOperation(Table<R> table)
                throws OperationException
Constructs for a table.

Parameters:
table - modify this table
Throws:
OperationException - if error
Method Detail

setRow

public void setRow(R row)
Sets parameters from a row object. For operations that affect one row. Use this as alternative to setParameters(Object...).

Parameters:
row - get parameter values from this row object

setRows

public void setRows(R[] rows)
Sets parameters from rows in an array. For operations that use array of rows.

Parameters:
rows - row objects to modify
Since:
1.9 and 2.3

setRows

public void setRows(java.util.Collection<R> rows)
Sets parameters from rows in a collection. For operations that use Collection of rows.

Parameters:
rows - row objects to modify

setRows

public void setRows(java.util.Map<?,R> rows)
Sets parameters from rows in a map. For operations that use Map of rows.

Parameters:
rows - row objects to modify

setParameters

public void setParameters(java.lang.Object... parameters)
Allows modification of table data using objects instead from row objects. This method is not recommended for updates or inserts but may be useful for delete when no row object is available. Use setRow(Object), setRows(Collection), or setRows(Map) instead. preExecute(Object) and postExecute(Object) will not be invoked if this method is used.

Overrides:
setParameters in class SqlOperation<R>
Parameters:
parameters - values to set in PreparedStatement for modify operation

isBatch

public boolean isBatch()
Gets batch mode.

Returns:
true if rows are to be inserted/updated/deleted in batch
Since:
1.9 and 2.3
See Also:
Statement.executeBatch()

setBatch

public void setBatch(boolean batch)
Sets batch mode. Set to true prior to 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.

Parameters:
batch - true to use JDBC batching for execute()
Since:
1.9 and 2.3
See Also:
Statement.executeBatch()

execute

public void execute()
             throws OperationException
Executes operation for all row parameters using current prepared statement. getRowsAffected() will return the sum of all rows affected.

Specified by:
execute in class SqlOperation<R>
Throws:
OperationException - if error

close

public void close()
           throws OperationException
Cleans up after operation is no longer needed. The connection is not closed but all other objects created by this operations are closed. Prepared statement is closed and close method is invoked on all CascadeOperation objects. This method should be invoked when operation is no longer needed for proper JDBC clean up.

Overrides:
close in class SqlOperation<R>
Throws:
OperationException - if error

getRowsAffected

public int getRowsAffected()
Gets the number of rows affected from most recent invocation of execute().

Returns:
count of rows affect by most recent execute()

modify

public int modify(R row)
           throws OperationException
Modifies one row. Set parameters, executes, closes.

Parameters:
row - row to use for parameters
Returns:
getRowsAffected()
Throws:
OperationException - if error
Since:
1.4

modifyAll

public int modifyAll(java.util.Collection<R> rows)
              throws OperationException
Modifies a collection of rows. Set parameters, executes, closes.

Parameters:
rows - collection of rows to use as parameters
Returns:
getRowsAffected()
Throws:
OperationException - if error
Since:
1.4

modify

public int modify(java.lang.Object... parameters)
           throws OperationException
Modifies row(s) with sql parametes as Objects

Parameters:
parameters - operation parameters as objects (see setParameters(Object...))
Returns:
count of rows affected
Throws:
OperationException - if error
Since:
1.4

preExecute

protected void preExecute(R row)
                   throws OperationException
Invoked prior to JDBC execute. Override to modify the row prior to JDBC execute. Default implementaion does nothing. This method is not invoked when setParameters(Object...) is used since no row is available.

Parameters:
row - row for JDBC execute
Throws:
OperationException - if error

postExecute

protected void postExecute(R row)
                    throws OperationException
Invoked after JDBC execute. Override to modify the row after JDBC execute has occured. Default implementaion does nothing. This method is not invoked when setParameters(Object...) is used since no row is available.

Parameters:
row - row for JDBC execute
Throws:
OperationException - if error

preExecuteCascade

protected void preExecuteCascade(R row)
                          throws OperationException
Invoked prior to JDBC execute. Performs all modify cascade operations where post flag is false.

Parameters:
row - row for JDBC execute
Throws:
OperationException
See Also:
InsertCascade.post(), UpdateCascade.post(), SaveCascade.post(), DeleteCascade.post()

postExecuteCascade

protected void postExecuteCascade(R row)
                           throws OperationException
Invoked after JDBC execute. Performs all modify cascade operations where post flag is true.

Parameters:
row - row for JDBC execute
Throws:
OperationException
See Also:
InsertCascade.post(), UpdateCascade.post(), SaveCascade.post(), DeleteCascade.post()

setRowsAffected

protected void setRowsAffected(int rowsAffected)