db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattba...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer JdbcAccess.java JdbcAccessImpl.java
Date Sun, 02 Feb 2003 03:35:25 GMT
mattbaird    2003/02/01 19:35:24

  Modified:    src/java/org/apache/ojb/broker/accesslayer JdbcAccess.java
                        JdbcAccessImpl.java
  Log:
  fix some potential leaks, and add scrollable parameter. Using scrollable cursors is a burden
on performance, so we'll want to have these scrollable parameters bubble all the way up to
the client.
  
  Revision  Changes    Path
  1.30      +5 -3      jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccess.java
  
  Index: JdbcAccess.java
  ===================================================================
  RCS file: /home/cvs//jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccess.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- JdbcAccess.java	19 Jan 2003 17:20:16 -0000	1.29
  +++ JdbcAccess.java	2 Feb 2003 03:35:24 -0000	1.30
  @@ -96,16 +96,18 @@
        * performs a SQL SELECT statement against RDBMS.
        * @param sqlStatement the query string.
        * @param cld ClassDescriptor providing meta-information.
  +	 * @param scrollable Does this resultset need cursor control for operations like last,
first and size
        */
  -    public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld) throws
PersistenceBrokerException;
  +    public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld, boolean
scrollable) throws PersistenceBrokerException;
   
       /**
        * performs a SQL SELECT statement against RDBMS.
        * @param sqlStatement the query string.
        * @param cld ClassDescriptor providing meta-information.
        * @param values The set of values to bind to the statement (may be null)
  +	 * @param scrollable Does this resultset need cursor control for operations like last,
first and size
        */
  -    public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld, Object[]
values) throws PersistenceBrokerException;
  +    public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld, Object[]
values, boolean scrollable) throws PersistenceBrokerException;
   
       /**
        * performs a SQL UPDTE, INSERT or DELETE statement against RDBMS.
  
  
  
  1.5       +46 -363   jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java
  
  Index: JdbcAccessImpl.java
  ===================================================================
  RCS file: /home/cvs//jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/JdbcAccessImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JdbcAccessImpl.java	31 Jan 2003 16:57:35 -0000	1.4
  +++ JdbcAccessImpl.java	2 Feb 2003 03:35:24 -0000	1.5
  @@ -233,7 +233,7 @@
       {
           if(logger.isDebugEnabled()) logger.safeDebug("executeQuery", query);
   
  -        ResultSetAndStatement retval = new ResultSetAndStatement();
  +        ResultSetAndStatement retval = new ResultSetAndStatement(broker.serviceConnectionManager().getSupportedPlatform());
   		/**
   		 * MBAIRD:
   		 * we should create a scrollable resultset if the start at index or end at index is set
  @@ -278,19 +278,35 @@
           catch (PersistenceBrokerException e)
           {
   			logger.error("PersistenceBrokerException during the execution of the query: " + e.getMessage(),
e);
  +			/**
  +			 * MBAIRD: error condition could result in our ResultSetAndStatement not being returned,
and not being closed
  +			 * since it is opened before the try loop, we should release it if there is a problem.
  +			 */
  +			if (retval != null)
  +			{
  +				retval.close();
  +			}
               throw e;
           }
           catch (SQLException e)
           {
   			logger.error("SQLException during the execution of the query (for a " + cld.getClassOfObject().getName()
+ "): " + e.getMessage(), e);
  +			/**
  +			 * MBAIRD: error condition could result in our ResultSetAndStatement not being returned,
and not being closed
  +			 * since it is opened before the try loop, we should release it if there is a problem.
  +			 */
  +			if (retval != null)
  +			{
  +				retval.close();
  +			}
               throw new PersistenceBrokerSQLException(e);
           }
  -
       }
   
  -    public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld) throws
PersistenceBrokerException
  +	public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld, boolean
scrollable)
  +			throws PersistenceBrokerException
       {
  -        return executeSQL(sqlStatement, cld, null);
  +        return executeSQL(sqlStatement, cld, null, scrollable);
       }
   
       /**
  @@ -298,15 +314,16 @@
        * @param sqlStatement the query string.
        * @param cld ClassDescriptor providing meta-information.
        */
  -    public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld, Object[]
values) throws PersistenceBrokerException
  +    public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld, Object[]
values, boolean scrollable)
  +			throws PersistenceBrokerException
       {
           if (logger.isDebugEnabled()) logger.debug("executeSQL: " + sqlStatement);
   
  -        ResultSetAndStatement retval = new ResultSetAndStatement();
  +        ResultSetAndStatement retval = new ResultSetAndStatement(broker.serviceConnectionManager().getSupportedPlatform());
           StatementManagerIF stmtMan = broker.serviceStatementManager();
           try
           {
  -            PreparedStatement stmt = stmtMan.getPreparedStatement(cld, sqlStatement, Query.SCROLLABLE);
  +            PreparedStatement stmt = stmtMan.getPreparedStatement(cld, sqlStatement, scrollable);
               stmtMan.bindValues(stmt, values, 1);
               ResultSet rs = stmt.executeQuery();
               // as we return the resultset for further operations, we cannot release the
statement yet.
  @@ -318,11 +335,28 @@
           catch (PersistenceBrokerException e)
           {
   			logger.error("PersistenceBrokerException during the execution of the SQL query: " +
e.getMessage(), e);
  +
  +			/**
  +			 * MBAIRD: error condition could result in our ResultSetAndStatement not being returned,
and not being closed
  +			 * since it is opened before the try loop, we should release it if there is a problem.
  +			 */
  +			if (retval != null)
  +			{
  +				retval.close();
  +			}
               throw e;
           }
           catch (SQLException e)
           {
   			logger.error("SQLException during the execution of the SQL query: " + e.getMessage(),
e);
  +			/**
  +			 * MBAIRD: error condition could result in our ResultSetAndStatement not being returned,
and not being closed
  +			 * since it is opened before the try loop, we should release it if there is a problem.
  +			 */
  +			if (retval != null)
  +			{
  +				retval.close();
  +			}
               throw new PersistenceBrokerSQLException(e);
           }
       }
  @@ -366,7 +400,10 @@
               {
                   throw new KeyConstraintViolatedException(e);
               }
  -            throw new PersistenceBrokerSQLException(e);
  +			else
  +			{
  +            	throw new PersistenceBrokerSQLException(e);
  +			}
           }
           finally
           {
  @@ -482,358 +519,4 @@
   			broker.serviceStatementManager().closeResources(stmt, rs);
           }
       }
  -
  -//    /**
  -//     * retrieves an Object from a ResultSet column.
  -//     * @param rs the ResultSet to be read from.
  -//     * @param fld The FIELDDESCRIPTOR containing metainfo on the column:
  -//     * it contins info on the expected JDBC Type and the name of the column.
  -//     * @return Object the read in object.
  -//     */
  -//    static Object getObjectFromColumn(ResultSet rs, FieldDescriptor fld) throws SQLException
  -//    {
  -//        return getObjectFromColumn(rs, fld.getColumnJdbcType(), fld.getColumnName());
  -//    }
  -//
  -//    static Object getObjectFromColumn(ResultSet rs, int jdbcType, String columnId) throws
SQLException
  -//    {
  -//        Object result = null;
  -//        /**
  -//         * we use these to avoid building an object for a null result column
  -//         */
  -//        long longVal;
  -//        int intVal;
  -//        boolean boolVal;
  -//        double doubleVal;
  -//        float floatVal;
  -//        short shortVal;
  -//        byte byteVal;
  -//
  -//        switch (jdbcType)
  -//        {
  -//            case Types.BIT :
  -//                {
  -//                    boolVal = rs.getBoolean( columnId );
  -//                    result = ( rs.wasNull() ? null : new Boolean( boolVal ) );
  -//                    break;
  -//                }
  -//            case Types.TINYINT :
  -//                {
  -//                    byteVal = rs.getByte( columnId );
  -//                    result = ( rs.wasNull() ? null : new Byte( byteVal ) );
  -//                    break;
  -//                }
  -//            case Types.SMALLINT :
  -//                {
  -//                    shortVal = rs.getShort( columnId );
  -//                    result = ( rs.wasNull() ? null : new Short( shortVal ) );
  -//                    break;
  -//                }
  -//            case Types.INTEGER :
  -//                {
  -//                    intVal = rs.getInt( columnId );
  -//                    result = ( rs.wasNull() ? null : new Integer( intVal ) );
  -//                    break;
  -//                }
  -//            case Types.BIGINT :
  -//                {
  -//                    longVal = rs.getLong( columnId );
  -//                    result = ( rs.wasNull() ? null : new Long( longVal ) );
  -//                    break;
  -//                }
  -//            case Types.DOUBLE :
  -//            case Types.FLOAT :
  -//                {
  -//                    doubleVal = rs.getDouble( columnId );
  -//                    result = ( rs.wasNull() ? null : new Double( doubleVal ) );
  -//                    break;
  -//                }
  -//            case Types.REAL :
  -//                {
  -//                    floatVal = rs.getFloat( columnId );
  -//                    result = ( rs.wasNull() ? null : new Float( floatVal ) );
  -//                    break;
  -//                }
  -//            case Types.NUMERIC :
  -//                {
  -//                    result = rs.getBigDecimal(columnId);
  -//                    break;
  -//                }
  -//            case Types.DECIMAL :
  -//                {
  -//                    result = rs.getBigDecimal(columnId);
  -//                    break;
  -//                }
  -//
  -//            case Types.CHAR :
  -//                {
  -//                    result = rs.getString(columnId);
  -//                    break;
  -//                }
  -//            case Types.VARCHAR :
  -//                {
  -//                    result = rs.getString(columnId);
  -//                    break;
  -//                }
  -//            case Types.LONGVARCHAR :
  -//                {
  -//                    result = rs.getString(columnId);
  -//                    break;
  -//                }
  -//
  -//            case Types.DATE :
  -//                {
  -//                    result = rs.getDate(columnId);
  -//                    break;
  -//                }
  -//            case Types.TIME :
  -//                {
  -//                    result = rs.getTime(columnId);
  -//                    break;
  -//                }
  -//            case Types.TIMESTAMP :
  -//                {
  -//                    result = rs.getTimestamp(columnId);
  -//                    break;
  -//                }
  -//
  -//            case Types.BINARY :
  -//                {
  -//                    result = rs.getBytes(columnId);
  -//                    break;
  -//                }
  -//            case Types.VARBINARY :
  -//                {
  -//                    result = rs.getBytes(columnId);
  -//                    break;
  -//                }
  -//            case Types.LONGVARBINARY :
  -//                {
  -//                    result = rs.getBytes(columnId);
  -//                    break;
  -//                }
  -//            case Types.CLOB :
  -//                {
  -//                    java.sql.Clob aClob = rs.getClob(columnId);
  -//                    result = ( rs.wasNull() ? null : aClob.getSubString(1L, (int) aClob.length())
);
  -//                    break;
  -//                }
  -//            case Types.BLOB :
  -//                {
  -//                    java.sql.Blob aBlob = rs.getBlob(columnId);
  -//                    result = ( rs.wasNull() ? null : aBlob.getBytes(1L, (int) aBlob.length())
);
  -//                    break;
  -//                }
  -//            default :
  -//                {
  -//                    throw new OJBRuntimeException(
  -//                        "The type "
  -//                            + jdbcType
  -//                            + " for attribute "
  -//                            + columnId
  -//                            + " can not be handled by OJB. Please specify only types
as defined by java.sql.Types.");
  -//                }
  -//        }
  -//        return result;
  -//    }
  -//
  -//     static Object getObjectFromColumn(ResultSet rs, int jdbcType, int columnId) throws
SQLException
  -//    {
  -//        Object result = null;
  -//        /**
  -//         * we use these to avoid building an object for a null result column
  -//         */
  -//        long longVal;
  -//        int intVal;
  -//        boolean boolVal;
  -//        double doubleVal;
  -//        float floatVal;
  -//        short shortVal;
  -//        byte byteVal;
  -//
  -//        switch (jdbcType)
  -//        {
  -//            case Types.BIT :
  -//                {
  -//                    boolVal = rs.getBoolean( columnId );
  -//                    result = ( rs.wasNull() ? null : new Boolean( boolVal ) );
  -//                    break;
  -//                }
  -//            case Types.TINYINT :
  -//                {
  -//                    byteVal = rs.getByte( columnId );
  -//                    result = ( rs.wasNull() ? null : new Byte( byteVal ) );
  -//                    break;
  -//                }
  -//            case Types.SMALLINT :
  -//                {
  -//                    shortVal = rs.getShort( columnId );
  -//                    result = ( rs.wasNull() ? null : new Short( shortVal ) );
  -//                    break;
  -//                }
  -//            case Types.INTEGER :
  -//                {
  -//                    intVal = rs.getInt( columnId );
  -//                    result = ( rs.wasNull() ? null : new Integer( intVal ) );
  -//                    break;
  -//                }
  -//            case Types.BIGINT :
  -//                {
  -//                    longVal = rs.getLong( columnId );
  -//                    result = ( rs.wasNull() ? null : new Long( longVal ) );
  -//                    break;
  -//                }
  -//            case Types.DOUBLE :
  -//            case Types.FLOAT :
  -//                {
  -//                    doubleVal = rs.getDouble( columnId );
  -//                    result = ( rs.wasNull() ? null : new Double( doubleVal ) );
  -//                    break;
  -//                }
  -//            case Types.REAL :
  -//                {
  -//                    floatVal = rs.getFloat( columnId );
  -//                    result = ( rs.wasNull() ? null : new Float( floatVal ) );
  -//                    break;
  -//                }
  -//            case Types.NUMERIC :
  -//                {
  -//                    result = rs.getBigDecimal(columnId);
  -//                    break;
  -//                }
  -//            case Types.DECIMAL :
  -//                {
  -//                    result = rs.getBigDecimal(columnId);
  -//                    break;
  -//                }
  -//
  -//            case Types.CHAR :
  -//                {
  -//                    result = rs.getString(columnId);
  -//                    break;
  -//                }
  -//            case Types.VARCHAR :
  -//                {
  -//                    result = rs.getString(columnId);
  -//                    break;
  -//                }
  -//            case Types.LONGVARCHAR :
  -//                {
  -//                    result = rs.getString(columnId);
  -//                    break;
  -//                }
  -//
  -//            case Types.DATE :
  -//                {
  -//                    result = rs.getDate(columnId);
  -//                    break;
  -//                }
  -//            case Types.TIME :
  -//                {
  -//                    result = rs.getTime(columnId);
  -//                    break;
  -//                }
  -//            case Types.TIMESTAMP :
  -//                {
  -//                    result = rs.getTimestamp(columnId);
  -//                    break;
  -//                }
  -//
  -//            case Types.BINARY :
  -//                {
  -//                    result = rs.getBytes(columnId);
  -//                    break;
  -//                }
  -//            case Types.VARBINARY :
  -//                {
  -//                    result = rs.getBytes(columnId);
  -//                    break;
  -//                }
  -//            case Types.LONGVARBINARY :
  -//                {
  -//                    result = rs.getBytes(columnId);
  -//                    break;
  -//                }
  -//            case Types.CLOB :
  -//                {
  -//                    java.sql.Clob aClob = rs.getClob(columnId);
  -//                    result = ( rs.wasNull() ? null : aClob.getSubString(1L, (int) aClob.length())
);
  -//                    break;
  -//                }
  -//            case Types.BLOB :
  -//                {
  -//                    java.sql.Blob aBlob = rs.getBlob(columnId);
  -//                    result = ( rs.wasNull() ? null : aBlob.getBytes(1L, (int) aBlob.length())
);
  -//                    break;
  -//                }
  -//            default :
  -//                {
  -//                    throw new OJBRuntimeException(
  -//                        "The type "
  -//                            + jdbcType
  -//                            + " for attribute "
  -//                            + columnId
  -//                            + " can not be handled by OJB. Please specify only types
as defined by java.sql.Types.");
  -//                }
  -//        }
  -//        return result;
  -//    }
  -//    /**
  -//     * determines the JDBC type (represented as an int value as specified
  -//     * by java.sql.Types) of a FIELDDESCRIPTOR idetified by index.
  -//     * @param cld The ClassDescriptor containing the FIELDDESCRIPTOR.
  -//     * @param index index identifies the FIELDDESCRIPTOR within cld.
  -//     * @return the int value representing the Type according to
  -//     * java.sql.Types
  -//     */
  -//    static int getSqlTypeAll(ClassDescriptor cld, int index)
  -//    {
  -//        FieldDescriptor fld = cld.getFieldDescriptions()[index];
  -//        return fld.getColumnJdbcType();
  -//    }
  -//
  -//    /**
  -//     * determines the JDBC type (represented as an int value as specified
  -//     * by java.sql.Types) of a FIELDDESCRIPTOR idetified by index.
  -//     * @param cld The ClassDescriptor containing the FIELDDESCRIPTOR.
  -//     * @param index index identifies the FIELDDESCRIPTOR within the
  -//     * Non-PrimaryKey-fields of cld.
  -//     * @return the int value representing the Type according to
  -//     * java.sql.Types
  -//     */
  -//    static int getSqlTypeNonPk(ClassDescriptor cld, int index)
  -//    {
  -//        FieldDescriptor fld = cld.getNonPkFields()[index];
  -//        return fld.getColumnJdbcType();
  -//    }
  -//
  -//    /**
  -//     * determines the JDBC type (represented as an int value as specified
  -//     * by java.sql.Types) of a FIELDDESCRIPTOR idetified by index.
  -//     * @param cld The ClassDescriptor containing the FIELDDESCRIPTOR.
  -//     * @param index index identifies the FIELDDESCRIPTOR within the
  -//     * PrimaryKey-fields of cld.
  -//     * @return the int value representing the Type according to
  -//     * java.sql.Types
  -//     */
  -//    static int getSqlTypePk(ClassDescriptor cld, int index)
  -//    {
  -//        FieldDescriptor fld = cld.getPkFields()[index];
  -//        return fld.getColumnJdbcType();
  -//    }
  -//
  -//    /**
  -//     * determines the JDBC type (represented as an int value as specified
  -//     * by java.sql.Types) of a FIELDDESCRIPTOR idetified by index.
  -//     * @param cld The ClassDescriptor containing the FIELDDESCRIPTOR.
  -//     * @param index index identifies the FIELDDESCRIPTOR within the
  -//     * PrimaryKey-fields of cld.
  -//     * @return the int value representing the Type according to
  -//     * java.sql.Types
  -//     */
  -//    static int getSqlTypeLocking(ClassDescriptor cld, int index)
  -//    {
  -//        FieldDescriptor fld = cld.getLockingFields()[index];
  -//        return fld.getColumnJdbcType();
  -//    }
   }
  
  
  

Mime
View raw message