com.arangodb.entity.DocumentField Java Examples
The following examples show how to use
com.arangodb.entity.DocumentField.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocumentCacheTest.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
@Test public void setValues() { final DocumentCache cache = new DocumentCache(); final BaseDocument doc = new BaseDocument(); assertThat(doc.getId(), is(nullValue())); assertThat(doc.getKey(), is(nullValue())); assertThat(doc.getRevision(), is(nullValue())); final Map<DocumentField.Type, String> values = new HashMap<>(); values.put(DocumentField.Type.ID, "testId"); values.put(DocumentField.Type.KEY, "testKey"); values.put(DocumentField.Type.REV, "testRev"); cache.setValues(doc, values); assertThat(doc.getId(), is("testId")); assertThat(doc.getKey(), is("testKey")); assertThat(doc.getRevision(), is("testRev")); }
Example #2
Source File: InternalArangoEdgeCollection.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected <T> ResponseDeserializer<EdgeEntity> insertEdgeResponseDeserializer(final T value) { return response -> { final VPackSlice body = response.getBody().get(EDGE); final EdgeEntity doc = util().deserialize(body, EdgeEntity.class); final Map<DocumentField.Type, String> values = new HashMap<>(); values.put(DocumentField.Type.ID, doc.getId()); values.put(DocumentField.Type.KEY, doc.getKey()); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); return doc; }; }
Example #3
Source File: InternalArangoEdgeCollection.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected <T> ResponseDeserializer<EdgeUpdateEntity> replaceEdgeResponseDeserializer(final T value) { return response -> { final VPackSlice body = response.getBody().get(EDGE); final EdgeUpdateEntity doc = util().deserialize(body, EdgeUpdateEntity.class); final Map<DocumentField.Type, String> values = new HashMap<>(); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); return doc; }; }
Example #4
Source File: InternalArangoEdgeCollection.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected <T> ResponseDeserializer<EdgeUpdateEntity> updateEdgeResponseDeserializer(final T value) { return response -> { final VPackSlice body = response.getBody().get(EDGE); final EdgeUpdateEntity doc = util().deserialize(body, EdgeUpdateEntity.class); final Map<DocumentField.Type, String> values = new HashMap<>(); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); return doc; }; }
Example #5
Source File: InternalArangoVertexCollection.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected <T> ResponseDeserializer<VertexEntity> insertVertexResponseDeserializer(final T value) { return response -> { final VPackSlice body = response.getBody().get(VERTEX); final VertexEntity doc = util().deserialize(body, VertexEntity.class); final Map<DocumentField.Type, String> values = new HashMap<>(); values.put(DocumentField.Type.ID, doc.getId()); values.put(DocumentField.Type.KEY, doc.getKey()); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); return doc; }; }
Example #6
Source File: InternalArangoVertexCollection.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected <T> ResponseDeserializer<VertexUpdateEntity> replaceVertexResponseDeserializer(final T value) { return response -> { final VPackSlice body = response.getBody().get(VERTEX); final VertexUpdateEntity doc = util().deserialize(body, VertexUpdateEntity.class); final Map<DocumentField.Type, String> values = new HashMap<>(); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); return doc; }; }
Example #7
Source File: InternalArangoVertexCollection.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected <T> ResponseDeserializer<VertexUpdateEntity> updateVertexResponseDeserializer(final T value) { return response -> { final VPackSlice body = response.getBody().get(VERTEX); final VertexUpdateEntity doc = util().deserialize(body, VertexUpdateEntity.class); final Map<DocumentField.Type, String> values = new HashMap<>(); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); return doc; }; }
Example #8
Source File: DocumentCache.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
public void setValues(final Object doc, final Map<DocumentField.Type, String> values) throws ArangoDBException { try { final Map<DocumentField.Type, Field> fields = getFields(doc.getClass()); for (final Entry<DocumentField.Type, String> value : values.entrySet()) { final Field field = fields.get(value.getKey()); if (field != null) { field.set(doc, value.getValue()); } } } catch (final IllegalArgumentException | IllegalAccessException e) { throw new ArangoDBException(e); } }
Example #9
Source File: DocumentCache.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
private Map<DocumentField.Type, Field> getFields(final Class<?> clazz) { Map<DocumentField.Type, Field> fields = new HashMap<>(); if (!isTypeRestricted(clazz)) { fields = cache.get(clazz); if (fields == null) { fields = createFields(clazz); cache.put(clazz, fields); } } return fields; }
Example #10
Source File: DocumentCache.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
private Map<DocumentField.Type, Field> createFields(final Class<?> clazz) { final Map<DocumentField.Type, Field> fields = new HashMap<>(); Class<?> tmp = clazz; final Collection<DocumentField.Type> values = new ArrayList<>( Arrays.asList(DocumentField.Type.values())); while (tmp != null && tmp != Object.class && values.size() > 0) { final Field[] declaredFields = tmp.getDeclaredFields(); for (int i = 0; i < declaredFields.length && values.size() > 0; i++) { findAnnotation(values, fields, declaredFields[i]); } tmp = tmp.getSuperclass(); } return fields; }
Example #11
Source File: DocumentCache.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
private void findAnnotation( final Collection<Type> values, final Map<DocumentField.Type, Field> fields, final Field field) { final DocumentField annotation = field.getAnnotation(DocumentField.class); if (annotation != null && !field.isSynthetic() && !Modifier.isStatic(field.getModifiers()) && String.class.isAssignableFrom(field.getType())) { final Type value = annotation.value(); if (values.contains(value)) { field.setAccessible(true); fields.put(value, field); values.remove(value); } } }
Example #12
Source File: DocumentCacheTest.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void setValuesMap() { final DocumentCache cache = new DocumentCache(); final Map<String, String> map = new HashMap<>(); final Map<DocumentField.Type, String> values = new HashMap<>(); values.put(DocumentField.Type.ID, "testId"); values.put(DocumentField.Type.KEY, "testKey"); values.put(DocumentField.Type.REV, "testRev"); cache.setValues(map, values); assertThat(map.isEmpty(), is(true)); }