cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1563610 - in /cayenne/main/trunk/cayenne-server/src: main/java/org/apache/cayenne/dba/JdbcPkGenerator.java test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
Date Sun, 02 Feb 2014 13:09:32 GMT
Author: aadamchik
Date: Sun Feb  2 13:09:32 2014
New Revision: 1563610

URL: http://svn.apache.org/r1563610
Log:
for sequence based PK generators we must drop pk and recreate
 for the test to work

Modified:
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java
    cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java
    cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java?rev=1563610&r1=1563609&r2=1563610&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/dba/JdbcPkGenerator.java
Sun Feb  2 13:09:32 2014
@@ -51,7 +51,7 @@ import org.apache.cayenne.util.IDUtil;
 public class JdbcPkGenerator implements PkGenerator {
 
     public static final int DEFAULT_PK_CACHE_SIZE = 20;
-    private static final long DEFAULT_PK_START_VALUE = 200;
+    static final long DEFAULT_PK_START_VALUE = 200;
 
     protected JdbcAdapter adapter;
     protected ConcurrentHashMap<String, Queue<Long>> pkCache = new ConcurrentHashMap<String,
Queue<Long>>();

Modified: cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java?rev=1563610&r1=1563609&r2=1563610&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/dba/JdbcPkGeneratorTest.java
Sun Feb  2 13:09:32 2014
@@ -26,6 +26,7 @@ import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.SchemaBuilder;
 import org.apache.cayenne.unit.di.server.ServerCase;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 
@@ -37,6 +38,28 @@ public class JdbcPkGeneratorTest extends
 
     @Inject
     private DataNode node;
+    
+    @Inject
+    private SchemaBuilder schemaBuilder;
+    
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        schemaBuilder.dropPKSupport();
+    }
+    
+    @Override
+    protected void tearDownBeforeInjection() throws Exception {
+
+        if (JdbcPkGenerator.class.isAssignableFrom(adapter.getPkGenerator().getClass()))
{
+            // reset PK gen properly before updating PKs in DB
+            JdbcPkGenerator pkGenerator = (JdbcPkGenerator) adapter.getPkGenerator();
+
+            pkGenerator.setPkStartValue(JdbcPkGenerator.DEFAULT_PK_START_VALUE);
+
+            schemaBuilder.dropPKSupport();
+            schemaBuilder.createPKSupport();
+        }
+    }
 
     public void testLongPk() throws Exception {
 
@@ -57,7 +80,7 @@ public class JdbcPkGeneratorTest extends
         }
         pkGenerator.createAutoPk(node, Collections.singletonList(artistEntity));
         pkGenerator.reset();
-
+        
         Object pk = pkGenerator.generatePk(node, pkAttribute);
         assertTrue(pk instanceof Long);
         assertTrue("PK is too small: " + pk, ((Long) pk).longValue() > Integer.MAX_VALUE);

Modified: cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java?rev=1563610&r1=1563609&r2=1563610&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/unit/di/server/SchemaBuilder.java
Sun Feb  2 13:09:32 2014
@@ -170,7 +170,7 @@ public class SchemaBuilder {
         }
     }
 
-    private void dropPKSupport() throws Exception {
+    public void dropPKSupport() throws Exception {
         for (DataNode node : domain.getDataNodes()) {
             dropPKSupport(node, node.getDataMaps().iterator().next());
         }
@@ -181,7 +181,7 @@ public class SchemaBuilder {
      * facilities provided by DbAdapter to generate any necessary database
      * objects and data for primary key support.
      */
-    private void createPKSupport() throws Exception {
+    public void createPKSupport() throws Exception {
         for (DataNode node : domain.getDataNodes()) {
             createPKSupport(node, node.getDataMaps().iterator().next());
         }



Mime
View raw message