diff options
Diffstat (limited to 'src/main/java/com/iciql/SQLDialectDerby.java')
-rw-r--r-- | src/main/java/com/iciql/SQLDialectDerby.java | 22 |
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));
|