aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/iciql/Db.java2
-rw-r--r--src/main/java/com/iciql/SQLDialect.java7
-rw-r--r--src/main/java/com/iciql/SQLDialectDefault.java102
3 files changed, 13 insertions, 98 deletions
diff --git a/src/main/java/com/iciql/Db.java b/src/main/java/com/iciql/Db.java
index ebcd352..4c99037 100644
--- a/src/main/java/com/iciql/Db.java
+++ b/src/main/java/com/iciql/Db.java
@@ -572,7 +572,7 @@ public class Db implements AutoCloseable {
Savepoint prepareSavepoint() {
// don't change auto-commit mode.
// don't create save point.
- if (!autoSavePoint) {
+ if (!autoSavePoint || !dialect.supportsSavePoints()) {
return null;
}
// create a savepoint
diff --git a/src/main/java/com/iciql/SQLDialect.java b/src/main/java/com/iciql/SQLDialect.java
index 7c45cc2..5d3522a 100644
--- a/src/main/java/com/iciql/SQLDialect.java
+++ b/src/main/java/com/iciql/SQLDialect.java
@@ -73,6 +73,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.
*
* @param sqlType
diff --git a/src/main/java/com/iciql/SQLDialectDefault.java b/src/main/java/com/iciql/SQLDialectDefault.java
index bcfa64f..d601302 100644
--- a/src/main/java/com/iciql/SQLDialectDefault.java
+++ b/src/main/java/com/iciql/SQLDialectDefault.java
@@ -74,6 +74,11 @@ public class SQLDialectDefault implements SQLDialect {
}
}
+ @Override
+ public boolean supportsSavePoints() {
+ return true;
+ }
+
/**
* Allows subclasses to change the type of a column for a CREATE statement.
*
@@ -398,101 +403,4 @@ public class SQLDialectDefault implements SQLDialect {
return o.toString();
}
- @SuppressWarnings("incomplete-switch")
- @Override
- public void prepareCreateConstraintForeignKey(SQLStatement stat, String schemaName, String tableName, ConstraintForeignKeyDefinition constraint) {
- StatementBuilder buff = new StatementBuilder();
- buff.append("ALTER TABLE ");
- buff.append(prepareTableName(schemaName, tableName));
- buff.append(" ADD CONSTRAINT ");
- buff.append(constraint.constraintName);
- buff.append(" FOREIGN KEY ");
- buff.append(" (");
- for (String col : constraint.foreignColumns) {
- buff.appendExceptFirst(", ");
- buff.append(prepareColumnName(col));
- }
- buff.append(") ");
- buff.append(" REFERENCES ");
- buff.append(constraint.referenceTable);
- buff.append(" (");
- buff.resetCount();
- for (String col : constraint.referenceColumns) {
- buff.appendExceptFirst(", ");
- buff.append(prepareColumnName(col));
- }
- buff.append(") ");
- if (constraint.deleteType != ConstraintDeleteType.UNSET) {
- buff.append(" ON DELETE ");
- switch (constraint.deleteType) {
- case CASCADE:
- buff.append("CASCADE ");
- break;
- case RESTRICT:
- buff.append("RESTRICT ");
- break;
- case SET_NULL:
- buff.append("SET NULL ");
- break;
- case NO_ACTION:
- buff.append("NO ACTION ");
- break;
- case SET_DEFAULT:
- buff.append("SET DEFAULT ");
- break;
- }
- }
- if (constraint.updateType != ConstraintUpdateType.UNSET) {
- buff.append(" ON UPDATE ");
- switch (constraint.updateType) {
- case CASCADE:
- buff.append("CASCADE ");
- break;
- case RESTRICT:
- buff.append("RESTRICT ");
- break;
- case SET_NULL:
- buff.append("SET NULL ");
- break;
- case NO_ACTION:
- buff.append("NO ACTION ");
- break;
- case SET_DEFAULT:
- buff.append("SET DEFAULT ");
- break;
- }
- }
- switch (constraint.deferrabilityType) {
- case DEFERRABLE_INITIALLY_DEFERRED:
- buff.append("DEFERRABLE INITIALLY DEFERRED ");
- break;
- case DEFERRABLE_INITIALLY_IMMEDIATE:
- buff.append("DEFERRABLE INITIALLY IMMEDIATE ");
- break;
- case NOT_DEFERRABLE:
- buff.append("NOT DEFERRABLE ");
- break;
- case UNSET:
- break;
- }
- stat.setSQL(buff.toString().trim());
- }
-
- @Override
- public void prepareCreateConstraintUnique(SQLStatement stat, String schemaName, String tableName, ConstraintUniqueDefinition constraint) {
- StatementBuilder buff = new StatementBuilder();
- buff.append("ALTER TABLE ");
- buff.append(prepareTableName(schemaName, tableName));
- buff.append(" ADD CONSTRAINT ");
- buff.append(constraint.constraintName);
- buff.append(" UNIQUE ");
- buff.append(" (");
- for (String col : constraint.uniqueColumns) {
- buff.appendExceptFirst(", ");
- buff.append(prepareColumnName(col));
- }
- buff.append(") ");
- stat.setSQL(buff.toString().trim());
- }
-
} \ No newline at end of file