aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/iciql/SQLDialectDerby.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/iciql/SQLDialectDerby.java')
-rw-r--r--src/com/iciql/SQLDialectDerby.java85
1 files changed, 5 insertions, 80 deletions
diff --git a/src/com/iciql/SQLDialectDerby.java b/src/com/iciql/SQLDialectDerby.java
index 019c285..fd06844 100644
--- a/src/com/iciql/SQLDialectDerby.java
+++ b/src/com/iciql/SQLDialectDerby.java
@@ -16,10 +16,6 @@
package com.iciql;
-import java.text.MessageFormat;
-
-import com.iciql.TableDefinition.FieldDefinition;
-import com.iciql.TableDefinition.IndexDefinition;
import com.iciql.util.StatementBuilder;
/**
@@ -68,14 +64,11 @@ public class SQLDialectDerby extends SQLDialectDefault {
}
@Override
- public String prepareColumnName(String name) {
- return name;
- }
-
- @Override
- protected boolean prepareColumnDefinition(StatementBuilder buff, boolean isAutoIncrement,
- boolean isPrimaryKey) {
- if (isAutoIncrement) {
+ protected boolean prepareColumnDefinition(StatementBuilder buff, String dataType,
+ boolean isAutoIncrement, boolean isPrimaryKey) {
+ String convertedType = convertSqlType(dataType);
+ buff.append(convertedType);
+ if (isIntegerType(dataType) && isAutoIncrement) {
buff.append(" GENERATED BY DEFAULT AS IDENTITY");
}
return false;
@@ -88,72 +81,4 @@ public class SQLDialectDerby extends SQLDialectDefault {
stat.setSQL(buff.toString());
return;
}
-
- @Override
- public void prepareCreateIndex(SQLStatement stat, String schema, String table, IndexDefinition index) {
- StatementBuilder buff = new StatementBuilder();
- buff.append("CREATE ");
- switch (index.type) {
- case UNIQUE:
- buff.append("UNIQUE ");
- break;
- case UNIQUE_HASH:
- buff.append("UNIQUE ");
- break;
- }
- buff.append("INDEX ");
- buff.append(index.indexName);
- buff.append(" ON ");
- buff.append(table);
- buff.append("(");
- for (String col : index.columnNames) {
- buff.appendExceptFirst(", ");
- buff.append(prepareColumnName(col));
- }
- buff.append(") ");
-
- stat.setSQL(buff.toString().trim());
- }
-
- /**
- * Derby does not support the SQL2003 MERGE syntax, but we can use a trick
- * to insert a row if it does not exist and call update() in Db.merge() if
- * the affected row count is 0;
- *
- * http://stackoverflow.com/questions/407688
- */
- @Override
- public <T> void prepareMerge(SQLStatement stat, String schemaName, String tableName,
- TableDefinition<T> def, Object obj) {
- StatementBuilder buff = new StatementBuilder("INSERT INTO ");
- buff.append(prepareTableName(schemaName, tableName));
- buff.append(" (");
- buff.resetCount();
- for (FieldDefinition field : def.fields) {
- buff.appendExceptFirst(", ");
- buff.append(prepareColumnName(field.columnName));
- }
- buff.append(") (SELECT ");
- buff.resetCount();
- for (FieldDefinition field : def.fields) {
- buff.appendExceptFirst(", ");
- buff.append('?');
- Object value = def.getValue(obj, field);
- stat.addParameter(value);
- }
- buff.append(" FROM ");
- buff.append(prepareTableName(schemaName, tableName));
- buff.append(" WHERE ");
- buff.resetCount();
- for (FieldDefinition field : def.fields) {
- if (field.isPrimaryKey) {
- buff.appendExceptFirst(" AND ");
- buff.append(MessageFormat.format("{0} = ?", prepareColumnName(field.columnName)));
- Object value = def.getValue(obj, field);
- stat.addParameter(value);
- }
- }
- buff.append(" HAVING count(*)=0)");
- stat.setSQL(buff.toString());
- }
} \ No newline at end of file