openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrba...@apache.org
Subject svn commit: r803612 - in /openjpa/trunk: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/pers...
Date Wed, 12 Aug 2009 17:22:52 GMT
Author: jrbauer
Date: Wed Aug 12 17:22:52 2009
New Revision: 803612

URL: http://svn.apache.org/viewvc?rev=803612&view=rev
Log:
OPENJPA-1115 Committing code and test updates contributed by Dianne Richards

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal2.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat2.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog2.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdResultSetAnnotations.java
  (with props)
Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Item.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java?rev=803612&r1=803611&r2=803612&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ResultSetResult.java
Wed Aug 12 17:22:52 2009
@@ -501,7 +501,9 @@
     protected int findObject(Object obj, Joins joins)
         throws SQLException {
         try {
-            return getResultSet().findColumn(obj.toString());
+          String s1 = obj.toString();
+          s1 = _dict.stripDelimiters(s1);
+          return getResultSet().findColumn(s1);
         } catch (SQLException se) {
             return 0;
         }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal.java?rev=803612&r1=803611&r2=803612&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal.java
Wed Aug 12 17:22:52 2009
@@ -27,8 +27,6 @@
 
 @Entity
 @Inheritance
-// Note: delimited columnDefinition is not supported on DB2 or Derby
-// TODO: Find out what DB supports this and write a specific test case for it
 @DiscriminatorColumn(name="\"discr col\"", columnDefinition="VARCHAR(10)")
 @Table(name="\"Animal\"")
 public class Animal {
@@ -39,6 +37,8 @@
     protected String type;
     @Column(name="\"animal name\"")
     protected String name;
+    @Column(name="\"animal age\"")
+    protected int age;
 
     public Animal() {}
     
@@ -87,4 +87,18 @@
     public void setName(String name) {
         this.name = name;
     }
+
+    /**
+     * @return the age
+     */
+    public int getAge() {
+        return age;
+    }
+
+    /**
+     * @param age the age to set
+     */
+    public void setAge(int age) {
+        this.age = age;
+    }
 }

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal2.java?rev=803612&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal2.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal2.java
Wed Aug 12 17:22:52 2009
@@ -0,0 +1,98 @@
+/*
+ * 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.delimited.identifiers;
+
+import javax.persistence.ColumnResult;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.Entity;
+import javax.persistence.EntityResult;
+import javax.persistence.FieldResult;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.SqlResultSetMapping;
+import javax.persistence.Table;
+
+@SqlResultSetMapping(name="AnimalResultSet",
+    entities={@EntityResult(entityClass=Animal2.class,
+        fields={
+        @FieldResult(name="type", column="\"animal type\""),
+        @FieldResult(name="name", column="\"animal name\"")
+    },
+    discriminatorColumn="\"discr col\"")},
+    columns={@ColumnResult(name="\"animal age\"")})
+    
+@Entity
+@Inheritance
+@DiscriminatorColumn(name="\"discr col\"", columnDefinition="VARCHAR(10)")
+@Table(name="\"Animal2\"")
+public class Animal2 {
+    @Id
+    private int id;
+    
+    protected String type;
+    protected String name;
+
+    public Animal2() {}
+    
+    public Animal2(int id) {
+        this.id = id;
+    }
+    
+    /**
+     * @return the id
+     */
+    public int getId() {
+        return id;
+    }
+
+    /**
+     * @param id the id to set
+     */
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    /**
+     * @return the type
+     */
+    public String getType() {
+        return type;
+    }
+
+    /**
+     * @param type the type to set
+     */
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    /**
+     * @return the name
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * @param name the name to set
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat2.java?rev=803612&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat2.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat2.java
Wed Aug 12 17:22:52 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.delimited.identifiers;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
+@Entity
+@DiscriminatorValue("Cat")
+public class Cat2 extends Animal2 {
+    public Cat2() {}
+    
+    public Cat2(int id) {
+        super(id);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog2.java?rev=803612&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog2.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog2.java
Wed Aug 12 17:22:52 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.delimited.identifiers;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
+@Entity
+@DiscriminatorValue("Dog")
+public class Dog2 extends Animal2 {
+    public Dog2() {}
+    
+    public Dog2(int id) {
+        super(id);
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdResultSetAnnotations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdResultSetAnnotations.java?rev=803612&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdResultSetAnnotations.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdResultSetAnnotations.java
Wed Aug 12 17:22:52 2009
@@ -0,0 +1,111 @@
+/*
+ * 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.delimited.identifiers;
+
+import java.util.List;
+
+import javax.persistence.Query;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestManualDelimIdResultSetAnnotations 
+        extends SQLListenerTestCase {
+    OpenJPAEntityManager em;
+    int id = 0;
+    Animal animal;
+    Dog dog;
+    Cat cat;
+    Animal2 animal2;
+    Dog2 dog2;
+    Cat2 cat2;
+    
+    @Override
+    public void setUp() throws Exception {
+        super.setUp(
+            org.apache.openjpa.persistence.delimited.identifiers.Animal.class,
+            org.apache.openjpa.persistence.delimited.identifiers.Dog.class,
+            org.apache.openjpa.persistence.delimited.identifiers.Cat.class,
+            org.apache.openjpa.persistence.delimited.identifiers.Animal2.class,
+            org.apache.openjpa.persistence.delimited.identifiers.Dog2.class,
+            org.apache.openjpa.persistence.delimited.identifiers.Cat2.class
+            );
+        assertNotNull(emf);
+        
+        em = emf.createEntityManager();
+        assertNotNull(em);
+    }
+
+    private void createCat(int id) {
+        cat = new Cat(id);
+        cat.setName("Puff");
+        cat.setType("cat");
+        cat.setAge(3);
+    }
+
+    private void createDog(int id) {
+        dog = new Dog(id);
+        dog.setName("Spot");
+        dog.setType("dog");
+        dog.setAge(9);
+    }
+
+    public void testCreate() {
+        id++;
+        createDog(id);
+        id++;
+        createCat(id);
+        
+        em.getTransaction().begin();
+        em.persist(dog);
+        em.persist(cat);
+        em.getTransaction().commit();
+        
+        runQueries();
+    }
+    
+    private void runQueries() {
+        em.clear();
+        resultSetQuery();
+    }
+    
+    private void resultSetQuery() {
+        String query = 
+            "SELECT a.id, a.\"animal type\", a.\"animal name\", " +
+            "a.\"discr col\", a.\"animal age\" " +
+            "FROM \"Animal\" a ";
+        Query q = em.createNativeQuery(query,"AnimalResultSet");
+        List<Object[]> results = (List<Object[]>)q.getResultList();
+        assertEquals(2,results.size());
+        
+        for (Object[] result : results) {
+            assertEquals(2, result.length);
+            assertTrue(result[0] instanceof Animal2);
+            assertTrue(result[1] instanceof Integer);
+            Animal2 animal2 = (Animal2)result[0];
+            Integer age = (Integer)result[1];
+            if (animal2.getName().equals("Spot")) {
+                assertEquals(9, age.intValue());
+            }
+            else if (animal2.getName().equals("Puff")) {
+                assertEquals(3, age.intValue());
+            }
+        }
+    }
+}

Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdResultSetAnnotations.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Item.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Item.java?rev=803612&r1=803611&r2=803612&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Item.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/simple/Item.java
Wed Aug 12 17:22:52 2009
@@ -29,7 +29,7 @@
 import javax.persistence.Table;
 
 @Entity
-@Table(name = "ITEM")
+@Table(name = "I_ITEM")
 public class Item implements Serializable {
 
     private static final long serialVersionUID = 489786296539819572L;
@@ -39,7 +39,7 @@
     public java.math.BigDecimal itemPrice;
     public String itemData;
 
-    @Column(name = "I_DATA", table = "ITEM")
+    @Column(name = "I_DATA", table = "I_ITEM")
     public String getItemData() {
         return itemData;
     }
@@ -49,7 +49,7 @@
     }
 
     @Id
-    @Column(name = "I_ID", table = "ITEM")
+    @Column(name = "I_ID", table = "I_ITEM")
     @GeneratedValue(strategy = GenerationType.AUTO)
     public int getItemId() {
         return itemId;
@@ -59,7 +59,7 @@
         this.itemId = itemId;
     }
 
-    @Column(name = "I_NAME", table = "ITEM")
+    @Column(name = "I_NAME", table = "I_ITEM")
     public String getItemName() {
         return itemName;
     }
@@ -69,7 +69,7 @@
     }
 
     @Basic
-    @Column(name = "I_PRICE", table = "ITEM")
+    @Column(name = "I_PRICE", table = "I_ITEM")
     public java.math.BigDecimal getItemPrice() {
         return itemPrice;
     }



Mime
View raw message