[jboss-svn-commits] JBL Code SVN: r28658 - labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jul 31 12:39:19 EDT 2009


Author: whitingjr
Date: 2009-07-31 12:39:19 -0400 (Fri, 31 Jul 2009)
New Revision: 28658

Modified:
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java
Log:
Added closing code for entitymanagaer.

Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java	2009-07-31 16:35:14 UTC (rev 28657)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java	2009-07-31 16:39:19 UTC (rev 28658)
@@ -53,19 +53,24 @@
    {
       /* get the currently active transaction on this thread, register a synchronization 
        * to close the Connection object. */
+      if (logger.isDebugEnabled())
+      {
+         logger.debug("STMEntityManagerImpl.close called.");
+      }
       
-      
       TransactionManager transactionManager = ServiceLocator.findLocalPersonManager();
       try
       {
          this.connection.close();
+         /*
          Transaction transaction = transactionManager.getTransaction();
          if (null != transaction)
          {
             transaction.registerSynchronization(new CloseSTMEM());
          }
+         */
       }
-      catch (SystemException se)
+      /*catch (SystemException se)
       {
          logger
                .error(
@@ -77,7 +82,7 @@
       {
          logger.error("Could not register a Synchronization for STMEntityManager");
          throw new RuntimeException(re);
-      }
+      }*/
       catch (SQLException sqle)
       {
          logger.error("SQLException occured when closing the connection object when, the EM is closed.");
@@ -150,9 +155,15 @@
     * Entity has one constructor that is public, contains only one field and is of
     * type {@link java.lang.Long}.
     * The entity class is annotated with the STMEntity annotation.
+    * This method does not hit the STM system and only uses reflection to create
+    * an instance of the entity.
     */
    public <T> T find(Class<T> entityClass, Object primaryKey)
    {
+      if (logger.isDebugEnabled())
+      {
+         logger.debug("STMEntityManagerImpl.find called.");
+      }
       T returnValue = null;
       // check if the class has been annotated using the STM annotations.
       boolean isstmEntity = false;
@@ -167,9 +178,7 @@
       {// STM entity class, create an instance
          try
          {
-            Class[] types = new Class[1];
-            types[0] = Long.TYPE;
-            Constructor<T> targetConstructor = entityClass.getConstructor(types);
+            Constructor<T> targetConstructor = entityClass.getConstructor(Long.class);
             returnValue = targetConstructor.newInstance(primaryKey);
          }
          catch (InstantiationException ie)
@@ -186,6 +195,14 @@
                   .error(
                         "Expected constructor does not exist, please create a public constructor taking the primary key field only.",
                         nsme);
+            if (logger.isDebugEnabled())
+            {
+               logger.debug(log(entityClass));
+               for (Constructor constructor : entityClass.getConstructors())
+               {
+                  logger.debug("Constructor ["+constructor.toGenericString()+"]");
+               }
+            }
          }
          catch (IllegalArgumentException illae)
          {
@@ -196,6 +213,13 @@
             logger.error("Something went wrong when getting creating an entity object", e);
          }
       }
+      else
+      {
+         if (logger.isDebugEnabled())
+         {
+            logger.debug(log(entityClass));
+         }
+      }
       return returnValue;
    }
 
@@ -207,6 +231,13 @@
          throw new UnsupportedOperationException("Unsupported operation createNamedQuery(String)");
       }
    }
+   
+   public String log(Class entityClass)
+   {
+      String name=entityClass.getName();
+      name=name.substring(name.lastIndexOf(".")+1) + ".class";
+      return name + " loaded from " + entityClass.getResource(name);  
+   }
 
    @Override
    public Object getDelegate()



More information about the jboss-svn-commits mailing list