tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1004872 - in /openejb/branches/openejb-3.1.x: assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/ container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ container/openejb-co...
Date Wed, 06 Oct 2010 01:30:12 GMT
Author: dblevins
Date: Wed Oct  6 01:30:11 2010
New Revision: 1004872

URL: http://svn.apache.org/viewvc?rev=1004872&view=rev
Log:
OPENEJB-1365: New log4j.category.OpenEJB.persistence log category
Also, ensure persistence unit name is always present for every refereces (set it when the
unit is resolved)
Time all JTA EntityManager operations
Log debug messages for EntityManager operations that don't do anything

Modified:
    openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatJndiBuilder.java
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/resources/embedded.logging.properties
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/resources/org/apache/openejb/assembler/classic/Messages.properties

Modified: openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatJndiBuilder.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatJndiBuilder.java?rev=1004872&r1=1004871&r2=1004872&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatJndiBuilder.java
(original)
+++ openejb/branches/openejb-3.1.x/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatJndiBuilder.java
Wed Oct  6 01:30:11 2010
@@ -285,7 +285,7 @@ public class TomcatJndiBuilder {
             }
 
             JtaEntityManagerRegistry jtaEntityManagerRegistry = SystemInstance.get().getComponent(JtaEntityManagerRegistry.class);
-            JtaEntityManager jtaEntityManager = new JtaEntityManager(jtaEntityManagerRegistry,
factory, ref.properties, ref.extended);
+            JtaEntityManager jtaEntityManager = new JtaEntityManager(ref.persistenceUnitName,
jtaEntityManagerRegistry, factory, ref.properties, ref.extended);
             Object object = jtaEntityManager;
             setResource(resource, object);
         }

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java?rev=1004872&r1=1004871&r2=1004872&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
Wed Oct  6 01:30:11 2010
@@ -25,7 +25,6 @@ import org.apache.openejb.core.Transacti
 import org.apache.openejb.core.JndiFactory;
 import org.apache.openejb.core.ivm.naming.CrossClassLoaderJndiReference;
 import org.apache.openejb.core.ivm.naming.IntraVmJndiReference;
-import org.apache.openejb.core.ivm.naming.IvmContext;
 import org.apache.openejb.core.ivm.naming.JaxWsServiceReference;
 import org.apache.openejb.core.ivm.naming.JndiReference;
 import org.apache.openejb.core.ivm.naming.JndiUrlReference;
@@ -42,7 +41,6 @@ import org.apache.openejb.persistence.Jt
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.core.timer.TimerServiceWrapper;
-import org.apache.xbean.naming.context.WritableContext;
 import org.omg.CORBA.ORB;
 
 import javax.ejb.EJBContext;
@@ -62,7 +60,6 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.ArrayList;
@@ -319,7 +316,7 @@ public class JndiEncBuilder {
                 throw new OpenEJBException("PersistenceUnit '" + contextInfo.unitId + "'
not found for EXTENDED ref '" + contextInfo.referenceName + "'");
             }
 
-            JtaEntityManager jtaEntityManager = new JtaEntityManager(jtaEntityManagerRegistry,
factory, contextInfo.properties, contextInfo.extended);
+            JtaEntityManager jtaEntityManager = new JtaEntityManager(contextInfo.persistenceUnitName,
jtaEntityManagerRegistry, factory, contextInfo.properties, contextInfo.extended);
             Reference reference = new PersistenceContextReference(jtaEntityManager);
             bindings.put(normalize(contextInfo.referenceName), reference);
         }

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java?rev=1004872&r1=1004871&r2=1004872&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java
Wed Oct  6 01:30:11 2010
@@ -18,6 +18,7 @@ package org.apache.openejb.assembler.cla
 
 import java.io.File;
 import java.util.HashMap;
+import java.util.concurrent.TimeUnit;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.spi.PersistenceProvider;
 import javax.persistence.spi.PersistenceUnitTransactionType;
@@ -175,13 +176,19 @@ public class PersistenceBuilder {
         }
         unitInfo.setPersistenceProviderClassName(persistenceProviderClassName);
 
-        Class clazz = classLoader.loadClass(persistenceProviderClassName);
-        PersistenceProvider persistenceProvider = (PersistenceProvider) clazz.newInstance();
+        final long start = System.nanoTime();
+        try {
+            Class clazz = classLoader.loadClass(persistenceProviderClassName);
+            PersistenceProvider persistenceProvider = (PersistenceProvider) clazz.newInstance();
+
+            // Create entity manager factory
+            EntityManagerFactory emf = persistenceProvider.createContainerEntityManagerFactory(unitInfo,
new HashMap());
+            return emf;
+        } finally {
+            final long time = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
+            logger.info("assembler.buildingPersistenceUnit", unitInfo.getPersistenceUnitName(),
unitInfo.getPersistenceProviderClassName(), time+"");
 
-        logger.info("assembler.buildingPersistenceUnit", unitInfo.getPersistenceUnitName(),
unitInfo.getPersistenceProviderClassName(), unitInfo.getPersistenceUnitRootUrl(), unitInfo.getTransactionType());
 
-        // Create entity manager factory
-        EntityManagerFactory emf = persistenceProvider.createContainerEntityManagerFactory(unitInfo,
new HashMap());
-        return emf;
+        }
     }
 }

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java?rev=1004872&r1=1004871&r2=1004872&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
Wed Oct  6 01:30:11 2010
@@ -232,6 +232,7 @@ public class AutoConfig implements Dynam
         }
 
         if (unit != null){
+            ref.setPersistenceUnitName(unit.getName());
             ref.setMappedName(unit.getId());
         } else {
 

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java?rev=1004872&r1=1004871&r2=1004872&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/persistence/JtaEntityManager.java
Wed Oct  6 01:30:11 2010
@@ -17,7 +17,12 @@
  */
 package org.apache.openejb.persistence;
 
+import org.apache.log4j.spi.LoggerFactory;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Logger;
+
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 import javax.persistence.FlushModeType;
 import javax.persistence.LockModeType;
 import javax.persistence.Query;
@@ -39,22 +44,28 @@ import javax.persistence.TransactionRequ
  * be thrown when entity manger is accessed.
  */
 public class JtaEntityManager implements EntityManager {
+    private static final Logger baseLogger = Logger.getInstance(LogCategory.OPENEJB.createChild("persistence"),
JtaEntityManager.class);
+
     private final JtaEntityManagerRegistry registry;
     private final EntityManagerFactory entityManagerFactory;
     private final Map properties;
     private final boolean extended;
+    private final String unitName;
+    private final Logger logger;
 
     public JtaEntityManager(JtaEntityManagerRegistry registry, EntityManagerFactory entityManagerFactory,
Map properties) {
-        this(registry, entityManagerFactory, properties, false);
-
+        this(null, registry, entityManagerFactory, properties, false);
     }
-    public JtaEntityManager(JtaEntityManagerRegistry registry, EntityManagerFactory entityManagerFactory,
Map properties, boolean extended) {
+
+    public JtaEntityManager(String unitName, JtaEntityManagerRegistry registry, EntityManagerFactory
entityManagerFactory, Map properties, boolean extended) {
         if (registry == null) throw new NullPointerException("registry is null");
         if (entityManagerFactory == null) throw new NullPointerException("entityManagerFactory
is null");
         this.registry = registry;
         this.entityManagerFactory = entityManagerFactory;
         this.properties = properties;
         this.extended = extended;
+        this.unitName = unitName;
+        logger = (unitName == null) ? baseLogger : baseLogger.getChildLogger(unitName);
     }
 
     private EntityManager getEntityManager() {
@@ -94,23 +105,43 @@ public class JtaEntityManager implements
 
     public void persist(Object entity) {
         assertTransactionActive();
-        getEntityManager().persist(entity);
+        final Timer timer = Op.persist.start(this);
+        try {
+            getEntityManager().persist(entity);
+        } finally {
+            timer.stop();
+        }
     }
 
     public <T>T merge(T entity) {
         assertTransactionActive();
-        return getEntityManager().merge(entity);
+        final Timer timer = Op.merge.start(this);
+        try {
+            return getEntityManager().merge(entity);
+        } finally {
+            timer.stop();
+        }
     }
 
     public void remove(Object entity) {
         assertTransactionActive();
-        getEntityManager().remove(entity);
+        final Timer timer = Op.remove.start(this);
+        try {
+            getEntityManager().remove(entity);
+        } finally {
+            timer.stop();
+        }
     }
 
     public <T>T find(Class<T> entityClass, Object primaryKey) {
         EntityManager entityManager = getEntityManager();
         try {
-            return entityManager.find(entityClass, primaryKey);
+            final Timer timer = Op.find.start(this);
+            try {
+                return entityManager.find(entityClass, primaryKey);
+            } finally {
+                timer.stop();
+            }
         } finally {
             closeIfNoTx(entityManager);
         }
@@ -119,7 +150,12 @@ public class JtaEntityManager implements
     public <T>T getReference(Class<T> entityClass, Object primaryKey) {
         EntityManager entityManager = getEntityManager();
         try {
-            return entityManager.getReference(entityClass, primaryKey);
+            final Timer timer = Op.getReference.start(this);
+            try {
+                return entityManager.getReference(entityClass, primaryKey);
+            } finally {
+                timer.stop();
+            }
         } finally {
             closeIfNoTx(entityManager);
         }
@@ -127,13 +163,23 @@ public class JtaEntityManager implements
 
     public void flush() {
         assertTransactionActive();
-        getEntityManager().flush();
+        final Timer timer = Op.flush.start(this);
+        try {
+            getEntityManager().flush();
+        } finally {
+            timer.stop();
+        }
     }
 
     public void setFlushMode(FlushModeType flushMode) {
         EntityManager entityManager = getEntityManager();
         try {
-            entityManager.setFlushMode(flushMode);
+            final Timer timer = Op.setFlushMode.start(this);
+            try {
+                entityManager.setFlushMode(flushMode);
+            } finally {
+                timer.stop();
+            }
         } finally {
             closeIfNoTx(entityManager);
         }
@@ -142,7 +188,12 @@ public class JtaEntityManager implements
     public FlushModeType getFlushMode() {
         EntityManager entityManager = getEntityManager();
         try {
-            return entityManager.getFlushMode();
+            final Timer timer = Op.getFlushMode.start(this);
+            try {
+                return entityManager.getFlushMode();
+            } finally {
+                timer.stop();
+            }
         } finally {
             closeIfNoTx(entityManager);
         }
@@ -150,53 +201,98 @@ public class JtaEntityManager implements
 
     public void lock(Object entity, LockModeType lockMode) {
         assertTransactionActive();
-        getEntityManager().lock(entity, lockMode);
+        final Timer timer = Op.lock.start(this);
+        try {
+            getEntityManager().lock(entity, lockMode);
+        } finally {
+            timer.stop();
+        }
     }
 
     public void refresh(Object entity) {
         assertTransactionActive();
-        getEntityManager().refresh(entity);
+        final Timer timer = Op.refresh.start(this);
+        try {
+            getEntityManager().refresh(entity);
+        } finally {
+            timer.stop();
+        }
     }
 
     public void clear() {
         if (!extended && !isTransactionActive()) {
             return;
         }
-        getEntityManager().clear();
+        final Timer timer = Op.clear.start(this);
+        try {
+            getEntityManager().clear();
+        } finally {
+            timer.stop();
+        }
     }
 
     public boolean contains(Object entity) {
-        return isTransactionActive() && getEntityManager().contains(entity);
+        final Timer timer = Op.contains.start(this);
+        try {
+            return isTransactionActive() && getEntityManager().contains(entity);
+        } finally {
+            timer.stop();
+        }
     }
 
     public Query createQuery(String qlString) {
-        EntityManager entityManager = getEntityManager();
-        Query query = entityManager.createQuery(qlString);
-        return proxyIfNoTx(entityManager, query);
+        final Timer timer = Op.createQuery.start(this);
+        try {
+            EntityManager entityManager = getEntityManager();
+            Query query = entityManager.createQuery(qlString);
+            return proxyIfNoTx(entityManager, query);
+        } finally {
+            timer.stop();
+        }
     }
 
     public Query createNamedQuery(String name) {
-        EntityManager entityManager = getEntityManager();
-        Query query = entityManager.createNamedQuery(name);
-        return proxyIfNoTx(entityManager, query);
+        final Timer timer = Op.createNamedQuery.start(this);
+        try {
+            EntityManager entityManager = getEntityManager();
+            Query query = entityManager.createNamedQuery(name);
+            return proxyIfNoTx(entityManager, query);
+        } finally {
+            timer.stop();
+        }
     }
 
     public Query createNativeQuery(String sqlString) {
-        EntityManager entityManager = getEntityManager();
-        Query query = entityManager.createNativeQuery(sqlString);
-        return proxyIfNoTx(entityManager, query);
+        final Timer timer = Op.createNativeQuery.start(this);
+        try {
+            EntityManager entityManager = getEntityManager();
+            Query query = entityManager.createNativeQuery(sqlString);
+            return proxyIfNoTx(entityManager, query);
+        } finally {
+            timer.stop();
+        }
     }
 
     public Query createNativeQuery(String sqlString, Class resultClass) {
-        EntityManager entityManager = getEntityManager();
-        Query query = entityManager.createNativeQuery(sqlString, resultClass);
-        return proxyIfNoTx(entityManager, query);
+        final Timer timer = Op.createNativeQuery.start(this);
+        try {
+            EntityManager entityManager = getEntityManager();
+            Query query = entityManager.createNativeQuery(sqlString, resultClass);
+            return proxyIfNoTx(entityManager, query);
+        } finally {
+            timer.stop();
+        }
     }
 
     public Query createNativeQuery(String sqlString, String resultSetMapping) {
-        EntityManager entityManager = getEntityManager();
-        Query query = entityManager.createNativeQuery(sqlString, resultSetMapping);
-        return proxyIfNoTx(entityManager, query);
+        final Timer timer = Op.createNativeQuery.start(this);
+        try {
+            EntityManager entityManager = getEntityManager();
+            Query query = entityManager.createNativeQuery(sqlString, resultSetMapping);
+            return proxyIfNoTx(entityManager, query);
+        } finally {
+            timer.stop();
+        }
     }
 
     private Query proxyIfNoTx(EntityManager entityManager, Query query) {
@@ -207,9 +303,15 @@ public class JtaEntityManager implements
     }
 
     public void joinTransaction() {
+        if (logger.isDebugEnabled()) {
+            logger.debug("PersistenceUnit(name=" + unitName + ") - entityManager.joinTransaction()
call ignored - not applicable to a JTA Managed EntityManager",  new Exception().fillInStackTrace());
+        }
     }
 
     public void close() {
+        if (logger.isDebugEnabled()) {
+            logger.debug("PersistenceUnit(name=" + unitName + ") - entityManager.close()
call ignored - not applicable to a JTA Managed EntityManager",  new Exception().fillInStackTrace());
+        }
     }
 
     public boolean isOpen() {
@@ -219,4 +321,31 @@ public class JtaEntityManager implements
     public EntityTransaction getTransaction() {
         throw new IllegalStateException("A JTA EntityManager can not use the EntityTransaction
API.  See JPA 1.0 section 5.5");
     }
+
+    public static class Timer {
+        private final long start = System.nanoTime();
+        private final Op operation;
+        private final JtaEntityManager em;
+
+        public Timer(Op operation, JtaEntityManager em) {
+            this.operation = operation;
+            this.em = em;
+        }
+
+        public void stop() {
+            if (!em.logger.isDebugEnabled()) return;
+
+            final long time = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
+
+            em.logger.debug("PersistenceUnit(name=" + em.unitName + ") - entityManager."
+ operation + " - " + time + "ms");
+        }
+    }
+
+    private static enum Op {
+        clear, close, contains, createNamedQuery, createNativeQuery, createQuery, find, flush,
getFlushMode, getReference, getTransaction, lock, merge, refresh, remove, setFlushMode, persist;
+
+        public Timer start(JtaEntityManager em) {
+            return new Timer(this, em);
+        }
+    }
 }

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/resources/embedded.logging.properties
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/resources/embedded.logging.properties?rev=1004872&r1=1004871&r2=1004872&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/resources/embedded.logging.properties
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/resources/embedded.logging.properties
Wed Oct  6 01:30:11 2010
@@ -49,6 +49,7 @@
 
 log4j.rootLogger                   = fatal,C
 log4j.category.OpenEJB             = warn
+log4j.category.OpenEJB.persistence = debug
 log4j.category.OpenEJB.options     = info
 log4j.category.OpenEJB.server      = info
 log4j.category.OpenEJB.startup     = info

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/resources/org/apache/openejb/assembler/classic/Messages.properties
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/resources/org/apache/openejb/assembler/classic/Messages.properties?rev=1004872&r1=1004871&r2=1004872&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/resources/org/apache/openejb/assembler/classic/Messages.properties
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/resources/org/apache/openejb/assembler/classic/Messages.properties
Wed Oct  6 01:30:11 2010
@@ -36,7 +36,7 @@ assembler.invalidConnectionManager=Inval
 
 # PersistenceBuilder.java
 # logger.info("assembler.buildingPersistenceUnit", unitInfo.getPersistenceUnitName(), unitInfo.getPersistenceProviderClassName(),
unitInfo.getPersistenceUnitRootUrl(), unitInfo.getTransactionType());
-assembler.buildingPersistenceUnit = PersistenceUnit(name={0}, provider={1})
+assembler.buildingPersistenceUnit = PersistenceUnit(name={0}, provider={1}) - provider time
{2}ms
 
 # Assembler
 # buildContainerSystem(OpenEjbConfiguration)



Mime
View raw message