@@ -50,6 +50,11 @@ public MergeOperation createMergeOperation(OptionalTableUpdate optionalTableUpda
50
50
);
51
51
}
52
52
53
+ @ Override
54
+ public void visitOptionalTableUpdate (OptionalTableUpdate tableUpdate ) {
55
+ renderMergeStatement (tableUpdate );
56
+ }
57
+
53
58
/**
54
59
* Renders the OptionalTableUpdate as a MERGE query.
55
60
*
@@ -207,8 +212,9 @@ protected void renderMergeInsert(OptionalTableUpdate optionalTableUpdate) {
207
212
208
213
protected void renderMergeDelete (OptionalTableUpdate optionalTableUpdate ) {
209
214
final List <ColumnValueBinding > valueBindings = optionalTableUpdate .getValueBindings ();
215
+ final List <ColumnValueBinding > optimisticLockBindings = optionalTableUpdate .getOptimisticLockBindings ();
210
216
211
- appendSql ( " when matched " );
217
+ renderWhenMatched ( optimisticLockBindings );
212
218
for ( int i = 0 ; i < valueBindings .size (); i ++ ) {
213
219
final ColumnValueBinding binding = valueBindings .get ( i );
214
220
appendSql ( " and " );
@@ -220,8 +226,10 @@ protected void renderMergeDelete(OptionalTableUpdate optionalTableUpdate) {
220
226
221
227
protected void renderMergeUpdate (OptionalTableUpdate optionalTableUpdate ) {
222
228
final List <ColumnValueBinding > valueBindings = optionalTableUpdate .getValueBindings ();
229
+ final List <ColumnValueBinding > optimisticLockBindings = optionalTableUpdate .getOptimisticLockBindings ();
223
230
224
- appendSql ( " when matched then update set " );
231
+ renderWhenMatched ( optimisticLockBindings );
232
+ appendSql ( " then update set " );
225
233
for ( int i = 0 ; i < valueBindings .size (); i ++ ) {
226
234
final ColumnValueBinding binding = valueBindings .get ( i );
227
235
if ( i > 0 ) {
@@ -232,4 +240,15 @@ protected void renderMergeUpdate(OptionalTableUpdate optionalTableUpdate) {
232
240
binding .getColumnReference ().appendColumnForWrite ( this , "s" );
233
241
}
234
242
}
243
+
244
+ private void renderWhenMatched (List <ColumnValueBinding > optimisticLockBindings ) {
245
+ appendSql ( " when matched" );
246
+ for (int i = 0 ; i < optimisticLockBindings .size (); i ++) {
247
+ final ColumnValueBinding binding = optimisticLockBindings .get ( i );
248
+ appendSql (" and " );
249
+ binding .getColumnReference ().appendColumnForWrite ( this , "t" );
250
+ appendSql ("<=" );
251
+ binding .getValueExpression ().accept ( this );
252
+ }
253
+ }
235
254
}
0 commit comments