[seam-commits] Seam SVN: r9695 - in trunk/src/main/org/jboss/seam: util and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Dec 2 04:43:58 EST 2008


Author: shane.bryzak at jboss.com
Date: 2008-12-02 04:43:58 -0500 (Tue, 02 Dec 2008)
New Revision: 9695

Added:
   trunk/src/main/org/jboss/seam/util/DelegatingInvocationHandler.java
Modified:
   trunk/src/main/org/jboss/seam/persistence/AbstractPersistenceProvider.java
   trunk/src/main/org/jboss/seam/persistence/EntityManagerProxy.java
   trunk/src/main/org/jboss/seam/persistence/FullTextEntityManagerProxy.java
   trunk/src/main/org/jboss/seam/persistence/FullTextHibernateSessionProxy.java
   trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
   trunk/src/main/org/jboss/seam/persistence/HibernateSessionProxy.java
   trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java
Log:
JBSEAM-3457

Modified: trunk/src/main/org/jboss/seam/persistence/AbstractPersistenceProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/AbstractPersistenceProvider.java	2008-12-02 01:09:08 UTC (rev 9694)
+++ trunk/src/main/org/jboss/seam/persistence/AbstractPersistenceProvider.java	2008-12-02 09:43:58 UTC (rev 9695)
@@ -1,6 +1,7 @@
 package org.jboss.seam.persistence;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.util.Date;
 
 import javax.persistence.EntityManager;
@@ -109,8 +110,10 @@
     * Wrap the entityManager before returning it to the application
     */
    public EntityManager proxyEntityManager(EntityManager entityManager)
-   {
-      return new EntityManagerProxy(entityManager);
+   {      
+      return (EntityManager) Proxy.newProxyInstance(EntityManager.class.getClassLoader(), 
+            new Class[] {EntityManager.class}, 
+            new EntityManagerProxy(entityManager));      
    }
 
    /**

Modified: trunk/src/main/org/jboss/seam/persistence/EntityManagerProxy.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/EntityManagerProxy.java	2008-12-02 01:09:08 UTC (rev 9694)
+++ trunk/src/main/org/jboss/seam/persistence/EntityManagerProxy.java	2008-12-02 09:43:58 UTC (rev 9695)
@@ -3,70 +3,30 @@
 import java.io.Serializable;
 
 import javax.persistence.EntityManager;
-import javax.persistence.EntityTransaction;
-import javax.persistence.FlushModeType;
-import javax.persistence.LockModeType;
 import javax.persistence.Query;
 
 import org.jboss.seam.security.permission.PermissionManager;
+import org.jboss.seam.util.DelegatingInvocationHandler;
 
 /**
- * Proxies the EntityManager, and implements EL interpolation
- * in JPA-QL
+ * Proxies the EntityManager, and implements EL interpolation in JPA-QL
  * 
  * @author Gavin King
- *
+ * @author Shane Bryzak
  */
-public class EntityManagerProxy implements EntityManager, Serializable
+public class EntityManagerProxy extends DelegatingInvocationHandler<EntityManager> implements Serializable
 {
-   private EntityManager delegate;
-
    public EntityManagerProxy(EntityManager entityManager)
    {
-      delegate = entityManager;
+      super(entityManager);
    }
 
-   public void clear()
-   {
-      delegate.clear();
-   }
-
-   public void close()
-   {
-      delegate.close();
-   }
-
-   public boolean contains(Object entity)
-   {
-      return delegate.contains(entity);
-   }
-
-   public Query createNamedQuery(String name)
-   {
-      return delegate.createNamedQuery(name);
-   }
-
-   public Query createNativeQuery(String sql, Class clazz)
-   {
-      return delegate.createNativeQuery(sql, clazz);
-   }
-
-   public Query createNativeQuery(String sql, String lang)
-   {
-      return delegate.createNativeQuery(sql, lang);
-   }
-
-   public Query createNativeQuery(String sql)
-   {
-      return delegate.createNativeQuery(sql);
-   }
-
    public Query createQuery(String ejbql)
    {
       if ( ejbql.indexOf('#')>0 )
       {
          QueryParser qp = new QueryParser(ejbql);
-         Query query = delegate.createQuery( qp.getEjbql() );
+         Query query = super.getDelegate().createQuery( qp.getEjbql() );
          for (int i=0; i<qp.getParameterValueBindings().size(); i++)
          {
             query.setParameter( 
@@ -78,78 +38,19 @@
       }
       else
       {
-         return delegate.createQuery(ejbql);
+         return super.getDelegate().createQuery(ejbql);
       }
    }
 
-   public <T> T find(Class<T> clazz, Object id)
+ /*  public Object getDelegate()
    {
-      return delegate.find(clazz, id);
-   }
+      return PersistenceProvider.instance().proxyDelegate( super.getDelegate().getDelegate() );
+   }*/
 
-   public void flush()
-   {
-      delegate.flush();
-   }
 
-   public Object getDelegate()
-   {
-      return PersistenceProvider.instance().proxyDelegate( delegate.getDelegate() );
-   }
-
-   public FlushModeType getFlushMode()
-   {
-      return delegate.getFlushMode();
-   }
-
-   public <T> T getReference(Class<T> clazz, Object id)
-   {
-      return delegate.getReference(clazz, id);
-   }
-
-   public EntityTransaction getTransaction()
-   {
-      return delegate.getTransaction();
-   }
-
-   public boolean isOpen()
-   {
-      return delegate.isOpen();
-   }
-
-   public void joinTransaction()
-   {
-      delegate.joinTransaction();
-   }
-
-   public void lock(Object entity, LockModeType lm)
-   {
-      delegate.lock(entity, lm);
-   }
-
-   public <T> T merge(T entity)
-   {
-      return delegate.merge(entity);
-   }
-
-   public void persist(Object entity)
-   {
-      delegate.persist(entity);
-   }
-
-   public void refresh(Object entity)
-   {
-      delegate.refresh(entity);
-   }
-
    public void remove(Object entity)
    {
-      delegate.remove(entity);
+      super.getDelegate().remove(entity);
       PermissionManager.instance().clearPermissions(entity);
    }
-
-   public void setFlushMode(FlushModeType fm)
-   {
-      delegate.setFlushMode(fm);
-   }
 }

Modified: trunk/src/main/org/jboss/seam/persistence/FullTextEntityManagerProxy.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/FullTextEntityManagerProxy.java	2008-12-02 01:09:08 UTC (rev 9694)
+++ trunk/src/main/org/jboss/seam/persistence/FullTextEntityManagerProxy.java	2008-12-02 09:43:58 UTC (rev 9695)
@@ -1,50 +1,19 @@
 //$Id$
 package org.jboss.seam.persistence;
 
-import java.io.Serializable;
-
-import org.apache.lucene.search.Query;
-import org.hibernate.search.SearchFactory;
 import org.hibernate.search.jpa.FullTextEntityManager;
-import org.hibernate.search.jpa.FullTextQuery;
+import org.jboss.seam.util.DelegatingInvocationHandler;
 
 /**
  * Wrap a FullTextEntityManager
  *
  * @author Emmanuel Bernard
+ * @author Shane Bryzak
  */
-public class FullTextEntityManagerProxy extends EntityManagerProxy implements FullTextEntityManager
+public class FullTextEntityManagerProxy extends DelegatingInvocationHandler<FullTextEntityManager>
 {
-   private FullTextEntityManager fullTextEntityManager;
-
    public FullTextEntityManagerProxy(FullTextEntityManager entityManager)
    {
       super(entityManager);
-      this.fullTextEntityManager = entityManager;
    }
-
-   public FullTextQuery createFullTextQuery(Query query, Class... classes)
-   {
-      return fullTextEntityManager.createFullTextQuery(query, classes);
-   }
-
-   public void index(Object object)
-   {
-      fullTextEntityManager.index(object);
-   }
-
-   public SearchFactory getSearchFactory()
-   {
-      return fullTextEntityManager.getSearchFactory();
-   }
-
-   public void purge(Class aClass, Serializable serializable)
-   {
-      fullTextEntityManager.purge(aClass, serializable);
-   }
-
-   public void purgeAll(Class aClass)
-   {
-      fullTextEntityManager.purgeAll(aClass);
-   }
 }

Modified: trunk/src/main/org/jboss/seam/persistence/FullTextHibernateSessionProxy.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/FullTextHibernateSessionProxy.java	2008-12-02 01:09:08 UTC (rev 9694)
+++ trunk/src/main/org/jboss/seam/persistence/FullTextHibernateSessionProxy.java	2008-12-02 09:43:58 UTC (rev 9695)
@@ -1,168 +1,20 @@
 package org.jboss.seam.persistence;
 
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Query;
-import org.hibernate.search.FullTextQuery;
 import org.hibernate.search.FullTextSession;
-import org.hibernate.search.SearchFactory;
-import org.hibernate.type.Type;
+import org.jboss.seam.util.DelegatingInvocationHandler;
 
 /**
  * Wraps a Hibernate Search session
  * 
  * @author Gavin King
+ * @author Shane Bryzak
  *
  */
 @SuppressWarnings("deprecation")
-public class FullTextHibernateSessionProxy extends HibernateSessionProxy implements FullTextSession
-{
-   private FullTextSession fullTextSession;
-   
+public class FullTextHibernateSessionProxy extends DelegatingInvocationHandler<FullTextSession>
+{   
    public FullTextHibernateSessionProxy(FullTextSession fullTextSession)
    {
       super(fullTextSession);
-      this.fullTextSession = fullTextSession;
    }
-
-   public void index(Object arg0)
-   {
-      fullTextSession.index(arg0);
-   }
-
-   public FullTextQuery createFullTextQuery(org.apache.lucene.search.Query arg0, Class... arg1)
-   {
-      return fullTextSession.createFullTextQuery(arg0, arg1);
-   }
-
-   public Query createSQLQuery(String arg0, String arg1, Class arg2)
-   {
-      return fullTextSession.createSQLQuery(arg0, arg1, arg2);
-   }
-
-   public Query createSQLQuery(String arg0, String[] arg1, Class[] arg2)
-   {
-      return fullTextSession.createSQLQuery(arg0, arg1, arg2);
-   }
-
-   public int delete(String arg0, Object arg1, Type arg2) throws HibernateException
-   {
-      return fullTextSession.delete(arg0, arg1, arg2);
-   }
-
-   public int delete(String arg0, Object[] arg1, Type[] arg2) throws HibernateException
-   {
-      return fullTextSession.delete(arg0, arg1, arg2);
-   }
-
-   public int delete(String arg0) throws HibernateException
-   {
-      return fullTextSession.delete(arg0);
-   }
-
-   public Collection filter(Object arg0, String arg1, Object arg2, Type arg3) throws HibernateException
-   {
-      return fullTextSession.filter(arg0, arg1, arg2, arg3);
-   }
-
-   public Collection filter(Object arg0, String arg1, Object[] arg2, Type[] arg3) throws HibernateException
-   {
-      return fullTextSession.filter(arg0, arg1, arg2, arg3);
-   }
-
-   public Collection filter(Object arg0, String arg1) throws HibernateException
-   {
-      return fullTextSession.filter(arg0, arg1);
-   }
-
-   public List find(String arg0, Object arg1, Type arg2) throws HibernateException
-   {
-      return fullTextSession.find(arg0, arg1, arg2);
-   }
-
-   public List find(String arg0, Object[] arg1, Type[] arg2) throws HibernateException
-   {
-      return fullTextSession.find(arg0, arg1, arg2);
-   }
-
-   public List find(String arg0) throws HibernateException
-   {
-      return fullTextSession.find(arg0);
-   }
-
-
-   public SearchFactory getSearchFactory()
-   {
-      return fullTextSession.getSearchFactory();
-   }
-
-   public void purge(Class aClass, Serializable serializable)
-   {
-      fullTextSession.purge(aClass, serializable);
-   }
-
-   public void purgeAll(Class aClass)
-   {
-      fullTextSession.purgeAll(aClass);
-   }
-
-   public Iterator iterate(String arg0, Object arg1, Type arg2) throws HibernateException
-   {
-      return fullTextSession.iterate(arg0, arg1, arg2);
-   }
-
-   public Iterator iterate(String arg0, Object[] arg1, Type[] arg2) throws HibernateException
-   {
-      return fullTextSession.iterate(arg0, arg1, arg2);
-   }
-
-   public Iterator iterate(String arg0) throws HibernateException
-   {
-      return fullTextSession.iterate(arg0);
-   }
-
-   public void save(Object arg0, Serializable arg1) throws HibernateException
-   {
-      fullTextSession.save(arg0, arg1);
-   }
-
-   public void save(String arg0, Object arg1, Serializable arg2) throws HibernateException
-   {
-      fullTextSession.save(arg0, arg1, arg2);
-   }
-
-   public Object saveOrUpdateCopy(Object arg0, Serializable arg1) throws HibernateException
-   {
-      return fullTextSession.saveOrUpdateCopy(arg0, arg1);
-   }
-
-   public Object saveOrUpdateCopy(Object arg0) throws HibernateException
-   {
-      return fullTextSession.saveOrUpdateCopy(arg0);
-   }
-
-   public Object saveOrUpdateCopy(String arg0, Object arg1, Serializable arg2) throws HibernateException
-   {
-      return fullTextSession.saveOrUpdateCopy(arg0, arg1, arg2);
-   }
-
-   public Object saveOrUpdateCopy(String arg0, Object arg1) throws HibernateException
-   {
-      return fullTextSession.saveOrUpdateCopy(arg0, arg1);
-   }
-
-   public void update(Object arg0, Serializable arg1) throws HibernateException
-   {
-      fullTextSession.update(arg0, arg1);
-   }
-
-   public void update(String arg0, Object arg1, Serializable arg2) throws HibernateException
-   {
-      fullTextSession.update(arg0, arg1, arg2);
-   }
-   
 }

Modified: trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2008-12-02 01:09:08 UTC (rev 9694)
+++ trunk/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2008-12-02 09:43:58 UTC (rev 9695)
@@ -4,6 +4,7 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.util.Collection;
 import java.util.Map;
 
@@ -16,6 +17,7 @@
 import org.hibernate.Session;
 import org.hibernate.StaleStateException;
 import org.hibernate.TransientObjectException;
+import org.hibernate.engine.SessionImplementor;
 import org.hibernate.metadata.ClassMetadata;
 import org.hibernate.proxy.HibernateProxy;
 import org.hibernate.type.VersionType;
@@ -93,7 +95,9 @@
    {
       if (FULL_TEXT_SESSION_PROXY_CONSTRUCTOR==null)
       {
-         return new HibernateSessionProxy(session);
+         return (Session) Proxy.newProxyInstance(Session.class.getClassLoader(), 
+               new Class[] {Session.class, SessionImplementor.class}, 
+               new HibernateSessionProxy(session));
       }
       else
       {
@@ -102,7 +106,9 @@
          }
          catch(Exception e) {
             log.warn("Unable to wrap into a FullTextSessionProxy, regular SessionProxy returned", e);
-            return new HibernateSessionProxy(session);
+            return (Session) Proxy.newProxyInstance(Session.class.getClassLoader(), 
+                  new Class[] {Session.class, SessionImplementor.class}, 
+                  new HibernateSessionProxy(session));
          }
       }
    }

Modified: trunk/src/main/org/jboss/seam/persistence/HibernateSessionProxy.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/HibernateSessionProxy.java	2008-12-02 01:09:08 UTC (rev 9694)
+++ trunk/src/main/org/jboss/seam/persistence/HibernateSessionProxy.java	2008-12-02 09:43:58 UTC (rev 9695)
@@ -1,36 +1,26 @@
 package org.jboss.seam.persistence;
 
 import java.io.Serializable;
-import java.sql.Connection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.hibernate.CacheMode;
-import org.hibernate.Criteria;
-import org.hibernate.EntityMode;
-import org.hibernate.Filter;
-import org.hibernate.FlushMode;
 import org.hibernate.HibernateException;
 import org.hibernate.Interceptor;
-import org.hibernate.LockMode;
 import org.hibernate.Query;
-import org.hibernate.ReplicationMode;
-import org.hibernate.SQLQuery;
 import org.hibernate.ScrollMode;
 import org.hibernate.ScrollableResults;
 import org.hibernate.Session;
-import org.hibernate.SessionFactory;
 import org.hibernate.Transaction;
 import org.hibernate.collection.PersistentCollection;
+import org.hibernate.engine.ActionQueue;
+import org.hibernate.engine.EntityEntry;
 import org.hibernate.engine.EntityKey;
 import org.hibernate.engine.PersistenceContext;
 import org.hibernate.engine.QueryParameters;
 import org.hibernate.engine.SessionFactoryImplementor;
 import org.hibernate.engine.SessionImplementor;
-import org.hibernate.engine.ActionQueue;
-import org.hibernate.engine.EntityEntry;
 import org.hibernate.engine.query.sql.NativeSQLQuerySpecification;
 import org.hibernate.event.EventListeners;
 import org.hibernate.event.EventSource;
@@ -39,8 +29,8 @@
 import org.hibernate.jdbc.JDBCContext;
 import org.hibernate.loader.custom.CustomQuery;
 import org.hibernate.persister.entity.EntityPersister;
-import org.hibernate.stat.SessionStatistics;
 import org.hibernate.type.Type;
+import org.jboss.seam.util.DelegatingInvocationHandler;
 
 /**
  * Proxies the Session, and implements EL interpolation
@@ -49,83 +39,25 @@
  * 
  * @author Gavin King
  * @author Emmanuel Bernard
- * FIXME: EventSource should not really be there, remove once HSearch is fixed
+ * @author Shane Bryzak
  *
  */
-public class HibernateSessionProxy implements Session, SessionImplementor, EventSource
-{
-   private Session delegate;
-
+public class HibernateSessionProxy extends DelegatingInvocationHandler<Session>
+{        
    /**
     * Don't use that constructor directly, use HibernatePersistenceProvider.proxySession()
     */
    public HibernateSessionProxy(Session session)
    {
-      delegate = session;
-   }
+      super(session);
+   }  
 
-   public Transaction beginTransaction() throws HibernateException
-   {
-      return delegate.beginTransaction();
-   }
-
-   public void cancelQuery() throws HibernateException
-   {
-      delegate.cancelQuery();
-   }
-
-   public void clear()
-   {
-      delegate.clear();
-   }
-
-   public Connection close() throws HibernateException
-   {
-      return delegate.close();
-   }
-
-   @SuppressWarnings("deprecation")
-   public Connection connection() throws HibernateException
-   {
-      return delegate.connection();
-   }
-
-   public boolean contains(Object arg0)
-   {
-      return delegate.contains(arg0);
-   }
-
-   public Criteria createCriteria(Class arg0, String arg1)
-   {
-      return delegate.createCriteria(arg0, arg1);
-   }
-
-   public Criteria createCriteria(Class arg0)
-   {
-      return delegate.createCriteria(arg0);
-   }
-
-   public Criteria createCriteria(String arg0, String arg1)
-   {
-      return delegate.createCriteria(arg0, arg1);
-   }
-
-   public Criteria createCriteria(String arg0)
-   {
-      return delegate.createCriteria(arg0);
-   }
-
-   public Query createFilter(Object arg0, String arg1) throws HibernateException
-   {
-      return delegate.createFilter(arg0, arg1);
-   }
-
    public Query createQuery(String hql) throws HibernateException
    {
       if ( hql.indexOf('#')>0 )
       {
          QueryParser qp = new QueryParser(hql);
-         Query query = delegate.createQuery( qp.getEjbql() );
+         Query query = getDelegate().createQuery( qp.getEjbql() );
          for (int i=0; i<qp.getParameterValueBindings().size(); i++)
          {
             query.setParameter( 
@@ -137,283 +69,23 @@
       }
       else
       {
-         return delegate.createQuery(hql);
+         return getDelegate().createQuery(hql);
       }
    }
 
-   public SQLQuery createSQLQuery(String arg0) throws HibernateException
-   {
-      return delegate.createSQLQuery(arg0);
-   }
-
-   public void delete(Object arg0) throws HibernateException
-   {
-      delegate.delete(arg0);
-   }
-
-   public void delete(String arg0, Object arg1) throws HibernateException
-   {
-      delegate.delete(arg0, arg1);
-   }
-
-   public void disableFilter(String arg0)
-   {
-      delegate.disableFilter(arg0);
-   }
-
-   public Connection disconnect() throws HibernateException
-   {
-      return delegate.disconnect();
-   }
-
-   public Filter enableFilter(String arg0)
-   {
-      return delegate.enableFilter(arg0);
-   }
-
-   public void evict(Object arg0) throws HibernateException
-   {
-      delegate.evict(arg0);
-   }
-
-   public void flush() throws HibernateException
-   {
-      delegate.flush();
-   }
-
-   public Object get(Class arg0, Serializable arg1, LockMode arg2) throws HibernateException
-   {
-      return delegate.get(arg0, arg1, arg2);
-   }
-
-   public Object get(Class arg0, Serializable arg1) throws HibernateException
-   {
-      return delegate.get(arg0, arg1);
-   }
-
-   public Object get(String arg0, Serializable arg1, LockMode arg2) throws HibernateException
-   {
-      return delegate.get(arg0, arg1, arg2);
-   }
-
-   public Object get(String arg0, Serializable arg1) throws HibernateException
-   {
-      return delegate.get(arg0, arg1);
-   }
-
-   public CacheMode getCacheMode()
-   {
-      return delegate.getCacheMode();
-   }
-
-   public LockMode getCurrentLockMode(Object arg0) throws HibernateException
-   {
-      return delegate.getCurrentLockMode(arg0);
-   }
-
-   public Filter getEnabledFilter(String arg0)
-   {
-      return delegate.getEnabledFilter(arg0);
-   }
-
-   public EntityMode getEntityMode()
-   {
-      return delegate.getEntityMode();
-   }
-
-   public String getEntityName(Object arg0) throws HibernateException
-   {
-      return delegate.getEntityName(arg0);
-   }
-
-   public FlushMode getFlushMode()
-   {
-      return delegate.getFlushMode();
-   }
-
-   public Serializable getIdentifier(Object arg0) throws HibernateException
-   {
-      return delegate.getIdentifier(arg0);
-   }
-
-   public Query getNamedQuery(String arg0) throws HibernateException
-   {
-      return delegate.getNamedQuery(arg0);
-   }
-
-   public Session getSession(EntityMode arg0)
-   {
-      return delegate.getSession(arg0);
-   }
-
-   public SessionFactory getSessionFactory()
-   {
-      return delegate.getSessionFactory();
-   }
-
-   public SessionStatistics getStatistics()
-   {
-      return delegate.getStatistics();
-   }
-
-   public Transaction getTransaction()
-   {
-      return delegate.getTransaction();
-   }
-
-   public boolean isConnected()
-   {
-      return delegate.isConnected();
-   }
-
-   public boolean isDirty() throws HibernateException
-   {
-      return delegate.isDirty();
-   }
-
-   public boolean isOpen()
-   {
-      return delegate.isOpen();
-   }
-
-   public Object load(Class arg0, Serializable arg1, LockMode arg2) throws HibernateException
-   {
-      return delegate.load(arg0, arg1, arg2);
-   }
-
-   public Object load(Class arg0, Serializable arg1) throws HibernateException
-   {
-      return delegate.load(arg0, arg1);
-   }
-
-   public void load(Object arg0, Serializable arg1) throws HibernateException
-   {
-      delegate.load(arg0, arg1);
-   }
-
-   public Object load(String arg0, Serializable arg1, LockMode arg2) throws HibernateException
-   {
-      return delegate.load(arg0, arg1, arg2);
-   }
-
-   public Object load(String arg0, Serializable arg1) throws HibernateException
-   {
-      return delegate.load(arg0, arg1);
-   }
-
-   public void lock(Object arg0, LockMode arg1) throws HibernateException
-   {
-      delegate.lock(arg0, arg1);
-   }
-
-   public void lock(String arg0, Object arg1, LockMode arg2) throws HibernateException
-   {
-      delegate.lock(arg0, arg1, arg2);
-   }
-
-   public Object merge(Object arg0) throws HibernateException
-   {
-      return delegate.merge(arg0);
-   }
-
-   public Object merge(String arg0, Object arg1) throws HibernateException
-   {
-      return delegate.merge(arg0, arg1);
-   }
-
-   public void persist(Object arg0) throws HibernateException
-   {
-      delegate.persist(arg0);
-   }
-
-   public void persist(String arg0, Object arg1) throws HibernateException
-   {
-      delegate.persist(arg0, arg1);
-   }
-
    public void reconnect() throws HibernateException
    {
       throw new UnsupportedOperationException("deprecated");
    }
-
-   public void reconnect(Connection arg0) throws HibernateException
-   {
-      delegate.reconnect(arg0);
-   }
-
-   public void refresh(Object arg0, LockMode arg1) throws HibernateException
-   {
-      delegate.refresh(arg0, arg1);
-   }
-
-   public void refresh(Object arg0) throws HibernateException
-   {
-      delegate.refresh(arg0);
-   }
-
-   public void replicate(Object arg0, ReplicationMode arg1) throws HibernateException
-   {
-      delegate.replicate(arg0, arg1);
-   }
-
-   public void replicate(String arg0, Object arg1, ReplicationMode arg2) throws HibernateException
-   {
-      delegate.replicate(arg0, arg1, arg2);
-   }
-
-   public Serializable save(Object arg0) throws HibernateException
-   {
-      return delegate.save(arg0);
-   }
-
-   public Serializable save(String arg0, Object arg1) throws HibernateException
-   {
-      return delegate.save(arg0, arg1);
-   }
-
-   public void saveOrUpdate(Object arg0) throws HibernateException
-   {
-      delegate.saveOrUpdate(arg0);
-   }
-
-   public void saveOrUpdate(String arg0, Object arg1) throws HibernateException
-   {
-      delegate.saveOrUpdate(arg0, arg1);
-   }
-
-   public void setCacheMode(CacheMode arg0)
-   {
-      delegate.setCacheMode(arg0);
-   }
-
-   public void setFlushMode(FlushMode arg0)
-   {
-      delegate.setFlushMode(arg0);
-   }
-
-   public void setReadOnly(Object arg0, boolean arg1)
-   {
-      delegate.setReadOnly(arg0, arg1);
-   }
-
-   public void update(Object arg0) throws HibernateException
-   {
-      delegate.update(arg0);
-   }
-
-   public void update(String arg0, Object arg1) throws HibernateException
-   {
-      delegate.update(arg0, arg1);
-   }
    
    private SessionImplementor getDelegateSessionImplementor()
    {
-      return (SessionImplementor) delegate;
+      return (SessionImplementor) getDelegate();
    }
 
    private EventSource getDelegateEventSource()
    {
-      return (EventSource) delegate;
+      return (EventSource) getDelegate();
    }
 
    public void afterScrollOperation()

Modified: trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java
===================================================================
--- trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java	2008-12-02 01:09:08 UTC (rev 9694)
+++ trunk/src/main/org/jboss/seam/persistence/PersistenceProvider.java	2008-12-02 09:43:58 UTC (rev 9695)
@@ -2,6 +2,7 @@
 import static org.jboss.seam.annotations.Install.BUILT_IN;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
 import java.util.Date;
 
 import javax.persistence.EntityManager;
@@ -136,8 +137,10 @@
    /**
     * Wrap the entityManager before returning it to the application
     */
-   public EntityManager proxyEntityManager(EntityManager entityManager) {
-      return new EntityManagerProxy(entityManager);
+   public EntityManager proxyEntityManager(EntityManager entityManager) {      
+      return (EntityManager) Proxy.newProxyInstance(EntityManager.class.getClassLoader(), 
+            new Class[] {EntityManager.class}, 
+            new EntityManagerProxy(entityManager));        
    }
    
    /**

Added: trunk/src/main/org/jboss/seam/util/DelegatingInvocationHandler.java
===================================================================
--- trunk/src/main/org/jboss/seam/util/DelegatingInvocationHandler.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/util/DelegatingInvocationHandler.java	2008-12-02 09:43:58 UTC (rev 9695)
@@ -0,0 +1,100 @@
+package org.jboss.seam.util;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.seam.log.Log;
+import org.jboss.seam.log.Logging;
+
+/**
+ * An InvocationHandler implementation that delegates method invocations to a specified object,
+ * optionally allowing the method to be overridden locally. 
+ * 
+ * @author Shane Bryzak
+ */
+public class DelegatingInvocationHandler<T> implements InvocationHandler
+{   
+   private static Log log = Logging.getLog(DelegatingInvocationHandler.class);     
+   
+   private class MethodTarget
+   {
+      public Method method;
+      public Object target;
+      
+      public MethodTarget(Object target, Method method)
+      {
+         this.target = target;
+         this.method = method;
+      }
+   }   
+   
+   private Map<Method,MethodTarget> methodCache = new HashMap<Method,MethodTarget>();
+   private T delegate;
+   
+   public DelegatingInvocationHandler(T delegate)
+   {
+      this.delegate = delegate;
+   }
+   
+   public T getDelegate()
+   {
+      return delegate;
+   }
+   
+   public Object invoke(Object proxy, Method method, Object[] args)
+         throws Throwable
+   {  
+      MethodTarget target = methodCache.get(method);      
+      
+      if (target == null && !methodCache.containsKey(method))
+      {
+         synchronized(methodCache)
+         {
+            if (!methodCache.containsKey(method))
+            {
+               try
+               {
+                  target = new MethodTarget(this, getClass().getMethod(method.getName(), method.getParameterTypes()));                  
+               }
+               catch (NoSuchMethodException ex)
+               {
+                  // Swallow this, we'll try to find a matching method on the delegate
+               }
+               
+               if (target == null)
+               {
+                  try
+                  {
+                     target = new MethodTarget(delegate, delegate.getClass().getMethod(method.getName(), method.getParameterTypes()));
+                  }
+                  catch (NoSuchMethodException ex)
+                  {
+                     // Swallow this, put a null entry in methodCache
+                  }
+               }
+               
+               methodCache.put(method, target);
+            }
+            else
+            {
+               target = methodCache.get(method);               
+            }
+         }                  
+      }
+      
+      if (target == null)
+      {
+         throw new IllegalStateException("Proxied session does not implement method " + method.getName() +
+               " with args [" + args + "]");
+      }
+      
+      if (log.isTraceEnabled())
+      {
+         log.trace("Delegating method " + method.getName() + " with args " + args);
+      }
+      
+      return target.method.invoke(target.target, args);      
+   }  
+}




More information about the seam-commits mailing list