Package org.ofbiz.core.entity.jdbc
Class SQLProcessor
java.lang.Object
org.ofbiz.core.entity.jdbc.SQLProcessor
- Direct Known Subclasses:
AutoCommitSQLProcessor,ExplcitCommitSQLProcessor,ExplicitCommitSQLProcessor,PassThruSQLProcessor,ReadOnlySQLProcessor
SQLProcessor - provides utility functions to ease database access
- Since:
- 2.0
- Version:
- $Revision: 1.7 $
- Author:
- David E. Jones
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringModule Name Used for debuggingstatic final DatabaseType -
Constructor Summary
ConstructorsConstructorDescriptionSQLProcessor(String helperName) Construct a SQLProcessor based on the helper/datasource.SQLProcessor(String helperName, Connection connection) Construct a SQLProcessor with an connection given. -
Method Summary
Modifier and TypeMethodDescriptionaddBatch()Adds a set of parameters to underlying PreparedStatement object's batch of commands.voidclose()Commit if required and remove all allocated resourcesvoidcommit()Commit all modificationsvoidexecQuery(String sql, ExecQueryCallbackFunctionIF aListener) Execute a query based on the SQL string given.int[]Execute a batch query based on the prepared statementExecute a query based on the prepared statementexecuteQuery(String sql) Execute a query based on the SQL string givenintExecute updatesintexecuteUpdate(String sql) Execute update based on the SQL statement givenGet a connection from the ConnectionFactoryGetter: get the prepared statementGetter: get the currently activ ResultSetbooleannext()Test if there more records availableprepareStatement(String sql) Prepare a statement.prepareStatement(String sql, boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency) Prepare a statement.voidrollback()Rollback all modificationssetBinaryStream(Object field) Set the next binding variable of the currently active prepared statement to write the serialized data of 'field' to a BLOB that is stored as an OID SQL type.setBlob(byte[] field) Set the next binding variable of the currently active prepared statement.setByteArray(byte[] field) Set the next binding variable of the currently active prepared statement.setByteArrayData(Object field) Set the next binding variable of the currently active prepared statement to write the serialized data of 'field' to a BLOB that is stored as a Byte Array SQL type.Set the next binding variable of the currently active prepared statement.Set the next binding variable of the currently active prepared statement.Set the next binding variable of the currently active prepared statement.Set the next binding variable of the currently active prepared statement.Set the next binding variable of the currently active prepared statement.Set the next binding variable of the currently active prepared statement.Set the next binding variable of the currently active prepared statement.Set the next binding variable of the currently active prepared statementSet the next binding variable of the currently active prepared statementSet the next binding variable of the currently active prepared statement.Set the next binding variable of the currently active prepared statement.Set the next binding variable of the currently active prepared statement.toString()
-
Field Details
-
module
Module Name Used for debugging -
MSSQL
-
-
Constructor Details
-
SQLProcessor
Construct a SQLProcessor based on the helper/datasource.It will be in
SQLProcessor.CommitMode.EXPLICIT_COMMITby defaultThis is the legacy mode of SQLProcessor as it was before the CommitMode support was added. This constructor has been left in place because other plugins may be using it and hence to preserve the API.
- Parameters:
helperName- The datasource helper (see entityengine.xml <datasource name="..">)
-
SQLProcessor
Construct a SQLProcessor with an connection given. The connection will not be closed by this SQLProcessor, but may be by some other.It does not participate in any commiting not does it set the autoCommit mode of the connection
- Parameters:
helperName- The datasource helper (see entityengine.xml <datasource name="..">)connection- The connection to be used
-
-
Method Details
-
getCommitMode
- Returns:
- the
SQLProcessor.CommitModethe SQLProcessor is in
-
commit
Commit all modifications- Throws:
GenericDataSourceException- if an SQLException occurs
-
rollback
Rollback all modifications- Throws:
GenericDataSourceException- if an SQLException occurs
-
close
Commit if required and remove all allocated resources- Throws:
GenericDataSourceException- if an SQLException occurs
-
getConnection
Get a connection from the ConnectionFactory- Returns:
- The connection created
- Throws:
GenericEntityException- if an SQLException occurs
-
prepareStatement
Prepare a statement. In case no connection has been given, allocate a new one.- Parameters:
sql- The SQL statement to be executed- Returns:
- this for method chaining
- Throws:
GenericEntityException- if an SQLException occurs
-
prepareStatement
public SQLProcessor prepareStatement(String sql, boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency) throws GenericEntityException Prepare a statement. In case no connection has been given, allocate a new one.- Parameters:
sql- The SQL statement to be executedspecifyTypeAndConcur- true if the result set Type and Concurrency has been specifiedresultSetType- a result set type; one ofResultSet.TYPE_FORWARD_ONLY,ResultSet.TYPE_SCROLL_INSENSITIVE, orResultSet.TYPE_SCROLL_SENSITIVEresultSetConcurrency- a concurrency type; one ofResultSet.CONCUR_READ_ONLYorResultSet.CONCUR_UPDATABLE- Returns:
- this for method chaining
- Throws:
GenericEntityException- if an SQLException occurs
-
executeQuery
Execute a query based on the prepared statement- Returns:
- The result set of the query
- Throws:
GenericDataSourceException- if an SQLException occurs
-
executeQuery
Execute a query based on the SQL string given- Parameters:
sql- The SQL string to be executed- Returns:
- The result set of the query
- Throws:
GenericDataSourceException- if an SQLException occursGenericEntityException
-
executeUpdate
Execute updates- Returns:
- The number of rows updated
- Throws:
GenericDataSourceException- if an SQLException occurs
-
executeUpdate
Execute update based on the SQL statement given- Parameters:
sql- SQL statement to be executed- Returns:
- either (1) the row count for SQL Data Manipulation Language (DML) statements
- Throws:
GenericDataSourceException- if an SQLException occurs or (2) 0 for SQL statements that return nothing
-
executeBatch
Execute a batch query based on the prepared statement- Returns:
- an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch.
- Throws:
GenericDataSourceException- if an SQLException occurs- See Also:
-
next
Test if there more records available- Returns:
- true, if there more records available
- Throws:
GenericDataSourceException- if an SQLException occurs
-
getResultSet
Getter: get the currently activ ResultSet- Returns:
- ResultSet
-
getPreparedStatement
Getter: get the prepared statement- Returns:
- PreparedStatement
-
execQuery
public void execQuery(String sql, ExecQueryCallbackFunctionIF aListener) throws GenericEntityException Execute a query based on the SQL string given. For each record of the ResultSet return, execute a callback function- Parameters:
sql- The SQL string to be executedaListener- The callback function object- Throws:
GenericEntityException- if an SQLException occurs
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if somethings goes wrong
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if somethings goes wrong
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if somethings goes wrong
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if somethings goes wrong
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if somethings goes wrong
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if somethings goes wrong
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if somethings goes wrong
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if somethings goes wrong
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if somethings goes wrong
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if somethings goes wrong
-
setValue
Set the next binding variable of the currently active prepared statement- Parameters:
field- the field value in play- Returns:
- Throws:
SQLException- if somethings goes wrong
-
setValue
Set the next binding variable of the currently active prepared statement- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if somethings goes wrong
-
setBlob
Set the next binding variable of the currently active prepared statement. Note that this *must* actually be aBLOBfield, not a PostgreSQLBYTEA, a SQLServerIMAGE, or an HSQLOTHERfield. UsesetByteArray(byte[])to set those!- Parameters:
field- the field value- Returns:
- Throws:
SQLException- if something goes wrong
-
setByteArray
Set the next binding variable of the currently active prepared statement. Note that this *must* actually be a PostgreSQLBYTEA, a SQLServerIMAGE, or an HSQLOTHERfield. UsesetBlob(byte[])to setBLOBs!- Parameters:
field- the field value- Returns:
- Throws:
SQLException- if something goes wrong
-
setBinaryStream
Set the next binding variable of the currently active prepared statement to write the serialized data of 'field' to a BLOB that is stored as an OID SQL type.- Parameters:
field- the field value in play- Returns:
- Throws:
SQLException- if somethings goes wrong
-
addBatch
Adds a set of parameters to underlying PreparedStatement object's batch of commands.- Returns:
- this for method chaining
- Throws:
SQLException- is something goes wrong- See Also:
-
setByteArrayData
Set the next binding variable of the currently active prepared statement to write the serialized data of 'field' to a BLOB that is stored as a Byte Array SQL type.This method is specifically added to support PostgreSQL BYTEA and SQLServer IMAGE datatypes.
- Parameters:
field- the field value in play- Returns:
- this for method chaining
- Throws:
SQLException- if something goes wrong
-
toString
-