|
22 | 22 |
|
23 | 23 | import java.lang.reflect.Type;
|
24 | 24 |
|
| 25 | +import com.arangodb.entity.Entity; |
25 | 26 | import com.arangodb.internal.util.ArangoSerializationFactory;
|
26 | 27 | import com.arangodb.internal.util.ArangoSerializationFactory.Serializer;
|
27 |
| -import com.arangodb.util.ArangoSerialization; |
28 | 28 | import com.arangodb.velocypack.exception.VPackException;
|
29 | 29 | import com.arangodb.velocystream.Response;
|
30 | 30 |
|
31 | 31 | /**
|
32 | 32 | * @author Mark Vollmary
|
33 |
| - * |
34 | 33 | */
|
35 | 34 | public abstract class ArangoExecutor {
|
36 | 35 |
|
37 |
| - public static interface ResponseDeserializer<T> { |
38 |
| - T deserialize(Response response) throws VPackException; |
39 |
| - } |
| 36 | + public static interface ResponseDeserializer<T> { |
| 37 | + T deserialize(Response response) throws VPackException; |
| 38 | + } |
40 | 39 |
|
41 |
| - private final DocumentCache documentCache; |
42 |
| - private final ArangoSerialization util; |
| 40 | + private final DocumentCache documentCache; |
| 41 | + private final ArangoSerializationFactory util; |
43 | 42 |
|
44 |
| - protected ArangoExecutor(final ArangoSerializationFactory util, final DocumentCache documentCache) { |
45 |
| - super(); |
46 |
| - this.documentCache = documentCache; |
47 |
| - this.util = util.get(Serializer.INTERNAL); |
48 |
| - } |
| 43 | + protected ArangoExecutor(final ArangoSerializationFactory util, final DocumentCache documentCache) { |
| 44 | + super(); |
| 45 | + this.documentCache = documentCache; |
| 46 | + this.util = util; |
| 47 | + } |
49 | 48 |
|
50 |
| - public DocumentCache documentCache() { |
51 |
| - return documentCache; |
52 |
| - } |
| 49 | + public DocumentCache documentCache() { |
| 50 | + return documentCache; |
| 51 | + } |
53 | 52 |
|
54 |
| - @SuppressWarnings("unchecked") |
55 |
| - protected <T> T createResult(final Type type, final Response response) { |
56 |
| - return (T) ((type != Void.class && response.getBody() != null) ? util.deserialize(response.getBody(), type) |
57 |
| - : null); |
58 |
| - } |
| 53 | + @SuppressWarnings("unchecked") |
| 54 | + protected <T> T createResult(final Type type, final Response response) { |
| 55 | + if (type != Void.class && response.getBody() != null) { |
| 56 | + if (type instanceof Class && Entity.class.isAssignableFrom((Class) type) ) { |
| 57 | + return (T) util.get(Serializer.INTERNAL).deserialize(response.getBody(), type); |
| 58 | + } else { |
| 59 | + return (T) util.get(Serializer.CUSTOM).deserialize(response.getBody(), type); |
| 60 | + } |
| 61 | + } else { |
| 62 | + return (T) null; |
| 63 | + } |
| 64 | + } |
59 | 65 |
|
60 | 66 | }
|
0 commit comments