openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From awh...@apache.org
Subject svn commit: r514847 - in /incubator/openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/
Date Mon, 05 Mar 2007 20:14:03 GMT
Author: awhite
Date: Mon Mar  5 12:14:02 2007
New Revision: 514847

URL: http://svn.apache.org/viewvc?view=rev&rev=514847
Log:
OPENJPA-162 : Allow explicit @OrderBy(<primary key field>).


Added:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyChild.java
  (with props)
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyParent.java
  (with props)
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIdOrderedOneMany.java
  (with props)
Modified:
    incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java

Modified: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java?view=diff&rev=514847&r1=514846&r2=514847
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java
(original)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/JDBCRelatedFieldOrder.java
Mon Mar  5 12:14:02 2007
@@ -38,7 +38,7 @@
 
     public JDBCRelatedFieldOrder(FieldMapping owner, FieldMapping rel,
         boolean asc) {
-        if (!rel.isInDefaultFetchGroup())
+        if (!rel.isInDefaultFetchGroup() && !rel.isPrimaryKey())
             throw new MetaDataException(_loc.get("nondfg-field-orderable",
                 owner, rel.getName()));
 

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyChild.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyChild.java?view=auto&rev=514847
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyChild.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyChild.java
Mon Mar  5 12:14:02 2007
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.persistence.relations;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Version;
+
+@Entity
+public class IdOrderedOneManyChild {
+
+    @Id
+    private long id;
+
+    private String name;
+
+    @ManyToOne
+    private IdOrderedOneManyParent explicitParent;
+
+    @ManyToOne
+    private IdOrderedOneManyParent implicitParent;
+
+    @Version
+    private int optLock;
+
+    public long getId() { 
+        return id; 
+    }
+
+    public void setId(long id) { 
+        this.id = id; 
+    }
+
+    public String getName() { 
+        return name; 
+    }
+
+    public void setName(String name) { 
+        this.name = name; 
+    }
+
+    public IdOrderedOneManyParent getExplicitParent() { 
+        return explicitParent; 
+    }
+
+    public void setExplicitParent(IdOrderedOneManyParent explicitParent) { 
+        this.explicitParent = explicitParent; 
+    }
+
+    public IdOrderedOneManyParent getImplicitParent() { 
+        return implicitParent; 
+    }
+
+    public void setImplicitParent(IdOrderedOneManyParent implicitParent) { 
+        this.implicitParent = implicitParent; 
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyChild.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyChild.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyParent.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyParent.java?view=auto&rev=514847
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyParent.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyParent.java
Mon Mar  5 12:14:02 2007
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.persistence.relations;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.OrderBy;
+import javax.persistence.Version;
+
+@Entity
+public class IdOrderedOneManyParent {
+
+    @Id
+    @GeneratedValue
+    private long id;
+
+    private String name;
+
+    @OneToMany(mappedBy="explicitParent")
+    @OrderBy("id ASC")
+    private List<IdOrderedOneManyChild> explicitChildren = 
+        new ArrayList<IdOrderedOneManyChild>();
+
+    @OneToMany(mappedBy="implicitParent")
+    @OrderBy
+    private List<IdOrderedOneManyChild> implicitChildren = 
+        new ArrayList<IdOrderedOneManyChild>();
+
+    @Version
+    private int optLock;
+
+    public long getId() { 
+        return id; 
+    }
+
+    public List<IdOrderedOneManyChild> getExplicitChildren() { 
+        return explicitChildren; 
+    }
+
+    public List<IdOrderedOneManyChild> getImplicitChildren() { 
+        return implicitChildren; 
+    }
+
+    public String getName() { 
+        return name; 
+    }
+
+    public void setName(String name) { 
+        this.name = name; 
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyParent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/IdOrderedOneManyParent.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIdOrderedOneMany.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIdOrderedOneMany.java?view=auto&rev=514847
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIdOrderedOneMany.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIdOrderedOneMany.java
Mon Mar  5 12:14:02 2007
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openjpa.persistence.relations;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+/**
+ * Test ordering a one-many field on the primary key of the related entity.
+ *
+ * @author Abe White
+ */
+public class TestIdOrderedOneMany
+    extends TestCase {
+
+    private EntityManagerFactory emf;
+    private long id;
+
+    public void setUp() {
+        Map props = new HashMap(System.getProperties());
+        props.put("openjpa.MetaDataFactory", "jpa(Types=" 
+            + IdOrderedOneManyParent.class.getName() + ";"
+            + IdOrderedOneManyChild.class.getName() + ")");
+        emf = Persistence.createEntityManagerFactory("test", props);
+
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+
+        IdOrderedOneManyParent parent = new IdOrderedOneManyParent();
+        parent.setName("parent");
+        em.persist(parent);
+
+        for (int i = 0; i < 3; i++) {
+            IdOrderedOneManyChild explicit = new IdOrderedOneManyChild();
+            explicit.setId(3 - i);
+            explicit.setName("explicit" + explicit.getId());
+            explicit.setExplicitParent(parent);
+            parent.getExplicitChildren().add(explicit);
+            em.persist(explicit);
+
+            IdOrderedOneManyChild implicit = new IdOrderedOneManyChild();
+            implicit.setId(100 - i);
+            implicit.setName("implicit" + implicit.getId());
+            implicit.setImplicitParent(parent);
+            parent.getImplicitChildren().add(implicit);
+            em.persist(implicit);
+        }
+
+        em.getTransaction().commit();
+        id = parent.getId();
+        em.close();
+    }
+
+    public void tearDown() {
+        if (emf == null)
+            return;
+        try {
+            EntityManager em = emf.createEntityManager();
+            em.getTransaction().begin();
+            em.createQuery("delete from IdOrderedOneManyChild").executeUpdate();
+            em.createQuery("delete from IdOrderedOneManyParent").
+                executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+            emf.close();
+        } catch (Exception e) {
+        }
+    }
+
+    public void testExplicitOrdering() {
+        EntityManager em = emf.createEntityManager();
+        IdOrderedOneManyParent parent = em.find(IdOrderedOneManyParent.class, 
+            id);
+        assertNotNull(parent);
+        assertEquals("parent", parent.getName());
+        assertEquals(3, parent.getExplicitChildren().size());
+        for (int i = 0; i < 3; i++) {
+            assertEquals(i + 1, parent.getExplicitChildren().get(i).getId());
+            assertEquals("explicit" + (i + 1), parent.getExplicitChildren().
+                get(i).getName());
+        }
+        em.close();
+    }
+
+    public void testImplicitOrdering() {
+        EntityManager em = emf.createEntityManager();
+        IdOrderedOneManyParent parent = em.find(IdOrderedOneManyParent.class, 
+            id);
+        assertNotNull(parent);
+        assertEquals("parent", parent.getName());
+        assertEquals(3, parent.getExplicitChildren().size());
+        for (int i = 0; i < 3; i++) {
+            assertEquals(i + 98, parent.getImplicitChildren().get(i).getId());
+            assertEquals("implicit" + (i + 98), parent.getImplicitChildren().
+                get(i).getName());
+        }
+        em.close();
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(TestIdOrderedOneMany.class);
+    }
+}
+

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestIdOrderedOneMany.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message