/** * 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; }
cursor = arangoDB.db(databaseName).query(aqlQuery, bindVars, null, VPackSlice.class); while (cursor.hasNext()) { VPackSlice aDocument = cursor.next();
arangoDB.db(databaseName).drop(); } catch (ArangoDBException e) { logger.info("Fail to delete DB: {}", databaseName); arangoDB.db(databaseName).createCollection(collectionName); logger.info("Collection created: " + collectionName); } catch (ArangoDBException e) {
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;
private ArangoCollection _collection( final String name, final ArangoPersistentEntity<?> persistentEntity, final CollectionCreateOptions options) { final ArangoDatabase db = db(); final Class<?> entityClass = persistentEntity != null ? persistentEntity.getType() : null; final CollectionCacheValue value = collectionCache.computeIfAbsent(new CollectionCacheKey(db.name(), name), key -> { final ArangoCollection collection = db.collection(name); if (!collection.exists()) { collection.create(options); } return new CollectionCacheValue(collection); }); final Collection<Class<?>> entities = value.getEntities(); final ArangoCollection collection = value.getCollection(); if (persistentEntity != null && !entities.contains(entityClass)) { value.addEntityClass(entityClass); ensureCollectionIndexes(collection(collection), persistentEntity); } return collection; }
@Override public void dropDatabase() throws DataAccessException { final ArangoDatabase db = db(); try { db.drop(); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } databaseCache.remove(db.name()); collectionCache.keySet().stream().filter(key -> key.getDb().equals(db.name())) .forEach(key -> collectionCache.remove(key)); }
@Override public UserEntity createUser(final String user, final String passwd, final UserCreateOptions options) throws ArangoDBException { return executor.execute(createUserRequest(db().name(), user, passwd, options), UserEntity.class); }
@Override public ArangoDBVersion getVersion() throws ArangoDBException { return db().getVersion(); }
boolean dropCollections) { if (db != null) { ArangoGraph graph = db.graph(name); if (graph.exists()) { Collection<String> edgeDefinitions = dropCollections ? graph.getEdgeDefinitions() : Collections.emptyList(); for (String definitionName : edgeDefinitions) { String collectioName = definitionName; if (db.collection(collectioName).exists()) { db.collection(collectioName).drop(); if (db.collection(collectioName).exists()) { db.collection(collectioName).drop();
/** * 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; }
/** * Delete the current database accessed by the driver. * * @throws ArangoDBGraphException if there was an error */ public void deleteDb() throws ArangoDBGraphException { logger.info("Delete current db"); if (db !=null) { try { db.drop(); } catch (ArangoDBException e) { throw ArangoDBExceptions.getArangoDBException(e); } } }
public static void checkCollection(String bucketName, ArangoDB arangoDB, String namespace) { checkDatabase(bucketName, arangoDB); List<String> collections = arangoDB.db(bucketName) .getCollections().stream() .map(CollectionEntity::getName) .collect(toList()); if (!collections.contains(namespace)) { arangoDB.db(bucketName).createCollection(namespace); } }
/** * Test if the db exists. * * @return true if the db exists */ public boolean dbExists() { return db == null ? false: db.exists(); }
private ArangoCollection _collection( final String name, final ArangoPersistentEntity<?> persistentEntity, final CollectionCreateOptions options) { final ArangoDatabase db = db(); final Class<?> entityClass = persistentEntity != null ? persistentEntity.getType() : null; final CollectionCacheValue value = collectionCache.computeIfAbsent(new CollectionCacheKey(db.name(), name), key -> { final ArangoCollection collection = db.collection(name); if (!collection.exists()) { collection.create(options); } return new CollectionCacheValue(collection); }); final Collection<Class<?>> entities = value.getEntities(); final ArangoCollection collection = value.getCollection(); if (persistentEntity != null && !entities.contains(entityClass)) { value.addEntityClass(entityClass); ensureCollectionIndexes(collection(collection), persistentEntity); } return collection; }
@Override public void dropDatabase() throws DataAccessException { final ArangoDatabase db = db(); try { db.drop(); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } databaseCache.remove(db.name()); collectionCache.keySet().stream().filter(key -> key.getDb().equals(db.name())) .forEach(key -> collectionCache.remove(key)); }
@Override public void deleteUser(final String user) throws ArangoDBException { executor.execute(deleteUserRequest(db().name(), user), Void.class); }
@Override public ArangoDBVersion getVersion() throws DataAccessException { try { if (version == null) { version = db().getVersion(); } return version; } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } }