/** * Insert a record in the database. Any field/value pairs in the specified * values HashMap will be written into the record with the specified record * key. * * @param table * The name of the table * @param key * The record key of the record to insert. * @param values * A HashMap of field/value pairs to insert in the record * @return Zero on success, a non-zero error code on error. See the * {@link DB} class's description for a discussion of error codes. */ @Override public Status insert(String table, String key, Map<String, ByteIterator> values) { try { BaseDocument toInsert = new BaseDocument(key); for (Map.Entry<String, ByteIterator> entry : values.entrySet()) { toInsert.addAttribute(entry.getKey(), byteIteratorToString(entry.getValue())); } DocumentCreateOptions options = new DocumentCreateOptions().waitForSync(waitForSync); arangoDB.db(databaseName).collection(table).insertDocument(toInsert, options); return Status.OK; } catch (ArangoDBException e) { logger.error("Exception while trying insert {} {} with ex {}", table, key, e.toString()); } return Status.ERROR; }
try { if (!transactionUpdate) { BaseDocument updateDoc = new BaseDocument(); for (Entry<String, ByteIterator> field : values.entrySet()) { updateDoc.addAttribute(field.getKey(), byteIteratorToString(field.getValue()));
@SuppressWarnings("unchecked") @Override public BaseDocument deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException, JsonProcessingException { return new BaseDocument(p.readValueAs(Map.class)); } };
@SuppressWarnings("rawtypes") @Override public BaseDocument deserialize( final VPackSlice parent, final VPackSlice vpack, final VPackDeserializationContext context) throws VPackException { return new BaseDocument((Map) context.deserialize(vpack, Map.class)); } };
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)); } }
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)); } }
static BaseDocument getBaseDocument(DocumentEntity entity) { Map<String, Object> map = new HashMap<>(); for (Document document : entity.getDocuments()) { map.put(document.getName(), convert(document.getValue())); } return new BaseDocument(map); }
@Override public <K, V> void put(K key, V value) throws NullPointerException { Objects.requireNonNull(key, "Key is required"); Objects.requireNonNull(value, "value is required"); BaseDocument baseDocument = new BaseDocument(); baseDocument.setKey(key.toString()); baseDocument.addAttribute(VALUE, JSONB.toJson(value)); if (arangoDB.db(bucketName).collection(namespace).documentExists(key.toString())) { arangoDB.db(bucketName).collection(namespace).deleteDocument(key.toString()); } arangoDB.db(bucketName).collection(namespace) .insertDocument(baseDocument); }