openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtyle...@apache.org
Subject svn commit: r790645 - /openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/oracle/TestAutoIncrement.java
Date Thu, 02 Jul 2009 16:20:30 GMT
Author: mtylenda
Date: Thu Jul  2 16:20:30 2009
New Revision: 790645

URL: http://svn.apache.org/viewvc?rev=790645&view=rev
Log:
OPENJPA-1147: Remove isTargetPlatform calls from TestAutoIncrement, add sequence creation
statement

Modified:
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/oracle/TestAutoIncrement.java

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/oracle/TestAutoIncrement.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/oracle/TestAutoIncrement.java?rev=790645&r1=790644&r2=790645&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/oracle/TestAutoIncrement.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/oracle/TestAutoIncrement.java
Thu Jul  2 16:20:30 2009
@@ -19,19 +19,23 @@
 package org.apache.openjpa.persistence.jdbc.oracle;
 
 import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
+import javax.persistence.Query;
 
+import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
+import org.apache.openjpa.persistence.OpenJPAEntityManagerSPI;
 import org.apache.openjpa.persistence.test.DatabasePlatform;
 import org.apache.openjpa.persistence.test.SingleEMFTestCase;
 
 /**
  * Tests identity value assignment with IDENTITY strategy specifically for
- * Oracle database. IDENTITY strategy for most database platform is supported
+ * Oracle database. IDENTITY strategy for most database platforms is supported
  * with auto-increment capabilities. As Oracle does not natively support
  * auto-increment, the same effect is achieved by a combination of a database
  * sequence and a pre-insert database trigger [1].
  * 
- * This test verifies that a persistence entity using IDENTITY generation type
- * is allocated identities in monotonic sequence on Oracle platform.
+ * This test verifies that a persistent entity using IDENTITY generation type
+ * is allocating identities in monotonic sequence on Oracle platform.
  * 
  * [1] http://jen.fluxcapacitor.net/geek/autoincr.html
  * 
@@ -41,14 +45,14 @@
 
 @DatabasePlatform("oracle.jdbc.driver.OracleDriver")
 public class TestAutoIncrement extends SingleEMFTestCase {
-	private static String PLATFORM = "oracle";
 
 	public void setUp() throws Exception {
         if ("testAutoIncrementIdentityWithNamedSequence".equals(getName())) {
+            String sequence = "autoIncrementSequence";
+            createSequence(sequence);
 			super.setUp(CLEAR_TABLES, PObject.class,
 			    "openjpa.jdbc.DBDictionary",
-			    "oracle(UseTriggersForAutoAssign=true," + 
-			    "autoAssignSequenceName=autoIncrementSequence)");
+			    "oracle(UseTriggersForAutoAssign=true,autoAssignSequenceName=" + sequence + ")");
 		} else {
 			super.setUp(CLEAR_TABLES, PObjectNative.class,
 					"openjpa.jdbc.DBDictionary",
@@ -56,10 +60,7 @@
 		}
 	}
 
-	public void testAutoIncrementIdentityWithNamedSequence() {
-		if (!isTargetPlatform(PLATFORM))
-			return;
-
+    public void testAutoIncrementIdentityWithNamedSequence() {
 		EntityManager em = emf.createEntityManager();
 		em.getTransaction().begin();
 		PObject pc1 = new PObject();
@@ -72,9 +73,6 @@
 	}
 
 	public void testAutoIncrementIdentityWithNativeSequence() {
-		if (!isTargetPlatform(PLATFORM))
-			return;
-
 		EntityManager em = emf.createEntityManager();
 		em.getTransaction().begin();
 		PObjectNative pc1 = new PObjectNative();
@@ -85,4 +83,23 @@
 
 		assertEquals(1, Math.abs(pc1.getId() - pc2.getId()));
 	}
+
+    /**
+     * Create sequence so that the test does not require manual intervention in database.
+     */
+    private void createSequence(String sequence) {
+        OpenJPAEntityManagerFactorySPI factorySPI = createEMF();
+        OpenJPAEntityManagerSPI em = factorySPI.createEntityManager();
+
+        try {
+            em.getTransaction().begin();
+            Query q = em.createNativeQuery("CREATE SEQUENCE " + sequence + " START WITH 1");
+            q.executeUpdate();
+            em.getTransaction().commit();
+        } catch (PersistenceException e) {          
+            // Sequence probably exists.
+            em.getTransaction().rollback();
+        }
+        closeEMF(factorySPI);
+    }
 }



Mime
View raw message