Skip to content

Commit 0e45426

Browse files
committed
removed unecessary deserializers
1 parent 4bc5ced commit 0e45426

13 files changed

+79
-84
lines changed

src/main/java/com/arangodb/async/internal/ArangoCollectionAsyncImpl.java

+15-10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.Objects;
3232
import java.util.concurrent.CompletableFuture;
3333

34+
import static com.arangodb.serde.SerdeUtils.constructParametricType;
35+
3436
/**
3537
* @author Mark Vollmary
3638
* @author Michele Rastelli
@@ -47,15 +49,15 @@ public class ArangoCollectionAsyncImpl
4749
public <T> CompletableFuture<DocumentCreateEntity<T>> insertDocument(final T value) {
4850
final DocumentCreateOptions options = new DocumentCreateOptions();
4951
return executor.execute(insertDocumentRequest(value, options),
50-
insertDocumentResponseDeserializer(value, options));
52+
constructParametricType(DocumentCreateEntity.class, value.getClass()));
5153
}
5254

5355
@Override
5456
public <T> CompletableFuture<DocumentCreateEntity<T>> insertDocument(
5557
final T value,
5658
final DocumentCreateOptions options) {
5759
return executor.execute(insertDocumentRequest(value, options),
58-
insertDocumentResponseDeserializer(value, options));
60+
constructParametricType(DocumentCreateEntity.class, value.getClass()));
5961
}
6062

6163
@Override
@@ -135,7 +137,7 @@ public <T> CompletableFuture<MultiDocumentEntity<T>> getDocuments(
135137
public <T> CompletableFuture<DocumentUpdateEntity<T>> replaceDocument(final String key, final T value) {
136138
final DocumentReplaceOptions options = new DocumentReplaceOptions();
137139
return executor.execute(replaceDocumentRequest(key, value, options),
138-
replaceDocumentResponseDeserializer(value, options));
140+
constructParametricType(DocumentUpdateEntity.class, value.getClass()));
139141
}
140142

141143
@Override
@@ -144,15 +146,15 @@ public <T> CompletableFuture<DocumentUpdateEntity<T>> replaceDocument(
144146
final T value,
145147
final DocumentReplaceOptions options) {
146148
return executor.execute(replaceDocumentRequest(key, value, options),
147-
replaceDocumentResponseDeserializer(value, options));
149+
constructParametricType(DocumentUpdateEntity.class, value.getClass()));
148150
}
149151

150152
@Override
151153
public <T> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocuments(
152154
final Collection<T> values) {
153155
final DocumentReplaceOptions params = new DocumentReplaceOptions();
154156
return executor.execute(replaceDocumentsRequest(values, params),
155-
replaceDocumentsResponseDeserializer(values, params));
157+
replaceDocumentsResponseDeserializer(values));
156158
}
157159

158160
@Override
@@ -161,7 +163,7 @@ public <T> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<T>>> repla
161163
final DocumentReplaceOptions options) {
162164
final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions());
163165
return executor.execute(replaceDocumentsRequest(values, params),
164-
replaceDocumentsResponseDeserializer(values, params));
166+
replaceDocumentsResponseDeserializer(values));
165167
}
166168

167169
@Override
@@ -170,6 +172,7 @@ public <T> CompletableFuture<DocumentUpdateEntity<T>> updateDocument(final Strin
170172
}
171173

172174
@Override
175+
@SuppressWarnings("unchecked")
173176
public <T> CompletableFuture<DocumentUpdateEntity<T>> updateDocument(
174177
final String key,
175178
final T value,
@@ -184,7 +187,7 @@ public <T, U> CompletableFuture<DocumentUpdateEntity<U>> updateDocument(
184187
final DocumentUpdateOptions options,
185188
final Class<U> returnType) {
186189
return executor.execute(updateDocumentRequest(key, value, options),
187-
updateDocumentResponseDeserializer(value, options, returnType));
190+
constructParametricType(DocumentUpdateEntity.class, returnType));
188191
}
189192

190193
@Override
@@ -194,10 +197,11 @@ public <T> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<T>>> updat
194197
}
195198

196199
@Override
200+
@SuppressWarnings("unchecked")
197201
public <T> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<T>>> updateDocuments(
198202
final Collection<T> values,
199203
final DocumentUpdateOptions options) {
200-
return updateDocuments(values, options, values.isEmpty() ? null : (Class<T>) values.iterator().next().getClass());
204+
return updateDocuments(values, options, values.isEmpty() ? null : (Class<T>) getCollectionContentClass(values));
201205
}
202206

203207
@Override
@@ -213,15 +217,16 @@ public <T, U> CompletableFuture<MultiDocumentEntity<DocumentUpdateEntity<U>>> up
213217
@Override
214218
public CompletableFuture<DocumentDeleteEntity<Void>> deleteDocument(final String key) {
215219
return executor.execute(deleteDocumentRequest(key, new DocumentDeleteOptions()),
216-
deleteDocumentResponseDeserializer(Void.class));
220+
constructParametricType(DocumentDeleteEntity.class, Void.class));
217221
}
218222

219223
@Override
220224
public <T> CompletableFuture<DocumentDeleteEntity<T>> deleteDocument(
221225
final String key,
222226
final Class<T> type,
223227
final DocumentDeleteOptions options) {
224-
return executor.execute(deleteDocumentRequest(key, options), deleteDocumentResponseDeserializer(type));
228+
return executor.execute(deleteDocumentRequest(key, options),
229+
constructParametricType(DocumentDeleteEntity.class, type));
225230
}
226231

227232
@Override

src/main/java/com/arangodb/async/internal/ArangoDatabaseAsyncImpl.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import java.util.concurrent.CompletionException;
4545
import java.util.concurrent.ExecutionException;
4646

47+
import static com.arangodb.serde.SerdeUtils.constructListType;
48+
4749
/**
4850
* @author Mark Vollmary
4951
* @author Michele Rastelli
@@ -282,13 +284,13 @@ public CompletableFuture<QueryTrackingPropertiesEntity> setQueryTrackingProperti
282284
@Override
283285
public CompletableFuture<Collection<QueryEntity>> getCurrentlyRunningQueries() {
284286
return executor.execute(getCurrentlyRunningQueriesRequest(),
285-
SerdeUtils.INSTANCE.constructListType(QueryEntity.class));
287+
constructListType(QueryEntity.class));
286288
}
287289

288290
@Override
289291
public CompletableFuture<Collection<QueryEntity>> getSlowQueries() {
290292
return executor.execute(getSlowQueriesRequest(),
291-
SerdeUtils.INSTANCE.constructListType(QueryEntity.class));
293+
constructListType(QueryEntity.class));
292294
}
293295

294296
@Override

src/main/java/com/arangodb/internal/ArangoCollectionImpl.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525
import com.arangodb.entity.*;
2626
import com.arangodb.internal.util.DocumentUtil;
2727
import com.arangodb.model.*;
28+
import com.arangodb.serde.SerdeUtils;
2829
import org.slf4j.Logger;
2930
import org.slf4j.LoggerFactory;
3031

3132
import java.util.Collection;
3233

34+
import static com.arangodb.serde.SerdeUtils.constructParametricType;
35+
3336
/**
3437
* @author Mark Vollmary
3538
* @author Michele Rastelli
@@ -51,8 +54,8 @@ public <T> DocumentCreateEntity<T> insertDocument(final T value) throws ArangoDB
5154
@Override
5255
public <T> DocumentCreateEntity<T> insertDocument(final T value, final DocumentCreateOptions options)
5356
throws ArangoDBException {
54-
return executor
55-
.execute(insertDocumentRequest(value, options), insertDocumentResponseDeserializer(value, options));
57+
return executor.execute(insertDocumentRequest(value, options),
58+
constructParametricType(DocumentCreateEntity.class, value.getClass()));
5659
}
5760

5861
@Override
@@ -142,7 +145,7 @@ public <T> DocumentUpdateEntity<T> replaceDocument(final String key, final T val
142145
public <T> DocumentUpdateEntity<T> replaceDocument(
143146
final String key, final T value, final DocumentReplaceOptions options) throws ArangoDBException {
144147
return executor.execute(replaceDocumentRequest(key, value, options),
145-
replaceDocumentResponseDeserializer(value, options));
148+
constructParametricType(DocumentUpdateEntity.class, value.getClass()));
146149
}
147150

148151
@Override
@@ -156,7 +159,7 @@ public <T> MultiDocumentEntity<DocumentUpdateEntity<T>> replaceDocuments(
156159
final Collection<T> values, final DocumentReplaceOptions options) throws ArangoDBException {
157160
final DocumentReplaceOptions params = (options != null ? options : new DocumentReplaceOptions());
158161
return executor
159-
.execute(replaceDocumentsRequest(values, params), replaceDocumentsResponseDeserializer(values, params));
162+
.execute(replaceDocumentsRequest(values, params), replaceDocumentsResponseDeserializer(values));
160163
}
161164

162165
@Override
@@ -165,6 +168,7 @@ public <T> DocumentUpdateEntity<T> updateDocument(final String key, final T valu
165168
}
166169

167170
@Override
171+
@SuppressWarnings("unchecked")
168172
public <T> DocumentUpdateEntity<T> updateDocument(
169173
final String key, final T value, final DocumentUpdateOptions options) throws ArangoDBException {
170174
return updateDocument(key, value, options, (Class<T>) value.getClass());
@@ -174,7 +178,7 @@ public <T> DocumentUpdateEntity<T> updateDocument(
174178
public <T, U> DocumentUpdateEntity<U> updateDocument(
175179
final String key, final T value, final DocumentUpdateOptions options, final Class<U> returnType) throws ArangoDBException {
176180
return executor.execute(updateDocumentRequest(key, value, options),
177-
updateDocumentResponseDeserializer(value, options, returnType));
181+
constructParametricType(DocumentUpdateEntity.class, returnType));
178182
}
179183

180184
@Override
@@ -184,9 +188,10 @@ public <T> MultiDocumentEntity<DocumentUpdateEntity<T>> updateDocuments(final Co
184188
}
185189

186190
@Override
191+
@SuppressWarnings("unchecked")
187192
public <T> MultiDocumentEntity<DocumentUpdateEntity<T>> updateDocuments(
188193
final Collection<T> values, final DocumentUpdateOptions options) throws ArangoDBException {
189-
return updateDocuments(values, options, values.isEmpty() ? null : (Class<T>) values.iterator().next().getClass());
194+
return updateDocuments(values, options, values.isEmpty() ? null : (Class<T>) getCollectionContentClass(values));
190195
}
191196

192197
@Override
@@ -200,13 +205,14 @@ public <T, U> MultiDocumentEntity<DocumentUpdateEntity<U>> updateDocuments(
200205
@Override
201206
public DocumentDeleteEntity<Void> deleteDocument(final String key) throws ArangoDBException {
202207
return executor.execute(deleteDocumentRequest(key, new DocumentDeleteOptions()),
203-
deleteDocumentResponseDeserializer(Void.class));
208+
constructParametricType(DocumentDeleteEntity.class, Void.class));
204209
}
205210

206211
@Override
207212
public <T> DocumentDeleteEntity<T> deleteDocument(
208213
final String key, final Class<T> type, final DocumentDeleteOptions options) throws ArangoDBException {
209-
return executor.execute(deleteDocumentRequest(key, options), deleteDocumentResponseDeserializer(type));
214+
return executor.execute(deleteDocumentRequest(key, options),
215+
constructParametricType(DocumentDeleteEntity.class, type));
210216
}
211217

212218
@Override

src/main/java/com/arangodb/internal/ArangoDatabaseImpl.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
import java.util.Collections;
3939
import java.util.Map;
4040

41+
import static com.arangodb.serde.SerdeUtils.constructListType;
42+
4143
/**
4244
* @author Mark Vollmary
4345
* @author Michele Rastelli
@@ -264,13 +266,13 @@ public QueryTrackingPropertiesEntity setQueryTrackingProperties(final QueryTrack
264266
@Override
265267
public Collection<QueryEntity> getCurrentlyRunningQueries() throws ArangoDBException {
266268
return executor.execute(getCurrentlyRunningQueriesRequest(),
267-
SerdeUtils.INSTANCE.constructListType(QueryEntity.class));
269+
constructListType(QueryEntity.class));
268270
}
269271

270272
@Override
271273
public Collection<QueryEntity> getSlowQueries() throws ArangoDBException {
272274
return executor.execute(getSlowQueriesRequest(),
273-
SerdeUtils.INSTANCE.constructListType(QueryEntity.class));
275+
constructListType(QueryEntity.class));
274276
}
275277

276278
@Override

src/main/java/com/arangodb/internal/InternalArangoCollection.java

+10-39
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
import java.lang.reflect.Type;
3636
import java.util.*;
3737

38+
import static com.arangodb.serde.SerdeUtils.constructListType;
39+
import static com.arangodb.serde.SerdeUtils.constructParametricType;
40+
3841
/**
3942
* @author Mark Vollmary
4043
* @author Michele Rastelli
@@ -93,14 +96,6 @@ protected <T> Request insertDocumentRequest(final T value, final DocumentCreateO
9396
return request;
9497
}
9598

96-
protected <T> ResponseDeserializer<DocumentCreateEntity<T>> insertDocumentResponseDeserializer(
97-
final T value, final DocumentCreateOptions options) {
98-
return response -> {
99-
Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentCreateEntity.class, value.getClass());
100-
return getSerde().deserialize(response.getBody(), type);
101-
};
102-
}
103-
10499
protected <T> Request insertDocumentsRequest(final Collection<T> values, final DocumentCreateOptions params) {
105100
final Request request = request(db.dbName(), RequestType.POST, PATH_API_DOCUMENT, name);
106101
request.putQueryParam(ArangoRequestParam.WAIT_FOR_SYNC, params.getWaitForSync());
@@ -130,7 +125,7 @@ protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentCreateEntity<T>>>
130125
errors.add(error);
131126
documentsAndErrors.add(error);
132127
} else {
133-
Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentCreateEntity.class, userDataClass);
128+
Type type = constructParametricType(DocumentCreateEntity.class, userDataClass);
134129
final DocumentCreateEntity<T> doc = getSerde().deserialize(next, type);
135130
docs.add(doc);
136131
documentsAndErrors.add(doc);
@@ -234,14 +229,6 @@ protected <T> Request replaceDocumentRequest(
234229
return request;
235230
}
236231

237-
protected <T> ResponseDeserializer<DocumentUpdateEntity<T>> replaceDocumentResponseDeserializer(
238-
final T value, final DocumentReplaceOptions options) {
239-
return response -> {
240-
Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, value.getClass());
241-
return getSerde().deserialize(response.getBody(), type);
242-
};
243-
}
244-
245232
protected <T> Request replaceDocumentsRequest(final Collection<T> values, final DocumentReplaceOptions params) {
246233
final Request request = request(db.dbName(), RequestType.PUT, PATH_API_DOCUMENT, name);
247234
request.putHeaderParam(ArangoRequestParam.IF_MATCH, params.getIfMatch());
@@ -256,7 +243,7 @@ protected <T> Request replaceDocumentsRequest(final Collection<T> values, final
256243
}
257244

258245
protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocumentsResponseDeserializer(
259-
final Collection<T> values, final DocumentReplaceOptions params) {
246+
final Collection<T> values) {
260247
return response -> {
261248
Class<?> userDataClass = getCollectionContentClass(values);
262249
final MultiDocumentEntity<DocumentUpdateEntity<T>> multiDocument = new MultiDocumentEntity<>();
@@ -271,7 +258,7 @@ protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentUpdateEntity<T>>>
271258
errors.add(error);
272259
documentsAndErrors.add(error);
273260
} else {
274-
Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, userDataClass);
261+
Type type = constructParametricType(DocumentUpdateEntity.class, userDataClass);
275262
final DocumentUpdateEntity<T> doc = getSerde().deserialize(next, type);
276263
docs.add(doc);
277264
documentsAndErrors.add(doc);
@@ -301,14 +288,6 @@ protected <T> Request updateDocumentRequest(final String key, final T value, fin
301288
return request;
302289
}
303290

304-
protected <T, U> ResponseDeserializer<DocumentUpdateEntity<U>> updateDocumentResponseDeserializer(
305-
final T value, final DocumentUpdateOptions options, final Class<U> returnType) {
306-
return response -> {
307-
Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, returnType);
308-
return getSerde().deserialize(response.getBody(), type);
309-
};
310-
}
311-
312291
protected <T> Request updateDocumentsRequest(final Collection<T> values, final DocumentUpdateOptions params) {
313292
final Request request = request(db.dbName(), RequestType.PATCH, PATH_API_DOCUMENT, name);
314293
final Boolean keepNull = params.getKeepNull();
@@ -340,7 +319,7 @@ protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentUpdateEntity<T>>>
340319
errors.add(error);
341320
documentsAndErrors.add(error);
342321
} else {
343-
Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentUpdateEntity.class, returnType);
322+
Type type = constructParametricType(DocumentUpdateEntity.class, returnType);
344323
final DocumentUpdateEntity<T> doc = getSerde().deserialize(next, type);
345324
docs.add(doc);
346325
documentsAndErrors.add(doc);
@@ -365,14 +344,6 @@ protected Request deleteDocumentRequest(final String key, final DocumentDeleteOp
365344
return request;
366345
}
367346

368-
protected <T> ResponseDeserializer<DocumentDeleteEntity<T>> deleteDocumentResponseDeserializer(
369-
final Class<T> userDataClass) {
370-
return response -> {
371-
Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentDeleteEntity.class, userDataClass);
372-
return getSerde().deserialize(response.getBody(), type);
373-
};
374-
}
375-
376347
protected <T> Request deleteDocumentsRequest(final Collection<T> keys, final DocumentDeleteOptions options) {
377348
final Request request = request(db.dbName(), RequestType.DELETE, PATH_API_DOCUMENT, name);
378349
final DocumentDeleteOptions params = (options != null ? options : new DocumentDeleteOptions());
@@ -399,7 +370,7 @@ protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentDeleteEntity<T>>>
399370
errors.add(error);
400371
documentsAndErrors.add(error);
401372
} else {
402-
Type type = SerdeUtils.INSTANCE.constructParametricType(DocumentDeleteEntity.class, userDataClass);
373+
Type type = constructParametricType(DocumentDeleteEntity.class, userDataClass);
403374
final DocumentDeleteEntity<T> doc = getSerde().deserialize(next, type);
404375
docs.add(doc);
405376
documentsAndErrors.add(doc);
@@ -514,7 +485,7 @@ protected Request getIndexesRequest() {
514485

515486
protected ResponseDeserializer<Collection<IndexEntity>> getIndexesResponseDeserializer() {
516487
return response -> getSerde().deserialize(response.getBody(), "/indexes",
517-
SerdeUtils.INSTANCE.constructListType(IndexEntity.class));
488+
constructListType(IndexEntity.class));
518489
}
519490

520491
protected Request truncateRequest(final CollectionTruncateOptions options) {
@@ -584,7 +555,7 @@ protected ResponseDeserializer<Permissions> getPermissionsResponseDeserialzer()
584555
return response -> getSerde().deserialize(response.getBody(), ArangoResponseField.RESULT_JSON_POINTER, Permissions.class);
585556
}
586557

587-
private Class<?> getCollectionContentClass(Collection<?> c) {
558+
protected Class<?> getCollectionContentClass(Collection<?> c) {
588559
if (c == null || c.isEmpty()) {
589560
return null;
590561
}

0 commit comments

Comments
 (0)