db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer SqlBasedRsIterator.java SQLCachingStatementsForClass.java StatementManager.java StatementManagerIF.java StatementsForClassIF.java StatementsForClassImpl.java RsIterator.java RowReaderDefaultImpl.java RowReader.java PkEnumeration.java JdbcAccess.java IndirectionHandler.java ConnectionManagerIF.java ConnectionManager.java ConnectionFactoryPooledImpl.java ConnectionFactoryDBCPImpl.java ConnectionFactoryAbstractImpl.java ConnectionFactory.java CollectionPrefetcher.java
Date Tue, 24 Dec 2002 13:02:20 GMT
arminw      2002/12/24 05:02:20

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        SqlBasedRsIterator.java
                        SQLCachingStatementsForClass.java
                        StatementManager.java StatementManagerIF.java
                        StatementsForClassIF.java
                        StatementsForClassImpl.java RsIterator.java
                        RowReaderDefaultImpl.java RowReader.java
                        PkEnumeration.java JdbcAccess.java
                        IndirectionHandler.java ConnectionManagerIF.java
                        ConnectionManager.java
                        ConnectionFactoryPooledImpl.java
                        ConnectionFactoryDBCPImpl.java
                        ConnectionFactoryAbstractImpl.java
                        ConnectionFactory.java CollectionPrefetcher.java
  Log:
  improve metadata handling:
  separate the object stuff (class descriptor, field descriptor, ...)
  from the connection stuff (jdbc descriptor).
  DescriptorRepository now handles only object
  specific properties.
  
  Do some performance improvements
  
  Revision  Changes    Path
  1.8       +5 -13     jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/SqlBasedRsIterator.java
  
  Index: SqlBasedRsIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/SqlBasedRsIterator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SqlBasedRsIterator.java	9 Oct 2002 15:17:18 -0000	1.7
  +++ SqlBasedRsIterator.java	24 Dec 2002 13:02:19 -0000	1.8
  @@ -59,12 +59,13 @@
   
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.singlevm.PersistenceBrokerImpl;
   
   /**
    * RsIterator based on SQL-Statement
  - * 
  + *
    * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
    * @version $Id$
    */
  @@ -72,17 +73,12 @@
   {
   	private String m_sql;
   
  -	protected SqlBasedRsIterator()
  -	{
  -	}
  -
  -	/**
  +    /**
   	 * SqlBasedRsIterator constructor.
   	 */
   	public SqlBasedRsIterator(String sqlStatement, ClassDescriptor cld, PersistenceBrokerImpl broker)
   		throws PersistenceBrokerException
   	{
  -		super();
   		m_sql = sqlStatement;
   		if (logger.isDebugEnabled())
   			logger.debug("SqlBasedRsIterator(" + sqlStatement + ", " + cld + ")");
  @@ -91,7 +87,6 @@
   		m_cld = cld;
   		itemProxyClass = cld.getProxyClass();
   		m_row = new HashMap();
  -
   	}
   
   	/**
  @@ -134,7 +129,7 @@
   		{
   			countSql = "select count(*) " + m_sql.substring(fromPos);
   		}
  -			
  +
   		rsStmt = new JdbcAccess(m_broker).executeSQL(countSql, m_cld);
   		try
   		{
  @@ -149,9 +144,6 @@
   		{
   			throw new PersistenceBrokerException(e);
   		}
  -
  -		
   		return count;
   	}
  -
   }
  
  
  
  1.7       +31 -34    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/SQLCachingStatementsForClass.java
  
  Index: SQLCachingStatementsForClass.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/SQLCachingStatementsForClass.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SQLCachingStatementsForClass.java	9 Sep 2002 20:42:00 -0000	1.6
  +++ SQLCachingStatementsForClass.java	24 Dec 2002 13:02:19 -0000	1.7
  @@ -58,6 +58,7 @@
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.broker.util.logging.Logger;
   
  @@ -72,51 +73,47 @@
   	 * the SQL String used for PK lookups
   	 */
   	private String selectByPKSQL;
  -
   	/**
   	 * the SQL String used for inserts
   	 */
   	private String insertSQL;
  -
   	/**
   	 * the SQL String used for updates
   	 */
   	private String updateSQL;
  -
   	/**
   	 * the SQL String used for deletes
   	 */
   	private String deleteSQL;
   
  -	public SQLCachingStatementsForClass(ClassDescriptor mif, PersistenceBroker broker)
  +	public SQLCachingStatementsForClass(final JdbcConnectionDescriptor jcd, final ClassDescriptor mif)
   	{
  -		super(broker, mif);
  -		logger = LoggerFactory.getLogger(this.getClass());
  +		super(jcd, mif);
   	}
   
  -	/**
  -	 * Obtains the connection from the ConnectionManager.
  -	 * This method is used for jdbc 1.0 drivers.
  -	 */
  -    protected Connection getConnection() throws SQLException
  -    {
  -        try
  -        {
  -            return connectionManager.getConnection();
  -        }
  -        catch (PersistenceBrokerException e)
  -        {
  -            throw new SQLException("OJB Error: could not obtain a Connection");
  -        }
  -        catch (LookupException e)
  -        {
  -            throw new SQLException("OJB Error: could not obtain a Connection");
  -        }
  -
  -    }
  +//	/**
  +//	 * Obtains the connection from the ConnectionManager.
  +//	 * This method is used for jdbc 1.0 drivers.
  +//	 */
  +//    protected Connection getConnection() throws SQLException
  +//    {
  +//        try
  +//        {
  +//            return connectionManager.getConnection();
  +//        }
  +//        catch (PersistenceBrokerException e)
  +//        {
  +//            throw new SQLException("OJB Error: could not obtain a Connection");
  +//        }
  +//        catch (LookupException e)
  +//        {
  +//            throw new SQLException("OJB Error: could not obtain a Connection");
  +//        }
  +//
  +//    }
   
   
  -	public PreparedStatement getDeleteStmt() throws SQLException
  +	public PreparedStatement getDeleteStmt(Connection con) throws SQLException
   	{
   		if (deleteSQL == null)
   		{
  @@ -129,7 +126,7 @@
   		}
   		try
   		{
  -			return prepareStatement(deleteSQL, Query.NOT_SCROLLABLE);
  +			return prepareStatement(con, deleteSQL, Query.NOT_SCROLLABLE);
   		}
   		catch (SQLException ex)
   		{
  @@ -138,7 +135,7 @@
   		}
   	}
   
  -	public PreparedStatement getInsertStmt() throws SQLException
  +	public PreparedStatement getInsertStmt(Connection con) throws SQLException
   	{
   		if (insertSQL == null)
   		{
  @@ -151,7 +148,7 @@
   		}
   		try
   		{
  -			return prepareStatement(insertSQL, Query.NOT_SCROLLABLE);
  +			return prepareStatement(con, insertSQL, Query.NOT_SCROLLABLE);
   		}
   		catch (SQLException ex)
   		{
  @@ -160,7 +157,7 @@
   		}
   	}
   
  -	public PreparedStatement getSelectByPKStmt() throws SQLException
  +	public PreparedStatement getSelectByPKStmt(Connection con) throws SQLException
   	{
   		if (selectByPKSQL == null)
   		{
  @@ -173,7 +170,7 @@
   		}
   		try
   		{
  -			return prepareStatement(selectByPKSQL, Query.NOT_SCROLLABLE);
  +			return prepareStatement(con, selectByPKSQL, Query.NOT_SCROLLABLE);
   		}
   		catch (SQLException ex)
   		{
  @@ -182,7 +179,7 @@
   		}
   	}
   
  -	public PreparedStatement getUpdateStmt() throws SQLException
  +	public PreparedStatement getUpdateStmt(Connection con) throws SQLException
   	{
   		if (updateSQL == null)
   		{
  @@ -195,7 +192,7 @@
   		}
   		try
   		{
  -			return prepareStatement(updateSQL, Query.NOT_SCROLLABLE);
  +			return prepareStatement(con, updateSQL, Query.NOT_SCROLLABLE);
   		}
   		catch (SQLException ex)
   		{
  
  
  
  1.15      +157 -66   jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java
  
  Index: StatementManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- StatementManager.java	28 Nov 2002 22:21:05 -0000	1.14
  +++ StatementManager.java	24 Dec 2002 13:02:19 -0000	1.15
  @@ -61,6 +61,7 @@
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  +import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
   import org.apache.ojb.broker.platforms.Platform;
   import org.apache.ojb.broker.platforms.PlatformException;
   import org.apache.ojb.broker.platforms.PlatformFactory;
  @@ -74,6 +75,7 @@
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.SelectionCriteria;
   import org.apache.ojb.broker.query.SqlCriteria;
  +import org.apache.ojb.broker.util.BrokerHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -84,8 +86,9 @@
   import java.sql.Types;
   import java.util.Collection;
   import java.util.Enumeration;
  -import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.Map;
  +import java.util.WeakHashMap;
   
   /**
    * manages JDBC Connection and Statement ressources.
  @@ -98,25 +101,24 @@
       private Logger log = LoggerFactory.getLogger(StatementManager.class);
   
       /** internal table of StatementForClass objects */
  -    protected HashMap statementTable = new HashMap();
  +    private Map statementTable = new WeakHashMap();
       /** the associated broker */
  -    protected PersistenceBroker broker;
  +    private final PersistenceBroker broker;
       private Platform platform;
  -    boolean m_eagerRelease;
  -
       /**
  -     * default constructor
  +     * Used when OJB run in JBoss
  +     * @todo Find a better solution to handle OJB within JBoss
  +     * --> the JCA implementation should solve this problem
        */
  -    public StatementManager()
  -    {
  -    }
  +    private boolean m_eagerRelease;
  +    private ConnectionManagerIF conMan;
   
  -    public StatementManager(PersistenceBroker pBroker)
  +    public StatementManager(final PersistenceBroker pBroker)
       {
           this.broker = pBroker;
  -        JdbcConnectionDescriptor jcd = pBroker.getDescriptorRepository().getDefaultJdbcConnection();
  -        m_eagerRelease = jcd.getEagerRelease();
  -        platform = PlatformFactory.getPlatformFor(jcd);
  +        this.conMan = broker.serviceConnectionManager();
  +        m_eagerRelease = conMan.getConnectionDescriptor().getEagerRelease();
  +        platform = PlatformFactory.getPlatformFor(conMan.getConnectionDescriptor());
       }
   
       /**
  @@ -132,7 +134,7 @@
           {
               synchronized (statementTable)
               {
  -                sfc = (StatementsForClassIF) new StatementsForClassImpl(broker, cds);
  +                sfc = (StatementsForClassIF) new StatementsForClassImpl(conMan.getConnectionDescriptor(), cds);
                   statementTable.put(cds, sfc);
               }
           }
  @@ -150,9 +152,15 @@
               {
                   //log.info("## close: "+stmt);
                   stmt.close();
  +
  +                /*
  +                *********************************************
  +                special stuff for OJB within JBoss
  +                ********************************************
  +                */
                   if (m_eagerRelease)
                   {
  -                    broker.getConnectionManager().releaseConnection();
  +                    conMan.releaseConnection();
                   }
   
               }
  @@ -172,14 +180,15 @@
       /**
        * binds the Identities Primary key values to the statement
        */
  -    public void bindDelete(PreparedStatement stmt, Identity oid) throws java.sql.SQLException
  +    public void bindDelete(PreparedStatement stmt, Identity oid, ClassDescriptor cld) throws java.sql.SQLException
       {
  -        ClassDescriptor cld = broker.getClassDescriptor(oid.getObjectsClass());
  -        Platform pf = PlatformFactory.getPlatformFor(cld.getConnectionDescriptor());
  -
  +        if(cld == null)
  +        {
  +            cld = broker.getClassDescriptor(oid.getObjectsClass());
  +        }
           for (int i = 0; i < oid.getPrimaryKeyValues().length; i++)
           {
  -            pf.setObjectForStatement(stmt, i + 1, oid.getPrimaryKeyValues()[i], JdbcAccess.getSqlTypePk(cld, i));
  +            platform.setObjectForStatement(stmt, i + 1, oid.getPrimaryKeyValues()[i], JdbcAccess.getSqlTypePk(cld, i));
           }
       }
   
  @@ -188,17 +197,16 @@
        */
       public void bindDelete(PreparedStatement stmt, ClassDescriptor cld, Object obj) throws java.sql.SQLException
       {
  -        Platform pf = PlatformFactory.getPlatformFor(cld.getConnectionDescriptor());
           int index = 1;
           Object[] values, currentLockingValues;
   
           currentLockingValues = cld.getCurrentLockingValues(obj);
   
           // parameters for WHERE-clause pk
  -        values = cld.getKeyValues(obj);
  +        values = broker.serviceBrokerHelper().getKeyValues(cld, obj);
           for (int i = 0; i < values.length; i++)
           {
  -            pf.setObjectForStatement(stmt, index, values[i], JdbcAccess.getSqlTypePk(cld, i));
  +            platform.setObjectForStatement(stmt, index, values[i], JdbcAccess.getSqlTypePk(cld, i));
               index++;
           }
   
  @@ -206,7 +214,7 @@
           values = currentLockingValues;
           for (int i = 0; i < values.length; i++)
           {
  -            pf.setObjectForStatement(stmt, index, values[i], JdbcAccess.getSqlTypeLocking(cld, i));
  +            platform.setObjectForStatement(stmt, index, values[i], JdbcAccess.getSqlTypeLocking(cld, i));
               index++;
           }
       }
  @@ -247,10 +255,9 @@
           if (fld != null)
           {
               // BRJ: use field conversions and platform
  -            Platform pf = PlatformFactory.getPlatformFor(cld.getConnectionDescriptor());
               if (value != null)
               {
  -                pf.setObjectForStatement(
  +                platform.setObjectForStatement(
                           stmt,
                           index,
                           fld.getFieldConversion().javaToSql(value),
  @@ -258,7 +265,7 @@
               }
               else
               {
  -                pf.setNullForStatement(stmt, index, fld.getColumnJdbcType());
  +                platform.setNullForStatement(stmt, index, fld.getColumnJdbcType());
               }
           }
           else
  @@ -289,7 +296,6 @@
               throws SQLException
       {
           FieldDescriptor fld = cld.getFieldDescriptorForPath(crit.getAttribute());
  -
           return bindStatementValue(stmt, index, crit.getValue(), cld, fld);
       }
   
  @@ -355,7 +361,6 @@
               throws SQLException
       {
           FieldDescriptor fld = cld.getFieldDescriptorForPath(crit.getAttribute());
  -
           index = bindStatementValue(stmt, index, crit.getValue(), cld, fld);
           return bindStatementValue(stmt, index, crit.getValue2(), cld, fld);
       }
  @@ -371,7 +376,6 @@
       private int bindStatement(PreparedStatement stmt, int index, InCriteria crit, ClassDescriptor cld) throws SQLException
       {
           FieldDescriptor fld = cld.getFieldDescriptorForPath(crit.getAttribute());
  -
           if (crit.getValue() instanceof Collection)
           {
               Collection values = (Collection) crit.getValue();
  @@ -473,36 +477,34 @@
       public void bindInsert(PreparedStatement stmt, ClassDescriptor cld, Object obj)
               throws java.sql.SQLException
       {
  -        Platform pf = PlatformFactory.getPlatformFor(cld.getConnectionDescriptor());
  -
           Object[] values;
           cld.updateLockingValues(obj); // BRJ : provide useful defaults for locking fields
   
  -        values = cld.getAllValues(obj);
  +        values = getAllValues(cld, obj);
           for (int i = 0; i < values.length; i++)
           {
               Object val = values[i];
               if (val != null)
               {
  -                pf.setObjectForStatement(stmt, i + 1, val, JdbcAccess.getSqlTypeAll(cld, i));
  +                platform.setObjectForStatement(stmt, i + 1, val, JdbcAccess.getSqlTypeAll(cld, i));
               }
               else
               {
  -                pf.setNullForStatement(stmt, i + 1, JdbcAccess.getSqlTypeAll(cld, i));
  +                platform.setNullForStatement(stmt, i + 1, JdbcAccess.getSqlTypeAll(cld, i));
               }
   
           }
       }
   
  -
       /**
        * binds the Identities Primary key values to the statement
        */
  -    public void bindSelect(PreparedStatement stmt, Identity oid) throws java.sql.SQLException
  +    public void bindSelect(PreparedStatement stmt, Identity oid, ClassDescriptor cld) throws SQLException
       {
  -        ClassDescriptor cld = broker.getClassDescriptor(oid.getObjectsClass());
  -        Platform pf = PlatformFactory.getPlatformFor(cld.getConnectionDescriptor());
  -
  +        if(cld == null)
  +        {
  +            cld = broker.getClassDescriptor(oid.getObjectsClass());
  +        }
           int i = 0;
           try
           {
  @@ -512,17 +514,17 @@
                   Object val = values[i];
                   if (val != null)
                   {
  -                    pf.setObjectForStatement(stmt, i + 1, val, JdbcAccess.getSqlTypePk(cld, i));
  +                    platform.setObjectForStatement(stmt, i + 1, val, JdbcAccess.getSqlTypePk(cld, i));
                   }
                   else
                   {
  -                    pf.setNullForStatement(stmt, i + 1, JdbcAccess.getSqlTypePk(cld, i));
  +                    platform.setNullForStatement(stmt, i + 1, JdbcAccess.getSqlTypePk(cld, i));
                   }
               }
           }
           catch (SQLException e)
           {
  -            LoggerFactory.getDefaultLogger().error(
  +            log.error(
                       "bindSelect failed for: "
                       + oid.toString()
                       + ", PK: "
  @@ -539,26 +541,25 @@
       public void bindUpdate(PreparedStatement stmt, ClassDescriptor cld, Object obj)
               throws java.sql.SQLException
       {
  -        Platform pf = PlatformFactory.getPlatformFor(cld.getConnectionDescriptor());
           int index = 1;
           Object[] values, currentLockingValues;
   
           currentLockingValues = cld.getCurrentLockingValues(obj);
           cld.updateLockingValues(obj); // BRJ
  -        values = cld.getNonKeyValues(obj);
  +        values = getNonKeyValues(broker, cld, obj);
   
           // parameters for SET-clause
           for (int i = 0; i < values.length; i++)
           {
               Object val = values[i];
               if (val != null)
  -                pf.setObjectForStatement(stmt, index, val, JdbcAccess.getSqlTypeNonPk(cld, i));
  +                platform.setObjectForStatement(stmt, index, val, JdbcAccess.getSqlTypeNonPk(cld, i));
               else
  -                pf.setNullForStatement(stmt, index, JdbcAccess.getSqlTypeNonPk(cld, i));
  +                platform.setNullForStatement(stmt, index, JdbcAccess.getSqlTypeNonPk(cld, i));
               index++;
           }
           // parameters for WHERE-clause pk
  -        values = cld.getKeyValues(obj);
  +        values = broker.serviceBrokerHelper().getKeyValues(cld, obj);
           for (int i = 0; i < values.length; i++)
           {
               Object val = values[i];
  @@ -586,16 +587,21 @@
       /**
        * return a prepared DELETE Statement fitting for the given ClassDescriptor
        */
  -    public PreparedStatement getDeleteStatement(ClassDescriptor cds)
  -            throws PersistenceBrokerSQLException
  +    public PreparedStatement getDeleteStatement(ClassDescriptor cld)
  +            throws PersistenceBrokerSQLException, PersistenceBrokerException
       {
           try
           {
  -            return getStatementsForClass(cds).getDeleteStmt();
  +            return getStatementsForClass(cld).getDeleteStmt(broker.serviceConnectionManager().getConnection());
           }
           catch (SQLException e)
           {
  -            throw new PersistenceBrokerSQLException(e);
  +            throw new PersistenceBrokerSQLException("Could not build statement ask for", e);
  +        }
  +        catch(LookupException e)
  +        {
  +            throw new PersistenceBrokerException(
  +                    "Used ConnectionManager instance could not obtain a connection",e);
           }
       }
   
  @@ -604,22 +610,35 @@
        */
       public Statement getGenericStatement(ClassDescriptor cds, boolean scrollable) throws PersistenceBrokerException
       {
  -        return getStatementsForClass(cds).getGenericStmt(scrollable);
  +        try
  +        {
  +            return getStatementsForClass(cds).getGenericStmt(conMan.getConnection(),scrollable);
  +        }
  +        catch(LookupException e)
  +        {
  +            throw new PersistenceBrokerException(
  +                    "Used ConnectionManager instance could not obtain a connection",e);
  +        }
       }
   
       /**
        * return a prepared Insert Statement fitting for the given ClassDescriptor
        */
       public PreparedStatement getInsertStatement(ClassDescriptor cds)
  -            throws PersistenceBrokerSQLException
  +            throws PersistenceBrokerSQLException, PersistenceBrokerException
       {
           try
           {
  -            return getStatementsForClass(cds).getInsertStmt();
  +            return getStatementsForClass(cds).getInsertStmt(conMan.getConnection());
           }
           catch (SQLException e)
           {
  -            throw new PersistenceBrokerSQLException(e);
  +            throw new PersistenceBrokerSQLException("Could not build statement ask for", e);
  +        }
  +        catch(LookupException e)
  +        {
  +            throw new PersistenceBrokerException(
  +                    "Used ConnectionManager instance could not obtain a connection",e);
           }
       }
   
  @@ -629,22 +648,35 @@
       public PreparedStatement getPreparedStatement(ClassDescriptor cds, String sql, boolean scrollable)
               throws PersistenceBrokerException
       {
  -        return getStatementsForClass(cds).getPreparedStmt(sql, scrollable);
  +        try
  +        {
  +            return getStatementsForClass(cds).getPreparedStmt(conMan.getConnection(), sql, scrollable);
  +        }
  +        catch(LookupException e)
  +        {
  +            throw new PersistenceBrokerException(
  +                    "Used ConnectionManager instance could not obtain a connection",e);
  +        }
       }
   
       /**
        * return a prepared Select Statement for the given ClassDescriptor
        */
       public PreparedStatement getSelectByPKStatement(ClassDescriptor cds)
  -            throws PersistenceBrokerSQLException
  +            throws PersistenceBrokerSQLException,PersistenceBrokerException
       {
           try
           {
  -            return getStatementsForClass(cds).getSelectByPKStmt();
  +            return getStatementsForClass(cds).getSelectByPKStmt(conMan.getConnection());
           }
           catch (SQLException e)
           {
  -            throw new PersistenceBrokerSQLException(e);
  +            throw new PersistenceBrokerSQLException("Could not build statement ask for", e);
  +        }
  +        catch(LookupException e)
  +        {
  +            throw new PersistenceBrokerException(
  +                    "Used ConnectionManager instance could not obtain a connection",e);
           }
       }
   
  @@ -652,16 +684,77 @@
        * return a prepared Update Statement fitting to the given ClassDescriptor
        */
       public PreparedStatement getUpdateStatement(ClassDescriptor cds)
  -            throws PersistenceBrokerSQLException
  +            throws PersistenceBrokerSQLException, PersistenceBrokerException
       {
           try
           {
  -            return getStatementsForClass(cds).getUpdateStmt();
  +            return getStatementsForClass(cds).getUpdateStmt(conMan.getConnection());
           }
           catch (SQLException e)
           {
  -            throw new PersistenceBrokerSQLException(e);
  +            throw new PersistenceBrokerSQLException("Could not build statement ask for", e);
  +        }
  +        catch(LookupException e)
  +        {
  +            throw new PersistenceBrokerException(
  +                    "Used ConnectionManager instance could not obtain a connection",e);
  +        }
  +    }
  +
  +    /**
  +     * returns an array containing values for all the Objects attribute
  +     * @throws MetadataException if tehre is an erros accessing obj field values
  +     */
  +    protected Object[] getAllValues(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
  +    {
  +        FieldDescriptor[] allFields = cld.getFieldDescriptions();
  +        Object[] result = new Object[allFields.length];
  +
  +        for (int i = 0; i < allFields.length; i++)
  +        {
  +            FieldDescriptor fmd = allFields[i];
  +            PersistentField f = fmd.getPersistentField();
  +            Object cv = f.get(obj);
  +
  +            // handle autoincrement attributes if not filled
  +            if (fmd.isAutoIncrement())
  +            {
  +                cv = broker.serviceBrokerHelper().getAutoIncrementValue(fmd, obj, cv);
  +            }
  +
  +            // apply type and value mapping
  +            cv = fmd.getFieldConversion().javaToSql(cv);
  +            result[i] = cv;
           }
  +        return result;
  +    }
  +
  +    /**
  +     * returns an Array with an Objects NON-PK VALUES
  +     * @throws MetadataException if there is an erros accessing o field values
  +     */
  +    protected Object[] getNonKeyValues(PersistenceBroker broker, ClassDescriptor cld, Object o) throws PersistenceBrokerException
  +    {
  +        FieldDescriptor[] nonPkFields = cld.getNonPkFields();
  +        Object[] result = new Object[nonPkFields.length];
  +
  +        for (int i = 0; i < result.length; i++)
  +        {
  +            FieldDescriptor fmd = nonPkFields[i];
  +            PersistentField f = fmd.getPersistentField();
  +            Object cv = f.get(o);
  +
  +            // handle autoincrement attributes if not filled
  +            if (fmd.isAutoIncrement())
  +            {
  +                cv = broker.serviceBrokerHelper().getAutoIncrementValue(fmd, o, cv);
  +            }
  +
  +            // apply type and value conversion
  +            cv = fmd.getFieldConversion().javaToSql(cv);
  +            result[i] = cv;
  +        }
  +        return result;
       }
   
       /**
  @@ -698,6 +791,4 @@
               }
           }
       }
  -
  -
   }
  
  
  
  1.4       +10 -4     jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManagerIF.java
  
  Index: StatementManagerIF.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementManagerIF.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StatementManagerIF.java	19 Jun 2002 14:57:19 -0000	1.3
  +++ StatementManagerIF.java	24 Dec 2002 13:02:19 -0000	1.4
  @@ -67,16 +67,22 @@
   
   public interface StatementManagerIF
   {
  -    /**
     * binds the Identities Primary key values to the statement
     */
  -    void bindDelete(PreparedStatement stmt, Identity oid) throws java.sql.SQLException;
  +    /**
     * Binds the Identities Primary key values to the statement.
  +     * @param stmt
  +     * @param oid
  +     * @param cld ClassDescriptor for the Object, if <i>null</i> will be lookup automatic
     */
  +    void bindDelete(PreparedStatement stmt, Identity oid, ClassDescriptor cld) throws java.sql.SQLException;
       /**
     * binds the objects primary key and locking values to the statement, BRJ
     */
       void bindDelete(PreparedStatement stmt, ClassDescriptor cld, Object obj)
        throws java.sql.SQLException;
       /**
     * bind a Query based Select Statement
     */
       int bindStatement(PreparedStatement stmt, Criteria crit, ClassDescriptor cld, int param)
        throws SQLException;
       /**
     * binds the values of the object obj to the statements parameters
     */
       void bindInsert(PreparedStatement stmt, ClassDescriptor cld, Object obj)
		throws SQLException;
  -    /**
     * binds the Identities Primary key values to the statement
     */
  -    void bindSelect(PreparedStatement stmt, Identity oid) throws SQLException;
  +    /**
     * binds the Identities Primary key values to the statement
  +     * @param stmt
  +     * @param oid
  +     * @param cld ClassDescriptor for the Object, if <i>null</i> will be lookup automatic
     */
  +    void bindSelect(PreparedStatement stmt, Identity oid, ClassDescriptor cld) throws SQLException;
       /**
     * binds the values of the object obj to the statements parameters
     */
       void bindUpdate(PreparedStatement stmt, ClassDescriptor cld, Object obj)
        throws SQLException;
       /**
     * return a prepared DELETE Statement fitting for the given ClassDescriptor
     */
  
  
  
  1.4       +10 -12    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementsForClassIF.java
  
  Index: StatementsForClassIF.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementsForClassIF.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StatementsForClassIF.java	5 Jul 2002 21:58:51 -0000	1.3
  +++ StatementsForClassIF.java	24 Dec 2002 13:02:19 -0000	1.4
  @@ -3,7 +3,7 @@
    * User: matthew.baird
    * Date: May 12, 2002
    * Time: 10:32:40 PM
  - * To change template for new interface use 
  + * To change template for new interface use
    * Code Style | Class Templates options (Tools | IDE Options).
    */
   package org.apache.ojb.broker.accesslayer;
  @@ -67,6 +67,7 @@
   import java.sql.PreparedStatement;
   import java.sql.SQLException;
   import java.sql.Statement;
  +import java.sql.Connection;
   
   public interface StatementsForClassIF
   {
  @@ -75,51 +76,48 @@
        * @return java.sql.PreparedStatement
        */
   
  -	PreparedStatement getDeleteStmt() throws SQLException;
  +	PreparedStatement getDeleteStmt(Connection con) throws SQLException;
   
   	/**
        * returns a generic unprepared Statement used for clazz.
        * @return java.sql.Statement
        */
   
  -	Statement getGenericStmt(boolean scrollable) throws PersistenceBrokerSQLException;
  +	Statement getGenericStmt(Connection con,boolean scrollable) throws PersistenceBrokerSQLException;
   
   	/**
        * returns the INSERT Statement used for clazz.
        * @return java.sql.PreparedStatement
        */
   
  -	PreparedStatement getInsertStmt() throws SQLException;
  +	PreparedStatement getInsertStmt(Connection con) throws SQLException;
   
   	/**
        * returns a prepared Statement used for clazz.
        * @return java.sql.Statement
        */
   
  -	PreparedStatement getPreparedStmt(String sql, boolean scrollable) throws PersistenceBrokerSQLException;
  +	PreparedStatement getPreparedStmt(Connection con, String sql, boolean scrollable) throws PersistenceBrokerSQLException;
   
   	/**
        * returns the SELECT Statement used for clazz.
        * @return java.sql.PreparedStatement
        */
   
  -	PreparedStatement getSelectByPKStmt() throws SQLException;
  +	PreparedStatement getSelectByPKStmt(Connection con) throws SQLException;
   
   	/**
        * returns the UPDATE Statement used for clazz.
        * @return java.sql.PreparedStatement
        */
   
  -	PreparedStatement getUpdateStmt() throws SQLException;
  -	
  +	PreparedStatement getUpdateStmt(Connection con) throws SQLException;
  +
   	/**
   	 * For single VM operation to not eat up Oracle resources, we need to close
   	 * the statements unless they are cached.
  -	 *  
  +	 *
   	 * @return if the statement is of type select, insert, update, or delete
  -	 * 
   	 */
  -	
   	boolean isCached(Statement stmt);
  -	
   }
  
  
  
  1.9       +55 -75    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java
  
  Index: StatementsForClassImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/StatementsForClassImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- StatementsForClassImpl.java	20 Dec 2002 02:11:34 -0000	1.8
  +++ StatementsForClassImpl.java	24 Dec 2002 13:02:19 -0000	1.9
  @@ -53,23 +53,25 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  -import org.apache.ojb.broker.PersistenceBrokerSQLException;
  -import org.apache.ojb.broker.PersistenceBroker;
  +
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.PersistenceBrokerSQLException;
  +import org.apache.ojb.broker.accesslayer.sql.SqlGenerator;
  +import org.apache.ojb.broker.accesslayer.sql.SqlGeneratorFactory;
  +import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
   import org.apache.ojb.broker.platforms.Platform;
  -import org.apache.ojb.broker.platforms.PlatformFactory;
   import org.apache.ojb.broker.platforms.PlatformException;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
  -import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.platforms.PlatformFactory;
   import org.apache.ojb.broker.query.Query;
  -import org.apache.ojb.broker.accesslayer.sql.*;
  -import org.apache.ojb.broker.metadata.ClassDescriptor;
  +import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  +import java.sql.Connection;
   import java.sql.PreparedStatement;
  +import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Statement;
  -import java.sql.Connection;
  -import java.sql.ResultSet;
   
   /**
    * This class serves as a cache for Statements that are
  @@ -80,36 +82,34 @@
   {
       private Logger log = LoggerFactory.getLogger(StatementsForClassImpl.class);
   
  -    protected ClassDescriptor classDescriptor;
  -    protected ConnectionManagerIF connectionManager;
  +    /**
  +     * sets the escape processing mode
  +     */
  +    // protected static boolean ESCAPEPROCESSING = false;
  +
  +    protected final ClassDescriptor classDescriptor;
       protected SqlGenerator sqlGenerator;
       protected Platform platform;
  -    private PersistenceBroker broker;
  -    private Class clazz;
  +    protected Class clazz;
       private String deleteSql;
       private String insertSql;
       private String updateSql;
       private String selectByPKSql;
  -    /**
  -     * sets the escape processing mode
  -     */
  -    protected static boolean ESCAPEPROCESSING = false;
  +
       /**
        * force use of JDBC 1.0 statement creation
        */
       protected boolean FORCEJDBC1_0 = false;
   
  -    public StatementsForClassImpl(PersistenceBroker broker, ClassDescriptor classDescriptor)
  +    public StatementsForClassImpl(final JdbcConnectionDescriptor jcd, final ClassDescriptor classDescriptor)
       {
  -        this.broker = broker;
           this.classDescriptor = classDescriptor;
           clazz = classDescriptor.getClassOfObject();
  -        connectionManager = broker.getConnectionManager();
  -        sqlGenerator = SqlGeneratorFactory.getInstance().createSqlGenerator();
  -        platform = PlatformFactory.getPlatformFor(broker.getDescriptorRepository().getDefaultJdbcConnection());
  +        platform = PlatformFactory.getPlatformFor(jcd);
  +        sqlGenerator = SqlGeneratorFactory.getInstance().createSqlGenerator(platform);
   
           // detect JDBC level
  -        double level = classDescriptor.getConnectionDescriptor().getJdbcLevel();
  +        double level = jcd.getJdbcLevel();
           if (level == 1.0)
           {
               FORCEJDBC1_0 = true;
  @@ -125,7 +125,7 @@
           return false;
       }
   
  -    public PreparedStatement getDeleteStmt() throws SQLException
  +    public PreparedStatement getDeleteStmt(Connection con) throws SQLException
       {
           if (deleteSql == null)
           {
  @@ -133,23 +133,23 @@
           }
           try
           {
  -            return prepareStatement(deleteSql, Query.NOT_SCROLLABLE);
  +            return prepareStatement(con, deleteSql, Query.NOT_SCROLLABLE);
           }
  -        catch (java.sql.SQLException ex)
  +        catch (SQLException ex)
           {
               log.error(ex);
               throw ex;
           }
       }
   
  -    public Statement getGenericStmt(boolean scrollable) throws PersistenceBrokerSQLException
  +    public Statement getGenericStmt(Connection con, boolean scrollable) throws PersistenceBrokerSQLException
       {
           Statement stmt = null;
           try
           {
  -            stmt = createStatement(scrollable);
  +            stmt = createStatement(con, scrollable);
           }
  -        catch (java.sql.SQLException ex)
  +        catch (SQLException ex)
           {
               log.error(ex);
               throw new PersistenceBrokerSQLException(ex);
  @@ -157,7 +157,7 @@
           return stmt;
       }
   
  -    public PreparedStatement getInsertStmt() throws SQLException
  +    public PreparedStatement getInsertStmt(Connection con) throws SQLException
       {
           if (insertSql == null)
           {
  @@ -165,27 +165,27 @@
           }
           try
           {
  -            return prepareStatement(insertSql, Query.NOT_SCROLLABLE);
  +            return prepareStatement(con, insertSql, Query.NOT_SCROLLABLE);
           }
  -        catch (java.sql.SQLException ex)
  +        catch (SQLException ex)
           {
               log.error(ex);
               throw ex;
           }
       }
   
  -    public PreparedStatement getPreparedStmt(String sql, boolean scrollable) throws PersistenceBrokerSQLException
  +    public PreparedStatement getPreparedStmt(Connection con, String sql, boolean scrollable) throws PersistenceBrokerSQLException
       {
           PreparedStatement stmt = null;
           try
           {
  -			/**
  -			 * always create scrollable resultsets because we are caching the statement
  -			 * if we want to refactor to remove the caching of statements, we might as well
  -			 * just move to the use of the SQLCachingStatementsForClass as it does this already
  -			 */
  +            /**
  +             * always create scrollable resultsets because we are caching the statement
  +             * if we want to refactor to remove the caching of statements, we might as well
  +             * just move to the use of the SQLCachingStatementsForClass as it does this already
  +             */
   
  -            stmt = prepareStatement(sql, scrollable);
  +            stmt = prepareStatement(con, sql, Query.SCROLLABLE);
           }
           catch (java.sql.SQLException ex)
           {
  @@ -195,7 +195,7 @@
           return stmt;
       }
   
  -    public PreparedStatement getSelectByPKStmt() throws SQLException
  +    public PreparedStatement getSelectByPKStmt(Connection con) throws SQLException
       {
           if (selectByPKSql == null)
           {
  @@ -203,16 +203,16 @@
           }
           try
           {
  -            return prepareStatement(selectByPKSql, Query.NOT_SCROLLABLE);
  +            return prepareStatement(con, selectByPKSql, Query.NOT_SCROLLABLE);
           }
  -        catch (java.sql.SQLException ex)
  +        catch (SQLException ex)
           {
               log.error(ex);
               throw ex;
           }
       }
   
  -    public PreparedStatement getUpdateStmt() throws SQLException
  +    public PreparedStatement getUpdateStmt(Connection con) throws SQLException
       {
           if (updateSql == null)
           {
  @@ -220,9 +220,9 @@
           }
           try
           {
  -            return prepareStatement(updateSql, Query.NOT_SCROLLABLE);
  +            return prepareStatement(con, updateSql, Query.NOT_SCROLLABLE);
           }
  -        catch (java.sql.SQLException ex)
  +        catch (SQLException ex)
           {
               log.error(ex);
               throw ex;
  @@ -232,18 +232,8 @@
       /**
        * prepares a statement with parameters that should work with most RDBMS
        */
  -    protected PreparedStatement prepareStatement(String sql, boolean scrollable) throws SQLException
  +    protected PreparedStatement prepareStatement(Connection con, String sql, boolean scrollable) throws SQLException
       {
  -        Connection connection;
  -        try
  -        {
  -            connection = connectionManager.getConnection();
  -        }
  -        catch (LookupException e)
  -        {
  -            log.error("Can't get connection from ConnectionManager", e);
  -            throw new PersistenceBrokerException(e);
  -        }
           PreparedStatement result = null;
   
           // if a JDBC1.0 driver is used the signature
  @@ -254,20 +244,20 @@
               // if necessary use JDB1.0 methods
               if (!FORCEJDBC1_0)
               {
  -                result = connection.prepareStatement(sql,
  +                result = con.prepareStatement(sql,
                           scrollable ? ResultSet.TYPE_SCROLL_INSENSITIVE : ResultSet.TYPE_FORWARD_ONLY,
                           ResultSet.CONCUR_READ_ONLY);
               }
               else
               {
  -                result = connection.prepareStatement(sql);
  +                result = con.prepareStatement(sql);
               }
           }
           catch (AbstractMethodError err)
           {
               // this exception is raised if Driver is not JDBC 2.0 compliant
               log.warn("Used driver seems not JDBC 2.0 compatible, use the JDBC 1.0 mode", err);
  -            result = connection.prepareStatement(sql);
  +            result = con.prepareStatement(sql);
               FORCEJDBC1_0 = true;
           }
           catch (SQLException eSql)
  @@ -278,7 +268,7 @@
               if (eSql.getClass().getName().equals("interbase.interclient.DriverNotCapableException"))
               {
                   log.warn("JDBC 2.0 problems with this interbase driver, we use the JDBC 1.0 mode");
  -                result = connection.prepareStatement(sql);
  +                result = con.prepareStatement(sql);
                   FORCEJDBC1_0 = true;
               }
               else
  @@ -300,31 +290,21 @@
       /**
        * creates a statement with parameters that should work with most RDBMS
        */
  -    private Statement createStatement(boolean scrollable) throws java.sql.SQLException
  +    private Statement createStatement(Connection con, boolean scrollable) throws java.sql.SQLException
       {
  -        Connection connection;
  -        try
  -        {
  -            connection = connectionManager.getConnection();
  -        }
  -        catch (LookupException e)
  -        {
  -            log.error("Can't get connection from ConnectionManager", e);
  -            throw new PersistenceBrokerException(e);
  -        }
           Statement result = null;
           try
           {
               // if necessary use JDBC1.0 methods
               if (!FORCEJDBC1_0)
               {
  -                result = connection.createStatement(
  +                result = con.createStatement(
                           scrollable ? ResultSet.TYPE_SCROLL_INSENSITIVE : ResultSet.TYPE_FORWARD_ONLY,
                           ResultSet.CONCUR_READ_ONLY);
               }
               else
               {
  -                result = connection.createStatement();
  +                result = con.createStatement();
               }
           }
           catch (AbstractMethodError err)
  @@ -333,7 +313,7 @@
               // createStatement(int, int) is  not defined.
               // we then call the JDBC1.0 variant createStatement()
               log.warn("Used driver seems not JDBC 2.0 compatible, use the JDBC 1.0 mode", err);
  -            result = connection.createStatement();
  +            result = con.createStatement();
               FORCEJDBC1_0 = true;
           }
           catch (SQLException eSql)
  @@ -345,7 +325,7 @@
               {
                   log.warn("JDBC 2.0 problems with this interbase driver, we use the JDBC 1.0 mode");
                   FORCEJDBC1_0 = true;
  -                result = connection.createStatement();
  +                result = con.createStatement();
               }
               else
               {
  
  
  
  1.23      +131 -126  jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java
  
  Index: RsIterator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/RsIterator.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- RsIterator.java	20 Dec 2002 19:25:30 -0000	1.22
  +++ RsIterator.java	24 Dec 2002 13:02:19 -0000	1.23
  @@ -54,6 +54,15 @@
    * <http://www.apache.org/>.
    */
   
  +import java.sql.SQLException;
  +import java.sql.ResultSet;
  +import java.util.Collection;
  +import java.util.HashMap;
  +import java.util.List;
  +import java.util.Map;
  +import java.util.NoSuchElementException;
  +import java.util.Vector;
  +
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.VirtualProxy;
  @@ -62,6 +71,7 @@
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.DescriptorRepository;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  +import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
   import org.apache.ojb.broker.platforms.PlatformFactory;
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.singlevm.LoadedObjectsRegistry;
  @@ -69,10 +79,6 @@
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  -import java.sql.SQLException;
  -import java.sql.ResultSet;
  -import java.util.*;
  -
   /**
    * RsIterator can be used to iterate over a jdbc ResultSet to retrieve
    * persistent objects step-by-step and not all at once.
  @@ -93,7 +99,7 @@
    */
   public class RsIterator implements OJBIterator
   {
  -	protected Logger logger;
  +	protected Logger logger = LoggerFactory.getLogger(this.getClass());
   
   	protected static ObjectCache cache = ObjectCacheFactory.getInstance().getObjectCache();
   
  @@ -132,22 +138,43 @@
   	 */
   	protected boolean hasCalledCheck = false;
   
  -	/**
  -	 * prefetch relationship:
  -	 * inBatchedMode true prevents releasing of DbResources
  -	 * IN_LIMIT defines the max number of values of sql (IN) , -1 for no limits
  -	 */
  -	protected boolean inBatchedMode = false;
  +    /**
  +     * prefetch relationship:
  +     * inBatchedMode true prevents releasing of DbResources
  +     * IN_LIMIT defines the max number of values of sql (IN) , -1 for no limits
  +     */
  +    protected boolean inBatchedMode = false;
   
   	/**
   	 * return value of the previously called hasNext from m_rs
   	 */
   	protected boolean hasNext = false;
  -
   	private boolean advancedJDBCSupport = false;
   	private boolean JDBCSupportAssessed = false;
   	private Query m_query = null;
  -	private int m_current_row = 0;
  +    private int m_current_row = 0;
  +
  +    protected RsIterator()
  +    {
  +    }
  +
  +    /**
  +	 * RsIterator constructor.
  +	 * @param query the SELECT producing the underlying resultset
  +	 * @param mif ClassDescriptor of the result-class
  +	 * @param broker the broker we should use.
  +	 */
  +	public RsIterator(Query query, ClassDescriptor mif, PersistenceBrokerImpl broker)
  +	{
  +		if (logger.isDebugEnabled())  logger.debug("RsIterator(" + query + ", " + mif + ")");
  +		m_rsAndStmt = new JdbcAccess(broker).executeQuery(query, mif);
  +		m_row = new HashMap();
  +		m_query = query;
  +		m_broker = broker;
  +		m_cld = mif;
  +		itemProxyClass = mif.getProxyClass();
  +  	    prefetchRelationships(query);
  +	}
   
   	protected Class getExtentClass()
   	{
  @@ -200,10 +227,10 @@
   			if (hasNext)
   			{
   				Object obj = getObjectFromResultSet();
  -				m_current_row++;
  +                m_current_row++;
   
   				// Invoke events on PersistenceBrokerAware instances and listeners
  -				m_broker.invokeEvent(obj, PersistenceBrokerImpl.EVENT_AFTER_LOOKUP);
  +                m_broker.fireBrokerEvent(obj,PersistenceBrokerImpl.EVENT_AFTER_LOOKUP);
   
   				return obj;
   			}
  @@ -226,36 +253,9 @@
   		throw new UnsupportedOperationException("removing not supported by RsIterator");
   	}
   
  -	protected RsIterator()
  -	{
  -		logger = LoggerFactory.getLogger(this.getClass());
  -	}
  -
  -	/**
  -	 * RsIterator constructor.
  -	 * @param query the SELECT producing the underlying resultset
  -	 * @param mif ClassDescriptor of the result-class
  -	 * @param broker the broker we should use.
  -	 */
  -	public RsIterator(Query query, ClassDescriptor mif, PersistenceBrokerImpl broker)
  -	{
  -		this();
  -		if (logger.isDebugEnabled()) logger.debug("RsIterator(" + query + ", " + mif + ")");
  -
  -		m_rsAndStmt = new JdbcAccess(broker).executeQuery(query, mif);
  -		m_row = new HashMap();
  -		m_query = query;
  -		m_broker = broker;
  -		m_cld = mif;
  -		itemProxyClass = mif.getProxyClass();
  -
  -		prefetchRelationships(query);
  -	}
  -
  -
  -	/**
  -	 * read all objects of this iterator. objects will be placed in cache
  -	 */
  +    /**
  +     * read all objects of this iterator. objects will be placed in cache
  +     */
   	private Collection getOwnerObjects()
   	{
   		Collection owners = new Vector();
  @@ -266,58 +266,58 @@
   		return owners;
   	}
   
  -	/**
  -	 * prefetch defined relationships
  -	 * requires JDBC level 2.0, does not work with Arrays
  -	 */
  +    /**
  +     * prefetch defined relationships
  +     * requires JDBC level 2.0, does not work with Arrays
  +     */
   	private void prefetchRelationships(Query query)
   	{
  -		List prefetchedRel;
  +        List prefetchedRel;
   		Collection owners;
  -		String relName;
  +        String relName;
   		RelationshipPrefetcher[] prefetchers;
   
   		if (query == null ||
  -				query.getCriteria() == null ||
  -				query.getCriteria().getPrefetchedRelationships().isEmpty())
  +			query.getCriteria() == null ||
  +			query.getCriteria().getPrefetchedRelationships().isEmpty())
   		{
   			return;
   		}
   
  -		if (!supportsAdvancedJDBCCursorControl())
  -		{
  -			logger.info("prefetching relationships requires JDBC level 2.0");
  -			return;
  -		}
  +        if (!supportsAdvancedJDBCCursorControl())
  +        {
  +            logger.info("prefetching relationships requires JDBC level 2.0");
  +            return;
  +        }
   
  -		// prevent releasing of DBResources
  -		inBatchedMode = true;
  +        // prevent releasing of DBResources
  +        inBatchedMode = true;
   
   		prefetchedRel = query.getCriteria().getPrefetchedRelationships();
   		prefetchers = new RelationshipPrefetcher[prefetchedRel.size()];
   
  -		// disable auto retrieve for all prefetched relationships
  -		for (int i = 0; i < prefetchedRel.size(); i++)
  -		{
  -			relName = (String) prefetchedRel.get(i);
  -			prefetchers[i] = RelationshipPrefetcherFactory.createRelationshipPrefetcher(m_broker, m_cld, relName);
  -			prefetchers[i].prepareRelationshipSettings();
  -		}
  -
  -		// materialize ALL owners of this Iterator
  -		owners = getOwnerObjects();
  -
  -		// prefetch relationships and associate with owners
  -		for (int i = 0; i < prefetchedRel.size(); i++)
  -		{
  -			prefetchers[i].prefetchRelationship(owners);
  -		}
  -
  -		// reset auto retrieve for all prefetched relationships
  +        // disable auto retrieve for all prefetched relationships
   		for (int i = 0; i < prefetchedRel.size(); i++)
   		{
  -			prefetchers[i].restoreRelationshipSettings();
  -		}
  +            relName = (String) prefetchedRel.get(i);
  +            prefetchers[i] = RelationshipPrefetcherFactory.createRelationshipPrefetcher(m_broker, m_cld, relName);
  +            prefetchers[i].prepareRelationshipSettings();
  +		}
  +
  +        // materialize ALL owners of this Iterator
  +        owners = getOwnerObjects();
  +
  +        // prefetch relationships and associate with owners
  +        for (int i = 0; i < prefetchedRel.size(); i++)
  +        {
  +        	prefetchers[i].prefetchRelationship(owners);
  +        }
  +
  +        // reset auto retrieve for all prefetched relationships
  +        for (int i = 0; i < prefetchedRel.size(); i++)
  +        {
  +            prefetchers[i].restoreRelationshipSettings();
  +        }
   
   		try
   		{
  @@ -325,11 +325,11 @@
   		}
   		catch (SQLException e)
   		{
  -			logger.error("beforeFirst failed !", e);
  +            logger.error("beforeFirst failed !",e);
   		}
   
  -		inBatchedMode = false;
  -		hasCalledCheck = false;
  +        inBatchedMode = false;
  +        hasCalledCheck = false;
   
   	}
   
  @@ -375,14 +375,14 @@
   		if (itemProxyClass != null)
   		{
   			// provide m_row with primary key data of current row
  -			m_cld.getRowReader().readPkValuesFrom(m_rsAndStmt.m_rs, m_cld, m_row);
  +			m_cld.getRowReader().readPkValuesFrom(m_rsAndStmt.m_rs, m_row);
   			// assert: m_row is filled with primary key values from db
   			return getProxyFromResultSet();
   		}
   		else
   		{
   			// 0. provide m_row with data of current row
  -			m_cld.getRowReader().readObjectArrayFrom(m_rsAndStmt.m_rs, m_cld, m_row);
  +			m_cld.getRowReader().readObjectArrayFrom(m_rsAndStmt.m_rs, m_row);
   			// assert: m_row is filled from db
   
   			// 1.read Identity
  @@ -395,32 +395,32 @@
   			{
   				// 3. If Object is not in cache
   				// materialize Object with primitive attributes filled from current row
  -				result = m_cld.getRowReader().readObjectFrom(m_row, m_cld);
  +				result = m_cld.getRowReader().readObjectFrom(m_row);
   				// result may still be null!
   				if (result != null)
   				{
  -					/*
  -					 * synchronize on result so the ODMG-layer can take a snapshot only of
  -					 * fully cached (i.e. with all references + collections) objects
  -					 */
  -					synchronized (result)
  -					{
  -						cache.cache(oid, result);
  -						LoadedObjectsRegistry.register(result);
  -						/**
  -						 * MBAIRD
  -						 * if you have multiple classes mapped to a table, and you query on the base class
  -						 * you could get back NON base class objects, so we shouldn't pass m_cld, but rather
  -						 * the class descriptor for the actual class.
  -						 */
  -						// fill reference and collection attributes
  -						ClassDescriptor cld = m_cld.getRepository().getDescriptorFor(result.getClass());
  -						// don't force loading of reference
  -						final boolean unforced = false;
  -						m_broker.retrieveReferences(result, cld, unforced);
  -						m_broker.retrieveCollections(result, cld, unforced);
  -					}
  -				}
  +                   /*
  +                    * synchronize on result so the ODMG-layer can take a snapshot only of
  +                    * fully cached (i.e. with all references + collections) objects
  +                    */
  +                    synchronized(result)
  +                    {
  +					   cache.cache(oid, result);
  +				           LoadedObjectsRegistry.register(result);
  +					   /**
  +					   * MBAIRD
  +					   * if you have multiple classes mapped to a table, and you query on the base class
  +					   * you could get back NON base class objects, so we shouldn't pass m_cld, but rather
  +					   * the class descriptor for the actual class.
  +					   */
  +					   // fill reference and collection attributes
  +					   ClassDescriptor cld = m_cld.getRepository().getDescriptorFor(result.getClass());
  +					   // don't force loading of reference
  +					   final boolean unforced = false;
  +					   m_broker.retrieveReferences(result, cld, unforced);
  +					   m_broker.retrieveCollections(result, cld, unforced);
  +				    }
  +                }
   			}
   			else
   			{
  @@ -458,7 +458,7 @@
   	{
   		if (!JDBCSupportAssessed)
   		{
  -			if (m_cld.getConnectionDescriptor().getJdbcLevel() >= 2.0)
  +			if (getConnectionDescriptor().getJdbcLevel() >= 2.0)
   				advancedJDBCSupport = true;
   			JDBCSupportAssessed = true;
   		}
  @@ -474,7 +474,7 @@
   		return m_broker.getCount(m_query);
   	}
   
  -	/**
  +    /**
   	 *
   	 * @return the size of the iterator, aka the number of rows in this iterator.
   	 */
  @@ -490,7 +490,7 @@
   		{
   		}
   		if (!supportsAdvancedJDBCCursorControl()
  -			|| PlatformFactory.getPlatformFor(m_cld.getConnectionDescriptor()).useCountForResultsetSize()
  +            || m_broker.serviceConnectionManager().getSupportedPlatform().useCountForResultsetSize()
   			|| forwardOnly)
   		{
   			/**
  @@ -557,8 +557,8 @@
   				if (m_rsAndStmt.m_rs != null)
   				{
   					retval = m_rsAndStmt.m_rs.absolute(row);
  -					m_current_row = row;
  -					hasCalledCheck = false;
  +                                        m_current_row = row;
  +                                        hasCalledCheck = false;
   				}
   			}
   			catch (SQLException e)
  @@ -619,7 +619,7 @@
   				if (m_rsAndStmt.m_rs != null)
   				{
   					retval = m_rsAndStmt.m_rs.relative(row);
  -					m_current_row += row;
  +                                        m_current_row += row;
   				}
   			}
   			catch (SQLException e)
  @@ -629,14 +629,14 @@
   		}
   		else
   		{
  -			if (row >= 0)
  -			{
  -				return absolute(m_current_row + row);
  -			}
  -			else
  -			{
  -				logger.info("Your driver does not support advanced JDBC Functionality, you cannot call relative() with a negative value");
  -			}
  +                    if (row >= 0)
  +                    {
  +                        return absolute(m_current_row + row);
  +                    }
  +                    else
  +                    {
  +			logger.info("Your driver does not support advanced JDBC Functionality, you cannot call relative() with a negative value");
  +                    }
   		}
   		return retval;
   	}
  @@ -649,10 +649,10 @@
   	 */
   	public void releaseDbResources()
   	{
  -		if (!inBatchedMode)     // resources are reused in batched mode
  -		{
  -			m_broker.getStatementManager().closeResources(m_rsAndStmt.m_stmt, m_rsAndStmt.m_rs);
  -		}
  +        if (!inBatchedMode)     // resources are reused in batched mode
  +        {
  +		  m_broker.serviceStatementManager().closeResources(m_rsAndStmt.m_stmt, m_rsAndStmt.m_rs);
  +        }
   	}
   
   	/**
  @@ -662,4 +662,9 @@
   	{
   		return m_broker.getDescriptorRepository();
   	}
  +
  +    protected JdbcConnectionDescriptor getConnectionDescriptor()
  +    {
  +        return m_broker.serviceConnectionManager().getConnectionDescriptor();
  +    }
   }
  
  
  
  1.13      +78 -59    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
  
  Index: RowReaderDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- RowReaderDefaultImpl.java	9 Nov 2002 00:51:36 -0000	1.12
  +++ RowReaderDefaultImpl.java	24 Dec 2002 13:02:19 -0000	1.13
  @@ -54,26 +54,35 @@
    * <http://www.apache.org/>.
    */
   
  -import java.lang.reflect.Constructor;
  -import java.lang.reflect.InvocationTargetException;
  -import java.sql.ResultSet;
  -import java.sql.SQLException;
  -import java.util.Map;
  -
   import org.apache.ojb.broker.PBFactoryException;
  -import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
  -import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   
  +import java.lang.reflect.Constructor;
  +import java.lang.reflect.InvocationTargetException;
  +import java.sql.ResultSet;
  +import java.sql.SQLException;
  +import java.util.Map;
  +
   /**
    * @version $Id$
    */
   
   public class RowReaderDefaultImpl implements RowReader
   {
  +    private ClassDescriptor cld;
  +
  +//    public RowReaderDefaultImpl()
  +//    {
  +//    }
  +
  +    public RowReaderDefaultImpl(ClassDescriptor cld)
  +    {
  +        this.cld = cld;
  +    }
  +
       /**
        * materialize a single object, described by cld,
        * from the first row of the ResultSet rs.
  @@ -101,11 +110,11 @@
        * same table.
        *
        */
  -    public Object readObjectFrom(Map row, ClassDescriptor descriptor) throws PersistenceBrokerException
  +    public Object readObjectFrom(Map row) throws PersistenceBrokerException
       {
           // allow to select a specific classdescriptor
  -        ClassDescriptor cld = selectClassDescriptor(row, descriptor);
  -        return buildWithReflection(cld, row);
  +        ClassDescriptor cld = selectClassDescriptor(row);
  +        return buildWithReflection(row, cld);
       }
   
       /**
  @@ -126,18 +135,20 @@
        *
        * @throws PersistenceBrokerException if there is an error accessing the access layer
        */
  -    public void readObjectArrayFrom(ResultSet rs, ClassDescriptor cld, Map row)
  +    public void readObjectArrayFrom(ResultSet rs, Map row)
       {
           FieldDescriptor[] fields = null;
   
  -        if(cld.getSuperClass() != null){
  +        if (cld.getSuperClass() != null)
  +        {
               /**
                * treeder
                * append super class fields if exist
                */
  -           fields =  cld.getFieldDescriptorsInHeirarchy();
  +            fields = cld.getFieldDescriptorsInHeirarchy();
           }
  -        else{
  +        else
  +        {
               fields = cld.getRepository().getFieldDescriptorsForMultiMappedTable(cld);
   
           }
  @@ -147,70 +158,67 @@
           Object val = null;
           try
           {
  -             for (int j=0; j< size; j++)
  -             {
  -                 fmd = fields[j];
  -                 conversion = fmd.getFieldConversion();
  -                 val = JdbcAccess.getObjectFromColumn(rs, fmd);
  -                 row.put(fmd.getColumnName() , conversion.sqlToJava(val));
  -             }
  +            for (int j = 0; j < size; j++)
  +            {
  +                fmd = fields[j];
  +                conversion = fmd.getFieldConversion();
  +                val = JdbcAccess.getObjectFromColumn(rs, fmd);
  +                row.put(fmd.getColumnName(), conversion.sqlToJava(val));
  +            }
           }
           catch (SQLException t)
           {
  -            throw new PersistenceBrokerException("Error reading from result set",t);
  +            throw new PersistenceBrokerException("Error reading from result set", t);
           }
       }
   
  -    protected ClassDescriptor selectClassDescriptor(Map row, ClassDescriptor cld) throws PersistenceBrokerException
  +    /**
  +     * Check if there is an attribute which tells us which concrete class is to be instantiated.
  +     */
  +    protected ClassDescriptor selectClassDescriptor(Map row) throws PersistenceBrokerException
       {
           // check if there is an attribute which tells us which concrete class is to be instantiated
  -		FieldDescriptor concreteClassFD = cld.getFieldDescriptorByName(ClassDescriptor.OJB_CONCRETE_CLASS);
  +        FieldDescriptor concreteClassFD = cld.getFieldDescriptorByName(ClassDescriptor.OJB_CONCRETE_CLASS);
   
           if (concreteClassFD == null)
               return cld;
           else
           {
  -            PersistenceBroker broker = null;
               try
               {
                   String concreteClass = (String) row.get(concreteClassFD.getColumnName());
                   if (concreteClass == null || concreteClass.trim().length() == 0)
  -                	throw new PersistenceBrokerException("ojbConcreteClass field returned null or 0-length string");
  +                {
  +                    throw new PersistenceBrokerException(
  +                            "ojbConcreteClass field returned null or 0-length string");
  +                }
                   else
  -                	concreteClass = concreteClass.trim();
  -                broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -                ClassDescriptor result = broker.getClassDescriptor(Class.forName(concreteClass, true, Thread.currentThread().getContextClassLoader()));
  +                {
  +                    concreteClass = concreteClass.trim();
  +                }
  +                ClassDescriptor result = cld.getRepository().getDescriptorFor(concreteClass);
                   if (result == null)
                   {
  -                	result = cld;
  +                    result = cld;
                   }
  -
                   return result;
               }
  -            catch (ClassNotFoundException e)
  +            catch (PBFactoryException e)
               {
                   throw new PersistenceBrokerException(e);
               }
  -            catch (PBFactoryException pbfe)
  -            {
  -            	throw new PersistenceBrokerException(pbfe);
  -            }
  -            finally
  -            {
  -            	if (broker != null)
  -            	{
  -            		broker.close();
  -            	}
  -            }
           }
       }
   
       /**
        * Creates an object instance according to clb, and fills its fileds width data provided by row.
  -     * @throws MetadataException if there was an error setting the field of a new object with values from row
  +     * @param row A {@link Map} contain the Object/Row mapping for the object.
  +     * @param targetClassDescriptor If the "ojbConcreteClass" feature was used, the target
  +     * {@link org.apache.ojb.broker.metadata.ClassDescriptor} could differ from the descriptor
  +     * this class was associated - see {@link #selectClassDescriptor}.
        * @throws PersistenceBrokerException if there ewas an error creating the new object
        */
  -    protected Object buildWithReflection(ClassDescriptor cld, Map row)
  +    protected Object buildWithReflection(Map row, ClassDescriptor targetClassDescriptor)
       {
           Object result;
           FieldDescriptor fmd;
  @@ -218,10 +226,10 @@
           {
   
               // 1. create an empty Object (persistent classes need a public default constructor)
  -            Class c = cld.getClassOfObject();
  +            Class c = targetClassDescriptor.getClassOfObject();
               result = c.newInstance();
               // 2. fill all scalar attributes of the new object
  -            FieldDescriptor[] fields = cld.getFieldDescriptions();
  +            FieldDescriptor[] fields = targetClassDescriptor.getFieldDescriptions();
               for (int i = 0; i < fields.length; i++)
               {
                   fmd = fields[i];
  @@ -229,14 +237,16 @@
               }
               return result;
           }
  -        catch(Exception ex)
  +        catch (Exception ex)
           {
  -            throw new PersistenceBrokerException("Unable to build object instance (MAYBE you don't have a constructor available):"+cld.getClassOfObject(),ex);
  +            throw new PersistenceBrokerException("Unable to build object instance (MAYBE you don't have a constructor available):" + cld.getClassOfObject(), ex);
           }
       }
   
   
  -    protected Object buildWithMultiArgsConstructor(ClassDescriptor cld, Map row, Constructor multiArgsConstructor) throws SQLException, InstantiationException, IllegalAccessException, InvocationTargetException, PersistenceBrokerException
  +    protected Object buildWithMultiArgsConstructor(Map row, Constructor multiArgsConstructor)
  +            throws SQLException, InstantiationException, IllegalAccessException,
  +            InvocationTargetException, PersistenceBrokerException
       {
           Object result;
           // 1. call the constructor to build the object
  @@ -249,10 +259,10 @@
        * @see RowReader#readPkValuesFrom(ResultSet, ClassDescriptor, Map)
        * @throws PersistenceBrokerException if there is an error accessing the access layer
        */
  -    public void readPkValuesFrom(ResultSet rs, ClassDescriptor cld, Map row)
  +    public void readPkValuesFrom(ResultSet rs, Map row)
       {
           try
  -    	{
  +        {
               FieldDescriptor[] pkFields = cld.getPkFields();
               for (int i = 0; i < pkFields.length; i++)
               {
  @@ -261,11 +271,20 @@
                   Object val = JdbcAccess.getObjectFromColumn(rs, fmd);
                   row.put(fmd.getColumnName(), conversion.sqlToJava(val));
               }
  -    	}
  -    	catch (SQLException t)
  -    	{
  -            throw new PersistenceBrokerException("Error reading from result set",t);
  -    	}
  +        }
  +        catch (SQLException t)
  +        {
  +            throw new PersistenceBrokerException("Error reading from result set", t);
  +        }
       }
   
  +    public void setClassDescriptor(ClassDescriptor cld)
  +    {
  +        this.cld = cld;
  +    }
  +
  +    public ClassDescriptor getClassDescriptor()
  +    {
  +        return cld;
  +    }
   }
  
  
  
  1.4       +93 -83    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReader.java
  
  Index: RowReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RowReader.java	19 Jun 2002 14:57:19 -0000	1.3
  +++ RowReader.java	24 Dec 2002 13:02:19 -0000	1.4
  @@ -1,83 +1,93 @@
  -package org.apache.ojb.broker.accesslayer;
  -
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:
  - *       "This product includes software developed by the
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowledgment may appear in the software itself,
  - *    if and wherever such third-party acknowledgments normally appear.
  - *
  - * 4. The names "Apache" and "Apache Software Foundation" and
  - *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
  - *    prior written permission of the Apache Software Foundation.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - */
  -
  -import org.apache.ojb.broker.metadata.ClassDescriptor;
  -
  -import java.io.Serializable;
  -import java.sql.ResultSet;
import java.util.Map;
  -
  -public interface RowReader extends Serializable
  -{
  -    /**
  -     * materialize a single object of a type described by cld,
  -     * from the first row of the ResultSet rs.
  -     * the implementor of this class must not care for materializing
  -     *  references or collection attributes, this is done later!
  -     */
  -    public abstract Object readObjectFrom(Map row, ClassDescriptor cld);
  -
  -	/**
  -	 * Read all fields from the current ResultRow into the Object[] row.#
  -	 * ConversionStrategies are applied here! 
  -	 */
  -	public abstract void readObjectArrayFrom(ResultSet rs, ClassDescriptor cld, Map row);
  -
  -	/**
  -	 * Read primary key fields from the current ResultRow into the Object[] row.#
  -	 * ConversionStrategies are applied here! 
  -	 */
  -	public abstract void readPkValuesFrom(ResultSet rs, ClassDescriptor cld, Map row);
  -}
  +package org.apache.ojb.broker.accesslayer;
  +
  +/* ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + *    if any, must include the following acknowledgment:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
  + *    derived from this software without prior written permission. For
  + *    written permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + *    "Apache ObjectRelationalBridge", nor may "Apache" appear in their name, without
  + *    prior written permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
  +import org.apache.ojb.broker.metadata.ClassDescriptor;
  +
  +import java.io.Serializable;
  +import java.sql.ResultSet;
import java.util.Map;
  +
  +public interface RowReader extends Serializable
  +{
  +    /**
  +     * materialize a single object of a type described by cld,
  +     * from the first row of the ResultSet rs.
  +     * the implementor of this class must not care for materializing
  +     *  references or collection attributes, this is done later!
  +     */
  +    public Object readObjectFrom(Map row);
  +
  +	/**
  +	 * Read all fields from the current ResultRow into the Object[] row.#
  +	 * ConversionStrategies are applied here!
  +	 */
  +	public void readObjectArrayFrom(ResultSet rs, Map row);
  +
  +	/**
  +	 * Read primary key fields from the current ResultRow into the Object[] row.#
  +	 * ConversionStrategies are applied here!
  +	 */
  +	public void readPkValuesFrom(ResultSet rs, Map row);
  +
  +    /**
  +     * Set the descriptor this <i>RowReader</i> worked with.
  +     */
  +    public void setClassDescriptor(ClassDescriptor cld);
  +
  +    /**
  +     * Returns the associated {@link org.apache.ojb.broker.metadata.ClassDescriptor}
  +     */
  +    public ClassDescriptor getClassDescriptor();
  +}
  
  
  
  1.5       +22 -21    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/PkEnumeration.java
  
  Index: PkEnumeration.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/PkEnumeration.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PkEnumeration.java	21 Sep 2002 15:35:14 -0000	1.4
  +++ PkEnumeration.java	24 Dec 2002 13:02:19 -0000	1.5
  @@ -54,21 +54,21 @@
    * <http://www.apache.org/>.
    */
   
  -import java.io.Serializable;
  -import java.lang.reflect.Constructor;
  -import java.sql.SQLException;
  -import java.util.Enumeration;
  -import java.util.NoSuchElementException;
  -
   import org.apache.ojb.broker.Identity;
  +import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
   import org.apache.ojb.broker.PersistenceBrokerSQLException;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.query.Query;
  -import org.apache.ojb.broker.singlevm.PersistenceBrokerImpl;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  +import java.io.Serializable;
  +import java.lang.reflect.Constructor;
  +import java.sql.SQLException;
  +import java.util.Enumeration;
  +import java.util.NoSuchElementException;
  +
   /**
    * this class can be used to create enumerations of PrimaryKey objects.
    * This is interesting for EJB finder methods
  @@ -97,10 +97,11 @@
        */
       protected Constructor constructor;
   
  -	/**
  -	 * the statement manager, we hold on to so we can close resources later.
  -	 */
  -	private StatementManagerIF m_statementManager;
  +    /**
  +     * the statement manager, we hold on to so we can close resources later.
  +     */
  +    private StatementManagerIF m_statementManager;
  +
       /**
        * PkEnumeration constructor.
        * @param query the SELECT statement gerating the underlying resultset
  @@ -108,12 +109,12 @@
        * @param primaryKeyClass the entity classes PrimaryKey class (say ArticleKey).
        * this key-class MUST have a constructor with one argument of type org.apache.ojb.broker.Identity !
        */
  -    public PkEnumeration(Query query, ClassDescriptor cld, Class primaryKeyClass, PersistenceBrokerImpl broker)
  +    public PkEnumeration(Query query, ClassDescriptor cld, Class primaryKeyClass, PersistenceBroker broker)
       {
           ResultSetAndStatement rsAndStmt = new JdbcAccess(broker).executeQuery(query, cld);
           this.resultSetAndStatment = rsAndStmt;
           this.classDescriptor = cld;
  -		this.m_statementManager = broker.getStatementManager();
  +        this.m_statementManager = broker.serviceStatementManager();
           // get a contructor object that can be used to build instances of class primaryKeyClass
           try
           {
  @@ -160,11 +161,11 @@
           }
           catch (SQLException e)
           {
  -            throw new PersistenceBrokerSQLException("Error reading object from column",e);
  +            throw new PersistenceBrokerSQLException("Error reading object from column", e);
           }
           catch (Exception e)
           {
  -            throw new PersistenceBrokerException("Error reading Identity from result set",e);
  +            throw new PersistenceBrokerException("Error reading Identity from result set", e);
           }
       }
   
  @@ -197,10 +198,10 @@
           return hasNext;
       }
   
  -   private void releaseDbResources()
  -   {
  -	   m_statementManager.closeResources(resultSetAndStatment.m_stmt, resultSetAndStatment.m_rs);
  -   }
  +    private void releaseDbResources()
  +    {
  +        m_statementManager.closeResources(resultSetAndStatment.m_stmt, resultSetAndStatment.m_rs);
  +    }
   
       /**
        * Returns the next element of this enumeration if this enumeration
  @@ -218,7 +219,7 @@
               if (hasNext)
               {
                   Identity oid = getIdentityFromResultSet();
  -                Identity[] args = { oid };
  +                Identity[] args = {oid};
                   return this.constructor.newInstance(args);
               }
               else
  
  
  
  1.25      +34 -35    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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- JdbcAccess.java	20 Dec 2002 02:11:34 -0000	1.24
  +++ JdbcAccess.java	24 Dec 2002 13:02:19 -0000	1.25
  @@ -110,13 +110,13 @@
           PreparedStatement stmt = null;
           try
           {
  -            stmt = broker.getStatementManager().getDeleteStatement(cld);
  +            stmt = broker.serviceStatementManager().getDeleteStatement(cld);
               if (stmt == null)
               {
               	logger.error("getDeleteStatement returned a null statement");
               	throw new PersistenceBrokerException("getDeleteStatement returned a null statement");
               }
  -            broker.getStatementManager().bindDelete(stmt, cld, obj);
  +            broker.serviceStatementManager().bindDelete(stmt, cld, obj);
               if (stmt.executeUpdate() == 0 && cld.isLocking()) //BRJ
               {
                   throw new OptimisticLockException("Object has been modified by someone else", obj);
  @@ -140,7 +140,7 @@
           }
          finally
           {
  -			broker.getStatementManager().closeResources(stmt, null);
  +			broker.serviceStatementManager().closeResources(stmt, null);
           }
       }
   
  @@ -157,9 +157,9 @@
   
   		try
   		{
  -			String sql = SqlGeneratorFactory.getInstance().createSqlGenerator().getPreparedDeleteStatement(query, cld);
  -			stmt = broker.getStatementManager().getPreparedStatement(cld, sql, false);
  -			broker.getStatementManager().bindStatement(stmt, query.getCriteria(), cld, 1);
  +			String sql = this.broker.serviceSqlGenerator().getPreparedDeleteStatement(query, cld);
  +			stmt = broker.serviceStatementManager().getPreparedStatement(cld, sql, false);
  +			broker.serviceStatementManager().bindStatement(stmt, query.getCriteria(), cld, 1);
   			stmt.executeUpdate();
   		}
   		catch (SQLException e)
  @@ -169,7 +169,7 @@
   		}
           finally
           {
  -			broker.getStatementManager().closeResources(stmt, null);
  +			broker.serviceStatementManager().closeResources(stmt, null);
           }
   	}
   
  @@ -181,17 +181,17 @@
       public void executeInsert(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
       {
           logger.safeDebug("executeInsert",obj);
  -        
  +
           PreparedStatement stmt = null;
           try
           {
  -            stmt = broker.getStatementManager().getInsertStatement(cld);
  +            stmt = broker.serviceStatementManager().getInsertStatement(cld);
               if (stmt == null)
               {
               	logger.error("getInsertStatement returned a null statement");
               	throw new PersistenceBrokerException("getInsertStatement returned a null statement");
               }
  -            broker.getStatementManager().bindInsert(stmt, cld, obj);
  +            broker.serviceStatementManager().bindInsert(stmt, cld, obj);
               stmt.executeUpdate();
           }
           catch (PersistenceBrokerException e)
  @@ -216,7 +216,7 @@
           }
           finally
           {
  -			broker.getStatementManager().closeResources(stmt, null);
  +			broker.serviceStatementManager().closeResources(stmt, null);
           }
       }
   
  @@ -228,7 +228,7 @@
       ResultSetAndStatement executeQuery(Query query, ClassDescriptor cld) throws PersistenceBrokerException
       {
           logger.safeDebug("executeQuery", query);
  -        
  +
           ResultSetAndStatement retval = new ResultSetAndStatement();
   		/**
   		 * MBAIRD:
  @@ -244,15 +244,14 @@
   		{
   			scrollable = true;
   		}
  -
           try
           {
               // if query has criteria, use them in where clause
               if (query.getCriteria() != null)
               {
  -                String sql = SqlGeneratorFactory.getInstance().createSqlGenerator().getPreparedSelectStatement(query, cld);
  -                PreparedStatement stmt = broker.getStatementManager().getPreparedStatement(cld, sql, scrollable);
  -                broker.getStatementManager().bindStatement(stmt, query.getCriteria(), cld, 1);
  +                String sql = this.broker.serviceSqlGenerator().getPreparedSelectStatement(query, cld);
  +                PreparedStatement stmt = broker.serviceStatementManager().getPreparedStatement(cld, sql, scrollable);
  +                broker.serviceStatementManager().bindStatement(stmt, query.getCriteria(), cld, 1);
                   ResultSet rs = stmt.executeQuery();
                   // as we return the resultset for further operations, we cannot release the statement yet.
                   // that has to be done by the JdbcAccess-clients (i.e. RsIterator, ProxyRsIterator and PkEnumeration.)
  @@ -264,8 +263,8 @@
               // if query has no criteria, perform select * from table
               else
               {
  -                Statement stmt = broker.getStatementManager().getGenericStatement(cld, scrollable);
  -                String sql = SqlGeneratorFactory.getInstance().createSqlGenerator().getSelectStatementDep(query, cld);
  +                Statement stmt = this.broker.serviceStatementManager().getGenericStatement(cld, scrollable);
  +                String sql = this.broker.serviceSqlGenerator().getSelectStatementDep(query, cld);
                   ResultSet rs = stmt.executeQuery(sql);
                   retval.m_rs = rs;
                   retval.m_stmt = stmt;
  @@ -293,11 +292,11 @@
       public ResultSetAndStatement executeSQL(String sqlStatement, ClassDescriptor cld) throws PersistenceBrokerException
       {
           if (logger.isDebugEnabled()) logger.debug("executeSQL: " + sqlStatement);
  -        
  +
           ResultSetAndStatement retval = new ResultSetAndStatement();
           try
           {
  -            Statement stmt = broker.getStatementManager().getGenericStatement(cld, Query.NOT_SCROLLABLE);
  +            Statement stmt = broker.serviceStatementManager().getGenericStatement(cld, Query.SCROLLABLE);
               ResultSet rs = stmt.executeQuery(sqlStatement);
               // as we return the resultset for further operations, we cannot release the statement yet.
               // that has to be done by the JdbcAccess-clients (i.e. RsIterator, ProxyRsIterator and PkEnumeration.)
  @@ -327,12 +326,12 @@
           throws PersistenceBrokerException
       {
           if (logger.isDebugEnabled()) logger.debug("executeUpdateSQL: " + sqlStatement);
  -        
  +
           int result;
           Statement stmt = null;
           try
           {
  -             stmt = broker.getStatementManager().getGenericStatement(cld, Query.NOT_SCROLLABLE);
  +             stmt = broker.serviceStatementManager().getGenericStatement(cld, Query.SCROLLABLE);
                result = stmt.executeUpdate(sqlStatement);
           }
           catch (PersistenceBrokerException e)
  @@ -351,7 +350,7 @@
           }
           finally
           {
  -			broker.getStatementManager().closeResources(stmt, null);
  +			broker.serviceStatementManager().closeResources(stmt, null);
           }
           return result;
       }
  @@ -364,23 +363,23 @@
       public void executeUpdate(ClassDescriptor cld, Object obj) throws PersistenceBrokerException
       {
           logger.safeDebug("executeUpdate",obj);
  -        
  +
           PreparedStatement stmt = null;
  -        
  +
           // obj with nothing but key fields is not updated
           if (cld.getNonPkFields().length == 0)
           {
  -        	return;	
  -        }	
  +        	return;
  +        }
           try
           {
  -            stmt = broker.getStatementManager().getUpdateStatement(cld);
  +            stmt = broker.serviceStatementManager().getUpdateStatement(cld);
               if (stmt == null)
               {
               	logger.error("getUpdateStatement returned a null statement");
               	throw new PersistenceBrokerException("getUpdateStatement returned a null statement");
               }
  -            broker.getStatementManager().bindUpdate(stmt, cld, obj);
  +            broker.serviceStatementManager().bindUpdate(stmt, cld, obj);
               if (stmt.executeUpdate() == 0 && cld.isLocking()) //BRJ
               {
                   throw new OptimisticLockException("Object has been modified by someone else", obj);
  @@ -408,7 +407,7 @@
           }
           finally
           {
  -			broker.getStatementManager().closeResources(stmt, null);
  +			broker.serviceStatementManager().closeResources(stmt, null);
           }
       }
   
  @@ -428,20 +427,20 @@
           PreparedStatement stmt = null;
           try
           {
  -            stmt = broker.getStatementManager().getSelectByPKStatement(cld);
  +            stmt = broker.serviceStatementManager().getSelectByPKStatement(cld);
               if (stmt == null)
               {
               	logger.error("getSelectByPKStatement returned a null statement");
               	throw new PersistenceBrokerException("getSelectByPKStatement returned a null statement");
               }
  -            broker.getStatementManager().bindSelect(stmt, oid);
  +            broker.serviceStatementManager().bindSelect(stmt, oid, cld);
               rs = stmt.executeQuery();
               // data available read object, else return null
               if (rs.next())
               {
                   Map row = new HashMap();
  -                cld.getRowReader().readObjectArrayFrom(rs, cld, row);
  -                return cld.getRowReader().readObjectFrom(row, cld);
  +                cld.getRowReader().readObjectArrayFrom(rs, row);
  +                return cld.getRowReader().readObjectFrom(row);
               }
               else
               {
  @@ -460,7 +459,7 @@
           }
           finally
           {
  -			broker.getStatementManager().closeResources(stmt, rs);
  +			broker.serviceStatementManager().closeResources(stmt, rs);
           }
       }
   
  
  
  
  1.12      +3 -3      jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/IndirectionHandler.java
  
  Index: IndirectionHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/IndirectionHandler.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- IndirectionHandler.java	26 Nov 2002 13:32:28 -0000	1.11
  +++ IndirectionHandler.java	24 Dec 2002 13:02:19 -0000	1.12
  @@ -257,11 +257,11 @@
               	return m.invoke(subject, args);
               }
           }
  -        catch (Exception t)
  +        catch (Exception e)
           {
               log.error("Method invoking failed for method *"+method.getName()+
  -                    "* on object "+subject, t);
  -            throw new PersistenceBrokerException("Error invoking:"+method.getName(),t);
  +                    "* on object "+subject, e);
  +            throw new PersistenceBrokerException("Error invoking:"+method.getName(),e);
           }
       }
   
  
  
  
  1.8       +18 -3     jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionManagerIF.java
  
  Index: ConnectionManagerIF.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionManagerIF.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ConnectionManagerIF.java	9 Dec 2002 22:00:08 -0000	1.7
  +++ ConnectionManagerIF.java	24 Dec 2002 13:02:19 -0000	1.8
  @@ -54,11 +54,26 @@
    * <http://www.apache.org/>.
    */
   
  +import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  +import org.apache.ojb.broker.platforms.Platform;
  +
   import java.sql.Connection;
   
   public interface ConnectionManagerIF
   {
       /**
  +     * Return the associated {@link org.apache.ojb.broker.metadata.JdbcConnectionDescriptor}
  +     */
  +    public JdbcConnectionDescriptor getConnectionDescriptor();
  +
  +    /**
  +     * Returns the supported {@link org.apache.ojb.broker.platforms.Platform}
  +     * determined by the {@link org.apache.ojb.broker.metadata.JdbcConnectionDescriptor}.
  +     * @see getConnectionDescriptor
  +     */
  +    public Platform getSupportedPlatform();
  +
  +    /**
        * checks if Connection conn is still open.
        * returns true, if connection is open, else false.
        */
  @@ -94,7 +109,7 @@
        * Release the hold connection.
        */
       public void releaseConnection();
  -    
  +
       /**
        * Sets the batch mode on or off.
        * @param the batch mode.
  @@ -105,12 +120,12 @@
        * @return the batch mode.
        */
       public boolean isBatchMode();
  -    
  +
       /**
        * Execute batch (if the batch mode where used).
        */
       public void executeBatch();
  -    
  +
       /**
        * Clear batch (if the batch mode where used).
        */
  
  
  
  1.19      +46 -10    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionManager.java
  
  Index: ConnectionManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionManager.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ConnectionManager.java	22 Dec 2002 15:56:41 -0000	1.18
  +++ ConnectionManager.java	24 Dec 2002 13:02:19 -0000	1.19
  @@ -54,8 +54,14 @@
    * <http://www.apache.org/>.
    */
   
  -import org.apache.ojb.broker.*;
  +import org.apache.ojb.broker.PBKey;
  +import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.TransactionAbortedException;
  +import org.apache.ojb.broker.TransactionInProgressException;
  +import org.apache.ojb.broker.TransactionNotInProgressException;
   import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  +import org.apache.ojb.broker.metadata.MetadataManager;
   import org.apache.ojb.broker.platforms.Platform;
   import org.apache.ojb.broker.platforms.PlatformConfiguration;
   import org.apache.ojb.broker.platforms.PlatformFactory;
  @@ -79,13 +85,13 @@
   public class ConnectionManager implements ConnectionManagerIF, Configurable
   {
       private Logger log = LoggerFactory.getLogger(ConnectionManager.class);
  +
       private PersistenceBroker broker = null;
       private ConnectionFactory connectionFactory;
       private JdbcConnectionDescriptor jcd;
       private Platform platform;
       private Connection con = null;
       private PBKey pbKey;
  -    private int useAutoCommit;
       private boolean originalAutoCommitState;
       private boolean isInLocalTransaction;
       private boolean batchMode;
  @@ -95,16 +101,28 @@
       {
           this.broker = broker;
           this.pbKey = broker.getPBKey();
  -        this.jcd = broker.getDescriptorRepository().getDefaultJdbcConnection();
  +        this.jcd = prepareJdbcConnectionDescriptor(pbKey);
           this.connectionFactory = ConnectionFactoryFactory.getInstance();
           this.platform = PlatformFactory.getPlatformFor(jcd);
  -        this.batchMode = this.jcd.getBatchMode();
           OjbConfigurator.getInstance().configure(this);
       }
   
       public void configure(Configuration pConfig) throws ConfigurationException
       {
  -        useAutoCommit = ((PlatformConfiguration) pConfig).useAutoCommit();
  +
  +    }
  +
  +    /**
  +     * Returns the associated {@link org.apache.ojb.broker.metadata.JdbcConnectionDescriptor}
  +     */
  +    public JdbcConnectionDescriptor getConnectionDescriptor()
  +    {
  +        return jcd;
  +    }
  +
  +    public Platform getSupportedPlatform()
  +    {
  +        return this.platform;
       }
   
       /**
  @@ -143,6 +161,23 @@
       }
   
       /**
  +     * Helper method: Because it's allowed to pass user/password with the PBKey
  +     * without declare it in the repository file, we had take care of it
  +     * and replace the dummies from the repository.
  +     */
  +    private JdbcConnectionDescriptor prepareJdbcConnectionDescriptor(PBKey key)
  +    {
  +        JdbcConnectionDescriptor result = MetadataManager.getInstance().connectionRepository()
  +                                            .getDescriptor(pbKey.getAlias());
  +        if (key.getUser() != null)
  +        {
  +            result.setUserName(key.getUser());
  +            result.setPassWord(key.getPassword());
  +        }
  +        return result;
  +    }
  +
  +    /**
        * Start transaction on the underlying connection.
        */
       public void localBegin()
  @@ -162,7 +197,7 @@
               /**
   			 * must throw to notify user that we couldn't start a connection
   			 */
  -			throw new PersistenceBrokerSQLException(e.getMessage());
  +			throw new PersistenceBrokerException(e.getMessage(), e);
           }
           if (platform.useAutoCommit() == Platform.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE)
           {
  @@ -248,7 +283,7 @@
           }
           catch (SQLException e)
           {
  -            log.error("IsAlive check failed", e);
  +            log.error("IsAlive check failed, running connection was invalid!!", e);
               return false;
           }
       }
  @@ -277,7 +312,7 @@
        * Sets the batch mode on or off.
        * @param mode the batch mode
        */
  -    public void setBatchMode(boolean mode) 
  +    public void setBatchMode(boolean mode)
       {
           batchMode = (mode && platform.supportsBatchOperations());
       }
  @@ -311,7 +346,8 @@
       /**
        * Clear batch (if the batch mode where used).
        */
  -    public void clearBatch() {
  +    public void clearBatch()
  +    {
           if (batchCon != null)
           {
               batchCon.clearBatch();
  
  
  
  1.2       +73 -18    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java
  
  Index: ConnectionFactoryPooledImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryPooledImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConnectionFactoryPooledImpl.java	28 Nov 2002 22:25:53 -0000	1.1
  +++ ConnectionFactoryPooledImpl.java	24 Dec 2002 13:02:19 -0000	1.2
  @@ -11,6 +11,8 @@
   
   import java.sql.Connection;
   import java.sql.SQLException;
  +import java.sql.Statement;
  +import java.sql.ResultSet;
   import java.util.Collection;
   import java.util.HashMap;
   import java.util.Iterator;
  @@ -53,7 +55,7 @@
           ObjectPool op = (ObjectPool) connectionPools.get(jcd.getDescriptorKey());
           if (op == null)
           {
  -            log.info("Create connection pool for JdbcDescriptorKey " + jcd.getDescriptorKey());
  +            log.info("Create new connection pool:" + jcd);
               op = createConnectionPool(jcd);
               synchronized (connectionPools)
               {
  @@ -81,7 +83,6 @@
           PoolableObjectFactory pof = new ConPoolFactory(this, jcd);
           GenericObjectPool.Config conf = jcd.getConnectionPoolDescriptor().getObjectPoolConfig();
           ObjectPool op = new GenericObjectPool(pof, conf);
  -        log.info(buildPoolInfo(op, jcd));
           return op;
       }
   
  @@ -111,19 +112,19 @@
           }
       }
   
  -    /**
  -     * Helper method, builds a bunch information properties about the
  -     * pool and jdbc-descriptor
  -     */
  -    public String buildPoolInfo(ObjectPool op, JdbcConnectionDescriptor jcd)
  -    {
  -        StringBuffer buf = new StringBuffer();
  -        buf.append("Create new connection pool for ");
  -        buf.append(JdbcConnectionDescriptor.class.getName() + ",");
  -        buf.append(LoggingHelper.LINE_SEPARATOR + " used descriptor: " + jcd);
  -        buf.append(LoggingHelper.LINE_SEPARATOR + "pool configuration was: " + jcd.getConnectionPoolDescriptor());
  -        return buf.toString();
  -    }
  +//    /**
  +//     * Helper method, builds a bunch information properties about the
  +//     * pool and jdbc-descriptor
  +//     */
  +//    public String buildPoolInfo(ObjectPool op, JdbcConnectionDescriptor jcd)
  +//    {
  +//        StringBuffer buf = new StringBuffer();
  +//        buf.append("Create new connection pool for ");
  +//        buf.append(JdbcConnectionDescriptor.class.getName() + ",");
  +//        buf.append(LoggingHelper.LINE_SEPARATOR + " used descriptor: " + jcd);
  +//        buf.append(LoggingHelper.LINE_SEPARATOR + "pool configuration was: " + jcd.getConnectionPoolDescriptor());
  +//        return buf.toString();
  +//    }
   
   
       //**************************************************************************************
  @@ -147,14 +148,68 @@
   
           public boolean validateObject(Object obj)
           {
  +            Connection con = (Connection) obj;
  +            String query = jcd.getConnectionPoolDescriptor().getValidationQuery();
  +            if(query == null)
  +            {
  +                try
  +                {
  +                    return !con.isClosed();
  +                }
  +                catch (SQLException e)
  +                {
  +                    log.warn("Connection validation failed: "+e.getMessage());
  +                    if(log.isDebugEnabled()) log.debug(e);
  +                    return false;
  +                }
  +            }
  +            else
  +            {
  +                return validateConnection(con, query);
  +            }
  +        }
  +
  +        private boolean validateConnection(Connection conn, String query)
  +        {
  +            Statement stmt = null;
  +            ResultSet rset = null;
               try
               {
  -                return !((Connection) obj).isClosed();
  +                stmt = conn.createStatement();
  +                rset = stmt.executeQuery(query);
  +                if (rset.next())
  +                {
  +                    return true;
  +                }
  +                else
  +                {
  +                    return false;
  +                }
               }
               catch (SQLException e)
               {
  -                log.error("Connection validation failed, remove connection from pool");
  +                log.warn("Validation query for connection failed: "+e.getSQLState());
  +                if(log.isDebugEnabled()) log.debug(e);
                   return false;
  +            }
  +            finally
  +            {
  +                try
  +                {
  +                    rset.close();
  +                }
  +                catch (Exception t)
  +                {
  +                    // ignored
  +                }
  +                try
  +                {
  +                    stmt.close();
  +                }
  +                catch (Exception t)
  +                {
  +                    // ignored
  +                }
               }
           }
   
  
  
  
  1.2       +2 -2      jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java
  
  Index: ConnectionFactoryDBCPImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConnectionFactoryDBCPImpl.java	28 Nov 2002 22:25:53 -0000	1.1
  +++ ConnectionFactoryDBCPImpl.java	24 Dec 2002 13:02:19 -0000	1.2
  @@ -88,7 +88,7 @@
   
       private DataSource setupDriver(JdbcConnectionDescriptor jcd) throws Exception
       {
  -        if (log.isDebugEnabled()) log.debug("Create pool for " + jcd);
  +        log.info("Create new DBCP connection pool:" + jcd);
           try
           {
               Class.forName(jcd.getDriver(), true, Thread.currentThread().getContextClassLoader()).newInstance();
  
  
  
  1.2       +28 -11    jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryAbstractImpl.java
  
  Index: ConnectionFactoryAbstractImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryAbstractImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConnectionFactoryAbstractImpl.java	28 Nov 2002 22:25:53 -0000	1.1
  +++ ConnectionFactoryAbstractImpl.java	24 Dec 2002 13:02:19 -0000	1.2
  @@ -103,21 +103,34 @@
                   log.error("Error during sanity check of new DB Connection, either it was closed", e);
                   throw new LookupException("Connection check failed", e);
               }
  -            // initialize connection
  -            // perform platform specific initializations:
  -            try
  -            {
  -                PlatformFactory.getPlatformFor(jcd).initializeJdbcConnection(conn);
  -            }
  -            catch (PlatformException e)
  -            {
  -                throw new LookupException("Platform dependent initialization of connection failed", e);
  -            }
           }
           return conn;
       }
   
       /**
  +     * Initialize the connection with the specified properties in OJB
  +     * configuration files and platform depended properties.
  +     * Invoke this method after a NEW connection was created.
  +     *
  +     * @see org.apache.ojb.broker.platforms.PlatformFactory
  +     * @see org.apache.ojb.broker.platforms.Platform
  +     */
  +    protected void initializeJdbcConnection(Connection con, JdbcConnectionDescriptor jcd)
  +            throws LookupException
  +    {
  +        // initialize connection
  +        // perform platform specific initializations:
  +        try
  +        {
  +            PlatformFactory.getPlatformFor(jcd).initializeJdbcConnection(con);
  +        }
  +        catch (PlatformException e)
  +        {
  +            throw new LookupException("Platform dependent initialization of connection failed", e);
  +        }
  +    }
  +
  +    /**
        * Override this method to do cleanup in your implenetation.
        * Do a <tt>super.releaseAllResources()</tt> in your method implementation
        * to free resources used by this class.
  @@ -182,6 +195,8 @@
               throw new LookupException("Naming Exception while looking up DataSource (" + jcd.getDatasourceName() +
                       ")", namingEx);
           }
  +        // initialize connection
  +        initializeJdbcConnection(retval, jcd);
           return retval;
       }
   
  @@ -228,6 +243,8 @@
               log.error("Instantiation of jdbc driver failed", e);
               throw new LookupException("Instantiation of jdbc driver failed", e);
           }
  +        // initialize connection
  +        initializeJdbcConnection(retval, jcd);
           return retval;
       }
   
  
  
  
  1.8       +4 -3      jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactory.java
  
  Index: ConnectionFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ConnectionFactory.java	28 Nov 2002 22:25:53 -0000	1.7
  +++ ConnectionFactory.java	24 Dec 2002 13:02:19 -0000	1.8
  @@ -62,9 +62,10 @@
    * Interface to implement connection factories used by the
    * {@link org.apache.ojb.broker.PersistenceBroker} implementation.
    *
  - * @see org.apache.ojb.broker.accesslayer.ConnectionFactoryDefaultImpl
  - * @see org.apache.ojb.broker.accesslayer.ConnectionFactoryConPooledImpl
  - * @see org.apache.ojb.broker.accesslayer.ConnectionFactoryStmtPooledImpl
  + * @see org.apache.ojb.broker.accesslayer.ConnectionFactoryPooledImpl
  + * @see org.apache.ojb.broker.accesslayer.ConnectionFactoryNotPooledImpl
  + * @see org.apache.ojb.broker.accesslayer.ConnectionFactoryDBCPImpl
  + * @see org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl
    */
   public interface ConnectionFactory
   {
  
  
  
  1.5       +7 -7      jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java
  
  Index: CollectionPrefetcher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/CollectionPrefetcher.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- CollectionPrefetcher.java	16 Dec 2002 18:18:25 -0000	1.4
  +++ CollectionPrefetcher.java	24 Dec 2002 13:02:19 -0000	1.5
  @@ -61,6 +61,7 @@
   import org.apache.ojb.broker.Identity;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.util.BrokerHelper;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.CollectionDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  @@ -73,7 +74,7 @@
   
   /**
    * Relationship Prefetcher for Collections.
  - * 
  + *
    * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
    * @version $Id$
    */
  @@ -91,7 +92,7 @@
   	}
   
   	/**
  -	 * Build the query (using IN(...) )to perform a batched read 
  +	 * Build the query (using IN(...) )to perform a batched read
   	 * get orderBy settings from CollectionDescriptor
   	 * @param owners Collection containing all objects of the ONE side
   	 */
  @@ -111,14 +112,14 @@
   			iter = owners.iterator();
   			while (iter.hasNext())
   			{
  -				pkValues.add(getOwnerClassDescriptor().getKeyValues(iter.next())[i]);
  +				pkValues.add(this.getBroker().serviceBrokerHelper().getKeyValues(getOwnerClassDescriptor(), iter.next())[i]);
   			}
   
   			// create IN (...) for each key field
   			if (!pkValues.isEmpty())
   			{
   				crit.addIn(fkFields[i].getAttributeName(), pkValues);
  -			}	
  +			}
   		}
   
           // check if collection must be ordered
  @@ -129,7 +130,7 @@
               {
                   crit.addOrderBy((FieldHelper)iter.next());
               }
  -        }    
  +        }
   
   		return QueryFactory.newQuery(cds.getItemClass(), crit);
   	}
  @@ -194,5 +195,4 @@
   			super.prefetchRelationship(owners);
   		}
   	}
  -
   }
  
  
  

Mime
View raw message