Skip to content

Commit d433ed8

Browse files
committed
Fix OracleUpsertAssembler and Db2UpsertAssembler
1 parent 74039ea commit d433ed8

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

doma-core/src/main/java/org/seasar/doma/jdbc/dialect/Db2UpsertAssembler.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ public void assemble() {
3939
tableNameAndAlias(entityType);
4040
buf.appendSql(" using (");
4141
excludeQuery();
42-
buf.appendSql(") as ");
42+
buf.appendSql(") ");
4343
excludeAlias();
44-
buf.appendSql(" on ");
44+
buf.appendSql(" on (");
4545
for (EntityPropertyType<?, ?> key : keys) {
4646
targetColumn(key);
4747
buf.appendSql(" = ");
4848
assignmentColumn(key);
4949
buf.appendSql(" and ");
5050
}
5151
buf.cutBackSql(5);
52-
buf.appendSql(" when not matched then insert (");
52+
buf.appendSql(") when not matched then insert (");
5353
for (Tuple2<EntityPropertyType<?, ?>, InParameter<?>> insertValue : insertValues) {
5454
column(insertValue.component1());
5555
buf.appendSql(", ");
@@ -76,26 +76,20 @@ public void assemble() {
7676

7777
private void excludeQuery() {
7878
buf.appendSql("select ");
79-
for (Tuple2<EntityPropertyType<?, ?>, InParameter<?>> insertValue : insertValues) {
80-
column(insertValue.component1());
81-
buf.appendSql(", ");
82-
}
83-
buf.cutBackSql(2);
84-
buf.appendSql(" from values (");
8579
for (Tuple2<EntityPropertyType<?, ?>, InParameter<?>> insertValue : insertValues) {
8680
buf.appendParameter(insertValue.component2());
8781
buf.appendSql(" as ");
8882
column(insertValue.component1());
8983
buf.appendSql(", ");
9084
}
9185
buf.cutBackSql(2);
92-
buf.appendSql(") as dual");
86+
buf.appendSql(" from dual");
9387
}
9488

9589
private void tableNameAndAlias(EntityType<?> entityType) {
9690
String sql =
9791
this.upsertAssemblerSupport.targetTable(
98-
entityType, UpsertAssemblerSupport.TableNameType.NAME_AS_ALIAS);
92+
entityType, UpsertAssemblerSupport.TableNameType.NAME_ALIAS);
9993
buf.appendSql(sql);
10094
}
10195

doma-core/src/main/java/org/seasar/doma/jdbc/dialect/OracleUpsertAssembler.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ public void assemble() {
3838
tableNameAndAlias(entityType);
3939
buf.appendSql(" using (");
4040
excludeQuery();
41-
buf.appendSql(") as ");
41+
buf.appendSql(") ");
4242
excludeAlias();
43-
buf.appendSql(" on ");
43+
buf.appendSql(" on (");
4444
for (EntityPropertyType<?, ?> key : keys) {
4545
targetColumn(key);
4646
buf.appendSql(" = ");
4747
assignmentColumn(key);
4848
buf.appendSql(" and ");
4949
}
5050
buf.cutBackSql(5);
51-
buf.appendSql(" when not matched then insert (");
51+
buf.appendSql(") when not matched then insert (");
5252
for (Tuple2<EntityPropertyType<?, ?>, InParameter<?>> insertValue : insertValues) {
5353
column(insertValue.component1());
5454
buf.appendSql(", ");
@@ -75,26 +75,20 @@ public void assemble() {
7575

7676
private void excludeQuery() {
7777
buf.appendSql("select ");
78-
for (Tuple2<EntityPropertyType<?, ?>, InParameter<?>> insertValue : insertValues) {
79-
column(insertValue.component1());
80-
buf.appendSql(", ");
81-
}
82-
buf.cutBackSql(2);
83-
buf.appendSql(" from values (");
8478
for (Tuple2<EntityPropertyType<?, ?>, InParameter<?>> insertValue : insertValues) {
8579
buf.appendParameter(insertValue.component2());
8680
buf.appendSql(" as ");
8781
column(insertValue.component1());
8882
buf.appendSql(", ");
8983
}
9084
buf.cutBackSql(2);
91-
buf.appendSql(") as dual");
85+
buf.appendSql(" from dual");
9286
}
9387

9488
private void tableNameAndAlias(EntityType<?> entityType) {
9589
String sql =
9690
this.upsertAssemblerSupport.targetTable(
97-
entityType, UpsertAssemblerSupport.TableNameType.NAME_AS_ALIAS);
91+
entityType, UpsertAssemblerSupport.TableNameType.NAME_ALIAS);
9892
buf.appendSql(sql);
9993
}
10094

0 commit comments

Comments
 (0)