public VPackSlice keyAt(final int index) { if (!isObject()) { throw new VPackValueTypeException(ValueType.OBJECT); } return getNthKey(index); }
public Iterator<Entry<String, VPackSlice>> objectIterator() { if (isObject()) { return new ObjectIterator(this); } else { throw new VPackValueTypeException(ValueType.OBJECT); } }
private Type determineType(final VPackSlice vpack, final Type type) { if (!vpack.isObject()) { return type; } final VPackSlice clazz = vpack.get(typeKey); try { return clazz.isString() ? Class.forName(clazz.getAsString()) : type; } catch (final ClassNotFoundException e) { throw new VPackParserException(e); } }
public VPackSlice valueAt(final int index) { if (!isObject()) { throw new VPackValueTypeException(ValueType.OBJECT); } final VPackSlice key = getNthKey(index); return new VPackSlice(vpack, key.start + key.getByteSize()); }
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; }
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()); }
@Override public VPackSlice deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException, JsonProcessingException { if (p instanceof VPackParser) { final VPackSlice vpack = ((VPackParser) p).getVPack(); // consume each element if (vpack.isArray() || vpack.isObject()) { for (int i = 0; i < vpack.size() + 1; i++) { p.nextToken(); } } return vpack; } return new VPackSlice(p.getBinaryValue()); } };
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; }
@Override public Integer deserialize(final Response response) throws VPackException { // compatibility with ArangoDB < 3.4 // https://docs.arangodb.com/devel/Manual/ReleaseNotes/UpgradingChanges34.html Integer count = null; final VPackSlice body = response.getBody(); if (body.isObject()) { final VPackSlice deletedCount = body.get("deletedCount"); if (deletedCount.isInteger()) { count = deletedCount.getAsInt(); } } return count; }; };
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()); }
@SuppressWarnings("unchecked") @Override public DocumentCreateEntity<T> deserialize(final Response response) throws VPackException { 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((T) util(Serializer.CUSTOM).deserialize(newDoc, value.getClass())); } final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, value.getClass())); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map<DocumentField.Type, String> values = new HashMap<DocumentField.Type, String>(); 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; } };
@SuppressWarnings("unchecked") @Override public DocumentUpdateEntity<T> deserialize(final Response response) throws VPackException { 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((T) util(Serializer.CUSTOM).deserialize(newDoc, value.getClass())); } final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, value.getClass())); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map<DocumentField.Type, String> values = new HashMap<DocumentField.Type, String>(); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); } return doc; } };
@SuppressWarnings("unchecked") @Override public DocumentUpdateEntity<T> deserialize(final Response response) throws VPackException { 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((T) util(Serializer.CUSTOM).deserialize(newDoc, value.getClass())); } final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, value.getClass())); } if (options == null || Boolean.TRUE != options.getSilent()) { final Map<DocumentField.Type, String> values = new HashMap<DocumentField.Type, String>(); values.put(DocumentField.Type.REV, doc.getRev()); executor.documentCache().setValues(value, values); } return doc; } };
final DocumentDeleteEntity<T> doc = util().deserialize(next, DocumentDeleteEntity.class); final VPackSlice oldDoc = next.get(OLD); if (oldDoc.isObject()) { doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, type));
public ObjectIterator(final VPackSlice slice) throws VPackValueTypeException { super(slice); if (!slice.isObject()) { throw new VPackValueTypeException(ValueType.OBJECT); } if (size > 0) { final byte head = slice.head(); if (head == 0x14) { current = slice.keyAt(0).getStart(); } else { current = slice.getStart() + slice.findDataOffset(); } } }
@SuppressWarnings("unchecked") @Override public DocumentDeleteEntity<T> deserialize(final Response response) throws VPackException { final VPackSlice body = response.getBody(); final DocumentDeleteEntity<T> doc = util().deserialize(body, DocumentDeleteEntity.class); final VPackSlice oldDoc = body.get(OLD); if (oldDoc.isObject()) { doc.setOld((T) util(Serializer.CUSTOM).deserialize(oldDoc, type)); } return doc; } };
private Type getType(final VPackSlice vpack) { final Type type; if (vpack.isObject()) { type = Map.class; } else if (vpack.isString()) { type = String.class; } else if (vpack.isBoolean()) { type = Boolean.class; } else if (vpack.isArray()) { type = Collection.class; } else if (vpack.isDate()) { type = Date.class; } else if (vpack.isDouble()) { type = Double.class; } else if (vpack.isNumber()) { type = Number.class; } else if (vpack.isCustom()) { type = String.class; } else { type = null; } return type; }
private Object readEntity( final TypeInformation<?> type, final VPackSlice source, final ArangoPersistentEntity<?> entity) { if (!source.isObject()) { throw new MappingException( String.format("Can't read entity type %s from VPack type %s!", type, source.getType())); } final EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); final ParameterValueProvider<ArangoPersistentProperty> provider = getParameterProvider(entity, source); final Object instance = instantiator.createInstance(entity, provider); final PersistentPropertyAccessor<?> accessor = entity.getPropertyAccessor(instance); final String id = source.get(_ID).isString() ? source.get(_ID).getAsString() : null; entity.doWithProperties((final ArangoPersistentProperty property) -> { if (!entity.isConstructorArgument(property)) { final VPackSlice value = source.get(property.getFieldName()); readProperty(entity, id, accessor, value, property); } }); entity.doWithAssociations((final Association<ArangoPersistentProperty> association) -> { final ArangoPersistentProperty property = association.getInverse(); if (!entity.isConstructorArgument(property)) { final VPackSlice value = source.get(property.getFieldName()); readProperty(entity, id, accessor, value, property); } }); return instance; }
private Object readEntity( final TypeInformation<?> type, final VPackSlice source, final ArangoPersistentEntity<?> entity) { if (!source.isObject()) { throw new MappingException( String.format("Can't read entity type %s from VPack type %s!", type, source.getType())); } final EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity); final ParameterValueProvider<ArangoPersistentProperty> provider = getParameterProvider(entity, source); final Object instance = instantiator.createInstance(entity, provider); final PersistentPropertyAccessor<?> accessor = entity.getPropertyAccessor(instance); final String id = source.get(_ID).isString() ? source.get(_ID).getAsString() : null; entity.doWithProperties((final ArangoPersistentProperty property) -> { if (!entity.isConstructorArgument(property)) { final VPackSlice value = source.get(property.getFieldName()); readProperty(entity, id, accessor, value, property); } }); entity.doWithAssociations((final Association<ArangoPersistentProperty> association) -> { final ArangoPersistentProperty property = association.getInverse(); if (!entity.isConstructorArgument(property)) { final VPackSlice value = source.get(property.getFieldName()); readProperty(entity, id, accessor, value, property); } }); return instance; }
if (isString()) { length = getStringLength(); } else if (!isArray() && !isObject()) { throw new VPackValueTypeException(ValueType.ARRAY, ValueType.OBJECT, ValueType.STRING); } else {