Java Code Examples for com.arangodb.velocypack.VPackSlice

The following examples show how to use com.arangodb.velocypack.VPackSlice. These examples are extracted from open source projects. 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 Project: spring-data   Source File: ArangoResultConverter.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 2
Source Project: spring-data   Source File: DefaultArangoConverter.java    License: Apache License 2.0 6 votes vote down vote up
private Object readMap(final TypeInformation<?> type, final VPackSlice source) {
	if (!source.isObject()) {
		throw new MappingException(
				String.format("Can't read map type %s from VPack type %s!", type, source.getType()));
	}

	final Class<?> keyType = getNonNullComponentType(type).getType();
	final TypeInformation<?> valueType = getNonNullMapValueType(type);
	final Map<Object, Object> map = CollectionFactory.createMap(type.getType(), keyType, source.size());

	final Iterator<Entry<String, VPackSlice>> iterator = source.objectIterator();

	while (iterator.hasNext()) {
		final Entry<String, VPackSlice> entry = iterator.next();
		if (typeMapper.isTypeKey(entry.getKey())) {
			continue;
		}

		final Object key = convertIfNecessary(entry.getKey(), keyType);
		final VPackSlice value = entry.getValue();

		map.put(key, readInternal(valueType, value));
	}

	return map;
}
 
Example 3
Source Project: spring-data   Source File: DefaultArangoConverter.java    License: Apache License 2.0 6 votes vote down vote up
private Object readCollection(final TypeInformation<?> type, final VPackSlice source) {
	if (!source.isArray()) {
		throw new MappingException(
				String.format("Can't read collection type %s from VPack type %s!", type, source.getType()));
	}

	final TypeInformation<?> componentType = getNonNullComponentType(type);
	final Class<?> collectionType = Iterable.class.equals(type.getType()) ? Collection.class : type.getType();
	final Collection<Object> collection = CollectionFactory.createCollection(collectionType,
		componentType.getType(), source.getLength());

	final Iterator<VPackSlice> iterator = source.arrayIterator();

	while (iterator.hasNext()) {
		final VPackSlice elem = iterator.next();
		collection.add(readInternal(componentType, elem));
	}

	return collection;
}
 
Example 4
Source Project: arangodb-java-driver-async   Source File: VPackExample.java    License: Apache License 2.0 6 votes vote down vote up
@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 5
Source Project: arangodb-java-driver-async   Source File: VPackExample.java    License: Apache License 2.0 6 votes vote down vote up
@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 6
Source Project: arangodb-java-driver   Source File: ArangoDatabaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void transactionallowImplicit() throws InterruptedException, ExecutionException {
    try {
        db.createCollection("someCollection", null).get();
        db.createCollection("someOtherCollection", null).get();
        final String action = "function (params) {" + "var db = require('internal').db;"
                + "return {'a':db.someCollection.all().toArray()[0], 'b':db.someOtherCollection.all().toArray()[0]};"
                + "}";
        final TransactionOptions options = new TransactionOptions().readCollections("someCollection");
        db.transaction(action, VPackSlice.class, options).get();
        try {
            options.allowImplicit(false);
            db.transaction(action, VPackSlice.class, options).get();
            fail();
        } catch (final ExecutionException e) {
            assertThat(e.getCause(), instanceOf(ArangoDBException.class));
        }
    } finally {
        db.collection("someCollection").drop().get();
        db.collection("someOtherCollection").drop().get();
    }
}
 
Example 7
@Test
public void aqlWithLimitQueryAsVPackObject() throws InterruptedException, ExecutionException {
    final String query = "FOR t IN " + COLLECTION_NAME
            + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN t";
    final Map<String, Object> bindVars = new MapBuilder().put("gender", Gender.FEMALE).get();
    db.query(query, bindVars, null, VPackSlice.class)
            .whenComplete((cursor, ex) -> {
                assertThat(cursor, is(notNullValue()));
                cursor.forEachRemaining(vpack -> {
                    assertThat(vpack.get("name").getAsString(),
                            isOneOf("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19"));
                    assertThat(vpack.get("gender").getAsString(), is(Gender.FEMALE.name()));
                    assertThat(vpack.get("age").getAsInt(), isOneOf(21, 23, 25, 27, 29));
                });
            })
            .get();
}
 
Example 8
@Test
public void transactionallowImplicit() throws InterruptedException, ExecutionException {
    try {
        db.createCollection("someCollection", null).get();
        db.createCollection("someOtherCollection", null).get();
        final String action = "function (params) {" + "var db = require('internal').db;"
                + "return {'a':db.someCollection.all().toArray()[0], 'b':db.someOtherCollection.all().toArray()[0]};"
                + "}";
        final TransactionOptions options = new TransactionOptions().readCollections("someCollection");
        db.transaction(action, VPackSlice.class, options).get();
        try {
            options.allowImplicit(false);
            db.transaction(action, VPackSlice.class, options).get();
            fail();
        } catch (final ExecutionException e) {
            assertThat(e.getCause(), instanceOf(ArangoDBException.class));
        }
    } finally {
        db.collection("someCollection").drop().get();
        db.collection("someOtherCollection").drop().get();
    }
}
 
Example 9
@Test
public void shouldIncludeExceptionMessage() throws InterruptedException, ExecutionException {
    final String exceptionMessage = "My error context";
    final String action = "function (params) {" + "throw '" + exceptionMessage + "';" + "}";
    try {
        db.transaction(action, VPackSlice.class, null).get();
        fail();
    } catch (final ExecutionException e) {
        assertThat(e.getCause(), instanceOf(ArangoDBException.class));
        ArangoDBException cause = ((ArangoDBException) e.getCause());
        assertThat(cause.getErrorNum(), is(1650));
        if (isAtLeastVersion(3, 4)) {
            assertThat(cause.getErrorMessage(), is(exceptionMessage));
        }
    }
}
 
Example 10
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 11
protected <T> ResponseDeserializer<MultiDocumentEntity<T>> getDocumentsResponseDeserializer(
        final Class<T> type, final DocumentReadOptions options) {
    return response -> {
        final MultiDocumentEntity<T> multiDocument = new MultiDocumentEntity<>();
        final Collection<T> docs = new ArrayList<>();
        final Collection<ErrorEntity> errors = new ArrayList<>();
        final Collection<Object> documentsAndErrors = new ArrayList<>();
        final VPackSlice body = response.getBody();
        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 T doc = util(Serializer.CUSTOM).deserialize(next, type);
                docs.add(doc);
                documentsAndErrors.add(doc);
            }
        }
        multiDocument.setDocuments(docs);
        multiDocument.setErrors(errors);
        multiDocument.setDocumentsAndErrors(documentsAndErrors);
        return multiDocument;
    };
}
 
Example 12
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 13
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 14
@Test
public void aqlWithLimitQueryAsVPackArray() throws InterruptedException, ExecutionException {
    final String query = "FOR t IN " + COLLECTION_NAME
            + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN [t.name, t.gender, t.age]";
    final Map<String, Object> bindVars = new MapBuilder().put("gender", Gender.FEMALE).get();
    db.query(query, bindVars, null, VPackSlice.class)
            .whenComplete((cursor, ex) -> {
                assertThat(cursor, is(notNullValue()));
                cursor.forEachRemaining(vpack -> {
                    assertThat(vpack.get(0).getAsString(),
                            isOneOf("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19"));
                    assertThat(vpack.get(1).getAsString(), is(Gender.FEMALE.name()));
                    assertThat(vpack.get(2).getAsInt(), isOneOf(21, 23, 25, 27, 29));
                });
            })
            .get();
}
 
Example 15
Source Project: arangodb-java-driver   Source File: ArangoCollectionImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Boolean documentExists(final String key, final DocumentExistsOptions options) throws ArangoDBException {
    try {
        executor.execute(documentExistsRequest(key, options), VPackSlice.class);
        return true;
    } catch (final ArangoDBException e) {

        // handle Response: 404, Error: 1655 - transaction not found
        if (e.getErrorNum() != null && e.getErrorNum() == 1655) {
            throw e;
        }

        if ((e.getResponseCode() != null && (e.getResponseCode() == 404 || e.getResponseCode() == 304
                || e.getResponseCode() == 412)) && (options == null || options.isCatchException())) {
            return false;
        }
        throw e;
    }
}
 
Example 16
Source Project: arangodb-java-driver   Source File: VPackExample.java    License: Apache License 2.0 6 votes vote down vote up
@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 17
Source Project: arangodb-java-driver   Source File: VstCommunication.java    License: Apache License 2.0 6 votes vote down vote up
protected Collection<Chunk> buildChunks(final Message message) {
    final Collection<Chunk> chunks = new ArrayList<>();
    final VPackSlice head = message.getHead();
    int size = head.getByteSize();
    final VPackSlice body = message.getBody();
    if (body != null) {
        size += body.getByteSize();
    }
    final int n = size / chunksize;
    final int numberOfChunks = (size % chunksize != 0) ? (n + 1) : n;
    int off = 0;
    for (int i = 0; size > 0; i++) {
        final int len = Math.min(chunksize, size);
        final long messageLength = (i == 0 && numberOfChunks > 1) ? size : -1L;
        final Chunk chunk = new Chunk(message.getId(), i, numberOfChunks, messageLength, off, len);
        size -= len;
        off += len;
        chunks.add(chunk);
    }
    return chunks;
}
 
Example 18
Source Project: arangodb-java-driver   Source File: VPackExample.java    License: Apache License 2.0 6 votes vote down vote up
@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 19
Source Project: arangodb-java-driver   Source File: VPackExample.java    License: Apache License 2.0 6 votes vote down vote up
@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 20
protected <E, V> ResponseDeserializer<TraversalEntity<V, E>> executeTraversalResponseDeserializer(
        final Class<V> vertexClass, final Class<E> edgeClass) {
    return response -> {
        final TraversalEntity<V, E> result = new TraversalEntity<>();
        final VPackSlice visited = response.getBody().get(ArangoResponseField.RESULT).get("visited");
        result.setVertices(deserializeVertices(vertexClass, visited));

        final Collection<PathEntity<V, E>> paths = new ArrayList<>();
        for (final Iterator<VPackSlice> iterator = visited.get("paths").arrayIterator(); iterator.hasNext(); ) {
            final PathEntity<V, E> path = new PathEntity<>();
            final VPackSlice next = iterator.next();
            path.setEdges(deserializeEdges(edgeClass, next));
            path.setVertices(deserializeVertices(vertexClass, next));
            paths.add(path);
        }
        result.setPaths(paths);
        return result;
    };
}
 
Example 21
@Test
public void serialize() {
    final BaseDocument entity = new BaseDocument();
    entity.addAttribute("foo", "bar");
    final VPackSlice vpack = util.serialize(entity);
    assertThat(vpack.get("foo").isString(), is(true));
    assertThat(vpack.get("foo").getAsString(), is("bar"));
}
 
Example 22
@Test
public void skipSerializeNullValues() {
    final BaseDocument entity = new BaseDocument();
    entity.addAttribute("bar", null);
    final VPackSlice vpack = util.serialize(entity);
    assertThat(vpack.get("bar").isNone(), is(true));
}
 
Example 23
Source Project: spring-data   Source File: DefaultArangoConverter.java    License: Apache License 2.0 5 votes vote down vote up
private void readProperty(
	final ArangoPersistentEntity<?> entity,
	final String parentId,
	final PersistentPropertyAccessor<?> accessor,
	final VPackSlice source,
	final ArangoPersistentProperty property) {

	final Object propertyValue = readPropertyValue(entity, parentId, source, property);
	if (propertyValue != null || !property.getType().isPrimitive()) {
		accessor.setProperty(property, propertyValue);
	}
}
 
Example 24
Source Project: spring-data   Source File: DefaultArangoConverter.java    License: Apache License 2.0 5 votes vote down vote up
private Object readPropertyValue(
	final ArangoPersistentEntity<?> entity,
	final String parentId,
	final VPackSlice source,
	final ArangoPersistentProperty property) {

	final Optional<Ref> ref = property.getRef();
	if (ref.isPresent()) {
		return readReference(source, property, ref.get()).orElse(null);
	}

	final Optional<Relations> relations = property.getRelations();
	if (relations.isPresent()) {
		return readRelation(entity, parentId, source, property, relations.get()).orElse(null);
	}

	final Optional<From> from = property.getFrom();
	if (from.isPresent()) {
		return readRelation(entity, parentId, source, property, from.get()).orElse(null);
	}

	final Optional<To> to = property.getTo();
	if (to.isPresent()) {
		return readRelation(entity, parentId, source, property, to.get()).orElse(null);
	}

	return readInternal(property.getTypeInformation(), source);
}
 
Example 25
Source Project: spring-data   Source File: DefaultArangoConverter.java    License: Apache License 2.0 5 votes vote down vote up
private <A extends Annotation> Optional<Object> readRelation(
	final ArangoPersistentEntity<?> entity,
	final String parentId,
	final VPackSlice source,
	final ArangoPersistentProperty property,
	final A annotation) {

	final Class<? extends Annotation> collectionType = entity.findAnnotation(Edge.class) != null ? Edge.class
			: Document.class;
	final Optional<RelationResolver<Annotation>> resolver = resolverFactory.getRelationResolver(annotation,
		collectionType);

	if (!resolver.isPresent()) {
		return Optional.empty();
	}

	else if (property.isCollectionLike()) {
		if (parentId == null) {
			return Optional.empty();
		}
		return resolver.map(res -> res.resolveMultiple(parentId, property.getTypeInformation(), annotation));
	}

	else if (source.isString()) {
		return resolver.map(res -> res.resolveOne(source.getAsString(), property.getTypeInformation(), annotation));
	}

	else {
		return resolver.map(res -> res.resolveOne(parentId, property.getTypeInformation(), annotation));
	}

}
 
Example 26
Source Project: spring-data   Source File: DefaultArangoConverter.java    License: Apache License 2.0 5 votes vote down vote up
private BaseDocument readBaseDocument(final Class<?> type, final VPackSlice source) {
	@SuppressWarnings("unchecked")
	final Map<String, Object> properties = (Map<String, Object>) readMap(ClassTypeInformation.MAP, source);

	if (BaseDocument.class.equals(type)) {
		return new BaseDocument(properties);
	} //
	else if (BaseEdgeDocument.class.equals(type)) {
		return new BaseEdgeDocument(properties);
	} //
	else {
		throw new MappingException(String.format("Can't read type %s as %s!", type, BaseDocument.class));
	}
}
 
Example 27
protected ResponseDeserializer<Collection<AnalyzerEntity>> getAnalyzersResponseDeserializer() {
    return response -> {
        final VPackSlice result = response.getBody().get(ArangoResponseField.RESULT);
        return util().deserialize(result, new Type<Collection<AnalyzerEntity>>() {
        }.getType());
    };
}
 
Example 28
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 29
@Test
public void aqlWithLimitQueryAsVPackObject() {
    final String query = "FOR t IN " + COLLECTION_NAME
            + " FILTER t.age >= 20 && t.age < 30 && t.gender == @gender RETURN t";
    final Map<String, Object> bindVars = new MapBuilder().put("gender", Gender.FEMALE).get();
    final ArangoCursor<VPackSlice> cursor = db.query(query, bindVars, null, VPackSlice.class);
    assertThat(cursor, is(notNullValue()));
    for (; cursor.hasNext(); ) {
        final VPackSlice vpack = cursor.next();
        assertThat(vpack.get("name").getAsString(),
                isOneOf("TestUser11", "TestUser13", "TestUser15", "TestUser17", "TestUser19"));
        assertThat(vpack.get("gender").getAsString(), is(Gender.FEMALE.name()));
        assertThat(vpack.get("age").getAsInt(), isOneOf(21, 23, 25, 27, 29));
    }
}
 
Example 30
Source Project: arangodb-java-driver   Source File: VPackDeserializers.java    License: Apache License 2.0 5 votes vote down vote up
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;
}