tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1499449 - in /tomee/tomee/trunk/tomee: tomee-common/src/main/java/org/apache/tomee/common/AbstractObjectFactory.java tomee-jdbc/src/main/java/org/apache/tomee/jdbc/TomEEDataSourceCreator.java
Date Wed, 03 Jul 2013 15:44:39 GMT
Author: rmannibucau
Date: Wed Jul  3 15:44:39 2013
New Revision: 1499449

URL: http://svn.apache.org/r1499449
Log:
TOMEE-988 cleaning up our tomee datasource creator + avoiding to leak due to our proxies

Modified:
    tomee/tomee/trunk/tomee/tomee-common/src/main/java/org/apache/tomee/common/AbstractObjectFactory.java
    tomee/tomee/trunk/tomee/tomee-jdbc/src/main/java/org/apache/tomee/jdbc/TomEEDataSourceCreator.java

Modified: tomee/tomee/trunk/tomee/tomee-common/src/main/java/org/apache/tomee/common/AbstractObjectFactory.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-common/src/main/java/org/apache/tomee/common/AbstractObjectFactory.java?rev=1499449&r1=1499448&r2=1499449&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-common/src/main/java/org/apache/tomee/common/AbstractObjectFactory.java
(original)
+++ tomee/tomee/trunk/tomee/tomee-common/src/main/java/org/apache/tomee/common/AbstractObjectFactory.java
Wed Jul  3 15:44:39 2013
@@ -55,9 +55,9 @@ public abstract class AbstractObjectFact
             if (jndiName.startsWith("java:")) {
                 try {
                     return new InitialContext().lookup(jndiName);
-                } catch (NameNotFoundException ignored) {
+                } catch (final NameNotFoundException ignored) {
                     // no-op
-                } catch (NoInitialContextException nice) {
+                } catch (final NoInitialContextException nice) {
                     final Properties props = new Properties();
                     props.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
                     try {

Modified: tomee/tomee/trunk/tomee/tomee-jdbc/src/main/java/org/apache/tomee/jdbc/TomEEDataSourceCreator.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-jdbc/src/main/java/org/apache/tomee/jdbc/TomEEDataSourceCreator.java?rev=1499449&r1=1499448&r2=1499449&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-jdbc/src/main/java/org/apache/tomee/jdbc/TomEEDataSourceCreator.java
(original)
+++ tomee/tomee/trunk/tomee/tomee-jdbc/src/main/java/org/apache/tomee/jdbc/TomEEDataSourceCreator.java
Wed Jul  3 15:44:39 2013
@@ -38,10 +38,8 @@ import org.apache.tomcat.jdbc.pool.Poole
 import javax.management.ObjectName;
 import javax.sql.DataSource;
 import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Proxy;
-import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Map;
 import java.util.Properties;
@@ -252,7 +250,11 @@ public class TomEEDataSourceCreator exte
             }
 
             // prevent overriding of the configuration
-            return (PoolConfiguration) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
CONNECTION_POOL_CLASS, new ReadOnlyConnectionpool(pool));
+            try {
+                return (PoolConfiguration) Proxy.newProxyInstance(TomEEDataSourceCreator.class.getClassLoader(),
CONNECTION_POOL_CLASS, new ReadOnlyConnectionpool(pool));
+            } catch (final Throwable e) {
+                return (PoolConfiguration) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
CONNECTION_POOL_CLASS, new ReadOnlyConnectionpool(pool));
+            }
         }
 
         private void initJmx(final String name) {
@@ -279,20 +281,6 @@ public class TomEEDataSourceCreator exte
                 }
             }
         }
-
-        @Override
-        public Connection getConnection() throws SQLException {
-            final Connection connection = super.getConnection();
-            return (Connection) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
-                    new Class<?>[] { Connection.class }, new ContantHashCodeHandler(connection,
connection.hashCode()));
-        }
-
-        @Override
-        public Connection getConnection(final String u, final String p) throws SQLException
{
-            final Connection connection = super.getConnection(u, p);
-            return (Connection) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
-                    new Class<?>[] { Connection.class }, new ContantHashCodeHandler(connection,
connection.hashCode()));
-        }
     }
 
     private static class ReadOnlyConnectionpool implements InvocationHandler {
@@ -334,26 +322,4 @@ public class TomEEDataSourceCreator exte
             return con;
         }
     }
-
-    private static class ContantHashCodeHandler implements InvocationHandler { // will be
fixed in tomcat-jdbc in next version
-        private final Object delegate;
-        private final int hashCode;
-
-        public ContantHashCodeHandler(final Object object, int hashCode) {
-            this.delegate = object;
-            this.hashCode = hashCode;
-        }
-
-        @Override
-        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
{
-            if ("hashCode".equals(method.getName())) {
-                return hashCode;
-            }
-            try {
-                return method.invoke(delegate, args);
-            } catch (InvocationTargetException ite) {
-                throw ite.getCause();
-            }
-        }
-    }
 }



Mime
View raw message