openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r803547 - in /openjpa/trunk: openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/ openjpa-persistence/src/main/java/org/apache/openjpa/persi...
Date Wed, 12 Aug 2009 15:03:45 GMT
Author: faywang
Date: Wed Aug 12 15:03:45 2009
New Revision: 803547

URL: http://svn.apache.org/viewvc?rev=803547&view=rev
Log:
OPENJPA-1240: Lob, Temporal, Enumerated on element collections annotations and in XML

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
    openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Coll_String.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java?rev=803547&r1=803546&r2=803547&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
Wed Aug 12 15:03:45 2009
@@ -995,14 +995,22 @@
     @Override
     protected void parseLobMapping(FieldMetaData fmd) {
         Column col = new Column();
-        if (fmd.getDeclaredTypeCode() == JavaTypes.STRING
-            || fmd.getDeclaredType() == char[].class
-            || fmd.getDeclaredType() == Character[].class)
+        int typeCode = fmd.isElementCollection() ? fmd.getElement().getDeclaredTypeCode()
:
+            fmd.getDeclaredTypeCode();
+        Class type = fmd.isElementCollection() ? fmd.getElement().getDeclaredType() :
+            fmd.getDeclaredType();
+   
+        if (typeCode == JavaTypes.STRING
+                || type == char[].class
+                || type == Character[].class)
             col.setType(Types.CLOB);
         else
             col.setType(Types.BLOB);
-        ((FieldMapping) fmd).getValueInfo().setColumns(Arrays.asList
-            (new Column[]{ col }));
+        if (fmd.isElementCollection())
+            ((FieldMapping) fmd).getElementMapping().getValueInfo().setColumns(Arrays.asList(new
Column[]{ col }));
+        else    
+            ((FieldMapping) fmd).getValueInfo().setColumns(Arrays.asList(new Column[]{ col
}));
+        
     }
 
     @Override
@@ -1439,7 +1447,10 @@
     private void parseEnumerated(FieldMapping fm, Enumerated anno) {
         String strat = EnumValueHandler.class.getName() + "(StoreOrdinal="
             + String.valueOf(anno.value() == EnumType.ORDINAL) + ")";
-        fm.getValueInfo().setStrategy(strat);
+        if (fm.isElementCollection()) 
+            fm.getElementMapping().getValueInfo().setStrategy(strat);
+        else
+            fm.getValueInfo().setStrategy(strat);
     }
 
     /**
@@ -1461,7 +1472,10 @@
                 String.valueOf(cols.size()), "1"));
         if (cols.isEmpty()) {
             cols = Arrays.asList(new Column[]{ new Column() });
-            fm.getValueInfo().setColumns(cols);
+            if (fm.isElementCollection())
+                fm.getElementMapping().getValueInfo().setColumns(cols);
+            else
+                fm.getValueInfo().setColumns(cols);
         }
 
         Column col = (Column) cols.get(0);

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java?rev=803547&r1=803546&r2=803547&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
Wed Aug 12 15:03:45 2009
@@ -573,7 +573,10 @@
         FieldMapping fm = (FieldMapping) currentElement();
         String strat = EnumValueHandler.class.getName() + "(StoreOrdinal="
             + String.valueOf(type == EnumType.ORDINAL) + ")";
-        fm.getValueInfo().setStrategy(strat);
+        if (fm.isElementCollection())
+            fm.getElementMapping().getValueInfo().setStrategy(strat);
+        else
+            fm.getValueInfo().setStrategy(strat);
     }
 
     /**
@@ -626,14 +629,17 @@
         // setup columns with cached lob and temporal info
         FieldMapping fm = (FieldMapping) field;
         if (_lob || _temporal != null) {
+            int typeCode = fm.isElementCollection() ? fm.getElement().getDeclaredTypeCode()
: 
+                fm.getDeclaredTypeCode();
+            Class type = fm.isElementCollection() ? fm.getElement().getDeclaredType() : fm.getDeclaredType();
 
             if (_cols == null) {
                 _cols = new ArrayList<Column>(1);
                 _cols.add(new Column());
             }
             for (Column col : _cols) {
-                if (_lob && (fm.getDeclaredTypeCode() == JavaTypes.STRING
-                    || fm.getDeclaredType() == char[].class
-                    || fm.getDeclaredType() == Character[].class)) {
+                if (_lob && (typeCode == JavaTypes.STRING
+                    || type == char[].class
+                    || type == Character[].class)) {
                     col.setSize(-1);
                     col.setType(Types.CLOB);
                 } else if (_lob)

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Coll_String.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Coll_String.java?rev=803547&r1=803546&r2=803547&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Coll_String.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/EntityA_Coll_String.java
Wed Aug 12 15:03:45 2009
@@ -19,14 +19,22 @@
 package org.apache.openjpa.persistence.embed;
 
 import java.io.Serializable;
+import java.sql.Timestamp;
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.FetchType;
 import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
 
 import javax.persistence.ElementCollection;
 import javax.persistence.CollectionTable;
@@ -49,6 +57,18 @@
     @Column(name="nicknames1", length=20)
     protected Set<String> nickNames = new HashSet<String>();
 
+    @ElementCollection
+    @Enumerated(EnumType.ORDINAL)
+    protected List<CreditRating> cr = new ArrayList<CreditRating>();
+    
+    @ElementCollection
+    @Temporal(TemporalType.DATE)
+    protected List<Timestamp> ts = new ArrayList<Timestamp>();
+
+    @ElementCollection
+    @Lob
+    protected List<String> lobs = new ArrayList<String>();
+
     public int getAge() {
         return age;
     }
@@ -80,5 +100,31 @@
     public void addNickName(String nickName) {
         nickNames.add(nickName);
     }
+
+    public List<CreditRating> getCreditRating() {
+        return cr;
+    }
+    
+    public void addCreditRating(CreditRating c) {
+        cr.add(c);
+    }
+    
+    public List<Timestamp> getTimestamps() {
+        return ts;
+    }
+    
+    public void addTimestamp(Timestamp t) {
+        ts.add(t);
+    }
+    
+    public List<String> getLobs() {
+        return lobs;
+    }
+    
+    public void addLob(String lob) {
+        lobs.add(lob);
+    }
+
+    public enum CreditRating { POOR, GOOD, EXCELLENT };
 }
 

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java?rev=803547&r1=803546&r2=803547&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddable.java
Wed Aug 12 15:03:45 2009
@@ -205,6 +205,9 @@
         a.setAge(id);
         for (int i = 0; i < numBasicTypes; i++)
             a.addNickName("nickName_" + id + i);
+        a.addCreditRating(EntityA_Coll_String.CreditRating.POOR);
+        a.addTimestamp(new Timestamp(System.currentTimeMillis()));
+        a.addLob("lob");
         em.persist(a);
     }
 
@@ -931,6 +934,9 @@
         Set<String> nickNames = a.getNickNames();
         for (String nickName : nickNames)
             assertEquals("nickName_" + id + "0", nickName);
+        List<EntityA_Coll_String.CreditRating> cr = a.getCreditRating();
+        for (EntityA_Coll_String.CreditRating c : cr)
+            assertEquals("POOR", c.toString());
     }
 
     /*
@@ -1549,6 +1555,10 @@
                 " EntityA_Embed_Coll_Integer a " +
                 " , in (a.embed.otherIntVals) e " +
                 " where e > 0) order by e",
+            "select e, a0.intVal2 from EntityA_Embed_Coll_Integer a " +
+                "JOIN a.embed a0 JOIN a0.otherIntVals e WHERE exists (select a from " +
+                " EntityA_Embed_Coll_Integer a JOIN a.embed a0 JOIN a0.otherIntVals e " +
+                " where e > 0) order by e",
         };
         List<Object[]> rs = null;
         for (int i = 0; i < query.length; i++) {

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?rev=803547&r1=803546&r2=803547&view=diff
==============================================================================
--- 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
Wed Aug 12 15:03:45 2009
@@ -1091,11 +1091,13 @@
     protected boolean startLob(Attributes attrs)
         throws SAXException {
         FieldMetaData fmd = (FieldMetaData) currentElement();
-        if (fmd.getDeclaredTypeCode() != JavaTypes.STRING
-            && fmd.getDeclaredType() != char[].class
-            && fmd.getDeclaredType() != Character[].class
-            && fmd.getDeclaredType() != byte[].class
-            && fmd.getDeclaredType() != Byte[].class)
+        int typeCode = fmd.isElementCollection() ? fmd.getElement().getDeclaredTypeCode()
: fmd.getDeclaredTypeCode();
+        Class type = fmd.isElementCollection() ? fmd.getElement().getDeclaredType() : fmd.getDeclaredType();
+        if (typeCode != JavaTypes.STRING
+            && type != char[].class
+            && type != Character[].class
+            && type != byte[].class
+            && type != Byte[].class)
             fmd.setSerialized(true);
         return true;
     }
@@ -1525,7 +1527,7 @@
         if (val != null)
             fmd.setInDefaultFetchGroup("EAGER".equals(val));
         fmd.setElementCollection(true);
-        if (JavaTypes.maybePC(fmd.getElement())) {
+        if (JavaTypes.maybePC(fmd.getElement()) && !fmd.getElement().getDeclaredType().isEnum())
{
             fmd.getElement().setEmbedded(true);
             if (fmd.getElement().getEmbeddedMetaData() == null)
 //                fmd.getElement().addEmbeddedMetaData();



Mime
View raw message