openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1005642 - in /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence: jdbc/schema/TestSchemaTool.java kernel/TestSuppressBatchOLE.java
Date Thu, 07 Oct 2010 21:26:53 GMT
Author: curtisr7
Date: Thu Oct  7 21:26:53 2010
New Revision: 1005642

URL: http://svn.apache.org/viewvc?rev=1005642&view=rev
Log:
OPENJPA-1415: Add test case.

Added:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaTool.java
  (with props)
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSuppressBatchOLE.java
  (with props)

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaTool.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaTool.java?rev=1005642&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaTool.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/schema/TestSchemaTool.java
Thu Oct  7 21:26:53 2010
@@ -0,0 +1,62 @@
+/*
+ * 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.schema;
+
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.query.Employee;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestSchemaTool extends SingleEMFTestCase {
+    @Override
+    public void setUp() throws Exception {
+        super.setUp(CLEAR_TABLES, Employee.class);
+    }
+
+    private void createSecondPU() {
+        createNamedEMF("mdr-pu", "openjpa.Log","SQL=trace","openjpa.jdbc.SynchronizeMappings",
+            "buildSchema(SchemaAction='add,refresh,deleteTableContents')").createEntityManager().close();
+    }
+
+    public void tearDown() throws Exception {
+
+    }
+
+    public void testRefreshDeleteTableContents() throws Exception {
+        String sql = "SELECT COUNT (e) from Employee e";
+        OpenJPAEntityManagerSPI em = emf.createEntityManager();
+
+        long before = em.createQuery(sql, Long.class).getSingleResult();
+
+        em.getTransaction().begin();
+        Employee e = new Employee();
+        e.setEmpId(System.currentTimeMillis());
+        em.persist(e);
+        em.getTransaction().commit();
+        // Make sure that we created a new one.
+        long update = em.createQuery(sql, Long.class).getSingleResult();
+        assertEquals(Long.valueOf(before + 1), Long.valueOf(update));
+        em.clear();
+        // Create the second PU, see if that cleans up tables it shouldn't be.
+        createSecondPU();
+
+        long after = em.createQuery(sql, Long.class).getSingleResult();
+        assertEquals(update, after);
+
+    }
+}

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

Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSuppressBatchOLE.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSuppressBatchOLE.java?rev=1005642&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSuppressBatchOLE.java
(added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/kernel/TestSuppressBatchOLE.java
Thu Oct  7 21:26:53 2010
@@ -0,0 +1,86 @@
+/*
+ * 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.kernel;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.RollbackException;
+
+import org.apache.openjpa.jdbc.kernel.EntityA;
+import org.apache.openjpa.jdbc.kernel.EntityB;
+import org.apache.openjpa.jdbc.kernel.EntityC;
+import org.apache.openjpa.jdbc.kernel.EntityD;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestSuppressBatchOLE extends SingleEMFTestCase {
+    @Override
+    public void setUp() throws Exception {
+        setUp(CLEAR_TABLES, org.apache.openjpa.jdbc.kernel.EntityA.class, org.apache.openjpa.jdbc.kernel.EntityB.class,
+            org.apache.openjpa.jdbc.kernel.EntityC.class, org.apache.openjpa.jdbc.kernel.EntityD.class,
+            "openjpa.BrokerImpl", "SuppressBatchOLELogging=true", "openjpa.jdbc.DBDictionary",
"batchLimit=-1",
+            "openjpa.DataCache", "false");
+    }
+
+    public void test() throws Exception {
+        OpenJPAEntityManagerSPI em1 = emf.createEntityManager();
+        OpenJPAEntityManagerSPI em2 = emf.createEntityManager();
+
+        em1.getTransaction().begin();
+        List<EntityA> entities = new ArrayList<EntityA>();
+        for (int i = 0; i < 25; i++) {
+            EntityA a = createEntity();
+            entities.add(a);
+            em1.persist(a);
+        }
+        em1.getTransaction().commit();
+        em1.clear();
+
+        em1.getTransaction().begin();
+        em2.getTransaction().begin();
+        for (EntityA a : entities) {
+            EntityA a1 = em1.find(EntityA.class, a.getId());
+            EntityA a2 = em2.find(EntityA.class, a.getId());
+            a1.setName("asdf");
+            a2.setName("asdf2");
+        }
+        em1.getTransaction().commit();
+        try {
+            em2.getTransaction().commit();
+        } catch (RollbackException e) {
+            assertTrue(e.getMessage().contains("Suppressing"));
+        }
+
+    }
+
+    EntityA createEntity() {
+        EntityA res = new EntityA();
+        EntityB b = new EntityB();
+        EntityC c = new EntityC();
+        EntityD d = new EntityD();
+
+        res.setEntityB(b);
+        b.setEntityC(c);
+        c.setEntityD(d);
+
+        return res;
+    }
+
+}

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



Mime
View raw message