dblevins    2005/08/23 00:12:53

  Modified:    modules/core/src/java/org/openejb/resource/jdbc
                        JdbcConnectionFactory.java
                        JdbcManagedConnection.java
                        JdbcManagedConnectionFactory.java
  Added:       modules/core/src/java/org/openejb/resource/jdbc
                        BasicManagedConnectionFactory.java
                        ManagedConnectionFactoryPathHack.java
  Log:

  Rewrote the ManagedConnectionFactory.  Allowed the 
BasicManagedConnectionFactory
  to be optionally wrapped to include a very nasty hack for dealing with 
embedded
  databases that use the system properties for resolving their configuration.
  This becomes really hard if you expect to have more than one instance of the
  embedded database.
  
  Revision  Changes    Path
  1.2       +31 -21    
openejb1/modules/core/src/java/org/openejb/resource/jdbc/JdbcConnectionFactory.java
  
  Index: JdbcConnectionFactory.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/resource/jdbc/JdbcConnectionFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JdbcConnectionFactory.java        26 Mar 2004 21:42:47 -0000      1.1
  +++ JdbcConnectionFactory.java        23 Aug 2005 04:12:53 -0000      1.2
  @@ -12,24 +12,24 @@
    *    following disclaimer in the documentation and/or other
    *    materials provided with the distribution.
    *
  - * 3. The name "Exolab" must not be used to endorse or promote
  + * 3. The name "OpenEJB" must not be used to endorse or promote
    *    products derived from this Software without prior written
  - *    permission of Exoffice Technologies.  For written permission,
  - *    please contact [EMAIL PROTECTED]
  + *    permission of The OpenEJB Group.  For written permission,
  + *    please contact [EMAIL PROTECTED]
    *
  - * 4. Products derived from this Software may not be called "Exolab"
  - *    nor may "Exolab" appear in their names without prior written
  - *    permission of Exoffice Technologies. Exolab is a registered
  - *    trademark of Exoffice Technologies.
  + * 4. Products derived from this Software may not be called "OpenEJB"
  + *    nor may "OpenEJB" appear in their names without prior written
  + *    permission of The OpenEJB Group. OpenEJB is a registered
  + *    trademark of The OpenEJB Group.
    *
  - * 5. Due credit should be given to the Exolab Project
  - *    (http://www.exolab.org/).
  + * 5. Due credit should be given to the OpenEJB Project
  + *    (http://openejb.org/).
    *
  - * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
  + * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
    * ``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
  - * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  + * THE OPENEJB GROUP 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)
  @@ -38,15 +38,17 @@
    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    * OF THE POSSIBILITY OF SUCH DAMAGE.
    *
  - * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
  + * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
    *
    * $Id$
  - */package org.openejb.resource.jdbc;
  + */
  +package org.openejb.resource.jdbc;
   
   import java.sql.SQLException;
   
   import javax.resource.ResourceException;
   import javax.resource.spi.ConnectionManager;
  +import javax.resource.spi.ManagedConnectionFactory;
   
   /*
   * As a connection factory the JdbcConnecitonFactory must implement the 
Serializable and 
  @@ -61,14 +63,18 @@
   javax.resource.Referenceable, 
   java.io.Serializable {
       
  -    protected transient JdbcManagedConnectionFactory mngdCxFactory;
  +    protected transient ManagedConnectionFactory mngdCxFactory;
       protected transient ConnectionManager cxManager;
       protected transient java.io.PrintWriter logWriter;
       protected int logTimeout = 0;
       
       // Reference to this ConnectionFactory
       javax.naming.Reference jndiReference;
  -    
  +    private final String jdbcUrl;
  +    private final String jdbcDriver;
  +    private final String defaultPassword;
  +    private final String defaultUserName;
  +
       // setReference is called by deployment code
       public void setReference(javax.naming.Reference ref) {
           jndiReference = ref;
  @@ -78,19 +84,23 @@
           return jndiReference;
       }
       
  -    public JdbcConnectionFactory(JdbcManagedConnectionFactory mngdCxFactory, 
ConnectionManager cxManager)
  +    public JdbcConnectionFactory(ManagedConnectionFactory mngdCxFactory, 
ConnectionManager cxManager, String jdbcUrl, String jdbcDriver, String 
defaultPassword, String defaultUserName)
       throws ResourceException{
           this.mngdCxFactory = mngdCxFactory;
           this.cxManager = cxManager;
  -        logWriter = mngdCxFactory.getLogWriter();
  +        this.logWriter = mngdCxFactory.getLogWriter();
  +        this.jdbcUrl = jdbcUrl;
  +        this.jdbcDriver = jdbcDriver;
  +        this.defaultPassword = defaultPassword;
  +        this.defaultUserName = defaultUserName;
       }
           
       public java.sql.Connection getConnection() throws SQLException{
  -        return getConnection(mngdCxFactory.getDefaultUserName(), 
mngdCxFactory.getDefaultPassword());
  +        return getConnection(defaultUserName, defaultPassword);
       }
  +
       public java.sql.Connection getConnection(java.lang.String username, 
java.lang.String password)throws SQLException{
  -        JdbcConnectionRequestInfo conInfo = new 
JdbcConnectionRequestInfo(username, password, mngdCxFactory.getJdbcDriver(), 
mngdCxFactory.getJdbcUrl());
  -        return getConnection(conInfo);
  +        return getConnection(new JdbcConnectionRequestInfo(username, 
password, jdbcDriver, jdbcUrl));
       }
       protected java.sql.Connection getConnection(JdbcConnectionRequestInfo 
conInfo) throws SQLException{
           try{
  
  
  
  1.3       +22 -16    
openejb1/modules/core/src/java/org/openejb/resource/jdbc/JdbcManagedConnection.java
  
  Index: JdbcManagedConnection.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/resource/jdbc/JdbcManagedConnection.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JdbcManagedConnection.java        25 Oct 2004 12:34:42 -0000      1.2
  +++ JdbcManagedConnection.java        23 Aug 2005 04:12:53 -0000      1.3
  @@ -12,24 +12,24 @@
    *    following disclaimer in the documentation and/or other
    *    materials provided with the distribution.
    *
  - * 3. The name "Exolab" must not be used to endorse or promote
  + * 3. The name "OpenEJB" must not be used to endorse or promote
    *    products derived from this Software without prior written
  - *    permission of Exoffice Technologies.  For written permission,
  - *    please contact [EMAIL PROTECTED]
  + *    permission of The OpenEJB Group.  For written permission,
  + *    please contact [EMAIL PROTECTED]
    *
  - * 4. Products derived from this Software may not be called "Exolab"
  - *    nor may "Exolab" appear in their names without prior written
  - *    permission of Exoffice Technologies. Exolab is a registered
  - *    trademark of Exoffice Technologies.
  + * 4. Products derived from this Software may not be called "OpenEJB"
  + *    nor may "OpenEJB" appear in their names without prior written
  + *    permission of The OpenEJB Group. OpenEJB is a registered
  + *    trademark of The OpenEJB Group.
    *
  - * 5. Due credit should be given to the Exolab Project
  - *    (http://www.exolab.org/).
  + * 5. Due credit should be given to the OpenEJB Project
  + *    (http://openejb.org/).
    *
  - * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
  + * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
    * ``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
  - * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  + * THE OPENEJB GROUP 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)
  @@ -38,7 +38,7 @@
    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    * OF THE POSSIBILITY OF SUCH DAMAGE.
    *
  - * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
  + * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
    *
    * $Id$
    */
  @@ -52,10 +52,12 @@
   import javax.resource.spi.ConnectionRequestInfo;
   import javax.resource.spi.ManagedConnection;
   import javax.resource.spi.ManagedConnectionMetaData;
  +import javax.resource.spi.ManagedConnectionFactory;
  +import javax.resource.ResourceException;
   
   public class JdbcManagedConnection implements ManagedConnection {
   
  -    private JdbcManagedConnectionFactory managedFactory;
  +    private ManagedConnectionFactory managedFactory;
       private java.sql.Connection sqlConn;
       private JdbcConnectionRequestInfo requestInfo;
       private JdbcManagedConnectionMetaData metaData;
  @@ -66,13 +68,17 @@
       private java.io.PrintWriter logWriter;
       private JdbcLocalTransaction localTransaction;
   
  -    public JdbcManagedConnection(JdbcManagedConnectionFactory 
managedFactory, java.sql.Connection sqlConn, JdbcConnectionRequestInfo rxInfo)
  +    public JdbcManagedConnection(ManagedConnectionFactory managedFactory, 
java.sql.Connection sqlConn, JdbcConnectionRequestInfo rxInfo)
       throws javax.resource.spi.ResourceAdapterInternalException {
           listeners = java.util.Collections.synchronizedSet(new HashSet());
           this.managedFactory = managedFactory;
           this.requestInfo = rxInfo;
           this.sqlConn = sqlConn;
  -        logWriter = managedFactory.getLogWriter();
  +        try {
  +            logWriter = managedFactory.getLogWriter();
  +        } catch (ResourceException e) {
  +            throw new RuntimeException(e);
  +        }
           try{
           metaData = new JdbcManagedConnectionMetaData(sqlConn.getMetaData());
           }catch(java.sql.SQLException sqlE){
  
  
  
  1.7       +80 -147   
openejb1/modules/core/src/java/org/openejb/resource/jdbc/JdbcManagedConnectionFactory.java
  
  Index: JdbcManagedConnectionFactory.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb1/modules/core/src/java/org/openejb/resource/jdbc/JdbcManagedConnectionFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JdbcManagedConnectionFactory.java 6 Jul 2005 02:04:03 -0000       1.6
  +++ JdbcManagedConnectionFactory.java 23 Aug 2005 04:12:53 -0000      1.7
  @@ -12,24 +12,24 @@
    *    following disclaimer in the documentation and/or other
    *    materials provided with the distribution.
    *
  - * 3. The name "Exolab" must not be used to endorse or promote
  + * 3. The name "OpenEJB" must not be used to endorse or promote
    *    products derived from this Software without prior written
  - *    permission of Exoffice Technologies.  For written permission,
  - *    please contact [EMAIL PROTECTED]
  + *    permission of The OpenEJB Group.  For written permission,
  + *    please contact [EMAIL PROTECTED]
    *
  - * 4. Products derived from this Software may not be called "Exolab"
  - *    nor may "Exolab" appear in their names without prior written
  - *    permission of Exoffice Technologies. Exolab is a registered
  - *    trademark of Exoffice Technologies.
  + * 4. Products derived from this Software may not be called "OpenEJB"
  + *    nor may "OpenEJB" appear in their names without prior written
  + *    permission of The OpenEJB Group. OpenEJB is a registered
  + *    trademark of The OpenEJB Group.
    *
  - * 5. Due credit should be given to the Exolab Project
  - *    (http://www.exolab.org/).
  + * 5. Due credit should be given to the OpenEJB Project
  + *    (http://openejb.org/).
    *
  - * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
  + * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
    * ``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
  - * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  + * THE OPENEJB GROUP 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)
  @@ -38,171 +38,104 @@
    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    * OF THE POSSIBILITY OF SUCH DAMAGE.
    *
  - * Copyright 1999 (C) Exoffice Technologies Inc. All Rights Reserved.
  + * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
    *
    * $Id$
    */
   package org.openejb.resource.jdbc;
   
  -import java.sql.DriverManager;
  +import org.openejb.core.EnvProps;
  +import org.openejb.util.Logger;
   
  +import javax.resource.ResourceException;
   import javax.resource.spi.ConnectionManager;
   import javax.resource.spi.ConnectionRequestInfo;
  -import javax.resource.spi.EISSystemException;
   import javax.resource.spi.ManagedConnection;
   import javax.resource.spi.ManagedConnectionFactory;
  -import javax.resource.spi.ResourceAdapter;
   import javax.resource.spi.ResourceAdapterInternalException;
  +import javax.security.auth.Subject;
  +import java.io.PrintWriter;
  +import java.util.Set;
   
  -import org.openejb.core.EnvProps;
  -import org.openejb.util.FileUtils;
  -import org.openejb.util.Logger;
  -import org.openejb.OpenEJB;
  +public class JdbcManagedConnectionFactory implements 
javax.resource.spi.ManagedConnectionFactory, java.io.Serializable {
   
  -
  -public class JdbcManagedConnectionFactory 
  -implements javax.resource.spi.ManagedConnectionFactory, java.io.Serializable 
{
  -    
       protected Logger logger = Logger.getInstance("OpenEJB.connector", 
"org.openejb.alt.util.resources");
  +    private ManagedConnectionFactory factory;
  +
  +    public void init(java.util.Properties props) throws 
javax.resource.spi.ResourceAdapterInternalException {
  +        String defaultUserName = props.getProperty(EnvProps.USER_NAME);
  +        String defaultPassword = props.getProperty(EnvProps.PASSWORD);
  +        String url = props.getProperty(EnvProps.JDBC_URL);
  +        String driver = props.getProperty(EnvProps.JDBC_DRIVER);
  +
  +        loadDriver(driver);
   
  -    protected String jdbcDriver;
  -    protected String jdbcUrl;
  -    protected String defaultUserName;
  -    protected String defaultPassword;
  -    protected java.io.PrintWriter logWriter;
  -    private int hashCode = 0;// assumes that this class is immutable
  -    
  -    public void init(java.util.Properties props)throws 
javax.resource.spi.ResourceAdapterInternalException{
  -        setDefaultUserName(props.getProperty(EnvProps.USER_NAME));   
  -        setDefaultPassword(props.getProperty(EnvProps.PASSWORD));   
  -        setJdbcUrl(props.getProperty(EnvProps.JDBC_URL));   
  -        setJdbcDriver(props.getProperty(EnvProps.JDBC_DRIVER));   
  -
  -        // Test the connection out, problems are logged
  -        testDriver();
  -    }
  -
  -    protected void testDriver() {
  -        java.sql.Connection physicalConn = null;
  -        try{
  -            physicalConn = DriverManager.getConnection(jdbcUrl, 
defaultUserName, defaultPassword);        
  -        }catch(Throwable e){
  -            logger.error("Testing driver failed.  " + "[" + jdbcUrl + "]  "
  +        factory = new BasicManagedConnectionFactory(driver, url, 
defaultUserName, defaultPassword);
  +
  +        if (driver.equals("org.enhydra.instantdb.jdbc.idbDriver")) {
  +            factory = new ManagedConnectionFactoryPathHack(factory);
  +        }
  +
  +        JdbcConnectionRequestInfo info = new 
JdbcConnectionRequestInfo(defaultUserName, defaultPassword, driver, url);
  +        ManagedConnection connection = null;
  +        try {
  +            connection = factory.createManagedConnection(null, info);
  +        } catch (Throwable e) {
  +            logger.error("Testing driver failed.  " + "[" + url + "]  "
                       + "Could not obtain a physical JDBC connection from the 
DriverManager."
                       + "\nThe error message was:\n" + e.getMessage() + 
"\nPossible cause:"
                       + "\n\to JDBC driver classes are not available to 
OpenEJB"
                       + "\n\to Relative paths are not resolved properly");
           } finally {
  -            try{
  -                physicalConn.close();
  -            } catch (Exception dontCare){}
  +            try {
  +                connection.destroy();
  +            } catch (ResourceException dontCare) {
  +            }
           }
       }
  -   
  -    public void setDefaultUserName(String dun){
  -        defaultUserName = dun;
  -    }
  -    public void setDefaultPassword(String dp){
  -        defaultPassword = dp;
  -    }
  -    public void setJdbcUrl(String url){
  -        jdbcUrl = url;
  -    }
  -    public void setJdbcDriver(String driver) throws 
javax.resource.spi.ResourceAdapterInternalException{
  -        jdbcDriver = driver;
  -        try{
  -            ClassLoader cl = OpenEJB.getContextClassLoader();
  -            Class.forName( jdbcDriver, true, cl);
  -        }catch(ClassNotFoundException cnf){
  -            //BUG: If this situtuation occurs, only the words:
  -            // java.lang.reflect.InvocationTargetException: 
javax.resource.spi.ResourceAdapterInternalException
  -            // are outputted to the screen.
  -           //cnf.printStackTrace(System.out);
  -           ResourceAdapterInternalException raie =  new 
ResourceAdapterInternalException("JDBC Driver class \""+jdbcDriver+"\" not 
found by class loader", ErrorCode.JDBC_0002);
  -           //raie.setLinkedException(cnf);
  -           throw raie;
  +
  +    private void loadDriver(String driver) throws 
ResourceAdapterInternalException {
  +        try {
  +            ClassLoader classLoader = (ClassLoader) 
java.security.AccessController.doPrivileged(new 
java.security.PrivilegedAction() {
  +                public Object run() {
  +                    return Thread.currentThread().getContextClassLoader();
  +                }
  +            });
  +            Class.forName(driver, true, classLoader);
  +        } catch (ClassNotFoundException cnf) {
  +            throw new ResourceAdapterInternalException("JDBC Driver class 
\"" + driver + "\" not found by class loader", ErrorCode.JDBC_0002);
           }
       }
  -    public String getDefaultUserName(){
  -        return defaultUserName;
  +
  +    public Object createConnectionFactory(ConnectionManager 
connectionManager) throws ResourceException {
  +        return factory.createConnectionFactory(connectionManager);
       }
  -    public String getDefaultPassword(){
  -        return defaultPassword;
  +
  +    public Object createConnectionFactory() throws ResourceException {
  +        return factory.createConnectionFactory();
       }
  -    public String getJdbcDriver(){
  -        return jdbcDriver;
  +
  +    public ManagedConnection createManagedConnection(Subject subject, 
ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
  +        return factory.createManagedConnection(subject, 
connectionRequestInfo);
       }
  -    public String getJdbcUrl(){
  -        return jdbcUrl;
  -    }
  -    
  -    public java.lang.Object createConnectionFactory()  throws 
javax.resource.ResourceException{
  -
  -        throw new javax.resource.NotSupportedException("This connector must 
be used with an application server connection manager");
  -    }
  -    public java.lang.Object createConnectionFactory(ConnectionManager 
cxManager)  throws javax.resource.ResourceException{
  -        // return the DataSource
  -        return new JdbcConnectionFactory(this, cxManager);
  -    } 
  -    
  -    public ManagedConnection 
createManagedConnection(javax.security.auth.Subject 
subject,ConnectionRequestInfo cxRequestInfo)  throws 
javax.resource.ResourceException{
  -        JdbcConnectionRequestInfo rxInfo = 
(JdbcConnectionRequestInfo)cxRequestInfo;
  -        java.sql.Connection physicalConn;
  -        String userDir = System.getProperty("user.dir");
  -        try{
  -            // @TODO: Why is it done?
  -            String openejbHome = System.getProperty("openejb.home");
  -            if (openejbHome != null) {
  -                System.setProperty("user.dir", openejbHome);
  -            }
  -            physicalConn = DriverManager.getConnection(jdbcUrl, 
rxInfo.getUserName(), rxInfo.getPassword());        
  -        }catch(java.sql.SQLException sqlE){
  -            EISSystemException eisse =  new EISSystemException("Could not 
obtain a physical JDBC connection from the DriverManager");
  -            eisse.setLinkedException(sqlE);
  -            throw eisse;
  -        } finally {
  -            System.setProperty("user.dir",userDir);
  -        }
  -        return new JdbcManagedConnection(this, physicalConn, rxInfo);
  -    } 
  -    public boolean equals(Object other){
  -        if(other instanceof JdbcManagedConnectionFactory){
  -            JdbcManagedConnectionFactory otherMCF = 
(JdbcManagedConnectionFactory)other;
  -            if(jdbcDriver.equals(otherMCF.jdbcDriver) && 
jdbcUrl.equals(otherMCF.jdbcUrl) &&
  -               defaultUserName.equals(otherMCF.defaultUserName) && 
defaultPassword.equals(otherMCF.defaultPassword) )  {
  -                return true;
  -            }
  -        }
  -        return false;
  +
  +    public ManagedConnection matchManagedConnections(Set set, Subject 
subject, ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
  +        return factory.matchManagedConnections(set, subject, 
connectionRequestInfo);
       }
  -    public java.io.PrintWriter getLogWriter(){
  -        return logWriter;
  -    } 
  -    public int hashCode(){
  -        if(hashCode != 0) return hashCode;
  -        hashCode = 
jdbcDriver.hashCode()^jdbcUrl.hashCode()^defaultUserName.hashCode()^defaultPassword.hashCode();
  -        return hashCode;
  -    }
  -    public ManagedConnection matchManagedConnections(java.util.Set 
connectionSet,javax.security.auth.Subject subject, ConnectionRequestInfo 
cxRequestInfo)  throws javax.resource.ResourceException{
  -        if(cxRequestInfo instanceof JdbcConnectionRequestInfo){
  -            Object [] connections = connectionSet.toArray();
  -            for(int i = 0; i < connections.length; i++){
  -                JdbcManagedConnection managedConn = 
(JdbcManagedConnection)connections[i];
  -                if(managedConn.getRequestInfo().equals(cxRequestInfo))
  -                    return managedConn;
  -            }
  -        }
  -        return null;
  -    } 
  -    public void setLogWriter(java.io.PrintWriter out) {
  -        logWriter = out;
  +
  +    public void setLogWriter(PrintWriter printWriter) throws 
ResourceException {
  +        factory.setLogWriter(printWriter);
       }
   
  -    public ResourceAdapter getResourceAdapter(){
  -        return null; //TODO: implement this
  +    public PrintWriter getLogWriter() throws ResourceException {
  +        return factory.getLogWriter();
       }
  -    public void setResourceAdapter(ResourceAdapter ra){
  -        //TODO: implement this
  +
  +    public int hashCode() {
  +        return factory.hashCode();
  +    }
  +
  +    public boolean equals(Object o) {
  +        return factory.equals(o);
       }
  -    
   }
  
  
  
  1.1                  
openejb1/modules/core/src/java/org/openejb/resource/jdbc/BasicManagedConnectionFactory.java
  
  Index: BasicManagedConnectionFactory.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 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 name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``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 OPENEJB GROUP 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.
   *
   * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: BasicManagedConnectionFactory.java,v 1.1 2005/08/23 04:12:53 dblevins 
Exp $
   */
  
  package org.openejb.resource.jdbc;
  
  import javax.resource.spi.ConnectionManager;
  import javax.resource.spi.ConnectionRequestInfo;
  import javax.resource.spi.EISSystemException;
  import javax.resource.spi.ManagedConnection;
  import javax.resource.spi.ResourceAdapter;
  import javax.security.auth.Subject;
  import java.sql.DriverManager;
  import java.sql.Connection;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2005/08/23 04:12:53 $
   */
  public class BasicManagedConnectionFactory implements 
javax.resource.spi.ManagedConnectionFactory, java.io.Serializable {
      private final String jdbcDriver;
      private final String jdbcUrl;
      private final String defaultUserName;
      private final String defaultPassword;
      private java.io.PrintWriter logWriter;
      private final int hashCode;
  
      public BasicManagedConnectionFactory(String jdbcDriver, String jdbcUrl, 
String defaultUserName, String defaultPassword) {
          this.jdbcDriver = jdbcDriver;
          this.jdbcUrl = jdbcUrl;
          this.defaultUserName = defaultUserName;
          this.defaultPassword = defaultPassword;
          hashCode = jdbcDriver.hashCode() ^ jdbcUrl.hashCode() ^ 
defaultUserName.hashCode() ^ defaultPassword.hashCode();
      }
  
      public Object createConnectionFactory() throws 
javax.resource.ResourceException {
          throw new javax.resource.NotSupportedException("This connector must 
be used with an application server connection manager");
      }
  
      public Object createConnectionFactory(ConnectionManager cxManager) throws 
javax.resource.ResourceException {
          return new JdbcConnectionFactory(this, cxManager, jdbcUrl, 
jdbcDriver, defaultPassword, defaultUserName);
      }
  
      public ManagedConnection createManagedConnection(Subject subject, 
ConnectionRequestInfo connectionRequestInfo) throws 
javax.resource.ResourceException {
          try {
              JdbcConnectionRequestInfo request = (JdbcConnectionRequestInfo) 
connectionRequestInfo;
              Connection connection = DriverManager.getConnection(jdbcUrl, 
request.getUserName(), request.getPassword());
              return new JdbcManagedConnection(this, connection, request);
          } catch (java.sql.SQLException e) {
              throw (EISSystemException)new EISSystemException("Could not 
obtain a physical JDBC connection from the DriverManager").initCause(e);
          }
      }
  
      public boolean equals(Object object) {
          if (!(object instanceof BasicManagedConnectionFactory)) {
              return false;
          }
          BasicManagedConnectionFactory that = (BasicManagedConnectionFactory) 
object;
          return jdbcDriver.equals(that.jdbcDriver) && 
jdbcUrl.equals(that.jdbcUrl) && defaultUserName.equals(that.defaultUserName) && 
defaultPassword.equals(that.defaultPassword);
      }
  
      public java.io.PrintWriter getLogWriter() {
          return logWriter;
      }
  
      public int hashCode() {
          return hashCode;
      }
  
      public ManagedConnection matchManagedConnections(java.util.Set 
connectionSet, javax.security.auth.Subject subject, ConnectionRequestInfo 
connectionInfo) throws javax.resource.ResourceException {
          if (!(connectionInfo instanceof JdbcConnectionRequestInfo)) {
              return null;
          }
  
          JdbcManagedConnection[] connections = (JdbcManagedConnection[]) 
connectionSet.toArray(new JdbcManagedConnection[]{});
          int i = 0;
          for (; i < connections.length && 
!connections[i].getRequestInfo().equals(connectionInfo); i++) {
          }
          return (i < connections.length) ? connections[i] : null;
      }
  
      public void setLogWriter(java.io.PrintWriter out) {
          logWriter = out;
      }
  
      public ResourceAdapter getResourceAdapter() {
          return null; //TODO: implement this
      }
  
      public void setResourceAdapter(ResourceAdapter ra) {
          //TODO: implement this
      }
  
  
  }
  
  
  
  1.1                  
openejb1/modules/core/src/java/org/openejb/resource/jdbc/ManagedConnectionFactoryPathHack.java
  
  Index: ManagedConnectionFactoryPathHack.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 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 name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.org/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``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 OPENEJB GROUP 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.
   *
   * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: ManagedConnectionFactoryPathHack.java,v 1.1 2005/08/23 04:12:53 
dblevins Exp $
   */
  
  package org.openejb.resource.jdbc;
  
  import org.openejb.loader.SystemInstance;
  
  import javax.resource.spi.ManagedConnectionFactory;
  import javax.resource.spi.ConnectionManager;
  import javax.resource.spi.ManagedConnection;
  import javax.resource.spi.ConnectionRequestInfo;
  import javax.resource.spi.EISSystemException;
  import javax.resource.ResourceException;
  import javax.security.auth.Subject;
  import java.util.Set;
  import java.util.Properties;
  import java.io.PrintWriter;
  import java.io.File;
  import java.sql.DriverManager;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2005/08/23 04:12:53 $
   */
  public class ManagedConnectionFactoryPathHack implements 
javax.resource.spi.ManagedConnectionFactory, java.io.Serializable {
      private final ManagedConnectionFactory factory;
  
      public ManagedConnectionFactoryPathHack(ManagedConnectionFactory factory) 
{
          this.factory = factory;
      }
  
      public Object createConnectionFactory(ConnectionManager 
connectionManager) throws ResourceException {
          return factory.createConnectionFactory(connectionManager);
      }
  
      public Object createConnectionFactory() throws ResourceException {
          return factory.createConnectionFactory();
      }
  
      public ManagedConnection createManagedConnection(Subject subject, 
ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
          // DMB: This hack makes me want to vomit, but it will have to do until
          // we figure out how to get relative file paths in nested configs, 
like
          // the instantdb config file, to resolve to openejb.base or something 
predictable.
          Properties systemProperties = System.getProperties();
          synchronized(systemProperties){
              String userDir = systemProperties.getProperty("user.dir");
              try{
                  File base = SystemInstance.get().getBase().getDirectory();
                  systemProperties.setProperty("user.dir", 
base.getAbsolutePath());
                  return factory.createManagedConnection(subject, 
connectionRequestInfo);
              } finally {
                  systemProperties.setProperty("user.dir",userDir);
              }
          }
      }
  
      public ManagedConnection matchManagedConnections(Set set, Subject 
subject, ConnectionRequestInfo connectionRequestInfo) throws ResourceException {
          return factory.matchManagedConnections(set, subject, 
connectionRequestInfo);
      }
  
      public void setLogWriter(PrintWriter printWriter) throws 
ResourceException {
          factory.setLogWriter(printWriter);
      }
  
      public PrintWriter getLogWriter() throws ResourceException {
          return factory.getLogWriter();
      }
  
      public int hashCode() {
          return factory.hashCode();
      }
  
      public boolean equals(Object o) {
          return factory.equals(o);
      }
  }
  
  
  

Reply via email to