com.arangodb.ArangoDBException Java Examples
The following examples show how to use
com.arangodb.ArangoDBException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArangoDBGraphClient.java From arangodb-tinkerpop-provider with Apache License 2.0 | 6 votes |
/** * Create a new graph. * * @param name the name of the new graph * @param edgeDefinitions the edge definitions for the graph * @param options additional graph options * @return the arango graph * @throws ArangoDBGraphException If the graph can not be created */ public ArangoGraph createGraph(String name, List<EdgeDefinition> edgeDefinitions, GraphCreateOptions options) throws ArangoDBGraphException { logger.info("Creating graph {}", name); try { logger.info("Creating graph in database."); db.createGraph(name, edgeDefinitions, options); } catch (ArangoDBException e) { logger.info("Error creating graph in database.", e); throw ArangoDBExceptions.getArangoDBException(e); } ArangoGraph g = db.graph(name); return g; }
Example #2
Source File: ArangoDBGraphClient.java From arangodb-tinkerpop-provider with Apache License 2.0 | 6 votes |
/** * Create a query to get all the edges of a vertex. * * @param vertex the vertex * @param edgeLabels a list of edge labels to follow, empty if all type of edges * @param direction the direction of the edges * @return ArangoDBBaseQuery the query object * @throws ArangoDBException if there is an error executing the query */ public ArangoCursor<ArangoDBEdge> getVertexEdges( ArangoDBVertex vertex, List<String> edgeLabels, Direction direction) throws ArangoDBException { logger.debug("Get Vertex's {}:{} Edges, in {}, from collections {}", vertex, direction, graph.name(), edgeLabels); Map<String, Object> bindVars = new HashMap<>(); ArangoDBQueryBuilder queryBuilder = new ArangoDBQueryBuilder(); ArangoDBQueryBuilder.Direction arangoDirection = ArangoDBUtil.getArangoDirectionFromGremlinDirection(direction); logger.debug("Creating query"); queryBuilder.iterateGraph(graph.name(), "v", Optional.of("e"), Optional.empty(), Optional.empty(), Optional.empty(), arangoDirection, vertex._id(), bindVars) .graphOptions(Optional.of(UniqueVertices.NONE), Optional.empty(), true) .filterSameCollections("e", edgeLabels, bindVars) .ret("e"); String query = queryBuilder.toString(); return executeAqlQuery(query, bindVars, null, ArangoDBEdge.class); }
Example #3
Source File: ResponseUtils.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
public static void checkError(final ArangoSerialization util, final Response response) throws ArangoDBException { try { final int responseCode = response.getResponseCode(); if (responseCode >= ERROR_STATUS) { if (responseCode == ERROR_INTERNAL && response.getMeta().containsKey(HEADER_ENDPOINT)) { throw new ArangoDBRedirectException(String.format("Response Code: %s", responseCode), response.getMeta().get(HEADER_ENDPOINT)); } else if (response.getBody() != null) { final ErrorEntity errorEntity = util.deserialize(response.getBody(), ErrorEntity.class); throw new ArangoDBException(errorEntity); } else { throw new ArangoDBException(String.format("Response Code: %s", responseCode), responseCode); } } } catch (final VPackParserException e) { throw new ArangoDBException(e); } }
Example #4
Source File: ArangoTemplate.java From spring-data with Apache License 2.0 | 6 votes |
@Override public DocumentEntity replace(final Object id, final Object value, final DocumentReplaceOptions options) throws DataAccessException { potentiallyEmitEvent(new BeforeSaveEvent<>(value)); final DocumentEntity result; try { result = _collection(value.getClass(), id).replaceDocument(determineDocumentKeyFromId(id), toVPack(value), options); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } updateDBFields(value, result); potentiallyEmitEvent(new AfterSaveEvent<>(value)); return result; }
Example #5
Source File: ArangoCollectionTest.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
@Test public void updateDocumentIgnoreRevsFalse() throws InterruptedException, ExecutionException { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); final DocumentCreateEntity<BaseDocument> createResult = db.collection(COLLECTION_NAME).insertDocument(doc, null) .get(); doc.updateAttribute("a", "test1"); doc.setRevision("no"); try { final DocumentUpdateOptions options = new DocumentUpdateOptions().ignoreRevs(false); db.collection(COLLECTION_NAME).updateDocument(createResult.getKey(), doc, options).get(); fail(); } catch (final ExecutionException e) { assertThat(e.getCause(), instanceOf(ArangoDBException.class)); } }
Example #6
Source File: ArangoCollectionAsyncImpl.java From arangodb-java-driver-async with Apache License 2.0 | 6 votes |
private <T> Function<Throwable, T> handleGetDocumentExceptions(Boolean isCatchException) { return throwable -> { if (throwable instanceof CompletionException) { if (throwable.getCause() instanceof ArangoDBException) { ArangoDBException arangoDBException = (ArangoDBException) throwable.getCause(); // handle Response: 404, Error: 1655 - transaction not found if (arangoDBException.getErrorNum() != null && arangoDBException.getErrorNum() == 1655) { throw (CompletionException) throwable; } if ((arangoDBException.getResponseCode() != null && (arangoDBException.getResponseCode() == 404 || arangoDBException.getResponseCode() == 304 || arangoDBException.getResponseCode() == 412)) && isCatchException) { return null; } } throw (CompletionException) throwable; } throw new CompletionException(throwable); }; }
Example #7
Source File: ArangoDBGraphClient.java From arangodb-tinkerpop-provider with Apache License 2.0 | 6 votes |
/** * Execute AQL query. * * @param <T> the generic type of the returned values * @param query the query string * @param bindVars the value of the bind parameters * @param aqlQueryOptions the aql query options * @param type the type of the result (POJO class, VPackSlice, String for Json, or Collection/List/Map) * @return the cursor result * @throws ArangoDBGraphException if executing the query raised an exception */ public <T> ArangoCursor<T> executeAqlQuery( String query, Map<String, Object> bindVars, AqlQueryOptions aqlQueryOptions, final Class<T> type) throws ArangoDBGraphException { logger.debug("Executing AQL query ({}) against db, with bind vars: {}", query, bindVars); try { return db.query(query, bindVars, aqlQueryOptions, type); } catch (ArangoDBException e) { logger.error("Error executing query", e); throw ArangoDBExceptions.getArangoDBException(e); } }
Example #8
Source File: ArangoCollectionTest.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
@Test public void replaceDocumentIgnoreRevsFalse() throws InterruptedException, ExecutionException { final BaseDocument doc = new BaseDocument(); doc.addAttribute("a", "test"); final DocumentCreateEntity<BaseDocument> createResult = db.collection(COLLECTION_NAME).insertDocument(doc, null) .get(); doc.getProperties().clear(); doc.addAttribute("b", "test"); doc.setRevision("no"); try { final DocumentReplaceOptions options = new DocumentReplaceOptions().ignoreRevs(false); db.collection(COLLECTION_NAME).replaceDocument(createResult.getKey(), doc, options).get(); fail(); } catch (final ExecutionException e) { assertThat(e.getCause(), instanceOf(ArangoDBException.class)); } }
Example #9
Source File: StreamTransactionTest.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
@Test public void abortCommittedStreamTransactionShouldThrow() throws ExecutionException, InterruptedException { assumeTrue(isSingleServer()); assumeTrue(isAtLeastVersion(3, 5)); assumeTrue(isStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb)); StreamTransactionEntity createdTx = db.beginStreamTransaction(null).get(); db.commitStreamTransaction(createdTx.getId()).get(); try { db.abortStreamTransaction(createdTx.getId()).get(); fail(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(ArangoDBException.class)); } }
Example #10
Source File: ArangoExecutorSync.java From arangodb-java-driver with Apache License 2.0 | 6 votes |
public <T> T execute( final Request request, final ResponseDeserializer<T> responseDeserializer, final HostHandle hostHandle) throws ArangoDBException { try { final Response response = protocol.execute(request, hostHandle); T deserialize = responseDeserializer.deserialize(response); if (deserialize instanceof MetaAware) { LOG.debug("Response is MetaAware " + deserialize.getClass().getName()); ((MetaAware) deserialize).setMeta(response.getMeta()); } return deserialize; } catch (final VPackException e) { throw new ArangoDBException(e); } }
Example #11
Source File: StreamTransactionTest.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void beginStreamTransactionWithNonExistingCollectionsShouldThrow() throws ExecutionException, InterruptedException { assumeTrue(isSingleServer()); assumeTrue(isAtLeastVersion(3, 5)); assumeTrue(isStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb)); try { db.beginStreamTransaction(new StreamTransactionOptions().writeCollections("notExistingCollection")).get(); fail(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(ArangoDBException.class)); } }
Example #12
Source File: ArangoAqlQueryTest.java From spring-data with Apache License 2.0 | 5 votes |
@Test(expected = ArangoDBException.class) public void findOneByIdInIncorrectNamedCollectionAqlTest() { repository.saveAll(customers); final Customer retrieved = repository.findOneByIdInIncorrectNamedCollectionAql(john.getId().split("/")[0], john.getId(), john.getId()); assertEquals(john, retrieved); }
Example #13
Source File: ExtendedHostResolver.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
private Collection<String> resolveFromServer() throws ArangoDBException { Collection<String> response; try { response = executor.execute( new Request(ArangoRequestParam.SYSTEM, RequestType.GET, "/_api/cluster/endpoints"), response1 -> { final VPackSlice field = response1.getBody().get("endpoints"); Collection<String> endpoints; if (field.isNone()) { endpoints = Collections.emptyList(); } else { final Collection<Map<String, String>> tmp = arangoSerialization.deserialize(field, Collection.class); endpoints = new ArrayList<>(); for (final Map<String, String> map : tmp) { endpoints.addAll(map.values()); } } return endpoints; }, null); } catch (final ArangoDBException e) { final Integer responseCode = e.getResponseCode(); // responseCode == 403: single server < 3.7 // responseCode == 501: single server >= 3.7 if (responseCode != null && (responseCode == 403 || responseCode == 501)) { response = Collections.emptyList(); } else { throw e; } } return response; }
Example #14
Source File: ArangoEdgeCollectionTest.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void deleteEdgeIfMatch() throws InterruptedException, ExecutionException { final BaseEdgeDocument doc = createEdgeValue(); final EdgeEntity createResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(doc, null) .get(); final EdgeDeleteOptions options = new EdgeDeleteOptions().ifMatch(createResult.getRev()); db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).deleteEdge(createResult.getKey(), options).get(); try { db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME) .getEdge(createResult.getKey(), BaseEdgeDocument.class, new GraphDocumentReadOptions().catchException(false)).get(); fail(); } catch (final ExecutionException e) { assertThat(e.getCause(), instanceOf(ArangoDBException.class)); } }
Example #15
Source File: HttpCommunication.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
public Response execute(final Request request, final HostHandle hostHandle) throws ArangoDBException, IOException { final AccessType accessType = RequestUtils.determineAccessType(request); Host host = hostHandler.get(hostHandle, accessType); try { while (true) { try { final HttpConnection connection = (HttpConnection) host.connection(); final Response response = connection.execute(request); hostHandler.success(); hostHandler.confirm(); return response; } catch (final SocketException se) { hostHandler.fail(); if (hostHandle != null && hostHandle.getHost() != null) { hostHandle.setHost(null); } final Host failedHost = host; host = hostHandler.get(hostHandle, accessType); if (host != null) { LOGGER.warn(String.format("Could not connect to %s. Try connecting to %s", failedHost.getDescription(), host.getDescription())); } else { throw se; } } } } catch (final ArangoDBException e) { if (e instanceof ArangoDBRedirectException) { final String location = ((ArangoDBRedirectException) e).getLocation(); final HostDescription redirectHost = HostUtils.createFromLocation(location); hostHandler.closeCurrentOnError(); hostHandler.fail(); return execute(request, new HostHandle().setHost(redirectHost)); } else { throw e; } } }
Example #16
Source File: DefaultCollectionOperations.java From spring-data with Apache License 2.0 | 5 votes |
@Override public Collection<IndexEntity> getIndexes() throws DataAccessException { try { return collection.getIndexes(); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } }
Example #17
Source File: ArangoCollectionTest.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void importDocumentsCompleteFail() throws InterruptedException { final Collection<BaseDocument> values = new ArrayList<>(); values.add(new BaseDocument("1")); values.add(new BaseDocument("2")); values.add(new BaseDocument("2")); try { db.collection(COLLECTION_NAME).importDocuments(values, new DocumentImportOptions().complete(true)).get(); fail(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(ArangoDBException.class)); assertThat(((ArangoDBException) e.getCause()).getErrorNum(), is(1210)); } }
Example #18
Source File: StreamTransactionTest.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void commitStreamTransactionWhenTransactionIdDoesNotExistsShouldThrow() throws ExecutionException, InterruptedException { assumeTrue(isSingleServer()); assumeTrue(isAtLeastVersion(3, 5)); assumeTrue(isStorageEngine(ArangoDBEngine.StorageEngineName.rocksdb)); try { db.commitStreamTransaction("000000").get(); fail(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(ArangoDBException.class)); } }
Example #19
Source File: ArangoTemplate.java From spring-data with Apache License 2.0 | 5 votes |
@Override public Iterable<UserEntity> getUsers() throws DataAccessException { try { return arango.getUsers(); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } }
Example #20
Source File: DefaultCollectionOperations.java From spring-data with Apache License 2.0 | 5 votes |
@Override public void resetAccess(final String username) { try { collection.resetAccess(username); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } }
Example #21
Source File: DocumentCache.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
public void setValues(final Object doc, final Map<DocumentField.Type, String> values) throws ArangoDBException { try { final Map<DocumentField.Type, Field> fields = getFields(doc.getClass()); for (final Entry<DocumentField.Type, String> value : values.entrySet()) { final Field field = fields.get(value.getKey()); if (field != null) { field.set(doc, value.getValue()); } } } catch (final IllegalArgumentException | IllegalAccessException e) { throw new ArangoDBException(e); } }
Example #22
Source File: DefaultCollectionOperations.java From spring-data with Apache License 2.0 | 5 votes |
@Override public CollectionPropertiesEntity getProperties() throws DataAccessException { try { return collection.getProperties(); } catch (final ArangoDBException e) { throw translateExceptionIfPossible(e); } }
Example #23
Source File: ArangoAqlQueryTest.java From spring-data with Apache License 2.0 | 5 votes |
@Test(expected = ArangoDBException.class) public void findOneByIdInNamedCollectionAqlRejectedTest() { repository.saveAll(customers); final Customer retrieved = repository.findOneByIdInNamedCollectionAqlRejected(john.getId().split("/")[0], john.getId()); assertEquals(john, retrieved); }
Example #24
Source File: ArangoDBGraphClient.java From arangodb-tinkerpop-provider with Apache License 2.0 | 5 votes |
/** * Delete a document from the graph. * @param document the document to delete * @throws ArangoDBGraphException If there was an error deleting the document */ public void deleteDocument(ArangoDBBaseDocument document) { logger.debug("Delete document {} in {}", document, graph.name()); try { db.graph(graph.name()) .vertexCollection(document.collection()) .deleteVertex(document._key()); } catch (ArangoDBException e) { logger.error("Failed to delete document: {}", e.getErrorMessage()); throw ArangoDBExceptions.getArangoDBException(e); } document.setPaired(false); }
Example #25
Source File: ShortestPathInAQLExample.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void queryShortestPathFromAToD() throws ArangoDBException { String queryString = "FOR v, e IN OUTBOUND SHORTEST_PATH 'circles/A' TO 'circles/D' GRAPH 'traversalGraph' RETURN {'vertex': v._key, 'edge': e._key}"; ArangoCursor<Pair> cursor = db.query(queryString, null, null, Pair.class); final Collection<String> collection = toVertexCollection(cursor); assertThat(collection.size(), is(4)); assertThat(collection, hasItems("A", "B", "C", "D")); queryString = "WITH circles FOR v, e IN OUTBOUND SHORTEST_PATH 'circles/A' TO 'circles/D' edges RETURN {'vertex': v._key, 'edge': e._key}"; db.query(queryString, null, null, Pair.class); assertThat(collection.size(), is(4)); assertThat(collection, hasItems("A", "B", "C", "D")); }
Example #26
Source File: ArangoEdgeCollectionImpl.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Override public <T> T getEdge(final String key, final Class<T> type) throws ArangoDBException { try { return executor.execute(getEdgeRequest(key, new GraphDocumentReadOptions()), getEdgeResponseDeserializer(type)); } catch (final ArangoDBException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); } return null; } }
Example #27
Source File: ArangoDatabaseAsyncImpl.java From arangodb-java-driver-async with Apache License 2.0 | 5 votes |
@Override public <T> CompletableFuture<T> getDocument(final String id, final Class<T> type, final DocumentReadOptions options) throws ArangoDBException { DocumentUtil.validateDocumentId(id); final String[] split = id.split("/"); return collection(split[0]).getDocument(split[1], type, options); }
Example #28
Source File: ArangoSearchImpl.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Override public boolean exists() throws ArangoDBException { try { getInfo(); return true; } catch (final ArangoDBException e) { if (ArangoErrors.ERROR_ARANGO_DATA_SOURCE_NOT_FOUND.equals(e.getErrorNum())) { return false; } throw e; } }
Example #29
Source File: ArangoViewImpl.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Override public boolean exists() throws ArangoDBException { try { getInfo(); return true; } catch (final ArangoDBException e) { if (ArangoErrors.ERROR_ARANGO_DATA_SOURCE_NOT_FOUND.equals(e.getErrorNum())) { return false; } throw e; } }
Example #30
Source File: ArangoEdgeCollectionTest.java From arangodb-java-driver with Apache License 2.0 | 5 votes |
@Test public void deleteEdgeIfMatchFail() throws InterruptedException, ExecutionException { final BaseEdgeDocument doc = createEdgeValue(); final EdgeEntity createResult = db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).insertEdge(doc, null) .get(); final EdgeDeleteOptions options = new EdgeDeleteOptions().ifMatch("no"); try { db.graph(GRAPH_NAME).edgeCollection(EDGE_COLLECTION_NAME).deleteEdge(createResult.getKey(), options).get(); fail(); } catch (final ExecutionException e) { assertThat(e.getCause(), instanceOf(ArangoDBException.class)); } }