Package org.apache.ofbiz.entity.jdbc
Class SQLProcessor
- java.lang.Object
-
- org.apache.ofbiz.entity.jdbc.SQLProcessor
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class SQLProcessor extends java.lang.Object implements java.lang.AutoCloseable
SQLProcessor - provides utility functions to ease database access
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
ENABLE_TEST
static int
MAX_CONNECTIONS
static java.lang.String
module
Module Name Used for debugging
-
Constructor Summary
Constructors Constructor Description SQLProcessor(Delegator delegator, GenericHelperInfo helperInfo)
Construct an object based on the helper/datasourceSQLProcessor(Delegator delegator, GenericHelperInfo helperInfo, java.sql.Connection connection)
Construct an object with an connection given.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Commit if required and remove all allocated resourcesvoid
commit()
Commit all modificationsvoid
execQuery(java.lang.String sql, ExecQueryCallbackFunctionIF aListener)
Execute a query based on the SQL string given.java.sql.ResultSet
executeQuery()
Execute a query based on the prepared statementjava.sql.ResultSet
executeQuery(java.lang.String sql)
Execute a query based on the SQL string givenint
executeUpdate()
Execute updatesint
executeUpdate(java.lang.String sql)
Execute update based on the SQL statement givenjava.sql.Connection
getConnection()
Get a connection from the TransactionFactoryLoaderDelegator
getDelegator()
java.sql.PreparedStatement
getPreparedStatement()
Getter: get the prepared statementjava.sql.ResultSet
getResultSet()
Getter: get the currently active ResultSetboolean
next()
Test if there more records availablevoid
prepareStatement(java.lang.String sql)
Prepare a statement.void
prepareStatement(java.lang.String sql, boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency)
Prepare a statement.void
prepareStatement(java.lang.String sql, boolean specifyTypeAndConcur, int resultSetType, int resultSetConcurrency, int fetchSize, int maxRows)
Prepare a statement.void
rollback()
Rollback all modificationsvoid
setBinaryStream(java.lang.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(java.sql.Statement stmt, int fetchSize)
void
setValue(java.lang.Boolean field)
Set the next binding variable of the currently active prepared statement.void
setValue(java.lang.Double field)
Set the next binding variable of the currently active prepared statement.void
setValue(java.lang.Float field)
Set the next binding variable of the currently active prepared statement.void
setValue(java.lang.Integer field)
Set the next binding variable of the currently active prepared statement.void
setValue(java.lang.Long field)
Set the next binding variable of the currently active prepared statement.void
setValue(java.lang.Object field)
Set the next binding variable of the currently active prepared statement.void
setValue(java.lang.String field)
Set the next binding variable of the currently active prepared statement.void
setValue(java.math.BigDecimal field)
Set the next binding variable of the currently active prepared statement.void
setValue(java.sql.Blob field)
Set the next binding variable of the currently active prepared statementvoid
setValue(java.sql.Clob field)
Set the next binding variable of the currently active prepared statementvoid
setValue(java.sql.Date field)
Set the next binding variable of the currently active prepared statement.void
setValue(java.sql.Time field)
Set the next binding variable of the currently active prepared statement.void
setValue(java.sql.Timestamp field)
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(java.sql.Connection con)
-
-
-
Field Detail
-
module
public static final java.lang.String module
Module Name Used for debugging
-
MAX_CONNECTIONS
public static final int MAX_CONNECTIONS
- See Also:
- Constant Field Values
-
ENABLE_TEST
public static final boolean ENABLE_TEST
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SQLProcessor
public SQLProcessor(Delegator delegator, GenericHelperInfo helperInfo)
Construct an object based on the helper/datasource- Parameters:
helperInfo
- The datasource helper (see entityengine.xml <datasource name="..">)
-
SQLProcessor
public SQLProcessor(Delegator delegator, GenericHelperInfo helperInfo, java.sql.Connection connection)
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 Detail
-
getDelegator
public Delegator getDelegator()
-
commit
public void commit() throws GenericDataSourceException
Commit all modifications- Throws:
GenericDataSourceException
-
rollback
public void rollback() throws GenericDataSourceException
Rollback all modifications- Throws:
GenericDataSourceException
-
close
public void close() throws GenericDataSourceException
Commit if required and remove all allocated resources- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
GenericDataSourceException
-
getConnection
public java.sql.Connection getConnection() throws GenericDataSourceException, GenericEntityException
Get a connection from the TransactionFactoryLoader- Returns:
- The connection created
- Throws:
GenericDataSourceException
GenericEntityException
-
prepareStatement
public void prepareStatement(java.lang.String sql) 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(java.lang.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(java.lang.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
public java.sql.ResultSet executeQuery() throws GenericDataSourceException
Execute a query based on the prepared statement- Returns:
- The result set of the query
- Throws:
GenericDataSourceException
-
executeQuery
public java.sql.ResultSet executeQuery(java.lang.String sql) throws GenericDataSourceException, GenericEntityException
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
public int executeUpdate() throws GenericDataSourceException
Execute updates- Returns:
- The number of rows updated
- Throws:
GenericDataSourceException
-
executeUpdate
public int executeUpdate(java.lang.String sql) throws GenericDataSourceException
Execute update based on the SQL statement given- Parameters:
sql
- SQL statement to be executed- Throws:
GenericDataSourceException
-
next
public boolean next() throws GenericDataSourceException
Test if there more records available- Returns:
- true, if there more records available
- Throws:
GenericDataSourceException
-
getResultSet
public java.sql.ResultSet getResultSet()
Getter: get the currently active ResultSet- Returns:
- ResultSet
-
getPreparedStatement
public java.sql.PreparedStatement getPreparedStatement()
Getter: get the prepared statement- Returns:
- PreparedStatement
-
execQuery
public void execQuery(java.lang.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
public <T> void setValue(JdbcValueHandler<T> handler, T field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
handler
-field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.lang.String field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.sql.Timestamp field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.sql.Time field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.sql.Date field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.lang.Integer field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.lang.Long field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.lang.Float field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.lang.Double field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.math.BigDecimal field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.lang.Boolean field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.lang.Object field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.sql.Blob field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement- Parameters:
field
-- Throws:
java.sql.SQLException
-
setValue
public void setValue(java.sql.Clob field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement- Parameters:
field
-- Throws:
java.sql.SQLException
-
setBinaryStream
public void setBinaryStream(java.lang.Object field) throws java.sql.SQLException
Set the next binding variable of the currently active prepared statement to write the serialized data of 'field' to a BLOB.- Parameters:
field
-- Throws:
java.sql.SQLException
-
setBytes
public void setBytes(byte[] bytes) throws java.sql.SQLException
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:
java.sql.SQLException
-
testConnection
protected void testConnection(java.sql.Connection con) throws GenericEntityException
- Throws:
GenericEntityException
-
setFetchSize
protected void setFetchSize(java.sql.Statement stmt, int fetchSize) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
-