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 ConnectionManager.java ConnectionFactoryNotPooledImpl.java ConnectionFactoryPooledImpl.java ConnectionFactoryDBCPImpl.java ConnectionFactoryAbstractImpl.java RsIterator.java
Date Thu, 09 Jan 2003 16:57:21 GMT
arminw      2003/01/09 08:57:21

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        ConnectionManager.java
                        ConnectionFactoryNotPooledImpl.java
                        ConnectionFactoryPooledImpl.java
                        ConnectionFactoryDBCPImpl.java
                        ConnectionFactoryAbstractImpl.java RsIterator.java
  Log:
  - move the whole sequence-manager
  properties stuff from the OJB.properties to
  the repository
  - move the 'useAutoCommit' and
  'ignoreAutocommitExceptions' properties from OJB.properties
  to jdbc-connection-descriptor
  
  - remove the 'maxConnectionsInPool'
  property from OJB.properties
  
  - rename DescriptorRepository#getExtentClass
  to #getTopLevelClass, deprecate PB#getExtentClass
  and add PB#getTopLevelClass
  
  Revision  Changes    Path
  1.22      +15 -38    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.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- ConnectionManager.java	28 Dec 2002 10:51:33 -0000	1.21
  +++ ConnectionManager.java	9 Jan 2003 16:57:21 -0000	1.22
  @@ -54,9 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -import java.sql.Connection;
  -import java.sql.SQLException;
  -
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
  @@ -75,13 +72,16 @@
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  +import java.sql.Connection;
  +import java.sql.SQLException;
  +
   /**
    * Manages Connection ressources.
    *
    * @author: Thomas Mahler
    * @version $Id$
    */
  -public class ConnectionManager implements ConnectionManagerIF, Configurable
  +public class ConnectionManager implements ConnectionManagerIF
   {
       private Logger log = LoggerFactory.getLogger(ConnectionManager.class);
   
  @@ -100,15 +100,9 @@
       {
           this.broker = broker;
           this.pbKey = broker.getPBKey();
  -        this.jcd = prepareJdbcConnectionDescriptor(pbKey);
  +        this.jcd = MetadataManager.getInstance().connectionRepository().getDescriptor(pbKey);
           this.connectionFactory = ConnectionFactoryFactory.getInstance();
           this.platform = PlatformFactory.getPlatformFor(jcd);
  -        OjbConfigurator.getInstance().configure(this);
  -    }
  -
  -    public void configure(Configuration pConfig) throws ConfigurationException
  -    {
  -
       }
   
       /**
  @@ -160,23 +154,6 @@
       }
   
       /**
  -     * 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()
  @@ -194,14 +171,14 @@
           catch (LookupException e)
           {
               /**
  -			 * must throw to notify user that we couldn't start a connection
  -			 */
  -			throw new PersistenceBrokerException(e.getMessage(), e);
  +             * must throw to notify user that we couldn't start a connection
  +             */
  +            throw new PersistenceBrokerException(e.getMessage(), e);
           }
  -        if (platform.useAutoCommit() == Platform.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE)
  +        if (jcd.getUseAutoCommit() == JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE)
           {
               if (log.isDebugEnabled()) log.debug("Try to change autoCommit state to 'false'");
  -            platform.changeAutoCommitState(connection, false);
  +            platform.changeAutoCommitState(jcd, connection, false);
           }
           this.isInLocalTransaction = true;
       }
  @@ -230,10 +207,10 @@
           finally
           {
               this.isInLocalTransaction = false;
  -            if (platform.useAutoCommit() == Platform.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE
&&
  +            if (jcd.getUseAutoCommit() == JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE
&&
                       originalAutoCommitState == true)
               {
  -                platform.changeAutoCommitState(con, true);
  +                platform.changeAutoCommitState(jcd, con, true);
               }
               this.releaseConnection();
           }
  @@ -262,10 +239,10 @@
           }
           finally
           {
  -            if (platform.useAutoCommit() == Platform.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE
&&
  +            if (jcd.getUseAutoCommit() == JdbcConnectionDescriptor.AUTO_COMMIT_SET_TRUE_AND_TEMPORARY_FALSE
&&
                       originalAutoCommitState == true)
               {
  -                platform.changeAutoCommitState(con, true);
  +                platform.changeAutoCommitState(jcd, con, true);
               }
               this.releaseConnection();
           }
  
  
  
  1.2       +9 -2      jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryNotPooledImpl.java
  
  Index: ConnectionFactoryNotPooledImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryNotPooledImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConnectionFactoryNotPooledImpl.java	28 Nov 2002 22:25:53 -0000	1.1
  +++ ConnectionFactoryNotPooledImpl.java	9 Jan 2003 16:57:21 -0000	1.2
  @@ -1,6 +1,8 @@
   package org.apache.ojb.broker.accesslayer;
   
   import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  +import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
   
   import java.sql.Connection;
   import java.sql.SQLException;
  @@ -13,8 +15,13 @@
    */
   public class ConnectionFactoryNotPooledImpl extends ConnectionFactoryAbstractImpl
   {
  +    private Logger log = LoggerFactory.getLogger(ConnectionFactoryNotPooledImpl.class);
  +
       public Connection getConnectionFromPool(JdbcConnectionDescriptor jcd) throws LookupException
       {
  +        if (log.isDebugEnabled())
  +            log.debug(
  +                    "getConnectionFromPool was called, this implementation ever return
a new connection");
           return this.newConnectionFromDriverManager(jcd);
       }
   
  @@ -27,7 +34,7 @@
           }
           catch (SQLException e)
           {
  -            // ignore
  +            log.warn("Connection.close() failed, message was " + e.getMessage());
           }
       }
   }
  
  
  
  1.4       +20 -32    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConnectionFactoryPooledImpl.java	28 Dec 2002 10:51:33 -0000	1.3
  +++ ConnectionFactoryPooledImpl.java	9 Jan 2003 16:57:21 -0000	1.4
  @@ -1,5 +1,13 @@
   package org.apache.ojb.broker.accesslayer;
   
  +import org.apache.commons.pool.BasePoolableObjectFactory;
  +import org.apache.commons.pool.ObjectPool;
  +import org.apache.commons.pool.PoolableObjectFactory;
  +import org.apache.commons.pool.impl.GenericObjectPool;
  +import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  +import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
  +
   import java.sql.Connection;
   import java.sql.ResultSet;
   import java.sql.SQLException;
  @@ -9,14 +17,6 @@
   import java.util.Iterator;
   import java.util.Map;
   
  -import org.apache.commons.pool.BasePoolableObjectFactory;
  -import org.apache.commons.pool.ObjectPool;
  -import org.apache.commons.pool.PoolableObjectFactory;
  -import org.apache.commons.pool.impl.GenericObjectPool;
  -import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
  -import org.apache.ojb.broker.util.logging.Logger;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
  -
   /**
    * Connection factory which pools the requested
    * connections for different JdbcConnectionDescriptors
  @@ -41,7 +41,7 @@
       {
           try
           {
  -            ((ObjectPool) this.connectionPools.get(jcd.getDescriptorKey())).returnObject(con);
  +            ((ObjectPool) this.connectionPools.get(jcd.getPBKey())).returnObject(con);
           }
           catch (Exception e)
           {
  @@ -51,14 +51,14 @@
   
       public Connection getConnectionFromPool(JdbcConnectionDescriptor jcd) throws LookupException
       {
  -        ObjectPool op = (ObjectPool) connectionPools.get(jcd.getDescriptorKey());
  +        ObjectPool op = (ObjectPool) connectionPools.get(jcd.getPBKey());
           if (op == null)
           {
               log.info("Create new connection pool:" + jcd);
               op = createConnectionPool(jcd);
               synchronized (connectionPools)
               {
  -                connectionPools.put(jcd.getDescriptorKey(), op);
  +                connectionPools.put(jcd.getPBKey(), op);
               }
           }
           try
  @@ -111,21 +111,6 @@
           }
       }
   
  -//    /**
  -//     * 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();
  -//    }
  -
  -
       //**************************************************************************************
       // Inner classes
       //************************************************************************************
  @@ -149,7 +134,7 @@
           {
               Connection con = (Connection) obj;
               String query = jcd.getConnectionPoolDescriptor().getValidationQuery();
  -            if(query == null)
  +            if (query == null || query.trim().equals(""))
               {
                   try
                   {
  @@ -157,8 +142,8 @@
                   }
                   catch (SQLException e)
                   {
  -                    log.warn("Connection validation failed: "+e.getMessage());
  -                    if(log.isDebugEnabled()) log.debug(e);
  +                    log.warn("Connection validation failed: " + e.getMessage());
  +                    if (log.isDebugEnabled()) log.debug(e);
                       return false;
                   }
               }
  @@ -182,13 +167,16 @@
                   }
                   else
                   {
  +                    log.warn("Validation query '" + query +
  +                            "' result set does not match, discard connection");
                       return false;
                   }
               }
               catch (SQLException e)
               {
  -                log.warn("Validation query for connection failed: "+e.getSQLState());
  -                if(log.isDebugEnabled()) log.debug(e);
  +                log.warn("Validation query for connection failed, discard connection. Message:
" +
  +                        e.getMessage());
  +                if (log.isDebugEnabled()) log.debug(e);
                   return false;
               }
               finally
  
  
  
  1.3       +7 -12     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConnectionFactoryDBCPImpl.java	24 Dec 2002 13:02:19 -0000	1.2
  +++ ConnectionFactoryDBCPImpl.java	9 Jan 2003 16:57:21 -0000	1.3
  @@ -36,14 +36,14 @@
   
       public Connection lookupConnection(JdbcConnectionDescriptor jcd) throws LookupException
       {
  -        DataSource ds = (DataSource) ds_map.get(jcd.getDescriptorKey());
  +        DataSource ds = (DataSource) ds_map.get(jcd.getPBKey());
           if (ds == null)
           {
               try
               {
                   ds = jcd.getDatasourceName() != null ? setupDataSource(jcd.getDatasourceName())
:
                           setupDriver(jcd);
  -                ds_map.put(jcd.getDescriptorKey(), ds);
  +                ds_map.put(jcd.getPBKey(), ds);
               }
               catch (Exception e)
               {
  @@ -121,18 +121,12 @@
   
           KeyedObjectPoolFactory statementPoolFactory = new GenericKeyedObjectPoolFactory(null);
   
  -        // TODO: get this query from the "platform" (database config)
  -        //String validationQuery = "select 1 from dual";
  -        String validationQuery = null;
  +        String validationQuery = jcd.getConnectionPoolDescriptor().getValidationQuery();
           boolean defaultReadOnly = false;
           boolean defaultAutoCommit = true;
   
  -        /* @todo make this configurable */
           // Abandoned configuration
  -        AbandonedConfig ac = new AbandonedConfig();
  -        ac.setLogAbandoned(false);
  -        ac.setRemoveAbandoned(false);
  -        ac.setRemoveAbandonedTimeout(100);
  +        AbandonedConfig ac = jcd.getConnectionPoolDescriptor().getAbandonedConfig();
   
           //
           // Now we'll create the PoolableConnectionFactory, which wraps
  @@ -145,7 +139,8 @@
                   statementPoolFactory,
                   validationQuery,
                   defaultReadOnly,
  -                defaultAutoCommit);
  +                defaultAutoCommit,
  +                ac);
   
           //
           // Finally, we create the PoolingDriver itself,
  
  
  
  1.3       +24 -12    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConnectionFactoryAbstractImpl.java	24 Dec 2002 13:02:19 -0000	1.2
  +++ ConnectionFactoryAbstractImpl.java	9 Jan 2003 16:57:21 -0000	1.3
  @@ -3,6 +3,7 @@
   import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
   import org.apache.ojb.broker.platforms.PlatformException;
   import org.apache.ojb.broker.platforms.PlatformFactory;
  +import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -10,6 +11,7 @@
   import javax.naming.NamingException;
   import javax.sql.DataSource;
   import java.sql.Connection;
  +import java.sql.DriverManager;
   import java.sql.SQLException;
   import java.util.HashMap;
   import java.util.Map;
  @@ -28,16 +30,26 @@
        * holds the datasource looked up from JNDI in a map, keyed
        * by the JNDI name.
        */
  -    private Map m_dsCache = new HashMap();
  +    private Map dataSourceCache = new HashMap();
   
       /**
  -     * Implement this method.
  +     * Implement this method. This method was called to obtain
  +     * a jdbc-connection from the pool.
  +     * <br/>
  +     * Note: This method was
  +     * not called, if jdbc-connection-descriptor use datasources - OJB
  +     * only pool connections from DriverManager.
        */
       public abstract Connection getConnectionFromPool(JdbcConnectionDescriptor jcd)
               throws LookupException;
   
       /**
  -     * Implement this method.
  +     * Implement this method. Was called to return a
  +     * connection to pool.
  +     * <br/>
  +     * Note: This method was
  +     * not called, if the jdbc-connection-descriptor uses datasources - OJB
  +     * only pool connections from DriverManager.
        */
       public abstract void returnConnectionToPool(JdbcConnectionDescriptor jcd, Connection
con)
               throws LookupException;
  @@ -122,7 +134,7 @@
           // perform platform specific initializations:
           try
           {
  -            PlatformFactory.getPlatformFor(jcd).initializeJdbcConnection(con);
  +            PlatformFactory.getPlatformFor(jcd).initializeJdbcConnection(jcd, con);
           }
           catch (PlatformException e)
           {
  @@ -137,7 +149,7 @@
        */
       public synchronized void releaseAllResources()
       {
  -        this.m_dsCache.clear();
  +        this.dataSourceCache.clear();
       }
   
       /**
  @@ -154,7 +166,7 @@
       {
           Connection retval = null;
           // use JNDI lookup
  -        DataSource ds = (DataSource) m_dsCache.get(jcd.getDatasourceName());
  +        DataSource ds = (DataSource) dataSourceCache.get(jcd.getDatasourceName());
           try
           {
               if (ds == null)
  @@ -163,14 +175,14 @@
                    * this synchronization block won't be a big deal as we only look up
                    * new datasources not found in the map.
                    */
  -                synchronized (m_dsCache)
  +                synchronized (dataSourceCache)
                   {
                       InitialContext ic = new InitialContext();
                       ds = (DataSource) ic.lookup(jcd.getDatasourceName());
                       /**
                        * cache the datasource lookup.
                        */
  -                    m_dsCache.put(jcd.getDatasourceName(), ds);
  +                    dataSourceCache.put(jcd.getDatasourceName(), ds);
                   }
               }
               if (jcd.getUserName() == null)
  @@ -218,14 +230,14 @@
           try
           {
               // loads the driver - NB call to newInstance() added to force initialisation
  -            Class.forName(driver, true, Thread.currentThread().getContextClassLoader()).newInstance();
  +            ClassHelper.getClass(driver, true);
               if (jcd.getUserName() == null)
               {
  -                retval = java.sql.DriverManager.getConnection(url);
  +                retval = DriverManager.getConnection(url);
               }
               else
               {
  -                retval = java.sql.DriverManager.getConnection(url, jcd.getUserName(), jcd.getPassWord());
  +                retval = DriverManager.getConnection(url, jcd.getUserName(), jcd.getPassWord());
               }
           }
           catch (SQLException sqlEx)
  
  
  
  1.25      +2 -2      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.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- RsIterator.java	28 Dec 2002 10:52:27 -0000	1.24
  +++ RsIterator.java	9 Jan 2003 16:57:21 -0000	1.25
  @@ -179,7 +179,7 @@
   	{
   		if (itemExtentClass == null)
   		{
  -			itemExtentClass = m_broker.getExtentClass(m_cld.getClassOfObject());
  +			itemExtentClass = m_broker.getTopLevelClass(m_cld.getClassOfObject());
   		}
   		return itemExtentClass;
   	}
  
  
  

Mime
View raw message