]> source.dussan.org Git - sonarqube.git/commitdiff
Try to fix Oracle tests
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 6 Dec 2011 15:12:47 +0000 (16:12 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 6 Dec 2011 15:13:20 +0000 (16:13 +0100)
sonar-core/src/test/java/org/sonar/persistence/dao/DaoTestCase.java
sonar-core/src/test/java/org/sonar/persistence/dao/DatabaseCommands.java

index 9b4f75e0cbf3144fe1bd63974a85be73fdab7fe9..e066c68812f6d1317ce5f3faac522dcde796bd8d 100644 (file)
@@ -103,7 +103,9 @@ public abstract class DaoTestCase {
 
       // 2. reset primary keys
       try {
-        statement.executeUpdate(databaseCommands.resetPrimaryKey(table));
+        for (String resetCommand : databaseCommands.resetPrimaryKey(table)) {
+          statement.executeUpdate(resetCommand);
+        }
         connection.commit();
       } catch (Exception e) {
         // this table has no primary key
index 7bf85bb5334b918184b9b6d297ef6a4632fe1c13..421e5a4c9570000afaa3ece8d72b800d5fa67f1a 100644 (file)
@@ -27,6 +27,9 @@ import org.dbunit.ext.oracle.Oracle10DataTypeFactory;
 import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory;
 import org.sonar.jpa.dialect.*;
 
+import java.util.Arrays;
+import java.util.List;
+
 abstract class DatabaseCommands {
 
   private IDataTypeFactory dbUnitFactory;
@@ -37,7 +40,7 @@ abstract class DatabaseCommands {
 
   abstract String truncate(String table);
 
-  abstract String resetPrimaryKey(String table);
+  abstract List<String> resetPrimaryKey(String table);
 
   final IDataTypeFactory dbUnitFactory() {
     return dbUnitFactory;
@@ -51,8 +54,8 @@ abstract class DatabaseCommands {
     }
 
     @Override
-    String resetPrimaryKey(String table) {
-      return "ALTER TABLE " + table + " ALTER COLUMN ID RESTART WITH 1";
+    List<String> resetPrimaryKey(String table) {
+      return Arrays.asList("ALTER TABLE " + table + " ALTER COLUMN ID RESTART WITH 1");
     }
   };
 
@@ -63,8 +66,8 @@ abstract class DatabaseCommands {
     }
 
     @Override
-    String resetPrimaryKey(String table) {
-      return "DBCC CHECKIDENT('" + table + "', RESEED, 1)";
+    List<String> resetPrimaryKey(String table) {
+      return Arrays.asList("DBCC CHECKIDENT('" + table + "', RESEED, 1)");
     }
   };
 
@@ -75,8 +78,8 @@ abstract class DatabaseCommands {
     }
 
     @Override
-    String resetPrimaryKey(String table) {
-      return "ALTER TABLE " + table + " AUTO_INCREMENT = 1";
+    List<String> resetPrimaryKey(String table) {
+      return Arrays.asList("ALTER TABLE " + table + " AUTO_INCREMENT = 1");
     }
   };
 
@@ -87,8 +90,11 @@ abstract class DatabaseCommands {
     }
 
     @Override
-    String resetPrimaryKey(String table) {
-      return "ALTER SEQUENCE " + table + "_SEQ INCREMENT BY 1 MINVALUE 1";
+    List<String> resetPrimaryKey(String table) {
+      return Arrays.asList(
+        "DROP SEQUENCE " + table + "_SEQ",
+        "CREATE SEQUENCE " + table + "_SEQ INCREMENT BY 1 MINVALUE 1 START WITH 1 NOORDER CACHE"
+      );
     }
   };
 
@@ -99,8 +105,8 @@ abstract class DatabaseCommands {
     }
 
     @Override
-    String resetPrimaryKey(String table) {
-      return "ALTER SEQUENCE " + table + "_id_seq RESTART WITH 1";
+    List<String> resetPrimaryKey(String table) {
+      return Arrays.asList("ALTER SEQUENCE " + table + "_id_seq RESTART WITH 1");
     }
   };