tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1208844 - in /openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb: assembler/classic/PersistenceBuilder.java assembler/classic/ReloadableEntityManagerFactory.java persistence/PersistenceUnitInfoImpl.java
Date Wed, 30 Nov 2011 22:22:41 GMT
Author: rmannibucau
Date: Wed Nov 30 22:22:40 2011
New Revision: 1208844

URL: http://svn.apache.org/viewvc?rev=1208844&view=rev
Log:
allowing to dump memory configuration of a persistence unit

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/PersistenceUnitInfoImpl.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java?rev=1208844&r1=1208843&r2=1208844&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java
Wed Nov 30 22:22:40 2011
@@ -68,6 +68,7 @@ public class PersistenceBuilder {
 
         // JTA Datasource
         String jtaDataSourceId = info.jtaDataSource;
+        unitInfo.setJtaDataSourceName(jtaDataSourceId);
         if (jtaDataSourceId != null) {
             if (!SystemInstance.get().hasProperty("openejb.geronimo")) {
 
@@ -109,6 +110,7 @@ public class PersistenceBuilder {
 
         // Non JTA Datasource
         String nonJtaDataSourceId = info.nonJtaDataSource;
+        unitInfo.setNonJtaDataSourceName(nonJtaDataSourceId);
         if (nonJtaDataSourceId != null) {
             if (!SystemInstance.get().hasProperty("openejb.geronimo")) {
                 try {

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java?rev=1208844&r1=1208843&r2=1208844&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ReloadableEntityManagerFactory.java
Wed Nov 30 22:22:40 2011
@@ -1,6 +1,10 @@
 package org.apache.openejb.assembler.classic;
 
 import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.jee.JAXBContextFactory;
+import org.apache.openejb.jee.Persistence;
+import org.apache.openejb.jee.PersistenceUnitCaching;
+import org.apache.openejb.jee.PersistenceUnitValidationMode;
 import org.apache.openejb.monitoring.DynamicMBeanWrapper;
 import org.apache.openejb.monitoring.LocalMBeanServer;
 import org.apache.openejb.monitoring.ObjectNameBuilder;
@@ -32,7 +36,11 @@ import javax.persistence.ValidationMode;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.metamodel.Metamodel;
 import javax.persistence.spi.PersistenceUnitTransactionType;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
 import java.io.File;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -377,6 +385,51 @@ public class ReloadableEntityManagerFact
             }
         }
 
+        @ManagedOperation
+        @Description("dump the current configuration for this persistence unit in a file")
+        public void dump(String file) {
+            PersistenceUnitInfoImpl info = reloadableEntityManagerFactory.entityManagerFactoryCallable.getUnitInfo();
+
+            Persistence.PersistenceUnit pu = new Persistence.PersistenceUnit();
+            pu.setJtaDataSource(info.getJtaDataSourceName());
+            pu.setNonJtaDataSource(info.getNonJtaDataSourceName());
+            pu.getClazz().addAll(info.getManagedClassNames());
+            pu.getMappingFile().addAll(info.getMappingFileNames());
+            pu.setName(info.getPersistenceUnitName());
+            pu.setProvider(info.getPersistenceProviderClassName());
+            pu.setTransactionType(info.getTransactionType().name());
+            pu.setExcludeUnlistedClasses(info.excludeUnlistedClasses());
+            pu.setSharedCacheMode(PersistenceUnitCaching.fromValue(info.getSharedCacheMode().name()));
+            pu.setValidationMode(PersistenceUnitValidationMode.fromValue(info.getValidationMode().name()));
+            for (URL url : info.getJarFileUrls()) {
+                pu.getJarFile().add(url.toString());
+            }
+            for (String key : info.getProperties().stringPropertyNames()) {
+                Persistence.PersistenceUnit.Properties.Property prop = new Persistence.PersistenceUnit.Properties.Property();
+                prop.setName(key);
+                prop.setValue(info.getProperties().getProperty(key));
+                if (pu.getProperties() == null) {
+                    pu.setProperties(new Persistence.PersistenceUnit.Properties());
+                }
+                pu.getProperties().getProperty().add(prop);
+            }
+
+            Persistence persistence = new Persistence();
+            persistence.setVersion(info.getPersistenceXMLSchemaVersion());
+            persistence.getPersistenceUnit().add(pu);
+
+            try {
+                FileWriter writer = new FileWriter(file);
+                JAXBContext jc = JAXBContextFactory.newInstance(Persistence.class);
+                Marshaller marshaller = jc.createMarshaller();
+                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+                marshaller.marshal(persistence, writer);
+                writer.close();
+            } catch (Exception e) {
+                LOGGER.error("can't dump pu " + reloadableEntityManagerFactory.getPUname()
+ " in file " + file, e);
+            }
+        }
+
         @ManagedAttribute
         @Description("get all properties")
         public TabularData getProperties() {

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/PersistenceUnitInfoImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/PersistenceUnitInfoImpl.java?rev=1208844&r1=1208843&r2=1208844&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/PersistenceUnitInfoImpl.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/persistence/PersistenceUnitInfoImpl.java
Wed Nov 30 22:22:40 2011
@@ -121,6 +121,11 @@ public class PersistenceUnitInfoImpl imp
     /** The validation mode to be used for the persistence unit */
     private ValidationMode validationMode;
 
+    /** just to be able to dump this PU at runtime */
+    private String jtaDataSourceName;
+    /** just to be able to dump this PU at runtime */
+    private String nonJtaDataSourceName;
+
     public PersistenceUnitInfoImpl() {
         this.persistenceClassLoaderHandler = null;
     }
@@ -346,4 +351,19 @@ public class PersistenceUnitInfoImpl imp
         this.validationMode = validationMode;
     }
 
+    public String getJtaDataSourceName() {
+        return jtaDataSourceName;
+    }
+
+    public void setJtaDataSourceName(String jtaDataSourceName) {
+        this.jtaDataSourceName = jtaDataSourceName;
+    }
+
+    public String getNonJtaDataSourceName() {
+        return nonJtaDataSourceName;
+    }
+
+    public void setNonJtaDataSourceName(String nonJtaDataSourceName) {
+        this.nonJtaDataSourceName = nonJtaDataSourceName;
+    }
 }



Mime
View raw message