Java Code Examples for com.arangodb.velocypack.VPackSlice#get()
The following examples show how to use
com.arangodb.velocypack.VPackSlice#get() .
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: ArangoResultConverter.java From spring-data with Apache License 2.0 | 6 votes |
/** * Construct a GeoResult from the given object * * @param object * object representing one document in the result * @return GeoResult object */ private GeoResult<?> buildGeoResult(final Object object) { if (object == null || !(object instanceof VPackSlice)) { return null; } final VPackSlice slice = (VPackSlice) object; final VPackSlice distSlice = slice.get("_distance"); final Double distanceInMeters = distSlice.isDouble() ? distSlice.getAsDouble() : null; if (distanceInMeters == null) { return null; } final Object entity = operations.getConverter().read(domainClass, slice); final Distance distance = new Distance(distanceInMeters / 1000, Metrics.KILOMETERS); return new GeoResult<>(entity, distance); }
Example 2
Source File: VPackExample.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
@Test public void buildObject() throws VPackException { final VPackBuilder builder = new VPackBuilder(); builder.add(ValueType.OBJECT);// object start builder.add("foo", 1); // add field "foo" with value 1 builder.add("bar", 2); // add field "bar" with value 2 builder.close();// object end final VPackSlice slice = builder.slice(); // create slice assertThat(slice.isObject(), is(true)); assertThat(slice.size(), is(2)); // number of fields final VPackSlice foo = slice.get("foo"); // get field "foo" assertThat(foo.isInteger(), is(true)); assertThat(foo.getAsInt(), is(1)); final VPackSlice bar = slice.get("bar"); // get field "bar" assertThat(bar.isInteger(), is(true)); assertThat(bar.getAsInt(), is(2)); // iterate over the fields for (final Iterator<Entry<String, VPackSlice>> iterator = slice.objectIterator(); iterator.hasNext(); ) { final Entry<String, VPackSlice> field = iterator.next(); assertThat(field.getValue().isInteger(), is(true)); } }
Example 3
Source File: VPackExample.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
@Test public void buildObjectInObject() throws VPackException { final VPackBuilder builder = new VPackBuilder(); builder.add(ValueType.OBJECT);// object start builder.add("foo", ValueType.OBJECT); // add object in field "foo" builder.add("bar", 2); // add field "bar" with value 2 to object "foo" builder.close();// object "foo" end builder.close();// object end final VPackSlice slice = builder.slice(); // create slice assertThat(slice.isObject(), is(true)); final VPackSlice foo = slice.get("foo"); assertThat(foo.isObject(), is(true)); final VPackSlice bar = foo.get("bar"); // get field "bar" from "foo" assertThat(bar.isInteger(), is(true)); }
Example 4
Source File: VPackExample.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
@Test public void buildObjectInObject() throws VPackException { final VPackBuilder builder = new VPackBuilder(); builder.add(ValueType.OBJECT);// object start builder.add("foo", ValueType.OBJECT); // add object in field "foo" builder.add("bar", 2); // add field "bar" with value 2 to object "foo" builder.close();// object "foo" end builder.close();// object end final VPackSlice slice = builder.slice(); // create slice assertThat(slice.isObject(), is(true)); final VPackSlice foo = slice.get("foo"); assertThat(foo.isObject(), is(true)); final VPackSlice bar = foo.get("bar"); // get field "bar" from "foo" assertThat(bar.isInteger(), is(true)); }
Example 5
Source File: InternalArangoCollection.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
protected <T, U> ResponseDeserializer<DocumentUpdateEntity<U>> updateDocumentResponseDeserializer( final T value, final DocumentUpdateOptions options, final Class<U> returnType) { return response -> { final VPackSlice body = response.getBody(); final DocumentUpdateEntity<U> doc = util().deserialize(body, DocumentUpdateEntity.class); final VPackSlice newDoc = body.get(NEW); if (newDoc.isObject()) { doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, returnType)); } final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, returnType)); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map<DocumentField.Type, String> values = new HashMap<>(); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); } return doc; }; }
Example 6
Source File: InternalArangoCollection.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
protected <T> ResponseDeserializer<DocumentUpdateEntity<T>> replaceDocumentResponseDeserializer( final T value, final DocumentReplaceOptions options) { return response -> { final VPackSlice body = response.getBody(); final DocumentUpdateEntity<T> doc = util().deserialize(body, DocumentUpdateEntity.class); final VPackSlice newDoc = body.get(NEW); if (newDoc.isObject()) { doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, value.getClass())); } final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, value.getClass())); } if (options == null || Boolean.TRUE != options.getSilent()) { 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: InternalArangoCollection.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
protected <T> ResponseDeserializer<DocumentCreateEntity<T>> insertDocumentResponseDeserializer( final T value, final DocumentCreateOptions options) { return response -> { final VPackSlice body = response.getBody(); final DocumentCreateEntity<T> doc = util().deserialize(body, DocumentCreateEntity.class); final VPackSlice newDoc = body.get(NEW); if (newDoc.isObject()) { doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, value.getClass())); } final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, value.getClass())); } if (options == null || Boolean.TRUE != options.getSilent()) { 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 8
Source File: VPackExample.java From arangodb-java-driver-async with Apache License 2.0 | 6 votes |
@Test public void buildObjectInObject() throws VPackException { final VPackBuilder builder = new VPackBuilder(); builder.add(ValueType.OBJECT);// object start builder.add("foo", ValueType.OBJECT); // add object in field "foo" builder.add("bar", 2); // add field "bar" with value 2 to object "foo" builder.close();// object "foo" end builder.close();// object end final VPackSlice slice = builder.slice(); // create slice assertThat(slice.isObject(), is(true)); final VPackSlice foo = slice.get("foo"); assertThat(foo.isObject(), is(true)); final VPackSlice bar = foo.get("bar"); // get field "bar" from "foo" assertThat(bar.isInteger(), is(true)); }
Example 9
Source File: VPackExample.java From arangodb-java-driver-async with Apache License 2.0 | 6 votes |
@Test public void buildObject() throws VPackException { final VPackBuilder builder = new VPackBuilder(); builder.add(ValueType.OBJECT);// object start builder.add("foo", 1); // add field "foo" with value 1 builder.add("bar", 2); // add field "bar" with value 2 builder.close();// object end final VPackSlice slice = builder.slice(); // create slice assertThat(slice.isObject(), is(true)); assertThat(slice.size(), is(2)); // number of fields final VPackSlice foo = slice.get("foo"); // get field "foo" assertThat(foo.isInteger(), is(true)); assertThat(foo.getAsInt(), is(1)); final VPackSlice bar = slice.get("bar"); // get field "bar" assertThat(bar.isInteger(), is(true)); assertThat(bar.getAsInt(), is(2)); // iterate over the fields for (final Iterator<Entry<String, VPackSlice>> iterator = slice.objectIterator(); iterator.hasNext();) { final Entry<String, VPackSlice> field = iterator.next(); assertThat(field.getValue().isInteger(), is(true)); } }
Example 10
Source File: ArangoResultConverter.java From spring-data with Apache License 2.0 | 6 votes |
/** * Build a GeoResult from the given ArangoCursor * * @param cursor * query result from driver * @return GeoResult object */ private GeoResult<?> buildGeoResult(final ArangoCursor<?> cursor) { GeoResult<?> geoResult = null; while (cursor.hasNext() && geoResult == null) { final Object object = cursor.next(); if (!(object instanceof VPackSlice)) { continue; } final VPackSlice slice = (VPackSlice) object; final VPackSlice distSlice = slice.get("_distance"); final Double distanceInMeters = distSlice.isDouble() ? distSlice.getAsDouble() : null; if (distanceInMeters == null) { continue; } final Object entity = operations.getConverter().read(domainClass, slice); final Distance distance = new Distance(distanceInMeters / 1000, Metrics.KILOMETERS); geoResult = new GeoResult<>(entity, distance); } return geoResult; }
Example 11
Source File: InternalArangoCollection.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentUpdateEntity<T>>> updateDocumentsResponseDeserializer( final Class<T> returnType) { return response -> { final MultiDocumentEntity<DocumentUpdateEntity<T>> multiDocument = new MultiDocumentEntity<>(); final Collection<DocumentUpdateEntity<T>> docs = new ArrayList<>(); final Collection<ErrorEntity> errors = new ArrayList<>(); final Collection<Object> documentsAndErrors = new ArrayList<>(); final VPackSlice body = response.getBody(); if (body.isArray()) { for (final Iterator<VPackSlice> iterator = body.arrayIterator(); iterator.hasNext(); ) { final VPackSlice next = iterator.next(); if (next.get(ArangoResponseField.ERROR).isTrue()) { final ErrorEntity error = util().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { final DocumentUpdateEntity<T> doc = util().deserialize(next, DocumentUpdateEntity.class); final VPackSlice newDoc = next.get(NEW); if (newDoc.isObject()) { doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, returnType)); } final VPackSlice oldDoc = next.get(OLD); if (oldDoc.isObject()) { doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, returnType)); } docs.add(doc); documentsAndErrors.add(doc); } } } multiDocument.setDocuments(docs); multiDocument.setErrors(errors); multiDocument.setDocumentsAndErrors(documentsAndErrors); return multiDocument; }; }
Example 12
Source File: BaseDocumentTest.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void serialize() throws VPackException { final BaseDocument entity = new BaseDocument(); entity.setKey("test"); entity.setRevision("test"); entity.addAttribute("a", "a"); final Builder builder = new VPack.Builder(); builder.registerModule(new VPackDriverModule()); final VPack vpacker = builder.build(); final VPackSlice vpack = vpacker.serialize(entity); assertThat(vpack, is(notNullValue())); assertThat(vpack.isObject(), is(true)); assertThat(vpack.size(), is(3)); final VPackSlice key = vpack.get("_key"); assertThat(key.isString(), is(true)); assertThat(key.getAsString(), is("test")); final VPackSlice rev = vpack.get("_rev"); assertThat(rev.isString(), is(true)); assertThat(rev.getAsString(), is("test")); final VPackSlice a = vpack.get("a"); assertThat(a.isString(), is(true)); assertThat(a.getAsString(), is("a")); }
Example 13
Source File: InternalArangoCollection.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected ResponseDeserializer<Permissions> getPermissionsResponseDeserialzer() { return response -> { final VPackSlice body = response.getBody(); if (body != null) { final VPackSlice result = body.get(ArangoResponseField.RESULT); if (!result.isNone()) { return util().deserialize(result, Permissions.class); } } return null; }; }
Example 14
Source File: InternalArangoDatabase.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected ResponseDeserializer<Permissions> getPermissionsResponseDeserialzer() { return response -> { final VPackSlice body = response.getBody(); if (body != null) { final VPackSlice result = body.get(ArangoResponseField.RESULT); if (!result.isNone()) { return util().deserialize(result, Permissions.class); } } return null; }; }
Example 15
Source File: DefaultArangoTypeMapper.java From spring-data with Apache License 2.0 | 5 votes |
public Alias readAliasFrom(final VPackSlice source) { if (source.isArray()) { return Alias.NONE; } if (source.isObject()) { final VPackSlice typeKey = source.get(this.typeKey); return Alias.ofNullable(typeKey.isString() ? typeKey.getAsString() : null); } throw new IllegalArgumentException("Cannot read alias from VPack type " + source.getType()); }
Example 16
Source File: InternalArangoDatabase.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected ResponseDeserializer<Collection<AqlFunctionEntity>> getAqlFunctionsResponseDeserializer() { return response -> { final VPackSlice body = response.getBody(); // compatibility with ArangoDB < 3.4 // https://www.arangodb.com/docs/stable/release-notes-upgrading-changes34.html final VPackSlice result = body.isArray() ? body : body.get(ArangoResponseField.RESULT); return util().deserialize(result, new Type<Collection<AqlFunctionEntity>>() { }.getType()); }; }
Example 17
Source File: InternalArangoDatabase.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected <T> ResponseDeserializer<T> transactionResponseDeserializer(final Class<T> type) { return response -> { final VPackSlice body = response.getBody(); if (body != null) { final VPackSlice result = body.get(ArangoResponseField.RESULT); if (!result.isNone() && !result.isNull()) { return util(Serializer.CUSTOM).deserialize(result, type); } } return null; }; }
Example 18
Source File: VPackDeserializers.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
protected static FieldLink deserializeField(final Entry<String, VPackSlice> field) { final VPackSlice value = field.getValue(); final FieldLink link = FieldLink.on(field.getKey()); final VPackSlice analyzers = value.get("analyzers"); if (analyzers.isArray()) { final Iterator<VPackSlice> analyzerIterator = analyzers.arrayIterator(); for (; analyzerIterator.hasNext(); ) { link.analyzers(analyzerIterator.next().getAsString()); } } final VPackSlice includeAllFields = value.get("includeAllFields"); if (includeAllFields.isBoolean()) { link.includeAllFields(includeAllFields.getAsBoolean()); } final VPackSlice trackListPositions = value.get("trackListPositions"); if (trackListPositions.isBoolean()) { link.trackListPositions(trackListPositions.getAsBoolean()); } final VPackSlice storeValues = value.get("storeValues"); if (storeValues.isString()) { link.storeValues(StoreValuesType.valueOf(storeValues.getAsString().toUpperCase())); } final VPackSlice fields = value.get("fields"); if (fields.isObject()) { final Iterator<Entry<String, VPackSlice>> fieldsIterator = fields.objectIterator(); for (; fieldsIterator.hasNext(); ) { link.fields(deserializeField(fieldsIterator.next())); } } return link; }
Example 19
Source File: InternalArangoCollection.java From arangodb-java-driver with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentCreateEntity<T>>> insertDocumentsResponseDeserializer( final Collection<T> values, final DocumentCreateOptions params) { return response -> { Class<T> type = null; if (Boolean.TRUE == params.getReturnNew()) { if (!values.isEmpty()) { type = (Class<T>) values.iterator().next().getClass(); } } final MultiDocumentEntity<DocumentCreateEntity<T>> multiDocument = new MultiDocumentEntity<>(); final Collection<DocumentCreateEntity<T>> docs = new ArrayList<>(); final Collection<ErrorEntity> errors = new ArrayList<>(); final Collection<Object> documentsAndErrors = new ArrayList<>(); final VPackSlice body = response.getBody(); if (body.isArray()) { for (final Iterator<VPackSlice> iterator = body.arrayIterator(); iterator.hasNext(); ) { final VPackSlice next = iterator.next(); if (next.get(ArangoResponseField.ERROR).isTrue()) { final ErrorEntity error = util().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { final DocumentCreateEntity<T> doc = util().deserialize(next, DocumentCreateEntity.class); final VPackSlice newDoc = next.get(NEW); if (newDoc.isObject()) { doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, type)); } final VPackSlice oldDoc = next.get(OLD); if (oldDoc.isObject()) { doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, type)); } docs.add(doc); documentsAndErrors.add(doc); } } } multiDocument.setDocuments(docs); multiDocument.setErrors(errors); multiDocument.setDocumentsAndErrors(documentsAndErrors); return multiDocument; }; }
Example 20
Source File: InternalArangoCollection.java From arangodb-java-driver with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") protected <T> ResponseDeserializer<MultiDocumentEntity<DocumentUpdateEntity<T>>> replaceDocumentsResponseDeserializer( final Collection<T> values, final DocumentReplaceOptions params) { return response -> { Class<T> type = null; if (Boolean.TRUE == params.getReturnNew() || Boolean.TRUE == params.getReturnOld()) { if (!values.isEmpty()) { type = (Class<T>) values.iterator().next().getClass(); } } final MultiDocumentEntity<DocumentUpdateEntity<T>> multiDocument = new MultiDocumentEntity<>(); final Collection<DocumentUpdateEntity<T>> docs = new ArrayList<>(); final Collection<ErrorEntity> errors = new ArrayList<>(); final Collection<Object> documentsAndErrors = new ArrayList<>(); final VPackSlice body = response.getBody(); if (body.isArray()) { for (final Iterator<VPackSlice> iterator = body.arrayIterator(); iterator.hasNext(); ) { final VPackSlice next = iterator.next(); if (next.get(ArangoResponseField.ERROR).isTrue()) { final ErrorEntity error = util().deserialize(next, ErrorEntity.class); errors.add(error); documentsAndErrors.add(error); } else { final DocumentUpdateEntity<T> doc = util().deserialize(next, DocumentUpdateEntity.class); final VPackSlice newDoc = next.get(NEW); if (newDoc.isObject()) { doc.setNew(util(Serializer.CUSTOM).deserialize(newDoc, type)); } final VPackSlice oldDoc = next.get(OLD); if (oldDoc.isObject()) { doc.setOld(util(Serializer.CUSTOM).deserialize(oldDoc, type)); } docs.add(doc); documentsAndErrors.add(doc); } } } multiDocument.setDocuments(docs); multiDocument.setErrors(errors); multiDocument.setDocumentsAndErrors(documentsAndErrors); return multiDocument; }; }