aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/iciql/SQLDialectDerby.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2017-01-31 19:38:17 -0500
committerJames Moger <james.moger@gitblit.com>2017-01-31 19:38:17 -0500
commitd18e27e799f4d887b22a5fc3cfcf59ddadde92f1 (patch)
tree8bf57a8241727c065b302eebf034a7ff2bc4f88b /src/main/java/com/iciql/SQLDialectDerby.java
parenta437098ced98696b407f1b6992c969bb5c8e9151 (diff)
downloadiciql-d18e27e799f4d887b22a5fc3cfcf59ddadde92f1.tar.gz
iciql-d18e27e799f4d887b22a5fc3cfcf59ddadde92f1.zip
Adjust CREATE TABLE column constraint syntax for MySQL 5.7 strict mode
Diffstat (limited to 'src/main/java/com/iciql/SQLDialectDerby.java')
-rw-r--r--src/main/java/com/iciql/SQLDialectDerby.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/com/iciql/SQLDialectDerby.java b/src/main/java/com/iciql/SQLDialectDerby.java
index fcaee1e..8ee395a 100644
--- a/src/main/java/com/iciql/SQLDialectDerby.java
+++ b/src/main/java/com/iciql/SQLDialectDerby.java
@@ -17,6 +17,7 @@
package com.iciql;
import com.iciql.util.StatementBuilder;
+import com.iciql.util.StringUtils;
/**
* Derby database dialect.
@@ -62,6 +63,27 @@ public class SQLDialectDerby extends SQLDialectDefault {
}
@Override
+ public String prepareColumnConstraint(boolean isAutoIncrement, boolean isPrimaryKey, boolean nullable, Class<?> fieldType, String dataType, String defaultValue) {
+ StringBuilder sb = new StringBuilder();
+ if (!isAutoIncrement && !isPrimaryKey) {
+
+ if (nullable && (defaultValue == null || ((dataType.equals("TIMESTAMP") || dataType.equals("DATETIME")) && StringUtils.isNullOrEmpty(defaultValue)))) {
+ sb.append(" DEFAULT NULL");
+ } else if (!StringUtils.isNullOrEmpty(defaultValue)) {
+ if (ModelUtils.isProperlyFormattedDefaultValue(defaultValue)
+ && ModelUtils.isValidDefaultValue(fieldType, defaultValue)) {
+ sb.append(" DEFAULT ").append(defaultValue);
+ }
+ }
+ }
+
+ if (!nullable) {
+ sb.append(" NOT NULL");
+ }
+ return sb.toString();
+ }
+
+ @Override
public <T> void prepareDropTable(SQLStatement stat, TableDefinition<T> def) {
StatementBuilder buff = new StatementBuilder("DROP TABLE "
+ prepareTableName(def.schemaName, def.tableName));