Java Code Examples for com.arangodb.velocypack.VPackBuilder#add()
The following examples show how to use
com.arangodb.velocypack.VPackBuilder#add() .
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 |
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 |
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 |
@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 |
@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 |
@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 |
@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 |
@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 |
@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 |
@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 |
private void addKeyIfNecessary( final ArangoPersistentEntity<?> entity, final Object source, final VPackBuilder sink) { if (!entity.hasIdProperty() || entity.getIdentifierAccessor(source).getIdentifier() == null) { final Object id = entity.getArangoIdAccessor(source).getIdentifier(); if (id != null) { sink.add(_KEY, MetadataUtils.determineDocumentKeyFromId((String) id)); } } }
Example 11
Source File: DefaultArangoConverter.java From spring-data with Apache License 2.0 | 5 votes |
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 12
Source File: DefaultArangoConverter.java From spring-data with Apache License 2.0 | 5 votes |
private void writeBaseDocument( final String attribute, final BaseDocument source, final VPackBuilder sink, final TypeInformation<?> definedType) { final VPackBuilder builder = new VPackBuilder(); writeMap(attribute, source.getProperties(), builder, definedType); builder.add(_ID, source.getId()); builder.add(_KEY, source.getKey()); builder.add(_REV, source.getRevision()); sink.add(attribute, builder.slice()); }
Example 13
Source File: DefaultArangoConverter.java From spring-data with Apache License 2.0 | 5 votes |
private void writeBaseEdgeDocument( final String attribute, final BaseEdgeDocument source, final VPackBuilder sink, final TypeInformation<?> definedType) { final VPackBuilder builder = new VPackBuilder(); writeMap(attribute, source.getProperties(), builder, definedType); builder.add(_ID, source.getId()); builder.add(_KEY, source.getKey()); builder.add(_REV, source.getRevision()); builder.add(_FROM, source.getFrom()); builder.add(_TO, source.getTo()); sink.add(attribute, builder.slice()); }
Example 14
Source File: VPackSerializers.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
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(); } }
Example 15
Source File: DefaultArangoConverter.java From spring-data with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private void writeSimple(final String attribute, final Object source, final VPackBuilder sink) { if (source == null) { sink.add(ValueType.NULL); } // com.arangodb.* else if (source instanceof VPackSlice) { sink.add(attribute, (VPackSlice) source); } // else if (source instanceof DBDocumentEntity) { writeMap(attribute, (Map<String, Object>) source, sink, ClassTypeInformation.MAP); } // java.lang.* else if (source instanceof Boolean) { sink.add(attribute, (Boolean) source); } // else if (source instanceof Byte) { sink.add(attribute, (Byte) source); } // else if (source instanceof Character) { sink.add(attribute, (Character) source); } // else if (source instanceof Short) { sink.add(attribute, (Short) source); } // else if (source instanceof Integer) { sink.add(attribute, (Integer) source); } // else if (source instanceof Long) { sink.add(attribute, (Long) source); } // else if (source instanceof Float) { sink.add(attribute, (Float) source); } // else if (source instanceof Double) { sink.add(attribute, (Double) source); } // else if (source instanceof String) { sink.add(attribute, (String) source); } // else if (source instanceof Class) { sink.add(attribute, ((Class<?>) source).getName()); } // else if (source instanceof Enum) { sink.add(attribute, ((Enum<?>) source).name()); } // primitive arrays else if (ClassUtils.isPrimitiveArray(source.getClass())) { writeArray(attribute, source, sink, ClassTypeInformation.OBJECT); } // java.util.Date / java.sql.Date / java.sql.Timestamp else if (source instanceof Date) { sink.add(attribute, DateUtil.format((Date) source)); } // java.math.* else if (source instanceof BigInteger) { sink.add(attribute, (BigInteger) source); } // else if (source instanceof BigDecimal) { sink.add(attribute, (BigDecimal) source); } // java.time.* else if (source instanceof Instant) { sink.add(attribute, JavaTimeUtil.format((Instant) source)); } // else if (source instanceof LocalDate) { sink.add(attribute, JavaTimeUtil.format((LocalDate) source)); } // else if (source instanceof LocalDateTime) { sink.add(attribute, JavaTimeUtil.format((LocalDateTime) source)); } // else if (source instanceof OffsetDateTime) { sink.add(attribute, JavaTimeUtil.format((OffsetDateTime) source)); } // else if (source instanceof ZonedDateTime) { sink.add(attribute, JavaTimeUtil.format((ZonedDateTime) source)); } // else { throw new MappingException(String.format("Type %s is not a simple type!", source.getClass())); } }
Example 16
Source File: DefaultArangoTypeMapper.java From spring-data with Apache License 2.0 | 4 votes |
public void writeTypeTo(final VPackBuilder sink, final Object alias) { if (this.typeKey != null) { sink.add(this.typeKey, alias.toString()); } }