Class 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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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 based on the SQL string given
      int executeUpdate()
      Execute updates
      int executeUpdate​(java.lang.String sql)
      Execute update based on the SQL statement given
      java.sql.Connection getConnection()
      Get a connection from the TransactionFactoryLoader
      Delegator getDelegator()  
      java.sql.PreparedStatement getPreparedStatement()
      Getter: get the prepared statement
      java.sql.ResultSet getResultSet()
      Getter: get the currently active 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.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 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.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)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • module

        public static final java.lang.String module
        Module Name Used for debugging
    • 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()
      • 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 executed
        aListener - 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
      • setFetchSize

        protected void setFetchSize​(java.sql.Statement stmt,
                                    int fetchSize)
                             throws java.sql.SQLException
        Throws:
        java.sql.SQLException