Search in sources :

Example 1 with DocumentCreateOptions

use of com.arangodb.model.DocumentCreateOptions in project YCSB by brianfrankcooper.

the class ArangoDB3Client method insert.

/**
   * 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, HashMap<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;
}
Also used : StringByteIterator(com.yahoo.ycsb.StringByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) BaseDocument(com.arangodb.entity.BaseDocument) DocumentCreateOptions(com.arangodb.model.DocumentCreateOptions) HashMap(java.util.HashMap) Map(java.util.Map) ArangoDBException(com.arangodb.ArangoDBException)

Aggregations

ArangoDBException (com.arangodb.ArangoDBException)1 BaseDocument (com.arangodb.entity.BaseDocument)1 DocumentCreateOptions (com.arangodb.model.DocumentCreateOptions)1 ByteIterator (com.yahoo.ycsb.ByteIterator)1 StringByteIterator (com.yahoo.ycsb.StringByteIterator)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1