deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From daniels...@apache.org
Subject deltaspike git commit: DELTASPIKE-942 DeltaSpike fails to start with corrupted persistence.xml file
Date Wed, 29 Jul 2015 13:43:46 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master b4a68137b -> 206dc2f6a


DELTASPIKE-942 DeltaSpike fails to start with corrupted persistence.xml file


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

Branch: refs/heads/master
Commit: 206dc2f6ad19edc2b1a1f366668ba359e236e8f3
Parents: b4a6813
Author: Daniel Cunha (soro) <danielsoro@apache.org>
Authored: Wed Jul 29 10:40:26 2015 -0300
Committer: Daniel Cunha (soro) <danielsoro@apache.org>
Committed: Wed Jul 29 10:40:26 2015 -0300

----------------------------------------------------------------------
 .../impl/meta/unit/PersistenceUnitReader.java   | 42 ++++++++++++++------
 1 file changed, 29 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/206dc2f6/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 64694ea..4fc31ee 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
@@ -18,16 +18,16 @@
  */
 package org.apache.deltaspike.data.impl.meta.unit;
 
-import java.io.IOException;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
 import org.apache.deltaspike.data.impl.meta.unit.EntityDescriptorReader.MappingFile;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import java.io.IOException;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
 public class PersistenceUnitReader extends DescriptorReader
 {
 
@@ -51,13 +51,13 @@ public class PersistenceUnitReader extends DescriptorReader
             Node node = list.item(i);
             String unitName = extractUnitName(node);
             String baseUrl = extractBaseUrl(descriptor.getUrl(), PersistenceUnit.RESOURCE_PATH);
-            List<EntityDescriptor> entities = extractMappings((Element) node, baseUrl);
+            List<EntityDescriptor> entities = extractMappings((Element) node, baseUrl,
unitName);
             result.add(new PersistenceUnit(unitName, entities));
         }
         return result;
     }
 
-    private List<EntityDescriptor> extractMappings(Element element, String baseUrl)
+    private List<EntityDescriptor> extractMappings(Element element, String baseUrl,
String unitName)
     {
         try
         {
@@ -65,12 +65,7 @@ public class PersistenceUnitReader extends DescriptorReader
             List<EntityDescriptor> entities = new LinkedList<EntityDescriptor>();
             List<MappedSuperclassDescriptor> superClasses = new LinkedList<MappedSuperclassDescriptor>();
             NodeList list = element.getElementsByTagName("mapping-file");
-            for (int i = 0; i < list.getLength(); i++)
-            {
-                MappingFile mappings = reader.readAll(baseUrl, list.item(i).getTextContent());
-                entities.addAll(mappings.getEntities());
-                superClasses.addAll(mappings.getSuperClasses());
-            }
+            readMappingFiles(baseUrl, unitName, reader, entities, superClasses, list);
             MappingFile mappings = reader.readDefaultOrm(baseUrl);
             entities.addAll(mappings.getEntities());
             superClasses.addAll(mappings.getSuperClasses());
@@ -83,6 +78,27 @@ public class PersistenceUnitReader extends DescriptorReader
         }
     }
 
+    private void readMappingFiles(String baseUrl, String unitName, EntityDescriptorReader
reader,
+                                  List<EntityDescriptor> entities, List<MappedSuperclassDescriptor>
superClasses,
+                                  NodeList list)
+    {
+        for (int i = 0; i < list.getLength(); i++)
+        {
+            String resource = list.item(i).getTextContent();
+            try
+            {
+                MappingFile mappings = reader.readAll(baseUrl, resource);
+                entities.addAll(mappings.getEntities());
+                superClasses.addAll(mappings.getSuperClasses());
+            }
+            catch (Exception e)
+            {
+                throw new RuntimeException("[PersistenceUnit: " + unitName + "] " +
+                        "Unable to resolve named mapping-file [" + resource + "]");
+            }
+        }
+    }
+
     private String extractUnitName(Node node)
     {
         return node.getAttributes().getNamedItem("name").getTextContent();


Mime
View raw message