deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tandrasc...@apache.org
Subject deltaspike git commit: DELTASPIKE-1035 Make DS PersistenceUnit public and also parse properties
Date Fri, 04 Dec 2015 12:15:40 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 74c0e3f84 -> fc33f2267


DELTASPIKE-1035 Make DS PersistenceUnit public and also parse properties

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/fc33f226
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/fc33f226
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/fc33f226

Branch: refs/heads/master
Commit: fc33f226735b1b3cd8e67a4cb60b8cdfa441aa0f
Parents: 74c0e3f
Author: tandraschko <tandraschko@apache.org>
Authored: Fri Dec 4 13:15:07 2015 +0100
Committer: tandraschko <tandraschko@apache.org>
Committed: Fri Dec 4 13:15:07 2015 +0100

----------------------------------------------------------------------
 .../data/impl/meta/unit/PersistenceUnit.java    | 12 ++++++++--
 .../impl/meta/unit/PersistenceUnitReader.java   | 25 +++++++++++++++++++-
 .../data/impl/meta/unit/PersistenceUnits.java   | 12 ++++++++++
 3 files changed, 46 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fc33f226/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnit.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnit.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnit.java
index 8494cfa..e238385 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnit.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnit.java
@@ -19,8 +19,9 @@
 package org.apache.deltaspike.data.impl.meta.unit;
 
 import java.util.List;
+import java.util.Map;
 
-class PersistenceUnit
+public class PersistenceUnit
 {
 
     public static final String RESOURCE_PATH = "META-INF/persistence.xml";
@@ -28,11 +29,13 @@ class PersistenceUnit
 
     private final String unitName;
     private final List<EntityDescriptor> entities;
+    private final Map<String, String> properties;
 
-    PersistenceUnit(String unitName, List<EntityDescriptor> entities)
+    PersistenceUnit(String unitName, List<EntityDescriptor> entities, Map<String,
String> properties)
     {
         this.unitName = unitName;
         this.entities = entities;
+        this.properties = properties;
     }
 
     public EntityDescriptor find(Class<?> entityClass)
@@ -51,6 +54,11 @@ class PersistenceUnit
     {
         return unitName;
     }
+    
+    public Map<String, String> getProperties()
+    {
+        return properties;
+    }
 
     @Override
     public String toString()

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fc33f226/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitReader.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitReader.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitReader.java
index 4fc31ee..ed30e32 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitReader.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitReader.java
@@ -25,8 +25,10 @@ import org.w3c.dom.NodeList;
 
 import java.io.IOException;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 
 public class PersistenceUnitReader extends DescriptorReader
 {
@@ -52,7 +54,8 @@ public class PersistenceUnitReader extends DescriptorReader
             String unitName = extractUnitName(node);
             String baseUrl = extractBaseUrl(descriptor.getUrl(), PersistenceUnit.RESOURCE_PATH);
             List<EntityDescriptor> entities = extractMappings((Element) node, baseUrl,
unitName);
-            result.add(new PersistenceUnit(unitName, entities));
+            Map<String, String> properties = extractProperties((Element) node);
+            result.add(new PersistenceUnit(unitName, entities, properties));
         }
         return result;
     }
@@ -104,4 +107,24 @@ public class PersistenceUnitReader extends DescriptorReader
         return node.getAttributes().getNamedItem("name").getTextContent();
     }
 
+    private Map<String, String> extractProperties(Element element)
+    {
+        Map<String, String> propertiesMap = new HashMap<String, String>();
+
+        Node propertiesNode = element.getElementsByTagName("properties").item(0);
+        if (propertiesNode != null)
+        {
+            NodeList propertyNodes = propertiesNode.getChildNodes();
+            for (int i = 0; i < propertyNodes.getLength(); i++)
+            {
+                if ("property".equals(propertyNodes.item(i).getNodeName()))
+                {
+                    Element propertyNode = (Element) propertyNodes.item(i);
+                    propertiesMap.put(propertyNode.getAttribute("name"), propertyNode.getAttribute("value"));
+                }
+            }
+        }
+
+        return Collections.unmodifiableMap(propertiesMap);
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/fc33f226/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnits.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnits.java
b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnits.java
index a3a2d75..9bbb0e7 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnits.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnits.java
@@ -45,6 +45,18 @@ public final class PersistenceUnits
         persistenceUnits = readPersistenceXmls();
     }
 
+    public PersistenceUnit get(String name)
+    {
+        for (PersistenceUnit unit : persistenceUnits)
+        {
+            if (name.equalsIgnoreCase(unit.getUnitName()))
+            {
+                return unit;
+            }
+        }
+        return null;
+    }
+
     public boolean isEntity(Class<?> entityClass)
     {
         return find(entityClass) != null;


Mime
View raw message