19
19
import org .hibernate .engine .spi .SharedSessionContractImplementor ;
20
20
import org .hibernate .metamodel .mapping .PluralAttributeMapping ;
21
21
import org .hibernate .sql .model .MutationType ;
22
+ import org .hibernate .sql .model .internal .AbstractMutationOperationGroup ;
23
+ import org .hibernate .sql .model .internal .MutationOperationGroupNone ;
22
24
import org .hibernate .sql .model .internal .MutationOperationGroupSingle ;
25
+ import org .hibernate .sql .model .jdbc .JdbcMutationOperation ;
23
26
24
27
/**
25
28
* UpdateRowsCoordinator implementation for cases with a separate collection table
31
34
public class UpdateRowsCoordinatorStandard extends AbstractUpdateRowsCoordinator implements UpdateRowsCoordinator {
32
35
private final RowMutationOperations rowMutationOperations ;
33
36
34
- private MutationOperationGroupSingle operationGroup ;
37
+ private AbstractMutationOperationGroup operationGroup ;
35
38
36
39
public UpdateRowsCoordinatorStandard (
37
40
CollectionMutationTarget mutationTarget ,
@@ -43,7 +46,7 @@ public UpdateRowsCoordinatorStandard(
43
46
44
47
@ Override
45
48
protected int doUpdate (Object key , PersistentCollection <?> collection , SharedSessionContractImplementor session ) {
46
- final MutationOperationGroupSingle operationGroup = getOperationGroup ();
49
+ final AbstractMutationOperationGroup operationGroup = getOperationGroup ();
47
50
48
51
final MutationExecutorService mutationExecutorService = session
49
52
.getFactory ()
@@ -115,42 +118,55 @@ private boolean processRow(
115
118
int entryPosition ,
116
119
MutationExecutor mutationExecutor ,
117
120
SharedSessionContractImplementor session ) {
118
- final PluralAttributeMapping attribute = getMutationTarget ().getTargetPart ();
119
- if ( !collection .needsUpdating ( entry , entryPosition , attribute ) ) {
120
- return false ;
121
- }
121
+ if ( rowMutationOperations .getUpdateRowOperation () != null ) {
122
+ final PluralAttributeMapping attribute = getMutationTarget ().getTargetPart ();
123
+ if ( !collection .needsUpdating ( entry , entryPosition , attribute ) ) {
124
+ return false ;
125
+ }
122
126
123
- rowMutationOperations .getUpdateRowValues ().applyValues (
124
- collection ,
125
- key ,
126
- entry ,
127
- entryPosition ,
128
- session ,
129
- mutationExecutor .getJdbcValueBindings ()
130
- );
127
+ rowMutationOperations .getUpdateRowValues ().applyValues (
128
+ collection ,
129
+ key ,
130
+ entry ,
131
+ entryPosition ,
132
+ session ,
133
+ mutationExecutor .getJdbcValueBindings ()
134
+ );
131
135
132
- rowMutationOperations .getUpdateRowRestrictions ().applyRestrictions (
133
- collection ,
134
- key ,
135
- entry ,
136
- entryPosition ,
137
- session ,
138
- mutationExecutor .getJdbcValueBindings ()
139
- );
136
+ rowMutationOperations .getUpdateRowRestrictions ().applyRestrictions (
137
+ collection ,
138
+ key ,
139
+ entry ,
140
+ entryPosition ,
141
+ session ,
142
+ mutationExecutor .getJdbcValueBindings ()
143
+ );
140
144
141
- mutationExecutor .execute ( collection , null , null , null , session );
142
- return true ;
145
+ mutationExecutor .execute ( collection , null , null , null , session );
146
+ return true ;
147
+ }
148
+ else {
149
+ return false ;
150
+ }
143
151
}
144
152
145
- protected MutationOperationGroupSingle getOperationGroup () {
153
+ protected AbstractMutationOperationGroup getOperationGroup () {
146
154
if ( operationGroup == null ) {
147
- operationGroup = new MutationOperationGroupSingle (
148
- MutationType .UPDATE ,
149
- getMutationTarget (),
150
- rowMutationOperations .getUpdateRowOperation ()
151
- );
155
+ final JdbcMutationOperation updateRowOperation = rowMutationOperations .getUpdateRowOperation ();
156
+ if ( updateRowOperation == null ) {
157
+ operationGroup = new MutationOperationGroupNone (
158
+ MutationType .UPDATE ,
159
+ getMutationTarget ()
160
+ );
161
+ }
162
+ else {
163
+ operationGroup = new MutationOperationGroupSingle (
164
+ MutationType .UPDATE ,
165
+ getMutationTarget (),
166
+ updateRowOperation
167
+ );
168
+ }
152
169
}
153
-
154
170
return operationGroup ;
155
171
}
156
172
0 commit comments