aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/iciql/SQLDialectH2.java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gmail.com>2011-08-10 09:18:43 -0400
committerJames Moger <james.moger@gmail.com>2011-08-10 09:18:43 -0400
commitf3faeb5d1ea631b0074441f97080e1f2a9145f4b (patch)
tree94fffd66c04d2740778614b9cb00c608b759e148 /src/com/iciql/SQLDialectH2.java
parent1d381026a5d256a59fe41da42c7f4e86bb60f02c (diff)
downloadiciql-f3faeb5d1ea631b0074441f97080e1f2a9145f4b.tar.gz
iciql-f3faeb5d1ea631b0074441f97080e1f2a9145f4b.zip
Moved dialects back to main package. Registered MySQL dialect.
Diffstat (limited to 'src/com/iciql/SQLDialectH2.java')
-rw-r--r--src/com/iciql/SQLDialectH2.java97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/com/iciql/SQLDialectH2.java b/src/com/iciql/SQLDialectH2.java
new file mode 100644
index 0000000..c65c277
--- /dev/null
+++ b/src/com/iciql/SQLDialectH2.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2011 James Moger.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.iciql;
+
+import com.iciql.TableDefinition.FieldDefinition;
+import com.iciql.TableDefinition.IndexDefinition;
+import com.iciql.util.StatementBuilder;
+
+/**
+ * H2 database dialect.
+ */
+public class SQLDialectH2 extends SQLDialectDefault {
+
+ @Override
+ public boolean supportsMemoryTables() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsMerge() {
+ return true;
+ }
+
+ @Override
+ public String prepareCreateIndex(String schema, String table, IndexDefinition index) {
+ StatementBuilder buff = new StatementBuilder();
+ buff.append("CREATE ");
+ switch (index.type) {
+ case STANDARD:
+ break;
+ case UNIQUE:
+ buff.append("UNIQUE ");
+ break;
+ case HASH:
+ buff.append("HASH ");
+ break;
+ case UNIQUE_HASH:
+ buff.append("UNIQUE HASH ");
+ break;
+ }
+ buff.append("INDEX IF NOT EXISTS ");
+ buff.append(index.indexName);
+ buff.append(" ON ");
+ buff.append(table);
+ buff.append("(");
+ for (String col : index.columnNames) {
+ buff.appendExceptFirst(", ");
+ buff.append(col);
+ }
+ buff.append(")");
+ return buff.toString();
+ }
+
+ @Override
+ public <T> void prepareMerge(SQLStatement stat, String schemaName, String tableName, TableDefinition<T> def, Object obj) {
+ StatementBuilder buff = new StatementBuilder("MERGE INTO ");
+ buff.append(prepareTableName(schemaName, tableName)).append(" (");
+ buff.resetCount();
+ for (FieldDefinition field : def.fields) {
+ buff.appendExceptFirst(", ");
+ buff.append(field.columnName);
+ }
+ buff.append(") KEY(");
+ buff.resetCount();
+ for (FieldDefinition field : def.fields) {
+ if (field.isPrimaryKey) {
+ buff.appendExceptFirst(", ");
+ buff.append(field.columnName);
+ }
+ }
+ buff.append(") ");
+ buff.resetCount();
+ buff.append("VALUES (");
+ for (FieldDefinition field : def.fields) {
+ buff.appendExceptFirst(", ");
+ buff.append('?');
+ Object value = def.getValue(obj, field);
+ stat.addParameter(value);
+ }
+ buff.append(')');
+ stat.setSQL(buff.toString());
+ }
+} \ No newline at end of file