77import org .seasar .doma .jdbc .query .DuplicateKeyType ;
88import org .seasar .doma .jdbc .query .QueryOperand ;
99import org .seasar .doma .jdbc .query .QueryOperandPair ;
10+ import org .seasar .doma .jdbc .query .QueryOperandPairList ;
11+ import org .seasar .doma .jdbc .query .QueryRows ;
1012import org .seasar .doma .jdbc .query .UpsertAssembler ;
1113import org .seasar .doma .jdbc .query .UpsertAssemblerContext ;
1214import org .seasar .doma .jdbc .query .UpsertAssemblerSupport ;
@@ -23,7 +25,7 @@ public class H2UpsertAssembler implements UpsertAssembler {
2325
2426 private final List <? extends EntityPropertyType <?, ?>> keys ;
2527
26- private final List < QueryOperandPair > insertValues ;
28+ private final QueryRows insertValues ;
2729
2830 private final List <QueryOperandPair > setValues ;
2931
@@ -34,12 +36,9 @@ public H2UpsertAssembler(UpsertAssemblerContext context) {
3436 this .entityType = context .entityType ;
3537 this .duplicateKeyType = context .duplicateKeyType ;
3638 this .keys = context .keys ;
37- this .insertValues = context .insertValues . first (). getPairs () ;
39+ this .insertValues = context .insertValues ;
3840 this .setValues = context .setValues .getPairs ();
3941 this .upsertAssemblerSupport = new UpsertAssemblerSupport (context .naming , context .dialect );
40- if (context .insertValues .getRows ().size () > 1 ) {
41- throw new UnsupportedOperationException ();
42- }
4342 }
4443
4544 @ Override
@@ -59,13 +58,13 @@ public void assemble() {
5958 }
6059 buf .cutBackSql (5 );
6160 buf .appendSql (" when not matched then insert (" );
62- for (QueryOperandPair pair : insertValues ) {
61+ for (QueryOperandPair pair : insertValues . first (). getPairs () ) {
6362 column (pair .getLeft ().getEntityPropertyType ());
6463 buf .appendSql (", " );
6564 }
6665 buf .cutBackSql (2 );
6766 buf .appendSql (") values (" );
68- for (QueryOperandPair pair : insertValues ) {
67+ for (QueryOperandPair pair : insertValues . first (). getPairs () ) {
6968 excludeColumn (pair .getLeft ().getEntityPropertyType ());
7069 buf .appendSql (", " );
7170 }
@@ -85,19 +84,24 @@ public void assemble() {
8584
8685 private void excludeQuery () {
8786 buf .appendSql ("select " );
88- for (QueryOperandPair pair : insertValues ) {
87+ for (QueryOperandPair pair : insertValues . first (). getPairs () ) {
8988 column (pair .getLeft ().getEntityPropertyType ());
9089 buf .appendSql (", " );
9190 }
9291 buf .cutBackSql (2 );
93- buf .appendSql (" from values (" );
94- for (QueryOperandPair pair : insertValues ) {
95- pair .getRight ().accept (queryOperandVisitor );
96- buf .appendSql (", " );
92+ buf .appendSql (" from values " );
93+ for (QueryOperandPairList row : insertValues .getRows ()) {
94+ buf .appendSql ("(" );
95+ for (QueryOperandPair pair : row .getPairs ()) {
96+ pair .getRight ().accept (queryOperandVisitor );
97+ buf .appendSql (", " );
98+ }
99+ buf .cutBackSql (2 );
100+ buf .appendSql ("), " );
97101 }
98102 buf .cutBackSql (2 );
99- buf .appendSql (") as x (" );
100- for (QueryOperandPair pair : insertValues ) {
103+ buf .appendSql (" as x (" );
104+ for (QueryOperandPair pair : insertValues . first (). getPairs () ) {
101105 column (pair .getLeft ().getEntityPropertyType ());
102106 buf .appendSql (", " );
103107 }
0 commit comments