final String LITERAL = "'";
- float databaseVersion;
- int databaseMajorVersion;
- int databaseMinorVersion;
- String databaseName;
- String productVersion;
- Mode mode;
- Map<Class<? extends DataTypeAdapter<?>>, DataTypeAdapter<?>> typeAdapters;
+ protected float databaseVersion;
+ protected int databaseMajorVersion;
+ protected int databaseMinorVersion;
+ protected String databaseName;
+ protected String productVersion;
+ protected Mode mode;
+ protected Map<Class<? extends DataTypeAdapter<?>>, DataTypeAdapter<?>> typeAdapters;
public SQLDialectDefault() {
typeAdapters = new ConcurrentHashMap<Class<? extends DataTypeAdapter<?>>, DataTypeAdapter<?>>();
\r
package com.iciql;\r
\r
+import com.iciql.TableDefinition.FieldDefinition;\r
import com.iciql.TableDefinition.IndexDefinition;\r
import com.iciql.util.StatementBuilder;\r
\r
stat.setSQL(buff.toString().trim());\r
}\r
\r
+ @Override\r
+ public <T> void prepareMerge(SQLStatement stat, String schemaName, String tableName,\r
+ TableDefinition<T> def, Object obj) {\r
+\r
+ if (databaseVersion < 9.5f) {\r
+ // simulated UPSERT for <= 9.4 release\r
+ super.prepareMerge(stat, schemaName, tableName, def, obj);\r
+ return;\r
+ }\r
+\r
+ // official UPSERT added in 9.5 release\r
+ StatementBuilder buff = new StatementBuilder("INSERT INTO ");\r
+ buff.append(prepareTableName(schemaName, tableName)).append(" (");\r
+ buff.resetCount();\r
+ for (FieldDefinition field : def.fields) {\r
+ buff.appendExceptFirst(", ");\r
+ buff.append(field.columnName);\r
+ }\r
+ buff.resetCount();\r
+ buff.append(") VALUES (");\r
+ for (FieldDefinition field : def.fields) {\r
+ buff.appendExceptFirst(", ");\r
+ buff.append('?');\r
+ Object value = def.getValue(obj, field);\r
+ Object parameter = serialize(value, field.typeAdapter);\r
+ stat.addParameter(parameter);\r
+ }\r
+ buff.append(") ON CONFLICT DO UPDATE SET");\r
+ stat.setSQL(buff.toString());\r
+ }\r
+\r
}
\ No newline at end of file