You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by jr...@apache.org on 2009/02/12 02:55:46 UTC

svn commit: r743594 - in /openjpa/trunk/openjpa-persistence-jdbc/src: main/java/org/apache/openjpa/persistence/jdbc/ test/java/org/apache/openjpa/persistence/jdbc/order/ test/resources/org/apache/openjpa/persistence/jdbc/order/

Author: jrbauer
Date: Thu Feb 12 01:55:45 2009
New Revision: 743594

URL: http://svn.apache.org/viewvc?rev=743594&view=rev
Log:
OPENJPA-869 Added support for order column table attribute

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Bicycle.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Car.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Home.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Owner.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Widget.java   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-orm-3.xml   (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-persistence-5.xml   (with props)
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/jdbc/order/TestOrderColumn.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=743594&r1=743593&r2=743594&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 Thu Feb 12 01:55:45 2009
@@ -1690,6 +1690,14 @@
      */
     private void parseJavaxOrderColumn(FieldMapping fm, 
         javax.persistence.OrderColumn order) {
+        // If a table name is specified on the annotation and a table
+        // name has not been defined, set the table name to the name
+        // specified.  This will be the name of the join table or
+        // collection table.
+        if (!StringUtils.isEmpty(order.table()) &&
+            StringUtils.isEmpty(fm.getMappingInfo().getTableName())) {
+            fm.getMappingInfo().setTableName(order.table());
+        }
         
         Column col = new Column();
         if (!StringUtils.isEmpty(order.name()))

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=743594&r1=743593&r2=743594&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 Thu Feb 12 01:55:45 2009
@@ -1091,6 +1091,15 @@
         if (obj instanceof FieldMapping) {
             FieldMapping fm = (FieldMapping)obj;
             fm.getMappingInfo().setOrderColumn(col);
+
+            // If a table name is specified on the element and a table
+            // name has not been defined, set the table name to the name
+            // specified.  This will be the name of the join table or
+            // collection table.
+            if (!StringUtils.isEmpty(col.getTableName()) &&
+                StringUtils.isEmpty(fm.getMappingInfo().getTableName())) {
+                fm.getMappingInfo().setTableName(col.getTableName());
+            }
         }
         return true;
     }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Bicycle.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Bicycle.java?rev=743594&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Bicycle.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Bicycle.java Thu Feb 12 01:55:45 2009
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.jdbc.order;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class Bicycle {
+    
+    @Column(name="bike_brand")
+    private String brand;
+    
+    @Column(name="bike_model")
+    private String model;
+
+    public Bicycle() {
+    }
+
+    public Bicycle(String brand, String model) {
+        this.brand = brand;
+        this.model = model;
+    }
+
+    public void setBrand(String brand) {
+        this.brand = brand;
+    }
+
+    public String getBrand() {
+        return brand;
+    }
+
+    public void setModel(String model) {
+        this.model = model;
+    }
+
+    public String getModel() {
+        return model;
+    }
+    
+    public boolean equals(Object obj) {
+        if (obj instanceof Bicycle) {
+            Bicycle bike = (Bicycle)obj;
+            return getBrand().equals(bike.getBrand()) &&
+              getModel().equals(bike.getModel());
+        }
+        return false;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Bicycle.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Car.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Car.java?rev=743594&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Car.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Car.java Thu Feb 12 01:55:45 2009
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.jdbc.order;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="OC_CAR")
+public class Car {
+
+    @Id
+    @GeneratedValue
+    private int id;
+        
+    @ManyToOne
+    private Owner owner;
+    
+    @Basic
+    private int modelYear;
+    
+    @Basic
+    private String make;
+    
+    @Basic
+    private String model;
+
+    public Car() {        
+    }
+    
+    public Car(int year, String make, String model){
+        this.modelYear = year;
+        this.make = make;
+        this.model = model;
+    }
+    
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setModelYear(int year) {
+        this.modelYear = year;
+    }
+
+    public int getModelYear() {
+        return modelYear;
+    }
+
+    public void setMake(String make) {
+        this.make = make;
+    }
+
+    public String getMake() {
+        return make;
+    }
+
+    public void setModel(String model) {
+        this.model = model;
+    }
+
+    public String getModel() {
+        return model;
+    }
+
+    public void setOwner(Owner owner) {
+        this.owner = owner;
+    }
+
+    public Owner getOwner() {
+        return owner;
+    }
+    
+    public boolean equals(Object obj) {
+        if (obj instanceof Car) {
+            Car car = (Car)obj;
+            return getId() == car.getId() &&
+                getMake().equals(car.getMake()) &&
+                getModel().equals(car.getModel()) &&
+                getModelYear() == car.getModelYear();
+        }
+        return false;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Car.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Home.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Home.java?rev=743594&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Home.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Home.java Thu Feb 12 01:55:45 2009
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.jdbc.order;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class Home {
+
+    @Id
+    @GeneratedValue
+    private int id;
+
+    @Basic
+    private int buildYear;
+    
+    public Home() {        
+    }
+
+    public Home(int year) {
+        this.buildYear = year;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setBuildYear(int buildYear) {
+        this.buildYear = buildYear;
+    }
+
+    public int getBuildYear() {
+        return buildYear;
+    }
+
+    public boolean equals(Object obj) {
+        if (obj instanceof Home) {
+            Home home = (Home)obj;
+            return getBuildYear() == home.getBuildYear() &&
+              getId() == home.getId();
+        }
+        return false;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Home.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Owner.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Owner.java?rev=743594&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Owner.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Owner.java Thu Feb 12 01:55:45 2009
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.jdbc.order;
+
+import java.util.Collection;
+
+import javax.persistence.CascadeType;
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToMany;
+import javax.persistence.OneToMany;
+import javax.persistence.OrderColumn;
+import javax.persistence.Table;
+
+import static javax.persistence.InheritanceType.SINGLE_TABLE;
+
+@Entity
+@Table(name="OC_OWNER")
+@Inheritance(strategy=SINGLE_TABLE)
+public class Owner extends Person {
+    
+    // bidirectional one-to-many w/ default join column
+    @OneToMany(mappedBy="owner", cascade=CascadeType.ALL)
+    @OrderColumn(name="car_o2m_order", table="car_o2m_table")
+    private Collection<Car> cars;
+
+    // unidirectional one-to-many w/ join column
+    @OneToMany(cascade=CascadeType.ALL)
+    @OrderColumn(table="home_o2m_table")
+    private Collection<Home> homes;
+    
+    @ManyToMany(cascade=CascadeType.ALL)
+    @OrderColumn(table="widget_m2m_table")
+    private Collection<Widget> widgets;
+    
+    // element collection
+    @ElementCollection
+    @OrderColumn(name="bike_coll_order", table="bike_table")
+    private Collection<Bicycle> bikeColl;
+
+    
+    
+    public void setCars(Collection<Car> cars) {
+        this.cars = cars;
+    }
+
+    public Collection<Car> getCars() {
+        return cars;
+    }
+
+    public void setHomes(Collection<Home> homes) {
+        this.homes = homes;
+    }
+
+    public Collection<Home> getHomes() {
+        return homes;
+    }
+
+    public void setBikeColl(Collection<Bicycle> bikeColl) {
+        this.bikeColl = bikeColl;
+    }
+
+    public Collection<Bicycle> getBikeColl() {
+        return bikeColl;
+    }
+
+    public void setWidgets(Collection<Widget> widgets) {
+        this.widgets = widgets;
+    }
+
+    public Collection<Widget> getWidgets() {
+        return widgets;
+    }    
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Owner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/TestOrderColumn.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/TestOrderColumn.java?rev=743594&r1=743593&r2=743594&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/TestOrderColumn.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/TestOrderColumn.java Thu Feb 12 01:55:45 2009
@@ -22,6 +22,9 @@
 import java.io.ByteArrayOutputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collection;
@@ -38,6 +41,9 @@
 import org.apache.openjpa.jdbc.meta.ClassMapping;
 import org.apache.openjpa.jdbc.meta.FieldMapping;
 import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.Sequence;
+import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
 import org.apache.openjpa.lib.meta.MetaDataSerializer;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.MetaDataRepository;
@@ -57,7 +63,9 @@
         super.setUp(DROP_TABLES,
                 Person.class, Player.class, BattingOrder.class,
                 Trainer.class, Game.class, Inning.class,
-                Course.class, Student.class);
+                Course.class, Student.class,
+                Owner.class, Bicycle.class, Car.class, Home.class,
+                Widget.class);
         try {
             createQueryData();
         } catch (Exception e) {
@@ -639,10 +647,13 @@
                 new Object[] { elems[6], elems[7], elems[8]}, "id",
                 bte.getId());
 
-// This test is disabled until INDEX projection supports element collections
+// This validator is disabled until INDEX projection supports element 
+// collections
 //        validateIndexAndValues(em, "BaseTestEntity", "collelems", 10, 
-//                new Object[] { elems[0], elems[1], elems[2]});
+//                new Object[] { elems[0], elems[1], elems[2]} "id",
+//                bte.getId());
 
+        em.close();
         try {
             if (emf1 != null)
                 cleanupEMF(emf1);
@@ -652,20 +663,118 @@
     }
 
     /*
-     * Validates the use of the table attribute on OrderColumn
+     * Validates the use of the table attribute on OrderColumn with
+     * o2o, o2m, m2m, and collection table - with and without join
+     * tables.
      */
-    public void verifyOrderColumnTable() {        
-        /*
-         * If the relationship is a many-to-many or unidirectional one-to-many 
-         * relationship, the table is the join table for the relationship. If 
-         * the relationship is a bidirectional one-to-many or unidirectional 
-         * one-to-many mapped by a join column, the table is the primary 
-         * table for the entity on the mapny side of the relationship. If the 
-         * ordering is for a collection of elements, the table is the 
-         * collection table for the element collection.
-         */      
+    public void testOrderColumnTable() {   
+        
+        OpenJPAEntityManagerSPI em = emf.createEntityManager();
+
+        validateOrderColumnTable(emf, Owner.class, "cars", 
+            "OC_CAR", "car_o2m_order"); 
+                
+        validateOrderColumnTable(emf, Owner.class, "homes", 
+             "home_o2m_table", "homes_ORDER"); 
+
+        validateOrderColumnTable(emf, Owner.class, "bikeColl", 
+             "bike_table", "bike_coll_order"); 
+
+        validateOrderColumnTable(emf, Owner.class, "widgets", 
+                "widget_m2m_table", "widgets_ORDER"); 
+
+        Owner owner = new Owner();
+        Collection<Car> cars = new ArrayList<Car>();
+        Collection<Home> homes = new ArrayList<Home>();
+        Collection<Bicycle> bicycles = new ArrayList<Bicycle>();
+        Collection<Widget> widgets = new ArrayList<Widget>();
+        Collection<Owner> owners = new ArrayList<Owner>(); 
+        owner.setCars(cars);
+        owner.setHomes(homes);
+        owner.setBikeColl(bicycles);
+        owner.setWidgets(widgets);
+        
+        for (int i = 0;  i < 5; i++){
+            Car car = new Car(2000 + 1, "Make"+i, "Model"+i);
+            car.setOwner(owner);
+            cars.add(car);
+            
+            Home home = new Home(2000 + i);
+            homes.add(home);
+            
+            Bicycle bike = new Bicycle("Brand"+i, "Model"+i);
+            bicycles.add(bike);   
+            
+            Widget widget = new Widget("Name"+i);
+            widgets.add(widget);
+            widget.setOwners(owners);
+        }
+        
+        Object[] carArr = cars.toArray();
+        Object[] homeArr = homes.toArray();
+        Object[] bikeArr = bicycles.toArray();
+        Object[] widgetArr = widgets.toArray();
+        
+        em.getTransaction().begin();
+        em.persist(owner);
+        em.getTransaction().commit();
+        String oid = owner.getId();
+        
+        em.clear();
+        
+        // Run queries to ensure the query component uses the correct tables
+        validateIndexAndValues(em, "Owner", "cars", 0, 
+                carArr, "id", 
+                oid);
+
+        validateIndexAndValues(em, "Owner", "homes", 0, 
+                homeArr, "id", 
+                oid);
+
+        validateIndexAndValues(em, "Owner", "widgets", 0, 
+                widgetArr, "id", 
+                oid);
+
+//      This validator is disabled until INDEX projection supports element 
+//      collections
+//        validateIndexAndValues(em, "Owner", "bikeColl", 0, 
+//                bikeArr, "id", 
+//                oid);
+        
+        em.close();
     }    
-    
+
+    /**
+     * Validates the use of the table attribute defined in XML
+     */
+    public void testOrderColumnTableXML() {   
+        
+        OpenJPAEntityManagerFactorySPI emf1 = 
+            (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
+            createEntityManagerFactory("TableTest", 
+            "org/apache/openjpa/persistence/jdbc/order/" +
+            "order-persistence-5.xml");
+        
+        OpenJPAEntityManagerSPI em = emf1.createEntityManager();
+        
+        validateOrderColumnTable(emf1, BaseTestEntity.class, "one2Melems", 
+            "xml_o2m_table", "one2MOrder"); 
+                    
+        validateOrderColumnTable(emf1, BaseTestEntity.class, "m2melems", 
+             "xml_m2m_table", "m2morder"); 
+
+        validateOrderColumnTable(emf1, BaseTestEntity.class, "collelems", 
+             "xml_coll_table", "collelems_ORDER"); 
+        
+        em.close();
+        try {
+            if (emf1 != null)
+                cleanupEMF(emf1);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }        
+    }
+
     /*
      * Validates the use of order column (via INDEX) in the predicate of a
      * JPQL query.
@@ -698,7 +807,9 @@
         qry.setParameter("widx", 1);
         idx0 = (Student)qry.getSingleResult();
         assertNotNull(idx0);
-        assertEquals(idx0, students[10]);        
+        assertEquals(idx0, students[10]);  
+        
+        em.close();
     }
 
     /*
@@ -727,6 +838,8 @@
         Long idx = (Long)qry.getSingleResult();       
         assertNotNull(idx);
         assertEquals((Long)idx, (Long)1L);
+        
+        em.close();
     }
     
     /*
@@ -735,14 +848,15 @@
      */
     public void testOrderColumnOrderBy() {
         
+        OpenJPAEntityManagerFactorySPI emf1 = null;
+        OpenJPAEntityManagerSPI em = null;
         try {
-            OpenJPAEntityManagerFactorySPI emf1 = 
-                (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
+            emf1 = (OpenJPAEntityManagerFactorySPI)OpenJPAPersistence.
                 createEntityManagerFactory("ObOcTest", 
                     "org/apache/openjpa/persistence/jdbc/order/" +
                     "order-persistence-3.xml");
         
-            OpenJPAEntityManagerSPI em = emf1.createEntityManager();
+            em = emf1.createEntityManager();
             
             ObOcEntity ent = new ObOcEntity();
             List<Integer> intList = new ArrayList<Integer>();
@@ -755,10 +869,20 @@
             em.getTransaction().commit();
 
             em.close();
+            em = null;
             fail("An exception should have been thrown.");
         } catch (Exception e) {
             assertException(e, ArgumentException.class);
+        } finally {
+            if (em != null)
+                em.close();
         }
+        try {
+            if (emf1 != null)
+                cleanupEMF(emf1);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }        
     }
     
     public void testOrderColumnMetaDataSerialization() 
@@ -809,7 +933,14 @@
         oc = fm.getOrderColumn();
         assertNotNull(oc);
         assertEquals(oc.getName(),"collelems_ORDER");
-        assertEquals(oc.getBase(), 10);        
+        assertEquals(oc.getBase(), 10);    
+
+        try {
+            if (emf1 != null)
+                cleanupEMF(emf1);
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }        
     }
     
     /*
@@ -852,6 +983,7 @@
         em.persist(courseA);
         em.persist(courseB);
         em.getTransaction().commit();
+        em.close();
     }
     
     private void validateIndexAndValues(OpenJPAEntityManagerSPI em, 
@@ -898,7 +1030,19 @@
         Column oc = getOrderColumn(emf1, clazz, fieldName);
         assertTrue(oc.getName().equalsIgnoreCase(columnName));
     }
-    
+
+    private void validateOrderColumnTable(
+            OpenJPAEntityManagerFactorySPI emf1, 
+            Class clazz, String fieldName, String tableName, 
+            String columnName) {        
+            Column oc = getOrderColumn(emf1, clazz, fieldName);
+            // Verify the oc has the correct table name
+            assertTrue(oc.getTableName().equalsIgnoreCase(tableName));
+            // Verify the table exists in the db
+            assertTrue(tableAndColumnExists(emf1, null, tableName, null, 
+                columnName));
+        }
+
     private void validateOrderColumnContiguous(
         OpenJPAEntityManagerFactorySPI emf1, Class clazz, String fieldName, 
         boolean contiguous) {        
@@ -935,6 +1079,44 @@
     }
 
     /**
+     * Method to verify a table was created for the given name and schema
+     */
+    private boolean tableAndColumnExists(OpenJPAEntityManagerFactorySPI emf1, 
+            OpenJPAEntityManagerSPI em, String tableName, String schemaName,
+            String columnName) {
+        JDBCConfiguration conf = (JDBCConfiguration) emf1.getConfiguration();
+        DBDictionary dict = conf.getDBDictionaryInstance();
+        OpenJPAEntityManagerSPI em1 = em;
+                
+        // If no em supplied, create one
+        if (em1 == null) {
+            em1 = emf1.createEntityManager();
+        }
+        Connection conn = (Connection)em1.getConnection();
+        try {
+            DatabaseMetaData dbmd = conn.getMetaData();
+            // (meta, catalog, schemaName, tableName, conn)
+            Column[] cols = dict.getColumns(dbmd, null, null, 
+                    tableName, columnName, conn);
+            if (cols != null && cols.length == 1) {
+                Column col = cols[0];
+                String colName = col.getName();
+                if (col.getTableName().equalsIgnoreCase(tableName) &&
+                    (schemaName == null || 
+                    col.getSchemaName().equalsIgnoreCase(schemaName)) &&
+                    colName.equalsIgnoreCase(columnName))
+                    return true;
+            }
+        } catch (Throwable e) {
+            fail("Unable to get column information.");
+        } finally {
+            if (em == null) {
+                em1.close();
+            }
+        }
+        return false;
+    }
+    /**
      * Closes a specific entity manager factory and cleans up 
      * associated tables.
      */

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Widget.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Widget.java?rev=743594&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Widget.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Widget.java Thu Feb 12 01:55:45 2009
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.jdbc.order;
+
+import java.util.Collection;
+
+import javax.persistence.Basic;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+
+@Entity
+public class Widget {
+
+    @Id
+    @GeneratedValue(generator="uuid-hex")
+    private String id;
+    
+    @Basic
+    private String name;
+    
+    @ManyToMany(mappedBy="widgets")
+    private Collection<Owner> owners;
+
+    public Widget() {        
+    }
+
+    public Widget(String name) {
+        this.name = name;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setOwners(Collection<Owner> owners) {
+        this.owners = owners;
+    }
+
+    public Collection<Owner> getOwners() {
+        return owners;
+    }
+    
+    public boolean equals(Object obj) {
+        if (obj instanceof Widget) {
+            Widget widget = (Widget)obj;
+            return getId().equals(widget.getId()) &&
+                getName().equals(widget.getName());
+        }
+        return false;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/order/Widget.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-orm-3.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-orm-3.xml?rev=743594&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-orm-3.xml (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-orm-3.xml Thu Feb 12 01:55:45 2009
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you 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.
+-->
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
+    version="2.0">
+    <package>
+        org.apache.openjpa.persistence.jdbc.order
+    </package>
+    <entity name="BaseTestTableElement" class="BaseTestElement" 
+        access="PROPERTY">
+        <table name="BTTEL"/>        
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <basic name="name"/>
+        </attributes>
+    </entity>
+    <entity name="BaseTestTableEntity" class="BaseTestEntity" access="FIELD">
+        <table name="BTNNEN"/>
+        <attributes>
+            <id name="id">
+                <generated-value/>
+            </id>
+            <one-to-many name="one2Melems">                
+                <order-column name="one2MOrder" table="xml_o2m_table" />
+                <cascade>
+                    <cascade-all/>
+                </cascade>
+            </one-to-many>
+
+            <many-to-many name="m2melems">
+                <order-column name="m2morder" table="xml_m2m_table" />
+                <cascade>
+                    <cascade-all/>
+                </cascade>
+            </many-to-many>
+            
+            <element-collection name="collelems">
+                <order-column table="xml_coll_table" />
+            </element-collection>
+            
+        </attributes>    
+    </entity>
+</entity-mappings>

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-orm-3.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-persistence-5.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-persistence-5.xml?rev=743594&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-persistence-5.xml (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-persistence-5.xml Thu Feb 12 01:55:45 2009
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you 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.
+-->
+<persistence
+    xmlns="http://java.sun.com/xml/ns/persistence"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
+        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+    version="2.0" >
+    <persistence-unit name="TableTest" transaction-type="RESOURCE_LOCAL">
+        <description>PU for order column testing</description>
+        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+        <mapping-file>org/apache/openjpa/persistence/jdbc/order/order-orm-3.xml</mapping-file>
+        <class>org.apache.openjpa.persistence.jdbc.order.BaseTestEntity</class>
+        <class>org.apache.openjpa.persistence.jdbc.order.BaseTestElement</class>
+        <properties>
+            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>    
+        </properties>
+    </persistence-unit>
+</persistence>
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/jdbc/order/order-persistence-5.xml
------------------------------------------------------------------------------
    svn:eol-style = native