Java Code Examples for com.arangodb.velocypack.VPackBuilder#close()

The following examples show how to use com.arangodb.velocypack.VPackBuilder#close() . 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: DefaultArangoConverter.java    From spring-data with Apache License 2.0 6 votes vote down vote up
private void writeMap(
	final String attribute,
	final Map<? extends Object, ? extends Object> source,
	final VPackBuilder sink,
	final TypeInformation<?> definedType) {

	sink.add(attribute, ValueType.OBJECT);

	for (final Entry<? extends Object, ? extends Object> entry : source.entrySet()) {
		final Object key = entry.getKey();
		final Object value = entry.getValue();

		writeInternal(convertId(key), value, sink, getNonNullMapValueType(definedType));
	}

	sink.close();
}
 
Example 2
Source File: DefaultArangoConverter.java    From spring-data with Apache License 2.0 6 votes vote down vote up
private void writeArray(
	final String attribute,
	final Object source,
	final VPackBuilder sink,
	final TypeInformation<?> definedType) {

	if (byte[].class.equals(source.getClass())) {
		sink.add(attribute, Base64Utils.encodeToString((byte[]) source));
	}

	else {
		sink.add(attribute, ValueType.ARRAY);
		for (int i = 0; i < Array.getLength(source); ++i) {
			final Object element = Array.get(source, i);
			writeInternal(null, element, sink, getNonNullComponentType(definedType));
		}
		sink.close();
	}
}
 
Example 3
Source File: VPackExample.java    From arangodb-java-driver-async with 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 4
Source File: VPackExample.java    From arangodb-java-driver-async with 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 5
Source File: VPackExample.java    From arangodb-java-driver with 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 6
Source File: VPackExample.java    From arangodb-java-driver with 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 7
Source File: BaseDocumentTest.java    From arangodb-java-driver with Apache License 2.0 6 votes vote down vote up
@Test
public void deserialize() throws VPackException {
    final VPackBuilder builder = new VPackBuilder();
    builder.add(ValueType.OBJECT);
    builder.add("_id", "test/test");
    builder.add("_key", "test");
    builder.add("_rev", "test");
    builder.add("a", "a");
    builder.close();

    final VPack.Builder vbuilder = new VPack.Builder();
    vbuilder.registerModule(new VPackDriverModule());
    final VPack vpacker = vbuilder.build();

    final BaseDocument entity = vpacker.deserialize(builder.slice(), BaseDocument.class);
    assertThat(entity.getId(), is(notNullValue()));
    assertThat(entity.getId(), is("test/test"));
    assertThat(entity.getKey(), is(notNullValue()));
    assertThat(entity.getKey(), is("test"));
    assertThat(entity.getRevision(), is(notNullValue()));
    assertThat(entity.getRevision(), is("test"));
    assertThat(entity.getProperties().size(), is(1));
    assertThat(String.valueOf(entity.getAttribute("a")), is("a"));
}
 
Example 8
Source File: VPackExample.java    From arangodb-java-driver with 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 9
Source File: VPackExample.java    From arangodb-java-driver with 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 10
Source File: DefaultArangoConverter.java    From spring-data with Apache License 2.0 5 votes vote down vote up
private void writeCollection(
	final String attribute,
	final Object source,
	final VPackBuilder sink,
	final TypeInformation<?> definedType) {

	sink.add(attribute, ValueType.ARRAY);

	for (final Object entry : asCollection(source)) {
		writeInternal(null, entry, sink, getNonNullComponentType(definedType));
	}

	sink.close();
}
 
Example 11
Source File: VPackSerializers.java    From arangodb-java-driver with Apache License 2.0 5 votes vote down vote up
private static void serializeFieldLinks(final VPackBuilder builder, final Collection<FieldLink> links) {
    if (!links.isEmpty()) {
        builder.add("fields", ValueType.OBJECT);
        for (final FieldLink fieldLink : links) {
            builder.add(fieldLink.getName(), ValueType.OBJECT);
            final Collection<String> analyzers = fieldLink.getAnalyzers();
            if (!analyzers.isEmpty()) {
                builder.add("analyzers", ValueType.ARRAY);
                for (final String analyzer : analyzers) {
                    builder.add(analyzer);
                }
                builder.close();
            }
            final Boolean includeAllFields = fieldLink.getIncludeAllFields();
            if (includeAllFields != null) {
                builder.add("includeAllFields", includeAllFields);
            }
            final Boolean trackListPositions = fieldLink.getTrackListPositions();
            if (trackListPositions != null) {
                builder.add("trackListPositions", trackListPositions);
            }
            final StoreValuesType storeValues = fieldLink.getStoreValues();
            if (storeValues != null) {
                builder.add("storeValues", storeValues.name().toLowerCase());
            }
            serializeFieldLinks(builder, fieldLink.getFields());
            builder.close();
        }
        builder.close();
    }
}