@@ -51,7 +51,7 @@ public <T> ExecutableUpdate<T> update(Class<T> domainType) {
51
51
52
52
Assert .notNull (domainType , "DomainType must not be null!" );
53
53
54
- return new ExecutableUpdateSupport <>(template , domainType , ALL_QUERY , null , null , null , null , null );
54
+ return new ExecutableUpdateSupport <>(template , domainType , ALL_QUERY , null , null , null , null , null , domainType );
55
55
}
56
56
57
57
/**
@@ -60,17 +60,19 @@ public <T> ExecutableUpdate<T> update(Class<T> domainType) {
60
60
*/
61
61
@ RequiredArgsConstructor
62
62
@ FieldDefaults (level = AccessLevel .PRIVATE , makeFinal = true )
63
- static class ExecutableUpdateSupport <T > implements ExecutableUpdate <T >, UpdateWithCollection <T >, UpdateWithQuery <T >,
64
- TerminatingUpdate <T >, FindAndReplaceWithOptions <T >, TerminatingFindAndReplace <T > {
63
+ static class ExecutableUpdateSupport <T >
64
+ implements ExecutableUpdate <T >, UpdateWithCollection <T >, UpdateWithQuery <T >, TerminatingUpdate <T >,
65
+ FindAndReplaceWithOptions <T >, TerminatingFindAndReplace <T >, FindAndReplaceWithProjection <T > {
65
66
66
67
@ NonNull MongoTemplate template ;
67
- @ NonNull Class < T > domainType ;
68
+ @ NonNull Class domainType ;
68
69
Query query ;
69
70
@ Nullable Update update ;
70
71
@ Nullable String collection ;
71
72
@ Nullable FindAndModifyOptions findAndModifyOptions ;
72
73
@ Nullable FindAndReplaceOptions findAndReplaceOptions ;
73
- @ Nullable T replacement ;
74
+ @ Nullable Object replacement ;
75
+ @ NonNull Class <T > targetType ;
74
76
75
77
/*
76
78
* (non-Javadoc)
@@ -82,7 +84,7 @@ public TerminatingUpdate<T> apply(Update update) {
82
84
Assert .notNull (update , "Update must not be null!" );
83
85
84
86
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
85
- findAndReplaceOptions , replacement );
87
+ findAndReplaceOptions , replacement , targetType );
86
88
}
87
89
88
90
/*
@@ -95,7 +97,7 @@ public UpdateWithQuery<T> inCollection(String collection) {
95
97
Assert .hasText (collection , "Collection must not be null nor empty!" );
96
98
97
99
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
98
- findAndReplaceOptions , replacement );
100
+ findAndReplaceOptions , replacement , targetType );
99
101
}
100
102
101
103
/*
@@ -108,33 +110,33 @@ public TerminatingFindAndModify<T> withOptions(FindAndModifyOptions options) {
108
110
Assert .notNull (options , "Options must not be null!" );
109
111
110
112
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , options ,
111
- findAndReplaceOptions , replacement );
113
+ findAndReplaceOptions , replacement , targetType );
112
114
}
113
115
114
116
/*
115
117
* (non-Javadoc)
116
118
* @see org.springframework.data.mongodb.core.ExecutableUpdateOperation.UpdateWithUpdate#replaceWith(Object)
117
119
*/
118
120
@ Override
119
- public FindAndReplaceWithOptions <T > replaceWith (T replacement ) {
121
+ public FindAndReplaceWithProjection <T > replaceWith (T replacement ) {
120
122
121
123
Assert .notNull (replacement , "Replacement must not be null!" );
122
124
123
125
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
124
- findAndReplaceOptions , replacement );
126
+ findAndReplaceOptions , replacement , targetType );
125
127
}
126
128
127
129
/*
128
130
* (non-Javadoc)
129
131
* @see org.springframework.data.mongodb.core.ExecutableUpdateOperation.FindAndReplaceWithOptions#withOptions(org.springframework.data.mongodb.core.FindAndReplaceOptions)
130
132
*/
131
133
@ Override
132
- public TerminatingFindAndReplace <T > withOptions (FindAndReplaceOptions options ) {
134
+ public FindAndReplaceWithProjection <T > withOptions (FindAndReplaceOptions options ) {
133
135
134
136
Assert .notNull (options , "Options must not be null!" );
135
137
136
138
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
137
- options , replacement );
139
+ options , replacement , targetType );
138
140
}
139
141
140
142
/*
@@ -147,7 +149,20 @@ public UpdateWithUpdate<T> matching(Query query) {
147
149
Assert .notNull (query , "Query must not be null!" );
148
150
149
151
return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
150
- findAndReplaceOptions , replacement );
152
+ findAndReplaceOptions , replacement , targetType );
153
+ }
154
+
155
+ /*
156
+ * (non-Javadoc)
157
+ * @see org.springframework.data.mongodb.core.ReactiveUpdateOperation.FindAndReplaceWithProjection#as(java.lang.Class)
158
+ */
159
+ @ Override
160
+ public <R > FindAndReplaceWithOptions <R > as (Class <R > resultType ) {
161
+
162
+ Assert .notNull (resultType , "ResultType must not be null!" );
163
+
164
+ return new ExecutableUpdateSupport <>(template , domainType , query , update , collection , findAndModifyOptions ,
165
+ findAndReplaceOptions , replacement , resultType );
151
166
}
152
167
153
168
/*
@@ -183,8 +198,9 @@ public UpdateResult upsert() {
183
198
*/
184
199
@ Override
185
200
public @ Nullable T findAndModifyValue () {
201
+
186
202
return template .findAndModify (query , update ,
187
- findAndModifyOptions != null ? findAndModifyOptions : new FindAndModifyOptions (), domainType ,
203
+ findAndModifyOptions != null ? findAndModifyOptions : new FindAndModifyOptions (), targetType ,
188
204
getCollectionName ());
189
205
}
190
206
@@ -194,9 +210,10 @@ public UpdateResult upsert() {
194
210
*/
195
211
@ Override
196
212
public @ Nullable T findAndReplaceValue () {
197
- return template .findAndReplace (query , replacement ,
198
- findAndReplaceOptions != null ? findAndReplaceOptions : new FindAndReplaceOptions (), domainType ,
199
- getCollectionName ());
213
+
214
+ return (T ) template .findAndReplace (query , replacement ,
215
+ findAndReplaceOptions != null ? findAndReplaceOptions : FindAndReplaceOptions .empty (), domainType ,
216
+ getCollectionName (), targetType );
200
217
}
201
218
202
219
private UpdateResult doUpdate (boolean multi , boolean upsert ) {
0 commit comments