Repository: deltaspike Updated Branches: refs/heads/master f30b389ab -> 6480a0e54
http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptor.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptor.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptor.java new file mode 100644 index 0000000..3315b77 --- /dev/null +++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptor.java @@ -0,0 +1,66 @@ +/* + * 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.deltaspike.jpa.spi.descriptor.xml; + +import java.util.List; + +public class EntityMappingsDescriptor +{ + private List<MappedSuperclassDescriptor> mappedSuperclassDescriptors; + private List<EntityDescriptor> entityDescriptors; + private String packageName; + + public EntityMappingsDescriptor(List<MappedSuperclassDescriptor> mappedSuperclassDescriptors, + List<EntityDescriptor> entityDescriptors, String packageName) + { + this.mappedSuperclassDescriptors = mappedSuperclassDescriptors; + this.entityDescriptors = entityDescriptors; + this.packageName = packageName; + } + + public List<MappedSuperclassDescriptor> getMappedSuperclassDescriptors() + { + return mappedSuperclassDescriptors; + } + + public void setMappedSuperclassDescriptors(List<MappedSuperclassDescriptor> mappedSuperclassDescriptors) + { + this.mappedSuperclassDescriptors = mappedSuperclassDescriptors; + } + + public List<EntityDescriptor> getEntityDescriptors() + { + return entityDescriptors; + } + + public void setEntityDescriptors(List<EntityDescriptor> entityDescriptors) + { + this.entityDescriptors = entityDescriptors; + } + + public String getPackageName() + { + return packageName; + } + + public void setPackageName(String packageName) + { + this.packageName = packageName; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptorParser.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptorParser.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptorParser.java new file mode 100644 index 0000000..90c5ef7 --- /dev/null +++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptorParser.java @@ -0,0 +1,235 @@ +/* + * 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.deltaspike.jpa.spi.descriptor.xml; + +import java.io.IOException; +import java.io.Serializable; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import javax.enterprise.inject.Typed; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +@Typed +public class EntityMappingsDescriptorParser extends DescriptorReader +{ + public static final String DEFAULT_ORM_PATH = "META-INF/orm.xml"; + + public EntityMappingsDescriptor readAll(String baseUrl, String resource) throws IOException + { + Document document = read(baseUrl, resource).getDocument(); + return readFromDocument(document); + } + + public EntityMappingsDescriptor readDefaultOrm(String baseUrl) throws IOException + { + try + { + Descriptor desc = read(baseUrl, DEFAULT_ORM_PATH); + return readFromDocument(desc.getDocument()); + } + catch (Exception e) + { + return new EntityMappingsDescriptor(Collections.<MappedSuperclassDescriptor>emptyList(), + Collections.<EntityDescriptor>emptyList(), null); + } + } + + protected EntityMappingsDescriptor readFromDocument(Document doc) + { + String packageName = + parsePackageName(doc); + List<MappedSuperclassDescriptor> mappedSuperclassDescriptors = + parseMappedSuperclassDescriptors(doc, packageName); + List<EntityDescriptor> entityDescriptors = + parseEntityDescriptors(doc, packageName); + + return new EntityMappingsDescriptor(mappedSuperclassDescriptors, entityDescriptors, packageName); + } + + protected String extractNodeAttribute(Element element, String childName, String attribute) + { + NodeList list = element.getElementsByTagName(childName); + if (list.getLength() == 0) + { + return null; + } + return extractAttribute(list.item(0), attribute); + } + + protected String extractAttribute(Node item, String name) + { + Node node = item.getAttributes().getNamedItem(name); + if (node != null) + { + return node.getTextContent(); + } + return null; + } + + protected String[] extractNodeAttributes(Element element, String childName, String attribute) + { + NodeList list = element.getElementsByTagName(childName); + if (list.getLength() == 0) + { + return null; + } + return extractAttributes(list, attribute); + } + + protected String[] extractAttributes(NodeList list, String name) + { + String[] values = null; + + for (int i = 0; i < list.getLength(); i++) + { + Node node = list.item(i).getAttributes().getNamedItem(name); + if (node != null) + { + if (values == null) + { + values = new String[list.getLength()]; + } + + values[i] = node.getTextContent(); + } + } + + return values; + } + + protected String extractNodeContent(Element element, String name) + { + NodeList list = element.getElementsByTagName(name); + if (list.getLength() == 0) + { + return null; + } + return list.item(0).getTextContent(); + } + + protected String parsePackageName(Document doc) + { + return extractNodeContent(doc.getDocumentElement(), "package"); + } + + protected List<MappedSuperclassDescriptor> parseMappedSuperclassDescriptors(Document doc, String packageName) + { + List<MappedSuperclassDescriptor> result = new LinkedList<MappedSuperclassDescriptor>(); + + NodeList mappings = doc.getElementsByTagName("mapped-superclass"); + for (int i = 0; i < mappings.getLength(); i++) + { + Node node = mappings.item(i); + + MappedSuperclassDescriptor entityDescriptor = new MappedSuperclassDescriptor(); + parseCommonEntityDescriptorAttributes(packageName, entityDescriptor, node); + + result.add(entityDescriptor); + } + + return result; + } + + protected List<EntityDescriptor> parseEntityDescriptors(Document doc, String packageName) + { + List<EntityDescriptor> result = new LinkedList<EntityDescriptor>(); + + NodeList mappings = doc.getElementsByTagName("entity"); + for (int i = 0; i < mappings.getLength(); i++) + { + Node node = mappings.item(i); + + EntityDescriptor entityDescriptor = new EntityDescriptor(); + parseCommonEntityDescriptorAttributes(packageName, entityDescriptor, node); + entityDescriptor.setTableName(extractNodeAttribute((Element) node, "table", "name")); + + result.add(entityDescriptor); + } + + return result; + } + + protected void parseCommonEntityDescriptorAttributes(String packageName, + AbstractEntityDescriptor entityDescriptor, Node node) + { + entityDescriptor.setName(extractAttribute(node, "name")); + entityDescriptor.setVersion(extractNodeAttribute((Element) node, "version", "name")); + + String[] id = extractNodeAttributes((Element) node, "id", "name"); + if (id != null) + { + entityDescriptor.setId(id); + } + else + { + String embeddedId = extractNodeAttribute((Element) node, "embedded-id", "name"); + if (embeddedId != null) + { + entityDescriptor.setId(new String[] { embeddedId }); + } + } + + String className = extractAttribute(node, "class"); + if (className != null) + { + try + { + entityDescriptor.setEntityClass(Class.forName(buildClassName(className, packageName))); + } + catch (ClassNotFoundException e) + { + throw new IllegalArgumentException("Can't get class " + buildClassName(className, packageName), e); + } + } + + String idClass = extractNodeAttribute((Element) node, "id-class", "class"); + if (idClass != null) + { + try + { + entityDescriptor.setIdClass( + (Class<? extends Serializable>) Class.forName(buildClassName(idClass, packageName))); + } + catch (ClassNotFoundException e) + { + throw new IllegalArgumentException("Can't get class " + buildClassName(className, packageName), e); + } + } + } + + protected String buildClassName(String clazzName, String packageName) + { + if (clazzName == null && packageName == null) + { + return null; + } + return (packageName != null && !isClassNameQualified(clazzName)) ? packageName + "." + clazzName : clazzName; + } + + protected boolean isClassNameQualified(String name) + { + return name.contains("."); + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/MappedSuperclassDescriptor.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/MappedSuperclassDescriptor.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/MappedSuperclassDescriptor.java new file mode 100644 index 0000000..2935ae3 --- /dev/null +++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/MappedSuperclassDescriptor.java @@ -0,0 +1,48 @@ +/* + * 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.deltaspike.jpa.spi.descriptor.xml; + +import java.io.Serializable; + +public class MappedSuperclassDescriptor extends AbstractEntityDescriptor +{ + public MappedSuperclassDescriptor() + { + } + + public MappedSuperclassDescriptor(String[] id, String version, String name, Class<?> entityClass, + Class<? extends Serializable> idClass, AbstractEntityDescriptor parent) + { + super(id, version, name, entityClass, idClass, parent); + } + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append("EntityDescriptor ") + .append("[entityClass=").append(getEntityClass().getName()) + .append(", name=").append(getName()) + .append(", idClass=").append(getIdClass().getName()) + .append(", id=").append(getId()) + .append(", superClass=").append(getParent()) + .append("]"); + return builder.toString(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptor.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptor.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptor.java new file mode 100644 index 0000000..948a0e6 --- /dev/null +++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptor.java @@ -0,0 +1,80 @@ +/* + * 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.deltaspike.jpa.spi.descriptor.xml; + +import java.util.List; +import java.util.Map; + +public class PersistenceUnitDescriptor +{ + private String name; + /* + private String transactionType; + private boolean excludeUnlistedClasses; + */ + private List<EntityDescriptor> entityDescriptors; + private Map<String, String> properties; + + public PersistenceUnitDescriptor(String name, List<EntityDescriptor> entityDescriptors, + Map<String, String> properties) + { + this.name = name; + this.entityDescriptors = entityDescriptors; + this.properties = properties; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public List<EntityDescriptor> getEntityDescriptors() + { + return entityDescriptors; + } + + public void setEntityDescriptors(List<EntityDescriptor> entityDescriptors) + { + this.entityDescriptors = entityDescriptors; + } + + public Map<String, String> getProperties() + { + return properties; + } + + public void setProperties(Map<String, String> properties) + { + this.properties = properties; + } + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append("PersistenceUnit [name=").append(name) + .append(", entityDescriptors=").append(entityDescriptors).append("]"); + return builder.toString(); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParser.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParser.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParser.java new file mode 100644 index 0000000..44dfcd0 --- /dev/null +++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParser.java @@ -0,0 +1,136 @@ +/* + * 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.deltaspike.jpa.spi.descriptor.xml; + +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.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import javax.enterprise.inject.Typed; + +@Typed +public class PersistenceUnitDescriptorParser extends DescriptorReader +{ + public static final String RESOURCE_PATH = "META-INF/persistence.xml"; + + private final EntityMappingsDescriptorParser entityMappingsDescriptorParser + = new EntityMappingsDescriptorParser(); + + public List<PersistenceUnitDescriptor> readAll() throws IOException + { + List<PersistenceUnitDescriptor> result = new LinkedList<PersistenceUnitDescriptor>(); + List<Descriptor> persistenceXmls = readAllFromClassPath(RESOURCE_PATH); + for (Descriptor desc : persistenceXmls) + { + result.addAll(lookupUnits(desc)); + } + return Collections.unmodifiableList(result); + } + + protected List<PersistenceUnitDescriptor> lookupUnits(Descriptor descriptor) + { + List<PersistenceUnitDescriptor> result = new LinkedList<PersistenceUnitDescriptor>(); + NodeList list = descriptor.getDocument().getDocumentElement().getElementsByTagName("persistence-unit"); + for (int i = 0; i < list.getLength(); i++) + { + Node node = list.item(i); + + String unitName = extractUnitName(node); + String baseUrl = extractBaseUrl(descriptor.getUrl(), RESOURCE_PATH); + List<EntityDescriptor> entities = extractMappings((Element) node, baseUrl, unitName); + Map<String, String> properties = extractProperties((Element) node); + + result.add(new PersistenceUnitDescriptor(unitName, entities, properties)); + } + return result; + } + + protected List<EntityDescriptor> extractMappings(Element element, String baseUrl, String unitName) + { + try + { + List<EntityDescriptor> entities = new LinkedList<EntityDescriptor>(); + List<MappedSuperclassDescriptor> superClasses = new LinkedList<MappedSuperclassDescriptor>(); + NodeList list = element.getElementsByTagName("mapping-file"); + readMappingFiles(baseUrl, unitName, entities, superClasses, list); + EntityMappingsDescriptor mappings = entityMappingsDescriptorParser.readDefaultOrm(baseUrl); + entities.addAll(mappings.getEntityDescriptors()); + superClasses.addAll(mappings.getMappedSuperclassDescriptors()); + AbstractEntityHierarchyBuilder.buildHierarchy(entities, superClasses); + return entities; + } + catch (Exception e) + { + throw new RuntimeException("Failed initializing mapping files", e); + } + } + + protected void readMappingFiles(String baseUrl, String unitName, + List<EntityDescriptor> entities, List<MappedSuperclassDescriptor> superClasses, + NodeList list) + { + for (int i = 0; i < list.getLength(); i++) + { + String resource = list.item(i).getTextContent(); + try + { + EntityMappingsDescriptor mappings = entityMappingsDescriptorParser.readAll(baseUrl, resource); + entities.addAll(mappings.getEntityDescriptors()); + superClasses.addAll(mappings.getMappedSuperclassDescriptors()); + } + catch (Exception e) + { + throw new RuntimeException("[PersistenceUnit: " + unitName + "] " + + "Unable to resolve named mapping-file [" + resource + "]"); + } + } + } + + protected String extractUnitName(Node node) + { + return node.getAttributes().getNamedItem("name").getTextContent(); + } + + protected 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/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProvider.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProvider.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProvider.java new file mode 100644 index 0000000..8f3d431 --- /dev/null +++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProvider.java @@ -0,0 +1,191 @@ +/* + * 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.deltaspike.jpa.spi.descriptor.xml; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import javax.enterprise.inject.Typed; +import org.apache.deltaspike.core.util.StringUtils; + +@Typed +public final class PersistenceUnitDescriptorProvider +{ + private static final PersistenceUnitDescriptorProvider INSTANCE = new PersistenceUnitDescriptorProvider(); + + private final PersistenceUnitDescriptorParser persistenceUnitDescriptorParser + = new PersistenceUnitDescriptorParser(); + + private List<PersistenceUnitDescriptor> persistenceUnitDescriptors = Collections.emptyList(); + + private PersistenceUnitDescriptorProvider() + { + } + + public static PersistenceUnitDescriptorProvider getInstance() + { + return INSTANCE; + } + + public void init() + { + try + { + persistenceUnitDescriptors = persistenceUnitDescriptorParser.readAll(); + } + catch (IOException e) + { + throw new RuntimeException("Failed to parse persitence.xml's", e); + } + } + + public PersistenceUnitDescriptor get(String name) + { + for (PersistenceUnitDescriptor unit : persistenceUnitDescriptors) + { + if (name.equalsIgnoreCase(unit.getName())) + { + return unit; + } + } + return null; + } + + public boolean isEntity(Class<?> entityClass) + { + return find(entityClass) != null; + } + + public String[] primaryKeyFields(Class<?> entityClass) + { + EntityDescriptor entity = find(entityClass); + if (entity != null) + { + if (entity.getId() != null) + { + return entity.getId(); + } + + AbstractEntityDescriptor parent = entity.getParent(); + while (parent != null) + { + if (parent.getId() != null) + { + return parent.getId(); + } + + parent = parent.getParent(); + } + } + return null; + } + + public String versionField(Class<?> entityClass) + { + EntityDescriptor entity = find(entityClass); + if (entity != null) + { + if (!StringUtils.isEmpty(entity.getVersion())) + { + return entity.getVersion(); + } + + AbstractEntityDescriptor parent = entity.getParent(); + while (parent != null) + { + if (!StringUtils.isEmpty(parent.getVersion())) + { + return parent.getVersion(); + } + + parent = parent.getParent(); + } + } + return null; + } + + public Class<?> primaryKeyIdClass(Class<?> entityClass) + { + EntityDescriptor entity = find(entityClass); + if (entity != null) + { + if (entity.getIdClass() != null) + { + return entity.getIdClass(); + } + + AbstractEntityDescriptor parent = entity.getParent(); + while (parent != null) + { + if (parent.getIdClass() != null) + { + return parent.getIdClass(); + } + + parent = parent.getParent(); + } + } + return null; + } + + public String entityName(Class<?> entityClass) + { + EntityDescriptor entity = find(entityClass); + if (entity != null) + { + return entity.getName(); + } + return null; + } + + public String entityTableName(Class<?> entityClass) + { + EntityDescriptor entity = find(entityClass); + if (entity != null) + { + return entity.getTableName(); + } + return null; + } + + public EntityDescriptor find(Class<?> entityClass) + { + for (PersistenceUnitDescriptor unit : persistenceUnitDescriptors) + { + EntityDescriptor entity = find(entityClass, unit); + if (entity != null) + { + return entity; + } + } + return null; + } + + protected EntityDescriptor find(Class<?> entityClass, PersistenceUnitDescriptor descriptor) + { + for (EntityDescriptor entity : descriptor.getEntityDescriptors()) + { + if (entity.getEntityClass().equals(entityClass)) + { + return entity; + } + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/EntityMappingsDescriptorParserTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/EntityMappingsDescriptorParserTest.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/EntityMappingsDescriptorParserTest.java new file mode 100644 index 0000000..6afd9ee --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/EntityMappingsDescriptorParserTest.java @@ -0,0 +1,114 @@ +/* + * 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.deltaspike.test.jpa.spi.descriptor.xml; + +import java.io.IOException; +import org.apache.deltaspike.jpa.spi.descriptor.xml.EntityMappingsDescriptor; +import org.apache.deltaspike.jpa.spi.descriptor.xml.EntityMappingsDescriptorParser; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class EntityMappingsDescriptorParserTest +{ + private EntityMappingsDescriptorParser entityMappingsDescriptorParser; + private EntityMappingsDescriptor descriptor; + + @Before + public void before() throws IOException + { + entityMappingsDescriptorParser + = new EntityMappingsDescriptorParser(); + descriptor + = entityMappingsDescriptorParser.readAll(getClass().getResource("/").getPath(), "META-INF/test-orm.xml"); + } + + @Test + public void testPackageName() throws IOException + { + Assert.assertEquals("org.apache.deltaspike.test.jpa.spi.descriptor.xml", + descriptor.getPackageName()); + } + + @Test + public void testEntityDescriptors() throws IOException + { + Assert.assertNotNull(descriptor.getEntityDescriptors()); + Assert.assertEquals(3, descriptor.getEntityDescriptors().size()); + } + + @Test + public void testMappedSuperclassDescriptors() throws IOException + { + Assert.assertNotNull(descriptor.getMappedSuperclassDescriptors()); + Assert.assertEquals(2, descriptor.getMappedSuperclassDescriptors().size()); + } + + @Test + public void testEntityClass() throws IOException + { + Assert.assertEquals(MappedOne.class, + descriptor.getEntityDescriptors().get(0).getEntityClass()); + Assert.assertEquals(MappedTwo.class, + descriptor.getEntityDescriptors().get(1).getEntityClass()); + Assert.assertEquals(MappedThree.class, + descriptor.getEntityDescriptors().get(2).getEntityClass()); + } + + @Test + public void testId() throws IOException + { + Assert.assertEquals("id", + descriptor.getEntityDescriptors().get(0).getId()[0]); + Assert.assertEquals("teeSetId", + descriptor.getEntityDescriptors().get(1).getId()[0]); + Assert.assertEquals("holeId", + descriptor.getEntityDescriptors().get(1).getId()[1]); + Assert.assertEquals(null, + descriptor.getEntityDescriptors().get(2).getId()); + } + + @Test + public void testVersion() throws IOException + { + Assert.assertEquals("version", + descriptor.getEntityDescriptors().get(0).getVersion()); + Assert.assertEquals(null, + descriptor.getEntityDescriptors().get(1).getVersion()); + Assert.assertEquals(null, + descriptor.getEntityDescriptors().get(2).getVersion()); + + Assert.assertEquals(null, descriptor.getMappedSuperclassDescriptors().get(0).getVersion()); + Assert.assertEquals("version", descriptor.getMappedSuperclassDescriptors().get(1).getVersion()); + } + + @Test + public void testName() throws IOException + { + Assert.assertEquals("Mapped_One", + descriptor.getEntityDescriptors().get(0).getName()); + } + + @Test + public void testTableName() throws IOException + { + Assert.assertEquals("mapped_three_table", + descriptor.getEntityDescriptors().get(2).getTableName()); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedId.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedId.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedId.java new file mode 100644 index 0000000..a4ddd50 --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedId.java @@ -0,0 +1,36 @@ +/* + * 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.deltaspike.test.jpa.spi.descriptor.xml; + +public class MappedId +{ + + private Long id; + + public Long getId() + { + return id; + } + + public void setId(Long id) + { + this.id = id; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedOne.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedOne.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedOne.java new file mode 100644 index 0000000..3f0a61a --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedOne.java @@ -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.deltaspike.test.jpa.spi.descriptor.xml; + +public class MappedOne +{ + + private Long id; + private String name; + + public MappedOne() + { + } + + public MappedOne(String name) + { + this.name = name; + } + + public Long getId() + { + return id; + } + + public void setId(Long id) + { + this.id = id; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedSuperclass.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedSuperclass.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedSuperclass.java new file mode 100644 index 0000000..59bdc00 --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedSuperclass.java @@ -0,0 +1,36 @@ +/* + * 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.deltaspike.test.jpa.spi.descriptor.xml; + +public class MappedSuperclass extends MappedId +{ + + private Long counter; + + public Long getCounter() + { + return counter; + } + + public void setCounter(Long id) + { + this.counter = id; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedThree.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedThree.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedThree.java new file mode 100644 index 0000000..9abe4dd --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedThree.java @@ -0,0 +1,36 @@ +/* + * 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.deltaspike.test.jpa.spi.descriptor.xml; + +public class MappedThree extends MappedSuperclass +{ + + private String name; + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedTwo.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedTwo.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedTwo.java new file mode 100644 index 0000000..6c069e5 --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedTwo.java @@ -0,0 +1,59 @@ +/* + * 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.deltaspike.test.jpa.spi.descriptor.xml; + +public class MappedTwo +{ + + private Long teeSetId; + private Long holeId; + + private String name; + + public Long getTeeSetId() + { + return teeSetId; + } + + public void setTeeSetId(Long teeSetId) + { + this.teeSetId = teeSetId; + } + + public Long getHoleId() + { + return holeId; + } + + public void setHoleId(Long holeId) + { + this.holeId = holeId; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParserTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParserTest.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParserTest.java new file mode 100644 index 0000000..7d8c227 --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParserTest.java @@ -0,0 +1,71 @@ +/* + * 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.deltaspike.test.jpa.spi.descriptor.xml; + +import java.io.IOException; +import java.util.List; +import org.apache.deltaspike.jpa.spi.descriptor.xml.PersistenceUnitDescriptor; +import org.apache.deltaspike.jpa.spi.descriptor.xml.PersistenceUnitDescriptorParser; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class PersistenceUnitDescriptorParserTest +{ + private PersistenceUnitDescriptorParser persistenceUnitDescriptorParser; + private List<PersistenceUnitDescriptor> descriptors; + + @Before + public void before() throws IOException + { + persistenceUnitDescriptorParser + = new PersistenceUnitDescriptorParser(); + descriptors + = persistenceUnitDescriptorParser.readAll(); + } + + @Test + public void testPackageName() throws IOException + { + Assert.assertEquals("test", descriptors.get(0).getName()); + Assert.assertEquals("test2", descriptors.get(1).getName()); + } + + @Test + public void testProperties() throws IOException + { + Assert.assertNotNull(descriptors.get(0).getProperties()); + Assert.assertEquals(1, descriptors.get(0).getProperties().size()); + + Assert.assertNotNull(descriptors.get(1).getProperties()); + Assert.assertEquals(3, descriptors.get(1).getProperties().size()); + + Assert.assertNotNull(descriptors.get(2).getProperties()); + Assert.assertEquals(0, descriptors.get(2).getProperties().size()); + } + + @Test + public void testEntityDescriptors() throws IOException + { + Assert.assertNotNull(descriptors.get(0).getEntityDescriptors()); + Assert.assertEquals(3, descriptors.get(0).getEntityDescriptors().size()); + Assert.assertEquals(MappedOne.class, + descriptors.get(0).getEntityDescriptors().get(0).getEntityClass()); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProviderTest.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProviderTest.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProviderTest.java new file mode 100644 index 0000000..5f863ce --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProviderTest.java @@ -0,0 +1,43 @@ +/* + * 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.deltaspike.test.jpa.spi.descriptor.xml; + +import java.io.IOException; +import junit.framework.Assert; +import org.apache.deltaspike.jpa.spi.descriptor.xml.PersistenceUnitDescriptorProvider; +import org.junit.Before; +import org.junit.Test; + +public class PersistenceUnitDescriptorProviderTest +{ + @Before + public void before() throws IOException + { + PersistenceUnitDescriptorProvider.getInstance().init(); + } + + @Test + public void bla() + { + String[] ids = + PersistenceUnitDescriptorProvider.getInstance().primaryKeyFields(MappedThree.class); + Assert.assertNotNull(ids); + Assert.assertEquals(1, ids.length); + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/TeeId.java ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/TeeId.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/TeeId.java new file mode 100644 index 0000000..ecd5dea --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/TeeId.java @@ -0,0 +1,103 @@ +/* + * 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.deltaspike.test.jpa.spi.descriptor.xml; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Embeddable; + +@Embeddable +@SuppressWarnings("serial") +public class TeeId implements Serializable +{ + + @Column(nullable = false) + private Long teeSetId; + + @Column(nullable = false) + private Long holeId; + + public TeeId() + { + } + + public TeeId(long teeSetId, long holeId) + { + this.teeSetId = teeSetId; + this.holeId = holeId; + } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + (int) (holeId ^ (holeId >>> 32)); + result = prime * result + (int) (teeSetId ^ (teeSetId >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (getClass() != obj.getClass()) + { + return false; + } + TeeId other = (TeeId) obj; + if (holeId != other.holeId) + { + return false; + } + if (teeSetId != other.teeSetId) + { + return false; + } + return true; + } + + public long getTeeSetId() + { + return teeSetId; + } + + public void setTeeSetId(long teeSetId) + { + this.teeSetId = teeSetId; + } + + public long getHoleId() + { + return holeId; + } + + public void setHoleId(long holeId) + { + this.holeId = holeId; + } +} http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/test/resources/META-INF/persistence.xml b/deltaspike/modules/jpa/impl/src/test/resources/META-INF/persistence.xml new file mode 100644 index 0000000..d938f26 --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> +<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> + <persistence-unit name="test"> + <jta-data-source>java:test/test</jta-data-source> + <mapping-file>META-INF/test-orm.xml</mapping-file> + <properties> + <property name="hibernate.hbm2ddl.auto" value="create-drop"/> + </properties> + </persistence-unit> + <persistence-unit name="test2"> + <properties> + <property name="hibernate.hbm2ddl.auto" value="create-drop"/> + <property name="anyOtherProperty" value="test"/> + <property name="anyOtherProperty2" value="test"/> + </properties> + </persistence-unit> + <persistence-unit name="test3"> + + </persistence-unit> +</persistence> http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/resources/META-INF/test-orm.xml ---------------------------------------------------------------------- diff --git a/deltaspike/modules/jpa/impl/src/test/resources/META-INF/test-orm.xml b/deltaspike/modules/jpa/impl/src/test/resources/META-INF/test-orm.xml new file mode 100644 index 0000000..2fe2055 --- /dev/null +++ b/deltaspike/modules/jpa/impl/src/test/resources/META-INF/test-orm.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> +<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd" version="2.0"> + + <package>org.apache.deltaspike.test.jpa.spi.descriptor.xml</package> + + <mapped-superclass class="MappedSuperclass"> + </mapped-superclass> + <mapped-superclass class="MappedId"> + <attributes> + <id name="id"> + <generated-value /> + </id> + <version name="version" /> + </attributes> + </mapped-superclass> + + <entity class="MappedOne" name="Mapped_One"> + <attributes> + <id name="id"> + <generated-value /> + </id> + <version name="version" /> + </attributes> + </entity> + <entity class="org.apache.deltaspike.test.jpa.spi.descriptor.xml.MappedTwo" name="Mapped_Two"> + <id-class class="org.apache.deltaspike.test.jpa.spi.descriptor.xml.TeeId"/> + <attributes> + <id name="teeSetId"/> + <id name="holeId"/> + </attributes> + </entity> + <entity class="MappedThree"> + <table name="mapped_three_table" /> + </entity> + + + +</entity-mappings> \ No newline at end of file
