org.sormula.operation
Class InsertOperation<R>

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

public class InsertOperation<R>
extends ModifyOperation<R>

SQL insert operation for row of type R.

Since:
1.0
Author:
Jeff Miller

Constructor Summary
InsertOperation(Table<R> table)
          Constructs for standard sql insert statement as:
INSERT INTO table (c1, c2, c3, ...) VALUES (?, ?, ?, ...)
 
Method Summary
protected  void initBaseSql()
          Sets base sql with SqlOperation.setBaseSql(String).
 int insert(java.lang.Object... parameters)
          Inserts rows based upon parameters.
 int insert(R row)
          Inserts a row.
 int insertAll(java.util.Collection<R> rows)
          Inserts all rows in collection.
protected  void postExecute(R row)
          Updates identity column with generated key if SqlOperation.isAutoGeneratedKeys() is true.
protected  java.util.List<CascadeOperation<R,?>> prepareCascades(java.lang.reflect.Field field)
          Creates and prepares cascade operations based upon cascade annotations for a field.
protected  void processIdentityColumn(R row)
          Reads the generated key using Statement.getGeneratedKeys().
 
Methods inherited from class org.sormula.operation.ModifyOperation
close, execute, getRowsAffected, isBatch, modify, modify, modifyAll, postExecuteCascade, preExecute, preExecuteCascade, setBatch, setParameters, setRow, setRows, setRows, setRows, setRowsAffected
 
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, 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

InsertOperation

public InsertOperation(Table<R> table)
                throws OperationException
Constructs for standard sql insert statement as:
INSERT INTO table (c1, c2, c3, ...) VALUES (?, ?, ?, ...)

Parameters:
table - insert into this table
Throws:
OperationException - if error
Method Detail

insert

public int insert(R row)
           throws OperationException
Inserts a row. Set parameters, executes, closes. Alias for ModifyOperation.modify(Object).

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

insertAll

public int insertAll(java.util.Collection<R> rows)
              throws OperationException
Inserts all rows in collection. Set parameters, executes, closes. Alias for ModifyOperation.modifyAll(Collection).

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

insert

public int insert(java.lang.Object... parameters)
           throws OperationException
Inserts rows based upon parameters. Set parameters, executes, closes. Alias for ModifyOperation.modify(Object...).

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

initBaseSql

protected void initBaseSql()
Sets base sql with SqlOperation.setBaseSql(String).


prepareCascades

protected java.util.List<CascadeOperation<R,?>> prepareCascades(java.lang.reflect.Field field)
                                                         throws OperationException
Creates and prepares cascade operations based upon cascade annotations for a field.

Specified by:
prepareCascades in class SqlOperation<R>
Parameters:
field - annotation is for this field of row class R
Returns:
list of cascade operations; empty list for none
Throws:
OperationException - if error

postExecute

protected void postExecute(R row)
                    throws OperationException
Updates identity column with generated key if SqlOperation.isAutoGeneratedKeys() is true.

Overrides:
postExecute in class ModifyOperation<R>
Parameters:
row - row for JDBC execute
Throws:
OperationException - if error

processIdentityColumn

protected void processIdentityColumn(R row)
                              throws OperationException
Reads the generated key using Statement.getGeneratedKeys(). The generated key is set in row using the ColumnTranslator from the table for this operation as RowTranslator.getIdentityColumnTranslator().

Parameters:
row - row to affect
Throws:
OperationException - if error