openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r934101 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/
Date Wed, 14 Apr 2010 18:37:31 GMT
Author: faywang
Date: Wed Apr 14 18:37:30 2010
New Revision: 934101

URL: http://svn.apache.org/viewvc?rev=934101&view=rev
Log:
OPENJPA-1627: fix OrderBy with EmbeddedId.

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Library1.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMultipleLevelDerivedIdentity1.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java?rev=934101&r1=934100&r2=934101&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java
Wed Apr 14 18:37:30 2010
@@ -76,8 +76,34 @@ class JDBCRelatedFieldOrder
 
     public void order(Select sel, ClassMapping elem, Joins joins) {
         FieldMapping fm = _fm;
-        if (elem != null)
-            fm = elem.getFieldMapping(_fm.getIndex());
+        if (elem != null) {
+            fm = getOrderByField(elem, fm);
+            if (fm == null)
+                fm = elem.getFieldMapping(_fm.getIndex());
+        }
         sel.orderBy(fm.getColumns(), _asc, joins, false);
     }
+    
+    private FieldMapping getOrderByField(ClassMapping elem, FieldMapping fm) {
+        ClassMapping owner = (ClassMapping)_fm.getDefiningMetaData();
+        if (owner.getDescribedType() == elem.getDescribedType())
+            return elem.getFieldMapping(_fm.getIndex());
+        else {
+            FieldMapping fms[] = elem.getFieldMappings();
+            for (int i = 0; i < fms.length; i++) {
+                ValueMapping vm = (ValueMapping)fms[i].getValue();
+                ClassMapping clm = (ClassMapping)vm.getEmbeddedMetaData();
+                if (clm != null) {
+                    if (clm.getDescribedType() == owner.getDescribedType()) {
+                        return owner.getFieldMapping(_fm.getIndex());
+                    } else {
+                        FieldMapping fm1 = getOrderByField(clm, fm);
+                        if (fm1 != null)
+                            return fm1;
+                    }
+                }
+            }
+        }
+        return null;
+    }
 }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Library1.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Library1.java?rev=934101&r1=934100&r2=934101&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Library1.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/Library1.java
Wed Apr 14 18:37:30 2010
@@ -24,8 +24,10 @@ import java.util.Set;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.FetchType;
 import javax.persistence.Id;
 import javax.persistence.OneToMany;
+import javax.persistence.OrderBy;
 import javax.persistence.Table;
 
 import org.apache.openjpa.persistence.jdbc.VersionColumn;
@@ -49,7 +51,8 @@ public class Library1 implements Seriali
     @Column(name="LIBRARY_NAME", nullable = false)
     private String name;
     
-    @OneToMany(cascade = CascadeType.ALL, mappedBy = "library")
+    @OneToMany(fetch=FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "library")
+    @OrderBy(value = "bid.library ASC, bid.name ASC")
     private Set<Book1> books = new HashSet<Book1>();
     
     private String location;

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMultipleLevelDerivedIdentity1.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMultipleLevelDerivedIdentity1.java?rev=934101&r1=934100&r2=934101&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMultipleLevelDerivedIdentity1.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/enhance/identity/TestMultipleLevelDerivedIdentity1.java
Wed Apr 14 18:37:30 2010
@@ -200,7 +200,14 @@ public class TestMultipleLevelDerivedIde
 	    assertEquals(NUM_PAGES-1, count(Page1.class));
 	}
 
-	
+    public void testOrderBy() {
+        sql.clear();
+        EntityManager em = emf.createEntityManager();
+        Library1 lib = em.find(Library1.class, LIBRARY_NAME);
+        assertNotNull(lib);
+        assertSQLFragnments(sql, "ORDER BY t1.LIBRARY_NAME ASC, t1.BOOK_NAME ASC");
+    }
+    
 	/**
 	 * Create a Library with a Book and three Pages.
 	 */



Mime
View raw message