/** * Delete a record from the database. * * @param table * The name of the table * @param key * The record key of the record to delete. * @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 delete(String table, String key) { try { arangoDB.db(databaseName).collection(table).deleteDocument(key); return Status.OK; } catch (ArangoDBException e) { logger.error("Exception while trying delete {} {} with ex {}", table, key, e.toString()); } return Status.ERROR; }
arangoDB.db(databaseName).drop(); } catch (ArangoDBException e) { logger.info("Fail to delete DB: {}", databaseName); arangoDB.createDatabase(databaseName); logger.info("Database created: " + databaseName); } catch (ArangoDBException e) { arangoDB.db(databaseName).createCollection(collectionName); logger.info("Collection created: " + collectionName); } catch (ArangoDBException e) {
/** * Cleanup any state for this DB. Called once per DB instance; there is one * DB instance per client thread. * * Actually, one client process will share one DB instance here.(Coincide to * mongoDB driver) */ @Override public void cleanup() throws DBException { if (INIT_COUNT.decrementAndGet() == 0) { arangoDB.shutdown(); arangoDB = null; logger.info("Local cleaned up."); } }
static void checkDatabase(String database, ArangoDB arangoDB) { Objects.requireNonNull(database, "database is required"); try { Collection<String> databases = arangoDB.getDatabases(); if (!databases.contains(database)) { arangoDB.createDatabase(database); } } catch (ArangoDBException e) { LOGGER.log(Level.WARNING, "Failed to create database: " + database, e); } }
public ArangoTemplate(final ArangoDB arango, final String database, final ArangoConverter converter, final PersistenceExceptionTranslator exceptionTranslator) { super(); this.arango = arango._setCursorInitializer(new ArangoCursorInitializer(converter)); this.databaseName = database; this.databaseExpression = PARSER.parseExpression(databaseName, ParserContext.TEMPLATE_EXPRESSION); this.converter = converter; this.exceptionTranslator = exceptionTranslator; this.context = new StandardEvaluationContext(); // set concurrency level to 1 as writes are very rare compared to reads collectionCache = new ConcurrentHashMap<>(8, 0.9f, 1); databaseCache = new ConcurrentHashMap<>(8, 0.9f, 1); version = null; }
@Override public void delete() throws DataAccessException { try { db.arango().deleteUser(username); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } }
@Override public UserEntity create(final String passwd, final UserCreateOptions options) throws DataAccessException { try { return db.arango().createUser(username, passwd); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } }
public ArangoTemplate(final ArangoDB arango, final String database, final ArangoConverter converter, final PersistenceExceptionTranslator exceptionTranslator) { super(); this.arango = arango._setCursorInitializer(new ArangoCursorInitializer(converter)); this.databaseName = database; this.databaseExpression = PARSER.parseExpression(databaseName, ParserContext.TEMPLATE_EXPRESSION); this.converter = converter; this.exceptionTranslator = exceptionTranslator; this.context = new StandardEvaluationContext(); // set concurrency level to 1 as writes are very rare compared to reads collectionCache = new ConcurrentHashMap<>(8, 0.9f, 1); databaseCache = new ConcurrentHashMap<>(8, 0.9f, 1); version = null; }
@Override public void delete() throws DataAccessException { try { db.arango().deleteUser(username); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } }
@Override public UserEntity create(final String passwd, final UserCreateOptions options) throws DataAccessException { try { return db.arango().createUser(username, passwd); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } }
/** * Read a record from the database. Each field/value pair from the result * will be stored in a HashMap. * * @param table * The name of the table * @param key * The record key of the record to read. * @param fields * The list of fields to read, or null for all of them * @param result * A HashMap of field/value pairs for the result * @return Zero on success, a non-zero error code on error or "not found". */ @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { try { VPackSlice document = arangoDB.db(databaseName).collection(table).getDocument(key, VPackSlice.class, null); if (!this.fillMap(result, document, fields)) { return Status.ERROR; } return Status.OK; } catch (ArangoDBException e) { logger.error("Exception while trying read {} {} with ex {}", table, key, e.toString()); } return Status.ERROR; }
throw new ArangoDBGraphException("Unable to read properties", e); db = driver.db(dbname); if (create) { if (!db.exists()) { logger.info("DB not found, attemtping to create it."); try { if (!driver.createDatabase(dbname)) { throw new ArangoDBGraphException("Unable to crate the database " + dbname);
@Override public void close() { arangoDB.shutdown(); }
@Override public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { context.setRootObject(applicationContext); context.setBeanResolver(new BeanFactoryResolver(applicationContext)); context.addPropertyAccessor(new BeanFactoryAccessor()); eventPublisher = applicationContext; arango._setCursorInitializer(new ArangoCursorInitializer(converter, applicationContext)); }
/** * 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; }
@Override public void close() { arangoDB.shutdown(); arangoDBAsync.shutdown(); } }
@Override public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { context.setRootObject(applicationContext); context.setBeanResolver(new BeanFactoryResolver(applicationContext)); context.addPropertyAccessor(new BeanFactoryAccessor()); eventPublisher = applicationContext; arango._setCursorInitializer(new ArangoCursorInitializer(converter, applicationContext)); }
updateDoc.addAttribute(field.getKey(), byteIteratorToString(field.getValue())); arangoDB.db(databaseName).collection(table).updateDocument(key, updateDoc); return Status.OK; } else { options.writeCollections(table); options.params(createDocumentHandle(table, key)); arangoDB.db(databaseName).transaction(transactionAction, Void.class, options); return Status.OK;
/** * Shutdown the client and free resources. */ public void shutdown() { logger.debug("Shutdown"); if (db != null) { if (db.exists()) { db.clearQueryCache(); } } if (driver != null) driver.shutdown(); db = null; driver = null; }
cursor = arangoDB.db(databaseName).query(aqlQuery, bindVars, null, VPackSlice.class); while (cursor.hasNext()) { VPackSlice aDocument = cursor.next();