org.ofbiz.entity.jdbc
Class SQLProcessor

java.lang.Object
  extended by org.ofbiz.entity.jdbc.SQLProcessor

public class SQLProcessor
extends java.lang.Object

SQLProcessor - provides utitlity functions to ease database access


Field Summary
static java.util.List<java.lang.String> CONNECTION_TEST_LIST
          Used for testing connections when test is enabled
static boolean ENABLE_TEST
           
static int MAX_CONNECTIONS
           
static java.lang.String module
          Module Name Used for debugging
 
Constructor Summary
SQLProcessor(java.lang.String helperName)
          Construct an object based on the helper/datasource
SQLProcessor(java.lang.String helperName, java.sql.Connection connection)
          Construct an object with an connection given.
 
Method Summary
 void close()
          Commit if required and remove all allocated resources
 void commit()
          Commit all modifications
 void 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 statement
 java.sql.ResultSet executeQuery(java.lang.String sql)
          Execute a query baed ont SQL string given
 int executeUpdate()
          Execute updates
 int executeUpdate(java.lang.String sql)
          Execute update based on the SQL statement given
protected  void finalize()
           
 java.sql.Connection getConnection()
          Get a connection from the ConnectionFactory
 java.sql.PreparedStatement getPreparedStatement()
          Getter: get the prepared statement
 java.sql.ResultSet getResultSet()
          Getter: get the currently activ ResultSet
 boolean next()
          Test if there more records available
 void 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 modifications
 void 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.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 statement
 void setValue(java.lang.Boolean field)
          Set the next binding variable of the currently active prepared statement.
 void setValue(java.sql.Clob field)
          Set the next binding variable of the currently active prepared statement
 void setValue(java.sql.Date 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.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.
protected  void testConnection(java.sql.Connection con)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

module

public static final java.lang.String module
Module Name Used for debugging


CONNECTION_TEST_LIST

public static java.util.List<java.lang.String> CONNECTION_TEST_LIST
Used for testing connections when test is enabled


MAX_CONNECTIONS

public static int MAX_CONNECTIONS

ENABLE_TEST

public static boolean ENABLE_TEST
Constructor Detail

SQLProcessor

public SQLProcessor(java.lang.String helperName)
Construct an object based on the helper/datasource

Parameters:
helperName - The datasource helper (see entityengine.xml <datasource name="..">)

SQLProcessor

public SQLProcessor(java.lang.String helperName,
                    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:
helperName - The datasource helper (see entityengine.xml <datasource name="..">)
connection - The connection to be used
Method Detail

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

Throws:
GenericDataSourceException

getConnection

public java.sql.Connection getConnection()
                                  throws GenericDataSourceException,
                                         GenericEntityException
Get a connection from the ConnectionFactory

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 baed ont 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 activ 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 executed
aListener - The callback function object
Throws:
GenericEntityException

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

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

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