tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1004381 - in /openejb/branches/openejb-3.1.x/container: openejb-core/src/main/java/org/apache/openejb/config/ openejb-core/src/test/java/org/apache/openejb/core/stateful/ openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/ openejb-j...
Date Mon, 04 Oct 2010 19:56:37 GMT
Author: dblevins
Date: Mon Oct  4 19:56:36 2010
New Revision: 1004381

URL: http://svn.apache.org/viewvc?rev=1004381&view=rev
Log:
Made a properties converter for the PersitenceUnit properties object.

Added:
    openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/PropertiesAdapter.java
  (with props)
Modified:
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
    openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
    openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java
    openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/Persistence.java
    openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/PersistenceUnit.java
    openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/persistence-example.xml

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java?rev=1004381&r1=1004380&r2=1004381&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/AppInfoBuilder.java
Mon Oct  4 19:56:36 2010
@@ -491,13 +491,7 @@ class AppInfoBuilder {
                 info.mappingFiles.addAll(persistenceUnit.getMappingFile());
 
                 // Handle Properties
-                org.apache.openejb.jee.jpa.unit.Properties puiProperties = persistenceUnit.getProperties();
-
-                if (puiProperties != null) {
-                    for (Property property : puiProperties.getProperty()) {
-                        info.properties.put(property.getName(), property.getValue());
-                    }
-                }
+                info.properties.putAll(persistenceUnit.getProperties());
 
                 Properties overrides = ConfigurationFactory.getSystemProperties(info.name,
"PersistenceUnit");
                 for (Map.Entry<Object, Object> entry : overrides.entrySet()) {

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java?rev=1004381&r1=1004380&r2=1004381&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
Mon Oct  4 19:56:36 2010
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
@@ -37,7 +38,6 @@ import org.apache.openejb.jee.*;
 import org.apache.openejb.jee.jpa.*;
 import org.apache.openejb.jee.jpa.unit.Persistence;
 import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
-import org.apache.openejb.jee.jpa.unit.Properties;
 import org.apache.openejb.jee.jpa.unit.TransactionType;
 import org.apache.openejb.jee.oejb3.EjbDeployment;
 import org.apache.openejb.jee.oejb3.OpenejbJar;

Modified: openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java?rev=1004381&r1=1004380&r2=1004381&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java
Mon Oct  4 19:56:36 2010
@@ -278,9 +278,8 @@ public class EntityManagerPropogationTes
 
         // Create a persistence-unit for this app
         PersistenceUnit unit = new PersistenceUnit("testUnit");
-        unit.getClazz().add(Color.class.getName());
-        unit.setProperties(new org.apache.openejb.jee.jpa.unit.Properties());
-        unit.getProperties().setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
+        unit.addClass(Color.class);
+        unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
 
         // Add the persistence.xml to the "ear"
         appModule.getPersistenceModules().add(new PersistenceModule("root", new Persistence(unit)));

Modified: openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/Persistence.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/Persistence.java?rev=1004381&r1=1004380&r2=1004381&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/Persistence.java
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/Persistence.java
Mon Oct  4 19:56:36 2010
@@ -104,6 +104,7 @@ public class Persistence {
 
     @XmlElement(name = "persistence-unit", required = true)
     protected List<PersistenceUnit> persistenceUnit;
+
     @XmlAttribute(required = true)
     @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
     protected String version = "1.0";
@@ -146,6 +147,15 @@ public class Persistence {
         return this.persistenceUnit;
     }
 
+    public PersistenceUnit addPersistenceUnit(PersistenceUnit unit) {
+        getPersistenceUnit().add(unit);
+        return unit;
+    }
+
+    public PersistenceUnit addPersistenceUnit(String unitName) {
+        return addPersistenceUnit(new PersistenceUnit(unitName));
+    }
+    
     /**
      * Gets the value of the version property.
      * 

Modified: openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/PersistenceUnit.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/PersistenceUnit.java?rev=1004381&r1=1004380&r2=1004381&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/PersistenceUnit.java
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/PersistenceUnit.java
Mon Oct  4 19:56:36 2010
@@ -23,8 +23,9 @@ import javax.xml.bind.annotation.XmlType
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlTransient;
-import java.util.List;
-import java.util.ArrayList;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import java.util.*;
+import java.util.Properties;
 
 /**
  *
@@ -109,7 +110,11 @@ public class PersistenceUnit {
     protected List<String> clazz;
     @XmlElement(name = "exclude-unlisted-classes", defaultValue = "false")
     protected Boolean excludeUnlistedClasses;
-    protected Properties properties;
+
+    @XmlElement(name = "properties")
+    @XmlJavaTypeAdapter(PropertiesAdapter.class)
+    protected java.util.Properties properties;
+
     @XmlAttribute(required = true)
     protected String name;
     @XmlAttribute(name = "transaction-type")
@@ -151,6 +156,10 @@ public class PersistenceUnit {
         this.provider = value;
     }
 
+    public void setProvider(Class value) {
+        setProvider(value == null ? null : value.getName());
+    }
+
     public String getJtaDataSource() {
         return jtaDataSource;
     }
@@ -188,6 +197,14 @@ public class PersistenceUnit {
         return this.clazz;
     }
 
+    public boolean addClass(String s) {
+        return clazz.add(s);
+    }
+
+    public boolean addClass(Class clazz) {
+        return addClass(clazz.getName());
+    }
+
     public Boolean isExcludeUnlistedClasses() {
         return excludeUnlistedClasses;
     }
@@ -197,11 +214,22 @@ public class PersistenceUnit {
     }
 
     public Properties getProperties() {
+        if (properties == null) {
+            properties = new Properties();
+        }
         return properties;
     }
 
-    public void setProperties(Properties value) {
-        this.properties = value;
+    public String getProperty(String key) {
+        return getProperties().getProperty(key);
+    }
+
+    public String getProperty(String key, String defaultValue) {
+        return getProperties().getProperty(key, defaultValue);
+    }
+
+    public Object setProperty(String key, String value) {
+        return getProperties().setProperty(key, value);
     }
 
     public String getName() {
@@ -222,4 +250,7 @@ public class PersistenceUnit {
     }
 
 
+    public void setProperties(Properties properties) {
+        this.properties = properties;
+    }
 }

Added: openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/PropertiesAdapter.java
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/PropertiesAdapter.java?rev=1004381&view=auto
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/PropertiesAdapter.java
(added)
+++ openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/PropertiesAdapter.java
Mon Oct  4 19:56:36 2010
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.jee.jpa.unit;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import java.util.Map;
+
+/**
+* @version $Rev$ $Date$
+*/
+public class PropertiesAdapter extends XmlAdapter<org.apache.openejb.jee.jpa.unit.Properties,
java.util.Properties> {
+
+    @Override
+    public org.apache.openejb.jee.jpa.unit.Properties marshal(java.util.Properties v) throws
Exception {
+
+        if (v == null) return null;
+
+        org.apache.openejb.jee.jpa.unit.Properties p = new org.apache.openejb.jee.jpa.unit.Properties();
+
+        for (Map.Entry<Object, Object> entry : v.entrySet()) {
+
+            p.setProperty(entry.getKey().toString(), entry.getValue().toString());
+
+        }
+
+        return p;
+    }
+
+    @Override
+    public java.util.Properties unmarshal(org.apache.openejb.jee.jpa.unit.Properties v) throws
Exception {
+
+        if (v == null) return null;
+
+        java.util.Properties properties = new java.util.Properties();
+
+        for (Property property : v.getProperty()) {
+            properties.setProperty(property.getName(), property.getValue());
+        }
+
+        return properties;
+    }
+}

Propchange: openejb/branches/openejb-3.1.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/unit/PropertiesAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/persistence-example.xml
URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/persistence-example.xml?rev=1004381&r1=1004380&r2=1004381&view=diff
==============================================================================
--- openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/persistence-example.xml
(original)
+++ openejb/branches/openejb-3.1.x/container/openejb-jee/src/test/resources/persistence-example.xml
Mon Oct  4 19:56:36 2010
@@ -1,24 +1,24 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<!--
-
-    Licensed to the Apache Software Foundation (ASF) under one or more
-    contributor license agreements.  See the NOTICE file distributed with
-    this work for additional information regarding copyright ownership.
-    The ASF licenses this file to You under the Apache License, Version 2.0
-    (the "License"); you may not use this file except in compliance with
-    the License.  You may obtain a copy of the License at
-
-       http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
--->
-
-<!-- $Rev$ $Date$ -->
-
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<!-- $Rev$ $Date$ -->
+
 <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
     <persistence-unit transaction-type="JTA" name="foo">
         <description>description</description>
@@ -33,9 +33,9 @@
         <class>org.acme.Animal</class>
         <exclude-unlisted-classes>true</exclude-unlisted-classes>
         <properties>
-            <property value="oof" name="foo"/>
             <property value="rab" name="bar"/>
             <property value="zab" name="baz"/>
+            <property value="oof" name="foo"/>
         </properties>
     </persistence-unit>
     <persistence-unit transaction-type="RESOURCE_LOCAL" name="bar">
@@ -51,8 +51,8 @@
         <class>org.acme.Animal2</class>
         <exclude-unlisted-classes>true</exclude-unlisted-classes>
         <properties>
-            <property value="oof2" name="foo2"/>
             <property value="rab2" name="bar2"/>
+            <property value="oof2" name="foo2"/>
             <property value="zab2" name="baz2"/>
         </properties>
     </persistence-unit>



Mime
View raw message