|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.sormula.operation.SqlOperation<R>
R
- class type which contains members for columns of a row in a tablepublic abstract class SqlOperation<R>
Base class for all database operations.
Constructor Summary | |
---|---|
SqlOperation(Table<R> table)
Constructs for a table. |
Method Summary | ||
---|---|---|
void |
cancel()
Requests cancel for currently executing statement. |
|
protected void |
cascade(R row,
boolean post)
Executes all cascade operations that were created by prepareCascades() . |
|
void |
close()
Cleans up after operation is no longer needed. |
|
protected void |
closeCascades()
Closes the CascadeOperation objects for this operation. |
|
protected void |
closeStatement()
Closes the prepared statement for this operation. |
|
protected SormulaField<R,?> |
createTargetField(java.lang.reflect.Field field)
Creates a SormulaField from Field . |
|
abstract void |
execute()
Invokes an execute method on a prepared statement. |
|
protected java.lang.String |
getBaseSql()
Gets the sql used by this operation. |
|
protected java.sql.Connection |
getConnection()
Gets the JDBC connection used in this operation. |
|
java.lang.String |
getCustomSql()
Gets custom sql set with setCustomSql(String) . |
|
protected int |
getNextParameter()
Gets the next JDBC parameter number used by PreparedStatement to set parameters. |
|
OperationTime |
getOperationTime()
Gets the timings for this operation that have accumulated since setTimings(boolean)
have been enabled. |
|
java.lang.Object[] |
getParameters()
Gets parameters that were set by setParameters(Object...) . |
|
java.lang.String |
getPreparedSql()
Gets sql that was used in prepare() . |
|
protected java.sql.PreparedStatement |
getPreparedStatement()
Gets the prepared statement used by this operation. |
|
int |
getQueryTimeout()
Gets the number of seconds the driver will wait for a Statement object to execute. |
|
protected java.lang.String |
getSql()
Gets full sql statement to prepare. |
|
Table<R> |
getTable()
Gets the table provided in the constructor. |
|
protected Table<?> |
getTargetTable(java.lang.Class<?> targetClass,
java.lang.reflect.Field targetField)
Gets a table object from database associated with this operation. |
|
java.lang.String |
getTimingId()
Gets the timing id for this operation. |
|
java.lang.String |
getWhereConditionName()
Gets where condition name supplied in setWhere(String) |
|
protected AbstractWhereTranslator<R> |
getWhereTranslator()
Gets the translator to map row object values into where condition. |
|
protected void |
initOperationTime()
Initializes OperationTime object that will record elapsed times for this operation. |
|
boolean |
isAutoGeneratedKeys()
If true, Statement.getGeneratedKeys() is used to read column defined as
identity and then sets the generated key value in the row. |
|
boolean |
isIncludeIdentityColumns()
Tests if identity columns are used in this operation. |
|
boolean |
isReadOnly()
Gets read-only indicator. |
|
boolean |
isTimings()
|
|
void |
logTimings()
Logs current timings for this operation to log. |
|
protected void |
prepare()
Creates prepared statement for this operation and invokes prepareCascades()
to prepare statements for any cascade operations. |
|
protected void |
prepareCascades()
Prepares cascades for all cascade annotations on row class. |
|
protected abstract 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 |
prepareCheck()
Prepares statement with prepare() if it is null. |
|
protected void |
prepareColumns(R row)
Deprecated. |
|
protected void |
prepareParameters()
Deprecated. |
|
protected void |
prepareWhere(R row)
Deprecated. |
|
void |
setAutoGeneratedKeys(boolean autoGeneratedKeys)
Sets when to get generated keys from database. |
|
protected void |
setBaseSql(java.lang.String sql)
Sets the base sql used by this operation. |
|
void |
setCustomSql(java.lang.String customSql)
Sets sql to be appended to base sql in operation. |
|
void |
setIncludeIdentityColumns(boolean includeIdentityColumns)
Sets when to generate identity columns. |
|
protected void |
setNextParameter(int nextParameter)
Sets the next column index to use in PreparedStatement . |
|
void |
setParameters(java.lang.Object... parameters)
Sets any parameters to be used by operation. |
|
void |
setQueryTimeout(int queryTimeout)
Sets the number of seconds the driver will wait for a Statement object to execute. |
|
void |
setReadOnly(boolean readOnly)
Sets read-only indicator. |
|
void |
setTimingId(java.lang.String timingId)
Sets the id for the operation times getOperationTime() . |
|
void |
setTimings(boolean on)
Enables timings for this operation. |
|
void |
setWhere(java.lang.String whereConditionName)
Sets where condition from annotation name as defined in Where.name() for row. |
|
protected void |
setWhereTranslator(AbstractWhereTranslator<R> whereTranslator)
Sets the translator to map row object values into where condition. |
|
protected void |
writeColumns(R row)
Sets all column parameters from a row using the table's RowTranslator . |
|
protected
|
writeParameter(int parameterIndex,
T parameter)
|
|
protected void |
writeParameters()
Prepares statement and then sets all parameters with PreparedStatement.setObject(int, Object) . |
|
protected void |
writeWhere(R row)
Sets all where parameters from a row using the table's WhereTranslator . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SqlOperation(Table<R> table) throws OperationException
The operation timings default to the current state of the database
Database.isTimings()
. If timings are enabled for database then
all operations will be timed unless explicitly disabled. Operation
gets the read only setting setReadOnly(boolean)
from the database
of the table Database.isReadOnly()
.
table
- operations are performed on this table
OperationException
- if errorMethod Detail |
---|
public void setParameters(java.lang.Object... parameters)
Column.primaryKey()
or Where
annotation.
parameters
- parameters as objects (not from row fields)public java.lang.Object[] getParameters()
setParameters(Object...)
.
public boolean isReadOnly()
Database.isReadOnly()
public void setReadOnly(boolean readOnly)
Database.isReadOnly()
. Set to true as a safe-guard
to prevent accidental modification of database.
readOnly
- true to prevent modify operationsDatabase.setReadOnly(boolean)
public int getQueryTimeout()
Statement.getQueryTimeout()
public void setQueryTimeout(int queryTimeout)
prepare()
.
queryTimeout
- the new query timeout limit in seconds; zero means there is no limitStatement.setQueryTimeout(int)
@Deprecated protected void prepareParameters() throws OperationException
writeParameters()
.
OperationException
protected void writeParameters() throws OperationException
PreparedStatement.setObject(int, Object)
.
prepareCheck()
or prepare()
must be invoked prior to using this method.
OperationException
- if errorprotected <T> void writeParameter(int parameterIndex, T parameter) throws java.lang.Exception
java.lang.Exception
public abstract void execute() throws OperationException
prepareCheck()
should be invoked
prior to executing sql or use some other means of set up for prepared statement.
OperationException
- if errorpublic void cancel() throws OperationException
OperationException
- if errorStatement.cancel()
public void close() throws OperationException
CascadeOperation
objects. This method should
be invoked when operation is no longer needed for proper JDBC clean up.
OperationException
- if errorpublic java.lang.String getTimingId()
getSql()
.
public void setTimingId(java.lang.String timingId)
getOperationTime()
. Typically the default id is
sufficient. The id is a key into Database.getOperationTimeMap()
which is used
to sum multiple instances of timings for this operation.
Use a custom id to force all operations that use the custom id to be summed into one
instance of OperationTime
in Database.getOperationTimeMap()
. A good
custom id to use would be the class name of the class that is using the operation,
Class.getName()
.
timingId
- unique id associated with an operation(s)public void setTimings(boolean on)
getOperationTime()
. Use logTimings()
to
write timings to log for this operation. Use Database.logTimings()
to write all operation
timings to log.
When on parameter is true, then instance of OperationTime
is created
at the start of execution for use by this operation. Use getOperationTime()
to
change default values.
on
- true to recording execution times for this operationpublic boolean isTimings()
public void logTimings()
OperationTime.logTimings()
.
public OperationTime getOperationTime()
setTimings(boolean)
have been enabled.
NoOperationTime
if
timings are not enabledprotected void initOperationTime()
OperationTime
object that will record elapsed times for this operation.
This method can't be invoked until timing id and/or sql is known so it is invoked by
execute()
.
protected void closeStatement() throws OperationException
OperationException
- if errorprotected void closeCascades() throws OperationException
CascadeOperation
objects for this operation.
OperationException
- if errorprotected void prepareCheck() throws OperationException
prepare()
if it is null. Invoke prior to using prepared statement to
insure that prepared statement has been set up through Connection.prepareStatement(String)
.
Usually invoked prior to invoking a method on PreparedStatement
.
OperationException
- if errorprotected void prepare() throws OperationException
prepareCascades()
to prepare statements for any cascade operations.
OperationException
- if errorprotected void prepareCascades() throws OperationException
OneToManyCascade
, OneToOneCascade
, and Cascade
.
OperationException
- if errorprotected abstract java.util.List<CascadeOperation<R,?>> prepareCascades(java.lang.reflect.Field field) throws OperationException
field
- annotation is for this field of row class R
OperationException
- if errorprotected void cascade(R row, boolean post) throws OperationException
prepareCascades()
.
row
- instance of source rowpost
- true if post cascades are to be executed; false if pre cascades are
to be executed
OperationException
- if errorprotected Table<?> getTargetTable(java.lang.Class<?> targetClass, java.lang.reflect.Field targetField) throws OperationException
targetClass
- class that cascade is to affecttargetField
- target of cascade
OperationException
- if errorprotected SormulaField<R,?> createTargetField(java.lang.reflect.Field field) throws OperationException
SormulaField
from Field
.
field
- creates for this field
OperationException
- if errorprotected java.lang.String getSql()
prepare()
public java.lang.String getPreparedSql()
prepare()
.
public void setCustomSql(java.lang.String customSql)
customSql
- additional sql to be added to base sql or null for nonepublic java.lang.String getCustomSql()
setCustomSql(String)
.
public Table<R> getTable()
protected java.sql.Connection getConnection()
Connection
public void setWhere(java.lang.String whereConditionName) throws OperationException
Where.name()
for row.
whereConditionName
- name of where condition to use;
"primaryKey" for key defined by Column.primaryKey()
;
empty string for no where condition
OperationException
public java.lang.String getWhereConditionName()
setWhere(String)
public boolean isIncludeIdentityColumns()
Column.identity()
public void setIncludeIdentityColumns(boolean includeIdentityColumns)
includeIdentityColumns
- true to include identity columns in sqlpublic boolean isAutoGeneratedKeys()
Statement.getGeneratedKeys()
is used to read column defined as
identity and then sets the generated key value in the row. Default is false. Typically
true for insert operations.
InsertOperation.processIdentityColumn(Object)
public void setAutoGeneratedKeys(boolean autoGeneratedKeys)
autoGeneratedKeys
- true if identity column is generated by database@Deprecated protected void prepareColumns(R row) throws OperationException
writeColumns(Object)
.
OperationException
protected void writeColumns(R row) throws OperationException
RowTranslator
.
row
- get column values from this row
OperationException
- if error@Deprecated protected void prepareWhere(R row) throws OperationException
writeWhere(Object)
.
OperationException
protected void writeWhere(R row) throws OperationException
WhereTranslator
.
row
- get where parameters from this row
OperationException
- if errorprotected java.lang.String getBaseSql()
protected void setBaseSql(java.lang.String sql)
getBaseSql()
for details.
sql
- base sql used by this operationprotected java.sql.PreparedStatement getPreparedStatement()
protected AbstractWhereTranslator<R> getWhereTranslator()
protected void setWhereTranslator(AbstractWhereTranslator<R> whereTranslator)
whereTranslator
- where translator or null if noneprotected int getNextParameter()
PreparedStatement
to set parameters.
Parameter number changes as column and where conditions are prepared. Parameter numbers
start at 1 and occur for every "?" in the SQL statement. The parameter numbers are used
as the first parameter in the various PreparedStatement
set methods.
PreparedStatement
parameter to useprotected void setNextParameter(int nextParameter)
PreparedStatement
. See getNextParameter()
for details.
nextParameter
- the next PreparedStatement
parameter to use
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |