openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r465623 - in /incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype: ./ IdentityGenerationType.java TestGenerationType.java
Date Thu, 19 Oct 2006 13:38:58 GMT
Author: kwsutter
Date: Thu Oct 19 06:38:57 2006
New Revision: 465623

URL: http://svn.apache.org/viewvc?view=rev&rev=465623
Log:
Testcase for a problem similar to the one described in OPENJPA-13.  
Revision 453016 resolved both of these problems.  We can use this
testcase for regression purposes.

Added:
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/IdentityGenerationType.java
    incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGenerationType.java

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/IdentityGenerationType.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/IdentityGenerationType.java?view=auto&rev=465623
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/IdentityGenerationType.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/IdentityGenerationType.java
Thu Oct 19 06:38:57 2006
@@ -0,0 +1,52 @@
+/*
+ * 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.generationtype;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+/**
+ * Using a class type (Long) instead of a primitive type (long)
+ * used to cause a problem with a GenerationType of IDENTITY.
+ * This was resolved via revision 453016.  We can use this testcase
+ * for regression purposes.
+ *
+ * @author Kevin Sutter
+ */
+@Entity
+public class IdentityGenerationType {
+
+    private Long orderId;
+    private String someData;
+
+    @Id
+    @GeneratedValue(strategy=GenerationType.IDENTITY)
+    public Long getOrderId() {
+        return orderId;
+    }
+    public void setOrderId(Long orderId) {
+        this.orderId = orderId;
+    }
+    public String getSomeData() {
+        return someData;
+    }
+    public void setSomeData(String someData) {
+        this.someData = someData;
+    }
+}
+

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGenerationType.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGenerationType.java?view=auto&rev=465623
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGenerationType.java
(added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/generationtype/TestGenerationType.java
Thu Oct 19 06:38:57 2006
@@ -0,0 +1,108 @@
+/*
+ * 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.generationtype;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Persistence;
+import javax.persistence.Query;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+
+/**
+ * Simple test case to test the GenerationType for @Id...
+ *
+ * @author Kevin Sutter
+ */
+public class TestGenerationType
+    extends TestCase {
+
+    private EntityManagerFactory emf;
+
+    public void setUp() {
+        Map props = new HashMap();
+        props.put("openjpa.MetaDataFactory",
+            "jpa(Types=" + IdentityGenerationType.class.getName() + ")");
+        emf = Persistence.createEntityManagerFactory("test", props);
+    }
+
+    public void tearDown() {
+        if (emf == null)
+            return;
+        try {
+            EntityManager em = emf.createEntityManager();
+            em.getTransaction().begin();
+            em.createQuery("delete from IdentityGenerationType").executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+            emf.close();
+        } catch (Exception e) {
+        }
+    }
+
+    public void testCreateEntityManager() {
+        EntityManager em = emf.createEntityManager();
+
+        EntityTransaction t = em.getTransaction();
+        assertNotNull(t);
+        t.begin();
+        t.setRollbackOnly();
+        t.rollback();
+
+        // openjpa-facade test
+        assertTrue(em instanceof OpenJPAEntityManager);
+        OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
+        ojem.getFetchPlan().setMaxFetchDepth(-1);
+        assertEquals(-1, ojem.getFetchPlan().getMaxFetchDepth());
+        em.close();
+    }
+
+    public void testPersist() {
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        em.persist(new IdentityGenerationType());
+        em.getTransaction().commit();
+        em.close();
+    }
+
+    public void testQuery() {
+        EntityManager em = emf.createEntityManager();
+        em.getTransaction().begin();
+        IdentityGenerationType igt = new IdentityGenerationType();
+        igt.setSomeData("SomeString");
+        em.persist(igt);
+        // add another IdentityGenerationType object
+        em.persist(new IdentityGenerationType());
+        em.getTransaction().commit();
+
+        // Check to make sure there are two objects...
+        Query q = em.createQuery("select x from IdentityGenerationType x");
+        List l = q.getResultList();
+        assertEquals(2, l.size());
+        em.close();
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(TestGenerationType.class);
+    }
+}
+



Mime
View raw message