]> source.dussan.org Git - iciql.git/commitdiff
Allow dialects to determine if they support savepoints
authorJames Moger <james.moger@gitblit.com>
Sat, 1 Nov 2014 15:49:52 +0000 (11:49 -0400)
committerJames Moger <james.moger@gitblit.com>
Mon, 3 Nov 2014 17:51:16 +0000 (12:51 -0500)
src/main/java/com/iciql/Db.java
src/main/java/com/iciql/SQLDialect.java
src/main/java/com/iciql/SQLDialectDefault.java

index ebcd3525083d39baab40066e38739f4e8edd989a..4c99037f1cd51079287413364693b017fb71c195 100644 (file)
@@ -572,7 +572,7 @@ public class Db implements AutoCloseable {
        Savepoint prepareSavepoint() {\r
                // don't change auto-commit mode.\r
                // don't create save point.\r
-               if (!autoSavePoint) {\r
+               if (!autoSavePoint || !dialect.supportsSavePoints()) {\r
                        return null;\r
                }\r
                // create a savepoint\r
index 7c45cc2d5f0d63064473f2ddab985614717eaa22..5d3522af5c739f1ffa25cd8961884005d5d39bce 100644 (file)
@@ -72,6 +72,13 @@ public interface SQLDialect {
         */
        void configureDialect(String databaseName, DatabaseMetaData data);
 
+       /**
+        * Returns true if savepoints are supported.
+        *
+        * @return true if savepoints may be used.
+        */
+       boolean supportsSavePoints();
+
        /**
         * Allows a dialect to substitute an SQL type.
         *
index bcfa64f9574e750aae13b139657d9aefaa4d3855..d6013022e62a72f586b899436a28ebcfd19a0483 100644 (file)
@@ -74,6 +74,11 @@ public class SQLDialectDefault implements SQLDialect {
                }\r
        }\r
 \r
+       @Override\r
+       public boolean supportsSavePoints() {\r
+               return true;\r
+       }\r
+\r
        /**\r
         * Allows subclasses to change the type of a column for a CREATE statement.\r
         *\r
@@ -398,101 +403,4 @@ public class SQLDialectDefault implements SQLDialect {
                return o.toString();\r
        }\r
 \r
-       @SuppressWarnings("incomplete-switch")\r
-       @Override\r
-       public void prepareCreateConstraintForeignKey(SQLStatement stat, String schemaName, String tableName, ConstraintForeignKeyDefinition constraint) {\r
-               StatementBuilder buff = new StatementBuilder();\r
-               buff.append("ALTER TABLE ");\r
-               buff.append(prepareTableName(schemaName, tableName));\r
-               buff.append(" ADD CONSTRAINT ");\r
-               buff.append(constraint.constraintName);\r
-               buff.append(" FOREIGN KEY ");\r
-               buff.append(" (");\r
-               for (String col : constraint.foreignColumns) {\r
-                       buff.appendExceptFirst(", ");\r
-                       buff.append(prepareColumnName(col));\r
-               }\r
-               buff.append(") ");\r
-               buff.append(" REFERENCES ");\r
-               buff.append(constraint.referenceTable);\r
-               buff.append(" (");\r
-               buff.resetCount();\r
-               for (String col : constraint.referenceColumns) {\r
-                       buff.appendExceptFirst(", ");\r
-                       buff.append(prepareColumnName(col));\r
-               }\r
-               buff.append(") ");\r
-               if (constraint.deleteType != ConstraintDeleteType.UNSET) {\r
-                       buff.append(" ON DELETE ");\r
-                       switch (constraint.deleteType) {\r
-                       case CASCADE:\r
-                               buff.append("CASCADE ");\r
-                               break;\r
-                       case RESTRICT:\r
-                               buff.append("RESTRICT ");\r
-                               break;\r
-                       case SET_NULL:\r
-                               buff.append("SET NULL ");\r
-                               break;\r
-                       case NO_ACTION:\r
-                               buff.append("NO ACTION ");\r
-                               break;\r
-                       case SET_DEFAULT:\r
-                               buff.append("SET DEFAULT ");\r
-                               break;\r
-                       }\r
-               }\r
-               if (constraint.updateType != ConstraintUpdateType.UNSET) {\r
-                       buff.append(" ON UPDATE ");\r
-                       switch (constraint.updateType) {\r
-                       case CASCADE:\r
-                               buff.append("CASCADE ");\r
-                               break;\r
-                       case RESTRICT:\r
-                               buff.append("RESTRICT ");\r
-                               break;\r
-                       case SET_NULL:\r
-                               buff.append("SET NULL ");\r
-                               break;\r
-                       case NO_ACTION:\r
-                               buff.append("NO ACTION ");\r
-                               break;\r
-                       case SET_DEFAULT:\r
-                               buff.append("SET DEFAULT ");\r
-                               break;\r
-                       }\r
-               }\r
-               switch (constraint.deferrabilityType) {\r
-               case DEFERRABLE_INITIALLY_DEFERRED:\r
-                       buff.append("DEFERRABLE INITIALLY DEFERRED ");\r
-                       break;\r
-               case DEFERRABLE_INITIALLY_IMMEDIATE:\r
-                       buff.append("DEFERRABLE INITIALLY IMMEDIATE ");\r
-                       break;\r
-               case NOT_DEFERRABLE:\r
-                       buff.append("NOT DEFERRABLE ");\r
-                       break;\r
-               case UNSET:\r
-                       break;\r
-               }\r
-               stat.setSQL(buff.toString().trim());\r
-       }\r
-\r
-       @Override\r
-       public void prepareCreateConstraintUnique(SQLStatement stat, String schemaName, String tableName, ConstraintUniqueDefinition constraint) {\r
-               StatementBuilder buff = new StatementBuilder();\r
-               buff.append("ALTER TABLE ");\r
-               buff.append(prepareTableName(schemaName, tableName));\r
-               buff.append(" ADD CONSTRAINT ");\r
-               buff.append(constraint.constraintName);\r
-               buff.append(" UNIQUE ");\r
-               buff.append(" (");\r
-               for (String col : constraint.uniqueColumns) {\r
-                       buff.appendExceptFirst(", ");\r
-                       buff.append(prepareColumnName(col));\r
-               }\r
-               buff.append(") ");\r
-               stat.setSQL(buff.toString().trim());\r
-       }\r
-\r
 }
\ No newline at end of file