[seam-commits] Seam SVN: r7686 - branches/Seam_2_0/src/main/org/jboss/seam/persistence.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Mar 25 07:44:28 EDT 2008


Author: shane.bryzak at jboss.com
Date: 2008-03-25 07:44:28 -0400 (Tue, 25 Mar 2008)
New Revision: 7686

Modified:
   branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
Log:
disabled hibernate entity security

Modified: branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2008-03-25 11:08:19 UTC (rev 7685)
+++ branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2008-03-25 11:44:28 UTC (rev 7686)
@@ -337,9 +337,9 @@
     * @param entityManager
     * @return
     */
-   private EntityCallbackHandler getCallbackHandler(EntityManager entityManager)
+   private EntityCallbackHandler getCallbackHandler(Session session)
    {
-      PostLoadEventListener[] listeners = ((SessionImplementor) getSession(entityManager))
+      PostLoadEventListener[] listeners = ((SessionImplementor) session)
       .getListeners().getPostLoadEventListeners();
    
       for (PostLoadEventListener listener : listeners)
@@ -371,9 +371,18 @@
    {
       try
       {
-         Field f = EntityCallbackHandler.class.getField(fieldName);
-         HashMap<Class,Callback[]> callbacks = (HashMap<Class,Callback[]>) f.get(handler);
-         return callbacks.get(beanClass);
+         Field f = EntityCallbackHandler.class.getDeclaredField(fieldName);
+         boolean isAccessible = f.isAccessible();
+         try
+         {
+            f.setAccessible(true);
+            HashMap<Class,Callback[]> callbacks = (HashMap<Class,Callback[]>) f.get(handler);
+            return callbacks.get(beanClass);
+         }
+         finally
+         {
+            f.setAccessible(isAccessible);
+         }
       }
       catch (Exception ex)
       {
@@ -381,10 +390,27 @@
       }
    }
    
-   private Method getCallbackMethod(EntityManager entityManager, Class beanClass, String callbackFieldName)
+   private Method getCallbackMethod(Object persistenceContext, Class beanClass, String callbackFieldName)
    {
-      Callback[] callbacks = getCallbacks(getCallbackHandler(entityManager), callbackFieldName, beanClass);
+      EntityCallbackHandler callbackHandler = null;
       
+      if (persistenceContext instanceof EntityManager)
+      {
+         callbackHandler = getCallbackHandler(getSession((EntityManager) persistenceContext));
+      }
+      else if (persistenceContext instanceof Session)
+      {
+         callbackHandler = getCallbackHandler((Session) persistenceContext);
+      }
+      
+      if (callbackHandler == null)
+      {
+         throw new RuntimeException("Could not determine callback handler for persistence context " +
+               persistenceContext);         
+      }
+      
+      Callback[] callbacks = getCallbacks(callbackHandler, callbackFieldName, beanClass);
+      
       if (callbacks != null)
       {
          for (Callback cb : callbacks)
@@ -396,30 +422,30 @@
       return null;      
    }
    
-   @Override
-   public Method getPostLoadMethod(Class beanClass, EntityManager entityManager)
+   /*@Override
+   public Method getPostLoadMethod(Class beanClass, Object persistenceContext)
    {
-      return getCallbackMethod(entityManager, beanClass, "postLoads");
+      return getCallbackMethod(persistenceContext, beanClass, "postLoads");
    }
    
    
    @Override
-   public Method getPrePersistMethod(Class beanClass, EntityManager entityManager)
+   public Method getPrePersistMethod(Class beanClass, Object persistenceContext)
    {
-      return getCallbackMethod(entityManager, beanClass, "preCreates");
+      return getCallbackMethod(persistenceContext, beanClass, "preCreates");
    }
    
    @Override
-   public Method getPreUpdateMethod(Class beanClass, EntityManager entityManager)
+   public Method getPreUpdateMethod(Class beanClass, Object persistenceContext)
    {
-      return getCallbackMethod(entityManager, beanClass, "preUpdates");
+      return getCallbackMethod(persistenceContext, beanClass, "preUpdates");
    }
    
    @Override
-   public Method getPreRemoveMethod(Class beanClass, EntityManager entityManager)
+   public Method getPreRemoveMethod(Class beanClass, Object persistenceContext)
    {
-      return getCallbackMethod(entityManager, beanClass, "preRemoves");
-   }
+      return getCallbackMethod(persistenceContext, beanClass, "preRemoves");
+   }*/
    
    private Session getSession(EntityManager entityManager)
    {




More information about the seam-commits mailing list