Package org.apache.ofbiz.entity.jdbc
Class SQLProcessor
java.lang.Object
org.apache.ofbiz.entity.jdbc.SQLProcessor
- All Implemented Interfaces:
AutoCloseable
SQLProcessor - provides utility functions to ease database access
-
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
static final int
-
Constructor Summary
ConstructorDescriptionSQLProcessor
(Delegator delegator, GenericHelperInfo helperInfo) Construct an object based on the helper/datasourceSQLProcessor
(Delegator delegator, GenericHelperInfo helperInfo, Connection connection) Construct an object with an connection given. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Commit if required and remove all allocated resourcesvoid
commit()
Commit all modificationsvoid
execQuery
(String sql, ExecQueryCallbackFunctionIF aListener) Execute a query based on the SQL string given.Execute a query based on the prepared statementexecuteQuery
(String sql) Execute a query based on the SQL string givenint
Execute updatesint
executeUpdate
(String sql) Execute update based on the SQL statement givenGet a connection from the TransactionFactoryLoaderGets delegator.Getter: get the prepared statementGetter: get the currently active ResultSetboolean
next()
Test if there more records availablevoid
prepareStatement
(String sql) Prepare a statement.void
prepareStatement
(String sql, boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency) Prepare a statement.void
prepareStatement
(String sql, boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency, int fetchSize, int maxRows) Prepare a statement.void
rollback()
Rollback all modificationsvoid
setBinaryStream
(Object field) Set the next binding variable of the currently active prepared statement to write the serialized data of 'field' to a BLOB.void
setBytes
(byte[] bytes) Set the next binding variable of the currently active prepared statement to write the serialized data of 'field' to a Blob with the given bytes.protected void
setFetchSize
(Statement stmt, int fetchSize) Sets fetch size.void
Set the next binding variable of the currently active prepared statement.void
Set the next binding variable of the currently active prepared statement.void
Set the next binding variable of the currently active prepared statement.void
Set the next binding variable of the currently active prepared statement.void
Set the next binding variable of the currently active prepared statement.void
Set the next binding variable of the currently active prepared statement.void
Set the next binding variable of the currently active prepared statement.void
setValue
(BigDecimal field) Set the next binding variable of the currently active prepared statement.void
Set the next binding variable of the currently active prepared statementvoid
Set the next binding variable of the currently active prepared statementvoid
Set the next binding variable of the currently active prepared statement.void
Set the next binding variable of the currently active prepared statement.void
Set the next binding variable of the currently active prepared statement.<T> void
setValue
(JdbcValueHandler<T> handler, T field) Set the next binding variable of the currently active prepared statement.protected void
testConnection
(Connection con) Test connection.
-
Field Details
-
MAX_CONNECTIONS
public static final int MAX_CONNECTIONS- See Also:
-
ENABLE_TEST
public static final boolean ENABLE_TEST- See Also:
-
-
Constructor Details
-
SQLProcessor
Construct an object based on the helper/datasource- Parameters:
helperInfo
- The datasource helper (see entityengine.xml <datasource name="..">)
-
SQLProcessor
Construct an object with an connection given. The connection will not be closed by this SQLProcessor, but may be by some other.- Parameters:
helperInfo
- The datasource helper (see entityengine.xml <datasource name="..">)connection
- The connection to be used
-
-
Method Details
-
getDelegator
Gets delegator.- Returns:
- the delegator
-
commit
Commit all modifications- Throws:
GenericDataSourceException
-
rollback
Rollback all modifications- Throws:
GenericDataSourceException
-
close
Commit if required and remove all allocated resources- Specified by:
close
in interfaceAutoCloseable
- Throws:
GenericDataSourceException
-
getConnection
Get a connection from the TransactionFactoryLoader- Returns:
- The connection created
- Throws:
GenericDataSourceException
GenericEntityException
-
prepareStatement
Prepare a statement. In case no connection has been given, allocate a new one.- Parameters:
sql
- The SQL statement to be executed- Throws:
GenericDataSourceException
GenericEntityException
-
prepareStatement
public void prepareStatement(String sql, boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency) throws GenericDataSourceException, GenericEntityException Prepare a statement. In case no connection has been given, allocate a new one.- Parameters:
sql
- The SQL statement to be executed- Throws:
GenericDataSourceException
GenericEntityException
-
prepareStatement
public void prepareStatement(String sql, boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency, int fetchSize, int maxRows) throws GenericDataSourceException, GenericEntityException Prepare a statement. In case no connection has been given, allocate a new one.- Parameters:
sql
- The SQL statement to be executed- Throws:
GenericDataSourceException
GenericEntityException
-
executeQuery
Execute a query based on the prepared statement- Returns:
- The result set of the query
- Throws:
GenericDataSourceException
-
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:
GenericEntityException
GenericDataSourceException
-
executeUpdate
Execute updates- Returns:
- The number of rows updated
- Throws:
GenericDataSourceException
-
executeUpdate
Execute update based on the SQL statement given- Parameters:
sql
- SQL statement to be executed- Throws:
GenericDataSourceException
-
next
Test if there more records available- Returns:
- true, if there more records available
- Throws:
GenericDataSourceException
-
getResultSet
Getter: get the currently active 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
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
handler
-field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement- Parameters:
field
-- Throws:
SQLException
-
setValue
Set the next binding variable of the currently active prepared statement- Parameters:
field
-- Throws:
SQLException
-
setBinaryStream
Set the next binding variable of the currently active prepared statement to write the serialized data of 'field' to a BLOB.- Parameters:
field
-- Throws:
SQLException
-
setBytes
Set the next binding variable of the currently active prepared statement to write the serialized data of 'field' to a Blob with the given bytes.- Parameters:
bytes
-- Throws:
SQLException
-
testConnection
Test connection.- Parameters:
con
- the con- Throws:
GenericEntityException
- the generic entity exception
-
setFetchSize
Sets fetch size.- Parameters:
stmt
- the stmtfetchSize
- the fetch size- Throws:
SQLException
- the sql exception
-