private void validateCollectionName(String name) throws ArangoDBException { if (name.indexOf('/') != -1) { throw new ArangoDBException("does not allow '/' in name."); } }
/** * 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; }
@Override public <T> T getDocument(final String key, final Class<T> type, final DocumentReadOptions options) throws ArangoDBException { DocumentUtil.validateDocumentKey(key); try { return executor.execute(getDocumentRequest(key, options), type); } catch (final ArangoDBException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); } if ((e.getResponseCode() != null && (e.getResponseCode().intValue() == 404 || e.getResponseCode().intValue() == 304 || e.getResponseCode().intValue() == 412)) && (options == null || options.isCatchException())) { return null; } throw e; } }
@Override public <T> T getEdge(final String key, final Class<T> type, final DocumentReadOptions options) throws ArangoDBException { try { return executor.execute(getEdgeRequest(key, options), getEdgeResponseDeserializer(type)); } catch (final ArangoDBException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); } return null; } }
@Override public Boolean documentExists(final String key, final DocumentExistsOptions options) throws ArangoDBException { try { executor.execute(documentExistsRequest(key, options), VPackSlice.class); return true; } catch (final ArangoDBException e) { if ((e.getResponseCode() != null && (e.getResponseCode().intValue() == 404 || e.getResponseCode().intValue() == 304 || e.getResponseCode().intValue() == 412)) && (options == null || options.isCatchException())) { return false; } throw e; } }
/** * Insert an edge in the graph. The edge is updated with the id, rev and key (if not * present) * @param edge the edge * @throws ArangoDBGraphException If there was an error inserting the edge */ public void insertEdge(ArangoDBBaseEdge edge) { String graphName; try { graphName = edge.graph().name(); } catch (NullPointerException ex) { logger.error("Edge not paired: {}", edge); throw new ArangoDBGraphException("Edge does not have a graph. Can only delete paired edges."); } logger.debug("Insert edge {} in {}", edge, graphName); try { db.graph(graphName) .edgeCollection(ArangoDBUtil.getCollectioName(graphName, edge.collection())) .insertEdge(edge); } catch (ArangoDBException e) { logger.error("Failed to insert edge: {}", e.getErrorMessage()); throw ArangoDBExceptions.getArangoDBException(e); } edge.setPaired(true); }
@Override public boolean exists() throws ArangoDBException { try { getInfo(); return true; } catch (final ArangoDBException e) { if (ArangoErrors.ERROR_GRAPH_NOT_FOUND.equals(e.getErrorNum())) { return false; } throw e; } }
} else if (ex instanceof ArangoDBException) { final ArangoDBException exception = ArangoDBException.class.cast(ex); final Integer responseCode = exception.getResponseCode(); if (responseCode != null) { switch (responseCode) { case ArangoErrors.ERROR_HTTP_UNAUTHORIZED: case ArangoErrors.ERROR_HTTP_FORBIDDEN: dae = new PermissionDeniedDataAccessException(exception.getMessage(), exception); break; case ArangoErrors.ERROR_HTTP_BAD_PARAMETER: case ArangoErrors.ERROR_HTTP_METHOD_NOT_ALLOWED: dae = new InvalidDataAccessApiUsageException(exception.getMessage(), exception); break; case ArangoErrors.ERROR_HTTP_NOT_FOUND: dae = new InvalidDataAccessResourceUsageException(exception.getMessage(), exception); break; case ArangoErrors.ERROR_HTTP_CONFLICT: dae = new DataIntegrityViolationException(exception.getMessage(), exception); break; case ArangoErrors.ERROR_HTTP_PRECONDITION_FAILED: case ArangoErrors.ERROR_HTTP_SERVICE_UNAVAILABLE: dae = new DataAccessResourceFailureException(exception.getMessage(), exception); break; case ArangoErrors.ERROR_HTTP_SERVER_ERROR: default: dae = new ArangoUncategorizedException(exception.getMessage(), exception); break;
@Override public <T> T getVertex(final String key, final Class<T> type, final DocumentReadOptions options) throws ArangoDBException { try { return executor.execute(getVertexRequest(key, options), getVertexResponseDeserializer(type)); } catch (final ArangoDBException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); } return null; } }
final Integer responseCode = e.getResponseCode(); if (responseCode != null && responseCode == 403) { response = Collections.<String> emptyList();
/** * 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) { String graphName; try { graphName = document.graph().name(); } catch (NullPointerException ex) { logger.error("Document not paired: {}", document); throw new ArangoDBGraphException("Document does not have a graph. Can only delete paired documents."); } logger.debug("Delete document {} in {}", document, graphName); try { db.graph(graphName) .vertexCollection(ArangoDBUtil.getCollectioName(graphName, document.collection())) .deleteVertex(document._key()); } catch (ArangoDBException e) { logger.error("Failed to delete document: {}", e.getErrorMessage()); throw ArangoDBExceptions.getArangoDBException(e); } document.setPaired(false); }
@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; } }
private static void validateName(final String type, final String regex, final CharSequence name) throws ArangoDBException { if (!Pattern.matches(regex, name)) { throw new ArangoDBException(String.format("%s %s is not valid.", type, name)); } } }
} else if (ex instanceof ArangoDBException) { final ArangoDBException exception = ArangoDBException.class.cast(ex); final Integer responseCode = exception.getResponseCode(); if (responseCode != null) { switch (responseCode) { case ArangoErrors.ERROR_HTTP_UNAUTHORIZED: case ArangoErrors.ERROR_HTTP_FORBIDDEN: dae = new PermissionDeniedDataAccessException(exception.getMessage(), exception); break; case ArangoErrors.ERROR_HTTP_BAD_PARAMETER: case ArangoErrors.ERROR_HTTP_METHOD_NOT_ALLOWED: dae = new InvalidDataAccessApiUsageException(exception.getMessage(), exception); break; case ArangoErrors.ERROR_HTTP_NOT_FOUND: dae = new InvalidDataAccessResourceUsageException(exception.getMessage(), exception); break; case ArangoErrors.ERROR_HTTP_CONFLICT: dae = new DataIntegrityViolationException(exception.getMessage(), exception); break; case ArangoErrors.ERROR_HTTP_PRECONDITION_FAILED: case ArangoErrors.ERROR_HTTP_SERVICE_UNAVAILABLE: dae = new DataAccessResourceFailureException(exception.getMessage(), exception); break; case ArangoErrors.ERROR_HTTP_SERVER_ERROR: default: dae = new ArangoUncategorizedException(exception.getMessage(), exception); break;
@Override public <T> T getEdge(final String key, final Class<T> type) throws ArangoDBException { try { return executor.execute(getEdgeRequest(key, new DocumentReadOptions()), getEdgeResponseDeserializer(type)); } catch (final ArangoDBException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); } return null; } }
/** * Update the edge in the graph. * @param edge the edge * @throws ArangoDBGraphException If there was an error updating the edge */ public void updateEdge(ArangoDBBaseEdge edge) { String graphName; try { graphName = edge.graph().name(); } catch (NullPointerException ex) { logger.error("Edge not paired: {}", edge); throw new ArangoDBGraphException("Edge does not have a graph. Can only delete paired edges."); } logger.debug("Update edge {} in {}", edge, graphName); EdgeUpdateEntity edgeEntity; try { edgeEntity = db.graph(graphName) .edgeCollection(ArangoDBUtil.getCollectioName(graphName, edge.collection())) .updateEdge(edge._key(), edge); } catch (ArangoDBException e) { logger.error("Failed to update vertex: {}", e.getErrorMessage()); throw ArangoDBExceptions.getArangoDBException(e); } logger.info("Edge updated, new rev {}", edgeEntity.getRev()); edge._rev(edgeEntity.getRev()); }
logger.info("Database created: " + databaseName); } catch (ArangoDBException e) { logger.error("Failed to create database: {} with ex: {}", databaseName, e.toString()); logger.info("Collection created: " + collectionName); } catch (ArangoDBException e) { logger.error("Failed to create collection: {} with ex: {}", collectionName, e.toString());
@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; } }
public Message get(final long messageId) throws ArangoDBException { final Message result = response.remove(messageId); if (result == null) { final Exception e = error.remove(messageId); if (e != null) { throw new ArangoDBException(e); } } return result; }
@Override public <T> T getVertex(final String key, final Class<T> type) throws ArangoDBException { try { return executor.execute(getVertexRequest(key, new DocumentReadOptions()), getVertexResponseDeserializer(type)); } catch (final ArangoDBException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); } return null; } }