R
- class type which contains members for columns of a row in a tablepublic class InsertOperation<R> extends ModifyOperation<R>
Constructor and Description |
---|
InsertOperation(Table<R> table)
Constructs for standard sql insert statement as:
INSERT INTO table (c1, c2, c3, ...) VALUES (?, ?, ?, ...) |
InsertOperation(Table<R> table,
boolean identity)
Constructs for optional identity column.
|
Modifier and Type | Method and Description |
---|---|
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.
|
void |
notifyCacheModified(R row)
Notifies cache that row has been inserted into database.
|
protected boolean |
notifyCacheModify(R row)
Tests if row is managed by cache.
|
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() . |
close, execute, getRows, getRowsAffected, isBatch, modify, modify, modifyAll, postExecuteCascade, preExecute, preExecuteCascade, setBatch, setParameters, setRow, setRows, setRows, setRows, setRowsAffected
cancel, cascade, closeCascades, closeStatement, createRowField, getBaseSql, getConnection, getCustomSql, getNamedParameterMap, getNextParameter, getOperationTime, getParameter, getParameters, getPreparedSql, getPreparedStatement, getQueryTimeout, getRequiredCascades, getSql, getTable, getTargetTable, getTimingId, getWhereAnnotation, getWhereConditionName, getWhereTranslator, initOperationTime, isAutoGeneratedKeys, isCached, isCascade, isCascading, isIncludeIdentityColumns, isPrimaryKey, isReadOnly, isRequiredCascade, isTimings, logTimings, prepare, prepareCascades, prepareCheck, setAutoGeneratedKeys, setBaseSql, setCached, setCascade, setCustomSql, setIncludeIdentityColumns, setNamedParameterMap, setNextParameter, setParameter, setQueryTimeout, setReadOnly, setRequiredCascades, setTimingId, setTimings, setWhere, setWhereTranslator, writeColumns, writeParameter, writeParameters, writeWhere
public InsertOperation(Table<R> table) throws OperationException
table
- insert into this tableOperationException
- if errorpublic InsertOperation(Table<R> table, boolean identity) throws OperationException
SqlOperation.setAutoGeneratedKeys(boolean)
.
To insert a row with an identity column defined but without generating keys, set
identity parameter to false.table
- insert into this tableidentity
- true to use autogenerated keys for identity columns;
false to insert identity columns as without generating keyOperationException
- if errorpublic int insert(R row) throws OperationException
ModifyOperation.modify(Object)
.row
- row to use for parametersModifyOperation.getRowsAffected()
OperationException
- if errorpublic int insertAll(java.util.Collection<R> rows) throws OperationException
ModifyOperation.modifyAll(Collection)
.rows
- collection of rows to use as parametersModifyOperation.getRowsAffected()
OperationException
- if errorpublic int insert(java.lang.Object... parameters) throws OperationException
ModifyOperation.modify(Object...)
.parameters
- operation parameters as objects (see ModifyOperation.setParameters(Object...)
)OperationException
- if errorprotected void initBaseSql()
SqlOperation.setBaseSql(String)
.protected 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 postExecute(R row) throws OperationException
SqlOperation.isAutoGeneratedKeys()
is true.postExecute
in class ModifyOperation<R>
row
- row for JDBC executeOperationException
- if errorprotected void processIdentityColumn(R row) throws OperationException
Statement.getGeneratedKeys()
. The
generated key is set in row using the ColumnTranslator
from the table for
this operation as RowTranslator.getIdentityColumnTranslator()
.row
- row to affectOperationException
- if errorprotected boolean notifyCacheModify(R row) throws OperationException
Cache.insert(Object)
.notifyCacheModify
in class ModifyOperation<R>
row
- test this rowOperationException
- if cache reports an errorpublic void notifyCacheModified(R row) throws OperationException
Cache.inserted(Object)
.notifyCacheModified
in class ModifyOperation<R>
row
- row that was insertedOperationException
- if cache reports an error