openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r563697 - in /openjpa/trunk: openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/ openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/ openjpa-persistence/src/main/java/org/apache/openjpa/per...
Date Tue, 07 Aug 2007 23:12:57 GMT
Author: pcl
Date: Tue Aug  7 16:12:56 2007
New Revision: 563697

URL: http://svn.apache.org/viewvc?view=rev&rev=563697
Log:
OPENJPA-86

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java?view=diff&rev=563697&r1=563696&r2=563697
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/SimpleXmlEntity.java
Tue Aug  7 16:12:56 2007
@@ -20,9 +20,13 @@
 
 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;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java?view=diff&rev=563697&r1=563696&r2=563697
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/xml/TestSimpleXmlEntity.java
Tue Aug  7 16:12:56 2007
@@ -28,6 +28,21 @@
         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();
     }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml?view=diff&rev=563697&r1=563696&r2=563697
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/xml/orm.xml
Tue Aug  7 16:12:56 2007
@@ -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>

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?view=diff&rev=563697&r1=563696&r2=563697
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
Tue Aug  7 16:12:56 2007
@@ -1110,21 +1110,30 @@
      * 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 @@
                     fmd.setValueStrategy(ValueStrategies.AUTOASSIGN);
                     break;
                 default:
-                    throw new UnsupportedException(gen.strategy().toString());
+                    throw new UnsupportedException(strategy.toString());
             }
         }
     }

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java?view=diff&rev=563697&r1=563696&r2=563697
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java
Tue Aug  7 16:12:56 2007
@@ -31,6 +31,7 @@
 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.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 @@
 
         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;
     }
 



Mime
View raw message