portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r728911 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-rdbms/ components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/ components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ jetspee...
Date Tue, 23 Dec 2008 09:42:17 GMT
Author: woonsan
Date: Tue Dec 23 01:42:17 2008
New Revision: 728911

URL: http://svn.apache.org/viewvc?rev=728911&view=rev
Log:
Makes it to be built with JDK 1.6 also.

Added:
    portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/DelegatingObjectProxy.java
  (with props)
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/pom.xml
    portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/DebuggingDataSourceJndiObjectFactoryBean.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionRepositoryEntry.java

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/pom.xml?rev=728911&r1=728910&r2=728911&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/pom.xml (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/pom.xml Tue Dec 23 01:42:17
2008
@@ -47,6 +47,11 @@
     </dependency>
     <dependency>
       <groupId>${pom.groupId}</groupId>
+      <artifactId>jetspeed-commons</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
       <artifactId>jetspeed-cm</artifactId>
       <version>${pom.version}</version>
     </dependency>

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/DebuggingDataSourceJndiObjectFactoryBean.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/DebuggingDataSourceJndiObjectFactoryBean.java?rev=728911&r1=728910&r2=728911&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/DebuggingDataSourceJndiObjectFactoryBean.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/jndi/DebuggingDataSourceJndiObjectFactoryBean.java
Tue Dec 23 01:42:17 2008
@@ -39,6 +39,8 @@
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.jndi.JndiObjectFactoryBean;
 
+import org.apache.jetspeed.util.DelegatingObjectProxy;
+
 /**
 * @version $Id$
 */
@@ -80,7 +82,7 @@
        long   totalOverhead;
    }
 
-   class ConnectionWrapper implements Connection
+   public class ConnectionWrapper
    {
        private Connection connection;
        private Integer connectionKey;
@@ -138,184 +140,9 @@
                }                
            }
        }
-
-       public void commit() throws SQLException
-       {
-           connection.commit();
-       }
-
-       public Statement createStatement() throws SQLException
-       {
-           return connection.createStatement();
-       }
-
-       public Statement createStatement(int resultSetType, int resultSetConcurrency, int
resultSetHoldability)
-                                                                                        
                     throws SQLException
-       {
-           return connection.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
-       }
-
-       public Statement createStatement(int resultSetType, int resultSetConcurrency) throws
SQLException
-       {
-           return connection.createStatement(resultSetType, resultSetConcurrency);
-       }
-
-       public boolean getAutoCommit() throws SQLException
-       {
-           return connection.getAutoCommit();
-       }
-
-       public String getCatalog() throws SQLException
-       {
-           return connection.getCatalog();
-       }
-
-       public int getHoldability() throws SQLException
-       {
-           return connection.getHoldability();
-       }
-
-       public DatabaseMetaData getMetaData() throws SQLException
-       {
-           return connection.getMetaData();
-       }
-
-       public int getTransactionIsolation() throws SQLException
-       {
-           return connection.getTransactionIsolation();
-       }
-
-       public Map<String, Class<?>> getTypeMap() throws SQLException
-       {
-           return connection.getTypeMap();
-       }
-
-       public SQLWarning getWarnings() throws SQLException
-       {
-           return connection.getWarnings();
-       }
-
-       public boolean isClosed() throws SQLException
-       {
-           return connection.isClosed();
-       }
-
-       public boolean isReadOnly() throws SQLException
-       {
-           return connection.isReadOnly();
-       }
-
-       public String nativeSQL(String sql) throws SQLException
-       {
-           return connection.nativeSQL(sql);
-       }
-
-       public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
-                                            int resultSetHoldability) throws SQLException
-       {
-           return connection.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
-       }
-
-       public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)
-                                                                                        
           throws SQLException
-       {
-           return connection.prepareCall(sql, resultSetType, resultSetConcurrency);
-       }
-
-       public CallableStatement prepareCall(String sql) throws SQLException
-       {
-           return connection.prepareCall(sql);
-       }
-
-       public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
-                                                 int resultSetHoldability) throws SQLException
-       {
-           return connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
-       }
-
-       public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
-                                                                                        
                throws SQLException
-       {
-           return connection.prepareStatement(sql, resultSetType, resultSetConcurrency);
-       }
-
-       public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws
SQLException
-       {
-           return connection.prepareStatement(sql, autoGeneratedKeys);
-       }
-
-       public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws
SQLException
-       {
-           return connection.prepareStatement(sql, columnIndexes);
-       }
-
-       public PreparedStatement prepareStatement(String sql, String[] columnNames) throws
SQLException
-       {
-           return connection.prepareStatement(sql, columnNames);
-       }
-
-       public PreparedStatement prepareStatement(String sql) throws SQLException
-       {
-           return connection.prepareStatement(sql);
-       }
-
-       public void releaseSavepoint(Savepoint savepoint) throws SQLException
-       {
-           connection.releaseSavepoint(savepoint);
-       }
-
-       public void rollback() throws SQLException
-       {
-           connection.rollback();
-       }
-
-       public void rollback(Savepoint savepoint) throws SQLException
-       {
-           connection.rollback(savepoint);
-       }
-
-       public void setAutoCommit(boolean autoCommit) throws SQLException
-       {
-           connection.setAutoCommit(autoCommit);
-       }
-
-       public void setCatalog(String catalog) throws SQLException
-       {
-           connection.setCatalog(catalog);
-       }
-
-       public void setHoldability(int holdability) throws SQLException
-       {
-           connection.setHoldability(holdability);
-       }
-
-       public void setReadOnly(boolean readOnly) throws SQLException
-       {
-           connection.setReadOnly(readOnly);
-       }
-
-       public Savepoint setSavepoint() throws SQLException
-       {
-           return connection.setSavepoint();
-       }
-
-       public Savepoint setSavepoint(String name) throws SQLException
-       {
-           return connection.setSavepoint(name);
-       }
-
-       public void setTransactionIsolation(int level) throws SQLException
-       {
-           connection.setTransactionIsolation(level);
-       }
-
-       public void setTypeMap(Map<String, Class<?>> map) throws SQLException
-       {
-           connection.setTypeMap(map);
-       }
    }
 
-   public class DataSourceWrapper implements DataSource
+   public class DataSourceWrapper
    {
        DataSource ds;
 
@@ -370,26 +197,6 @@
                throw e;
            }
        }
-
-       public int getLoginTimeout() throws SQLException
-       {
-           return ds.getLoginTimeout();
-       }
-
-       public PrintWriter getLogWriter() throws SQLException
-       {
-           return ds.getLogWriter();
-       }
-
-       public void setLoginTimeout(int seconds) throws SQLException
-       {
-           ds.setLoginTimeout(seconds);
-       }
-
-       public void setLogWriter(PrintWriter out) throws SQLException
-       {
-           ds.setLogWriter(out);
-       }
    }
 
    public void setDebugCallStackPackages(List list)
@@ -436,7 +243,9 @@
                {
                    cachedWrapper = new DataSourceWrapper(ds);
                }
-               return cachedWrapper;
+               
+               DataSource dsProxy = (DataSource) DelegatingObjectProxy.createProxy(new Class
[] { DataSource.class }, cachedWrapper, ds);
+               return dsProxy;
            }
        }
        return ds;
@@ -462,8 +271,9 @@
                    }
                    statistics.callCount++;
                    Integer connectionKey = new Integer(connectionSequence++);
-                   connection = new ConnectionWrapper(connection, connectionKey, statisticsKey,
startTime);
-                   cachedConnections.put(connectionKey, (ConnectionWrapper)connection);
+                   ConnectionWrapper cw = new ConnectionWrapper(connection, connectionKey,
statisticsKey, startTime);
+                   connection = (Connection) DelegatingObjectProxy.createProxy(new Class
[] { Connection.class }, cw, connection);
+                   cachedConnections.put(connectionKey, cw);
                }
            }
        }
@@ -581,6 +391,10 @@
                i++;
                for (; i < ste.length; i++)
                {
+                   if (ste[i].getClassName().equals("org.apache.jetspeed.util.DelegatingObjectProxy")
&& ste[i].getMethodName().equals("invoke"))
+                   {
+                       continue;
+                   }                                    
                    if (ste[i].getClassName().equals("org.apache.jetspeed.components.rdbms.ojb.ConnectionManagerImpl")
&& ste[i].getMethodName().equals("getConnection"))
                    {
                        continue;

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionRepositoryEntry.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionRepositoryEntry.java?rev=728911&r1=728910&r2=728911&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionRepositoryEntry.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-rdbms/src/main/java/org/apache/jetspeed/components/rdbms/ojb/ConnectionRepositoryEntry.java
Tue Dec 23 01:42:17 2008
@@ -426,7 +426,7 @@
             // #ifdef JDBC4 return getConnection().isWrapperFor(iface);
         }
 
-        <T> T unwrap(Class<T> iface) throws SQLException
+        public <T> T unwrap(Class<T> iface) throws SQLException
         {
             throw new SQLException("PoolingDataSource is not a wrapper.");
             //#ifdef JDBC4 return getConnection().unwrap(iface);

Added: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/DelegatingObjectProxy.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/DelegatingObjectProxy.java?rev=728911&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/DelegatingObjectProxy.java
(added)
+++ portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/DelegatingObjectProxy.java
Tue Dec 23 01:42:17 2008
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.util;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * DelegatingObjectProxy is a convenient utility class to provide a dynamic proxy
+ * by using delegating object(s).
+ * If a delegator object containing the invoked method is found, 
+ * the proxy will invoke the method of the delegator object.
+ * 
+ * @author <a href="mailto:woonsan@apache.org">Woonsan Ko</a>
+ * @version $Id$
+ */
+public class DelegatingObjectProxy extends BaseObjectProxy
+{
+    protected Object [] delegatorObjects;
+    protected Class [] proxyInterfaces;
+    protected Map<Method, ObjectMethodPair> delegatorObjectMethodPairCache = new HashMap<Method,
ObjectMethodPair>();
+
+    public static Object createProxy(Class [] proxyInterfaces, Object... delegatorObjects)
+    {
+        if (proxyInterfaces == null || proxyInterfaces.length == 0)
+        {
+            throw new IllegalArgumentException("No proxy interface.");
+        }
+        
+        if (delegatorObjects == null || delegatorObjects.length == 0)
+        {
+            throw new IllegalArgumentException("No delegator object.");
+        }
+        
+        return createProxy(proxyInterfaces, delegatorObjects[0].getClass().getClassLoader(),
delegatorObjects);
+    }
+    
+    public static Object createProxy(Class [] proxyInterfaces, ClassLoader classLoader, Object...
delegatorObjects)
+    {
+        if (proxyInterfaces == null || proxyInterfaces.length == 0)
+        {
+            throw new IllegalArgumentException("No proxy interface.");
+        }
+        
+        if (delegatorObjects == null || delegatorObjects.length == 0)
+        {
+            throw new IllegalArgumentException("No delegator object.");
+        }
+        
+        InvocationHandler handler = new DelegatingObjectProxy(proxyInterfaces, delegatorObjects);
+        return Proxy.newProxyInstance(classLoader, proxyInterfaces, handler);
+    }
+    
+    public DelegatingObjectProxy(Class [] proxyInterfaces, Object... delegatorObjects)
+    {
+        this.proxyInterfaces = proxyInterfaces;
+        this.delegatorObjects = delegatorObjects;
+    }
+    
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+    {
+        Class targetProxyInterface = null;
+        Class declaringClass = method.getDeclaringClass();
+        
+        for (Class proxyInterface : this.proxyInterfaces)
+        {
+            if (declaringClass == proxyInterface)
+            {
+                targetProxyInterface = proxyInterface;
+                break;
+            }
+        }
+        
+        if (targetProxyInterface != null)
+        {
+            ObjectMethodPair targetObjectMethodPair = findDelegatorObjectMethodPair(targetProxyInterface,
method);
+            return targetObjectMethodPair.method.invoke(targetObjectMethodPair.object, args);
+        }
+        else
+        {
+            return super.invoke(proxy, method, args);
+        }
+    }
+
+    private ObjectMethodPair findDelegatorObjectMethodPair(Class proxyInterface, Method method)
throws SecurityException, NoSuchMethodException
+    {
+        ObjectMethodPair objectMethodPair = this.delegatorObjectMethodPairCache.get(method);
+        
+        if (objectMethodPair == null)
+        {
+            Method delegatorMethod = null;
+            Class targetType = null;
+            
+            for (Object delegatorObject : this.delegatorObjects)
+            {
+                targetType = delegatorObject.getClass();
+
+                if (proxyInterface.isAssignableFrom(targetType))
+                {
+                    targetType = proxyInterface;
+                }
+                
+                try
+                {
+                    delegatorMethod = targetType.getMethod(method.getName(), method.getParameterTypes());
+                }
+                catch (Throwable th)
+                {
+                }
+                
+                if (delegatorMethod != null)
+                {
+                    objectMethodPair = new ObjectMethodPair(delegatorObject, delegatorMethod);
+                    this.delegatorObjectMethodPairCache.put(method, objectMethodPair);
+                    break;
+                }
+            }
+            
+            if (objectMethodPair == null)
+            {
+                throw new NoSuchMethodException(method.toString());
+            }
+        }
+        
+        return objectMethodPair;
+    }
+    
+    private class ObjectMethodPair
+    {
+        Object object;
+        Method method;
+        
+        ObjectMethodPair(Object object, Method method)
+        {
+            this.object = object;
+            this.method = method;
+        }
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/DelegatingObjectProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/DelegatingObjectProxy.java
------------------------------------------------------------------------------
    svn:keywords = Id



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message