@@ -47,31 +47,33 @@ public <T> ExecutableUpdate<T> update(Class<T> domainType) {
47
47
48
48
Assert .notNull (domainType , "DomainType must not be null" );
49
49
50
- return new ExecutableUpdateSupport <>(template , domainType , ALL_QUERY , null , null , null , null , null , domainType );
50
+ return new ExecutableUpdateSupport <>(template , domainType , ALL_QUERY , null , null , null , null , null , domainType , QueryResultConverter . entity () );
51
51
}
52
52
53
53
/**
54
54
* @author Christoph Strobl
55
55
* @since 2.0
56
56
*/
57
57
@ SuppressWarnings ("rawtypes" )
58
- static class ExecutableUpdateSupport <T >
58
+ static class ExecutableUpdateSupport <S , T >
59
59
implements ExecutableUpdate <T >, UpdateWithCollection <T >, UpdateWithQuery <T >, TerminatingUpdate <T >,
60
60
FindAndReplaceWithOptions <T >, TerminatingFindAndReplace <T >, FindAndReplaceWithProjection <T > {
61
61
62
62
private final MongoTemplate template ;
63
- private final Class domainType ;
63
+ private final Class <?> domainType ;
64
64
private final Query query ;
65
65
@ Nullable private final UpdateDefinition update ;
66
66
@ Nullable private final String collection ;
67
67
@ Nullable private final FindAndModifyOptions findAndModifyOptions ;
68
68
@ Nullable private final FindAndReplaceOptions findAndReplaceOptions ;
69
69
@ Nullable private final Object replacement ;
70
- private final Class <T > targetType ;
70
+ private final QueryResultConverter <? super S , ? extends T > resultConverter ;
71
+ private final Class <S > targetType ;
71
72
72
- ExecutableUpdateSupport (MongoTemplate template , Class domainType , Query query , @ Nullable UpdateDefinition update ,
73
+ ExecutableUpdateSupport (MongoTemplate template , Class <?> domainType , Query query , @ Nullable UpdateDefinition update ,
73
74
@ Nullable String collection , @ Nullable FindAndModifyOptions findAndModifyOptions ,
74
- @ Nullable FindAndReplaceOptions findAndReplaceOptions , @ Nullable Object replacement , Class <T > targetType ) {
75
+ @ Nullable FindAndReplaceOptions findAndReplaceOptions , @ Nullable Object replacement , Class <S > targetType ,
76
+ QueryResultConverter <? super S , ? extends T > resultConverter ) {
75
77
76
78
this .template = template ;
77
79
this .domainType = domainType ;
@@ -82,6 +84,7 @@ static class ExecutableUpdateSupport<T>
82
84
this .findAndReplaceOptions = findAndReplaceOptions ;
83
85
this .replacement = replacement ;
84
86
this .targetType = targetType ;
87
+ this .resultConverter = resultConverter ;
85
88
}
86
89
87
90
@ Override
@@ -91,7 +94,7 @@ public TerminatingUpdate<T> apply(UpdateDefinition update) {
91
94
Assert .notNull (update , "Update must not be null" );
92
95
93
96
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
94
- findAndReplaceOptions , replacement , targetType );
97
+ findAndReplaceOptions , replacement , targetType , resultConverter );
95
98
}
96
99
97
100
@ Override
@@ -101,7 +104,7 @@ public UpdateWithQuery<T> inCollection(String collection) {
101
104
Assert .hasText (collection , "Collection must not be null nor empty" );
102
105
103
106
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
104
- findAndReplaceOptions , replacement , targetType );
107
+ findAndReplaceOptions , replacement , targetType , resultConverter );
105
108
}
106
109
107
110
@ Override
@@ -111,7 +114,7 @@ public TerminatingFindAndModify<T> withOptions(FindAndModifyOptions options) {
111
114
Assert .notNull (options , "Options must not be null" );
112
115
113
116
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , options ,
114
- findAndReplaceOptions , replacement , targetType );
117
+ findAndReplaceOptions , replacement , targetType , resultConverter );
115
118
}
116
119
117
120
@ Override
@@ -121,7 +124,7 @@ public FindAndReplaceWithProjection<T> replaceWith(T replacement) {
121
124
Assert .notNull (replacement , "Replacement must not be null" );
122
125
123
126
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
124
- findAndReplaceOptions , replacement , targetType );
127
+ findAndReplaceOptions , replacement , targetType , resultConverter );
125
128
}
126
129
127
130
@ Override
@@ -131,7 +134,7 @@ public FindAndReplaceWithProjection<T> withOptions(FindAndReplaceOptions options
131
134
Assert .notNull (options , "Options must not be null" );
132
135
133
136
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
134
- options , replacement , targetType );
137
+ options , replacement , targetType , resultConverter );
135
138
}
136
139
137
140
@ Override
@@ -143,7 +146,7 @@ public TerminatingReplace withOptions(ReplaceOptions options) {
143
146
target .upsert ();
144
147
}
145
148
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
146
- target , replacement , targetType );
149
+ target , replacement , targetType , resultConverter );
147
150
}
148
151
149
152
@ Override
@@ -153,7 +156,7 @@ public UpdateWithUpdate<T> matching(Query query) {
153
156
Assert .notNull (query , "Query must not be null" );
154
157
155
158
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
156
- findAndReplaceOptions , replacement , targetType );
159
+ findAndReplaceOptions , replacement , targetType , resultConverter );
157
160
}
158
161
159
162
@ Override
@@ -163,7 +166,7 @@ public <R> FindAndReplaceWithOptions<R> as(Class<R> resultType) {
163
166
Assert .notNull (resultType , "ResultType must not be null" );
164
167
165
168
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
166
- findAndReplaceOptions , replacement , resultType );
169
+ findAndReplaceOptions , replacement , resultType , QueryResultConverter . entity () );
167
170
}
168
171
169
172
@ Override
@@ -181,22 +184,35 @@ public UpdateResult upsert() {
181
184
return doUpdate (true , true );
182
185
}
183
186
187
+ @ Override
188
+ public <R > TerminatingFindAndModify <R > map (QueryResultConverter <? super T , ? extends R > converter ) {
189
+
190
+ return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
191
+ findAndReplaceOptions , replacement , targetType , this .resultConverter .andThen (converter ));
192
+ }
193
+
194
+ @ Override
195
+ public <R > TerminatingFindAndReplace <R > mapResult (QueryResultConverter <? super T , ? extends R > converter ) {
196
+ return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
197
+ findAndReplaceOptions , replacement , targetType , this .resultConverter .andThen (converter ));
198
+ }
199
+
184
200
@ Override
185
201
@ SuppressWarnings ("NullAway" )
186
202
public @ Nullable T findAndModifyValue () {
187
203
188
204
return template .findAndModify (query , update ,
189
205
findAndModifyOptions != null ? findAndModifyOptions : new FindAndModifyOptions (), targetType ,
190
- getCollectionName ());
206
+ getCollectionName (), resultConverter );
191
207
}
192
208
193
209
@ Override
194
210
@ SuppressWarnings ({ "unchecked" , "NullAway" })
195
211
public @ Nullable T findAndReplaceValue () {
196
212
197
213
return (T ) template .findAndReplace (query , replacement ,
198
- findAndReplaceOptions != null ? findAndReplaceOptions : FindAndReplaceOptions .empty (), domainType ,
199
- getCollectionName (), targetType );
214
+ findAndReplaceOptions != null ? findAndReplaceOptions : FindAndReplaceOptions .empty (), ( Class ) domainType ,
215
+ getCollectionName (), targetType , ( QueryResultConverter ) resultConverter );
200
216
}
201
217
202
218
@ Override
0 commit comments