mirror of https://github.com/apache/openjpa.git
OPENJPA-142: read entity names specified in XML. Also added comment clarifying that ClassMetaData.setTypeAlias() is only used at enhance time.
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@516682 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d35bc8a306
commit
b5bab78e04
|
@ -588,7 +588,8 @@ public class ClassMetaData
|
|||
/**
|
||||
* Sets the alias for the described type. The alias can be
|
||||
* any arbitrary string that the implementation can later use to
|
||||
* refer to the class.
|
||||
* refer to the class. Note that at runtime, only the alias
|
||||
* computed when the persistent type was enhanced is used.
|
||||
*
|
||||
* @param alias the alias name to apply to the described type
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.openjpa.persistence.xml;
|
||||
|
||||
public class SimpleXmlEntity {
|
||||
|
||||
private long id;
|
||||
private int version;
|
||||
private String stringField;
|
||||
|
||||
public String getStringField() {
|
||||
return stringField;
|
||||
}
|
||||
|
||||
public void setStringField(String stringField) {
|
||||
this.stringField = stringField;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package org.apache.openjpa.persistence.xml;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.apache.openjpa.persistence.test.SingleEMTest;
|
||||
import org.apache.openjpa.persistence.ArgumentException;
|
||||
|
||||
public class TestSimpleXmlEntity
|
||||
extends SingleEMTest {
|
||||
|
||||
public TestSimpleXmlEntity() {
|
||||
super(SimpleXmlEntity.class);
|
||||
}
|
||||
|
||||
protected void setEMFProps(Map props) {
|
||||
super.setEMFProps(props);
|
||||
}
|
||||
|
||||
public void testNamedQueryInXmlNamedEntity() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.createNamedQuery("SimpleXml.findAll").getResultList();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testNamedQueryInXmlUsingShortClassName() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
try {
|
||||
em.createNamedQuery("SimpleXmlEntity.findAll").getResultList();
|
||||
fail("should not be able to execute query using short class name " +
|
||||
"for entity that has an entity name specified");
|
||||
} catch (ArgumentException ae) {
|
||||
// expected
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testNamedEntityInDynamicQuery() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.createQuery("select o from SimpleXml o").getResultList();
|
||||
em.close();
|
||||
}
|
||||
|
||||
public void testShortClassNameInDynamicQuery() {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
try {
|
||||
em.createQuery("select o from SimpleXmlEntity o").getResultList();
|
||||
fail("should not be able to execute query using short class name " +
|
||||
"for entity that has an entity name specified");
|
||||
} catch (ArgumentException ae) {
|
||||
// expected
|
||||
}
|
||||
em.close();
|
||||
}
|
||||
}
|
|
@ -24,6 +24,13 @@
|
|||
org.apache.openjpa.persistence.PersistenceProviderImpl
|
||||
</provider>
|
||||
-->
|
||||
<!--
|
||||
This needs to be listed because the OpenJPA test framework
|
||||
does not provide any other means to incrementally enhance classes
|
||||
for particular test cases, and the XML data must be available at
|
||||
enhance time for XML data to get incorporated into PCRegistry
|
||||
-->
|
||||
<mapping-file>org/apache/openjpa/persistence/xml/orm.xml</mapping-file>
|
||||
<properties>
|
||||
<!--
|
||||
These properties are instead passed via System properties
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<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 orm_1_0.xsd"
|
||||
version="1.0">
|
||||
<package>
|
||||
org.apache.openjpa.persistence.xml
|
||||
</package>
|
||||
<entity name="SimpleXml" class="SimpleXmlEntity">
|
||||
<named-query name="SimpleXml.findAll">
|
||||
<query>select o from SimpleXml o</query>
|
||||
</named-query>
|
||||
<named-query name="SimpleXmlEntity.findAll">
|
||||
<query>select o from SimpleXmlEntity o</query>
|
||||
</named-query>
|
||||
<attributes>
|
||||
<id name="id"/>
|
||||
<basic name="stringField"/>
|
||||
<version name="version"/>
|
||||
</attributes>
|
||||
</entity>
|
||||
</entity-mappings>
|
|
@ -61,6 +61,7 @@ import static org.apache.openjpa.persistence.MetaDataTag.*;
|
|||
import static org.apache.openjpa.persistence.PersistenceStrategy.*;
|
||||
import org.apache.openjpa.util.ImplHelper;
|
||||
import org.apache.openjpa.util.UnsupportedException;
|
||||
import serp.util.Strings;
|
||||
|
||||
/**
|
||||
* Custom SAX parser used by the system to quickly parse persistence i
|
||||
|
@ -721,7 +722,8 @@ public class XMLPersistenceMetaDataParser
|
|||
// query mode only?
|
||||
_cls = classForName(currentClassName());
|
||||
if (_mode == MODE_QUERY) {
|
||||
if (_parser != null && !"true".equals(attrs.getValue("metadata-complete")))
|
||||
if (_parser != null &&
|
||||
!"true".equals(attrs.getValue("metadata-complete")))
|
||||
_parser.parse(_cls);
|
||||
return true;
|
||||
}
|
||||
|
@ -759,7 +761,8 @@ public class XMLPersistenceMetaDataParser
|
|||
meta.setSourceMode(MODE_NONE);
|
||||
|
||||
// parse annotations first so XML overrides them
|
||||
if (_parser != null && !"true".equals(attrs.getValue("metadata-complete")))
|
||||
if (_parser != null &&
|
||||
!"true".equals(attrs.getValue("metadata-complete")))
|
||||
_parser.parse(_cls);
|
||||
}
|
||||
|
||||
|
@ -768,6 +771,9 @@ public class XMLPersistenceMetaDataParser
|
|||
meta.setSource(getSourceFile(), meta.SRC_XML);
|
||||
meta.setSourceMode(MODE_META, true);
|
||||
meta.setListingIndex(_clsPos);
|
||||
String name = attrs.getValue("name");
|
||||
if (!StringUtils.isEmpty(name))
|
||||
meta.setTypeAlias(name);
|
||||
meta.setEmbeddedOnly(mappedSuper || "embeddable".equals(elem));
|
||||
if (mappedSuper)
|
||||
meta.setIdentityType(meta.ID_UNKNOWN);
|
||||
|
|
Loading…
Reference in New Issue