Entry<String, VPackSlice> next = iterator.next(); VPackSlice value = next.getValue(); if (value.isString()) { resultMap.put(next.getKey(), stringToByteIterator(value.getAsString())); } else if (!value.isCustom()) { for (String field : fields) { VPackSlice value = document.get(field); if (value.isString()) { resultMap.put(field, stringToByteIterator(value.getAsString())); } else if (!value.isCustom()) {
public BigDecimal getAsBigDecimal() { if (isString()) { return new BigDecimal(getAsString()); } else if (isDouble()) { return BigDecimal.valueOf(getAsDouble()); } else { throw new VPackValueTypeException(ValueType.STRING, ValueType.DOUBLE); } }
public ArangoPropertyValueProvider(final ArangoPersistentEntity<?> entity, final VPackSlice source) { this.entity = entity; this.source = source; this.id = source.get(_ID).isString() ? source.get(_ID).getAsString() : null; }
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 ArangoPropertyValueProvider(final ArangoPersistentEntity<?> entity, final VPackSlice source) { this.entity = entity; this.source = source; this.id = source.get(_ID).isString() ? source.get(_ID).getAsString() : null; }
@Override public java.sql.Date deserialize( final VPackSlice parent, final VPackSlice vpack, final VPackDeserializationContext context) throws VPackException { final java.sql.Date date; if (vpack.isString()) { try { date = new java.sql.Date(DateUtil.parse(vpack.getAsString()).getTime()); } catch (final ParseException e) { throw new VPackParserException(e); } } else { date = vpack.getAsSQLDate(); } return date; } };
@Override public Timestamp deserialize( final VPackSlice parent, final VPackSlice vpack, final VPackDeserializationContext context) throws VPackException { final java.sql.Timestamp date; if (vpack.isString()) { try { date = new java.sql.Timestamp(DateUtil.parse(vpack.getAsString()).getTime()); } catch (final ParseException e) { throw new VPackParserException(e); } } else { date = vpack.getAsSQLTimestamp(); } return date; } };
@Override @SuppressWarnings("unchecked") public <T> T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException { try { final T doc; if (type == String.class && !vpack.isString()) { doc = (T) vpackParser.toJson(vpack, true); } else { doc = vpacker.deserialize(vpack, type); } return doc; } catch (final VPackException e) { throw new ArangoDBException(e); } } }
public String getAsString() { if (!isString()) { throw new VPackValueTypeException(ValueType.STRING); } return isLongString() ? getLongString() : getShortString(); }
protected VPackSlice makeKey() throws VPackKeyTypeException, VPackNeedAttributeTranslatorException { if (isString()) { return this; } if (isInteger()) { if (VPackSlice.attributeTranslator == null) { throw new VPackNeedAttributeTranslatorException(); } return translateUnchecked(); } throw new VPackKeyTypeException("Cannot translate key of this type"); }
@Override public ReplicationFactor deserialize( final VPackSlice parent, final VPackSlice vpack, final VPackDeserializationContext context) throws VPackException { final ReplicationFactor replicationFactor = new ReplicationFactor(); if (vpack.isString() && vpack.getAsString().equals("satellite")) { replicationFactor.setSatellite(true); } else { replicationFactor.setReplicationFactor(vpack.getAsInt()); } return replicationFactor; } };
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()); }
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()); }
public BigInteger getAsBigInteger() { if (isString()) { return new BigInteger(getAsString()); } else if (isSmallInt() || isInt()) { return BigInteger.valueOf(getAsLong()); } else if (isUInt()) { return NumberUtil.toBigInteger(vpack, start + 1, length()); } else { throw new VPackValueTypeException(ValueType.STRING, ValueType.INT, ValueType.UINT, ValueType.SMALLINT); } }
@SuppressWarnings("unchecked") @Override public <T> T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException { try { final T doc; if (type == String.class && !vpack.isString()) { final JsonNode node = vpackMapper.readTree( Arrays.copyOfRange(vpack.getBuffer(), vpack.getStart(), vpack.getStart() + vpack.getByteSize())); doc = (T) jsonMapper.writeValueAsString(node); } else { doc = vpackMapper.readValue(vpack.getBuffer(), vpack.getStart(), vpack.getStart() + vpack.getByteSize(), (Class<T>) type); } return doc; } catch (final IOException e) { throw new ArangoDBException(e); } }
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)); } }
@Override public Date deserialize( final VPackSlice parent, final VPackSlice vpack, final VPackDeserializationContext context) throws VPackException { final Date date; if (vpack.isString()) { try { date = DateUtil.parse(vpack.getAsString()); } catch (final ParseException e) { throw new VPackParserException(e); } } else { date = vpack.getAsDate(); } return date; } };
@Override public byte[] getBinaryValue(final Base64Variant b64variant) throws IOException { if (currentValue.isBinary()) { return currentValue.getAsBinary(); } else if (currentValue.isString()) { return b64variant.decode(currentValue.getAsString()); } return Arrays.copyOfRange(currentValue.getBuffer(), currentValue.getStart(), currentValue.getStart() + currentValue.getByteSize()); }
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; }
@Override public ConsolidationPolicy deserialize( final VPackSlice parent, final VPackSlice vpack, final VPackDeserializationContext context) throws VPackException { final VPackSlice type = vpack.get("type"); if (type.isString()) { final ConsolidationPolicy consolidate = ConsolidationPolicy .of(ConsolidationType.valueOf(type.getAsString().toUpperCase())); final VPackSlice threshold = vpack.get("threshold"); if (threshold.isNumber()) { consolidate.threshold(threshold.getAsDouble()); } final VPackSlice segmentThreshold = vpack.get("segmentThreshold"); if (segmentThreshold.isInteger()) { consolidate.segmentThreshold(segmentThreshold.getAsLong()); } return consolidate; } return null; } };