mirror of https://github.com/apache/openjpa.git
OPENJPA-86
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@563697 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d260d34d69
commit
86e47000db
|
@ -20,10 +20,14 @@ package org.apache.openjpa.persistence.xml;
|
|||
|
||||
public class SimpleXmlEntity {
|
||||
|
||||
private long id;
|
||||
private String id;
|
||||
private int version;
|
||||
private String stringField;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getStringField() {
|
||||
return stringField;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,21 @@ public class TestSimpleXmlEntity
|
|||
setUp(SimpleXmlEntity.class);
|
||||
}
|
||||
|
||||
public void testId() {
|
||||
em.getTransaction().begin();
|
||||
SimpleXmlEntity e = new SimpleXmlEntity();
|
||||
em.persist(e);
|
||||
em.flush();
|
||||
assertNotNull(e.getId());
|
||||
try {
|
||||
Integer.parseInt(e.getId());
|
||||
fail("uuid-based id should not be an integer; was " + e.getId());
|
||||
} catch (NumberFormatException nfe) {
|
||||
// expected
|
||||
}
|
||||
em.getTransaction().rollback();
|
||||
}
|
||||
|
||||
public void testNamedQueryInXmlNamedEntity() {
|
||||
em.createNamedQuery("SimpleXml.findAll").getResultList();
|
||||
}
|
||||
|
|
|
@ -32,7 +32,9 @@
|
|||
<query>select o from SimpleXmlEntity o</query>
|
||||
</named-query>
|
||||
<attributes>
|
||||
<id name="id"/>
|
||||
<id name="id">
|
||||
<generated-value generator="uuid-hex"/>
|
||||
</id>
|
||||
<basic name="stringField"/>
|
||||
<version name="version"/>
|
||||
</attributes>
|
||||
|
|
|
@ -1110,21 +1110,30 @@ public class AnnotationPersistenceMetaDataParser
|
|||
* Sets value generation information for the given field.
|
||||
*/
|
||||
private void parseGeneratedValue(FieldMetaData fmd, GeneratedValue gen) {
|
||||
int strat = getGeneratedValueStrategy(fmd, gen.strategy(),
|
||||
gen.generator());
|
||||
GenerationType strategy = gen.strategy();
|
||||
String generator = gen.generator();
|
||||
parseGeneratedValue(fmd, strategy, generator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets value generation information for the given field.
|
||||
*/
|
||||
static void parseGeneratedValue(FieldMetaData fmd, GenerationType strategy,
|
||||
String generator) {
|
||||
int strat = getGeneratedValueStrategy(fmd, strategy, generator);
|
||||
if (strat != -1)
|
||||
fmd.setValueStrategy(strat);
|
||||
else {
|
||||
switch (gen.strategy()) {
|
||||
switch (strategy) {
|
||||
case TABLE:
|
||||
case SEQUENCE:
|
||||
// technically we should have separate system table and
|
||||
// sequence generators, but it's easier to just rely on
|
||||
// the system org.apache.openjpa.Sequence setting for both
|
||||
if (StringUtils.isEmpty(gen.generator()))
|
||||
if (StringUtils.isEmpty(generator))
|
||||
fmd.setValueSequenceName(SequenceMetaData.NAME_SYSTEM);
|
||||
else
|
||||
fmd.setValueSequenceName(gen.generator());
|
||||
fmd.setValueSequenceName(generator);
|
||||
break;
|
||||
case AUTO:
|
||||
fmd.setValueSequenceName(SequenceMetaData.NAME_SYSTEM);
|
||||
|
@ -1133,7 +1142,7 @@ public class AnnotationPersistenceMetaDataParser
|
|||
fmd.setValueStrategy(ValueStrategies.AUTOASSIGN);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedException(gen.strategy().toString());
|
||||
throw new UnsupportedException(strategy.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.GenerationType;
|
||||
import static javax.persistence.CascadeType.*;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
@ -62,12 +63,9 @@ import org.apache.openjpa.meta.Order;
|
|||
import org.apache.openjpa.meta.QueryMetaData;
|
||||
import org.apache.openjpa.meta.SequenceMetaData;
|
||||
import org.apache.openjpa.meta.ValueMetaData;
|
||||
import org.apache.openjpa.meta.ValueStrategies;
|
||||
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
|
||||
|
@ -992,20 +990,12 @@ public class XMLPersistenceMetaDataParser
|
|||
|
||||
String strategy = attrs.getValue("strategy");
|
||||
String generator = attrs.getValue("generator");
|
||||
GenerationType type = StringUtils.isEmpty(strategy)
|
||||
? GenerationType.AUTO : GenerationType.valueOf(strategy);
|
||||
|
||||
// TODO UUID_HEX / UUID_STRING
|
||||
FieldMetaData fmd = (FieldMetaData) currentElement();
|
||||
if (StringUtils.isEmpty(strategy) || "AUTO".equals(strategy))
|
||||
fmd.setValueSequenceName(SequenceMetaData.NAME_SYSTEM);
|
||||
else if ("TABLE".equals(strategy) || "SEQUENCE".equals(strategy)) {
|
||||
if (StringUtils.isEmpty(generator))
|
||||
fmd.setValueSequenceName(SequenceMetaData.NAME_SYSTEM);
|
||||
else
|
||||
fmd.setValueSequenceName(generator);
|
||||
} else if ("IDENTITY".equals(strategy))
|
||||
fmd.setValueStrategy(ValueStrategies.AUTOASSIGN);
|
||||
else
|
||||
throw new UnsupportedException(strategy);
|
||||
AnnotationPersistenceMetaDataParser.parseGeneratedValue(fmd, type,
|
||||
generator);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue