import com.iciql.Iciql.DataTypeAdapter;
import com.iciql.TableDefinition.IndexDefinition;
+import com.iciql.util.StatementBuilder;
import java.sql.ResultSet;
<T, A> void prepareBitwiseXor(SQLStatement stat, Query<T> query, A x, A y);
+ /**
+ * Specifies the syntax for a column constraint.
+ *
+ * @param isAutoIncrement
+ * @param isPrimaryKey
+ * @param isNullable
+ * @param fieldType
+ * @param dataType
+ * @param defaultValue
+ * @return the column constraint
+ */
+ String prepareColumnConstraint(boolean isAutoIncrement, boolean isPrimaryKey, boolean isNullable,
+ Class<?> fieldType, String dataType, String defaultValue);
+
}
hasIdentityColumn |= prepareColumnDefinition(buff, convertSqlType(dataType),
field.isAutoIncrement, field.isPrimaryKey);
}
-
- // default values
- if (!field.isAutoIncrement && !field.isPrimaryKey) {
- String dv = field.defaultValue;
- if (!StringUtils.isNullOrEmpty(dv)) {
- if (ModelUtils.isProperlyFormattedDefaultValue(dv)
- && ModelUtils.isValidDefaultValue(field.field.getType(), dv)) {
- buff.append(" DEFAULT " + dv);
- }
- }
- }
-
- if (!field.nullable) {
- buff.append(" NOT NULL");
- }
+
+ buff.append(prepareColumnConstraint(field.isAutoIncrement, field.isPrimaryKey, field.nullable, field.field.getType(),
+ field.dataType, field.defaultValue));
}
// if table does not have identity column then specify primary key
return false;
}
+ @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(" 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 void prepareCreateIndex(SQLStatement stat, String schemaName, String tableName,
IndexDefinition index) {
package com.iciql;\r
\r
import com.iciql.util.StatementBuilder;\r
+import com.iciql.util.StringUtils;\r
\r
/**\r
* Derby database dialect.\r
return false;\r
}\r
\r
+ @Override\r
+ public String prepareColumnConstraint(boolean isAutoIncrement, boolean isPrimaryKey, boolean nullable, Class<?> fieldType, String dataType, String defaultValue) {\r
+ StringBuilder sb = new StringBuilder();\r
+ if (!isAutoIncrement && !isPrimaryKey) {\r
+\r
+ if (nullable && (defaultValue == null || ((dataType.equals("TIMESTAMP") || dataType.equals("DATETIME")) && StringUtils.isNullOrEmpty(defaultValue)))) {\r
+ sb.append(" DEFAULT NULL");\r
+ } else if (!StringUtils.isNullOrEmpty(defaultValue)) {\r
+ if (ModelUtils.isProperlyFormattedDefaultValue(defaultValue)\r
+ && ModelUtils.isValidDefaultValue(fieldType, defaultValue)) {\r
+ sb.append(" DEFAULT ").append(defaultValue);\r
+ }\r
+ }\r
+ }\r
+\r
+ if (!nullable) {\r
+ sb.append(" NOT NULL");\r
+ }\r
+ return sb.toString();\r
+ }\r
+\r
@Override\r
public <T> void prepareDropTable(SQLStatement stat, TableDefinition<T> def) {\r
StatementBuilder buff = new StatementBuilder("DROP TABLE "\r
} else if (dbName.equals("Apache Derby")) {
// Derby uses java.sql.Timestamp not java.util.Date
// Derby uses username as schema name
- assertEquals(1601, models.get(0).length());
+ assertEquals(1643, models.get(0).length());
} else if (dbName.equals("PostgreSQL")) {
assertEquals(1643, models.get(0).length());
} else if (dbName.equals("MySQL")) {