@Override public RuntimeException translateExceptionIfPossible(Throwable e) { if (e instanceof ServiceUnavailableException) { return new ConnectionException(e.getMessage(), e); } if (e instanceof RuntimeException) { return (RuntimeException) e; } return new RuntimeException(e); } }
private Session newSession(Transaction.Type type, Iterable<String> bookmarks) { Session boltSession; try { AccessMode accessMode = type.equals(Transaction.Type.READ_ONLY) ? AccessMode.READ : AccessMode.WRITE; boltSession = boltDriver.session(accessMode, bookmarks); } catch (ClientException ce) { throw new ConnectionException( "Error connecting to graph database using Bolt: " + ce.code() + ", " + ce.getMessage(), ce); } catch (Exception e) { throw new ConnectionException("Error connecting to graph database using Bolt", e); } return boltSession; }
private Session newSession(Transaction.Type type, Iterable<String> bookmarks) { Session boltSession; try { AccessMode accessMode = type.equals(Transaction.Type.READ_ONLY) ? AccessMode.READ : AccessMode.WRITE; boltSession = boltDriver.session(accessMode, bookmarks); } catch (ClientException ce) { throw new ConnectionException( "Error connecting to graph database using Bolt: " + ce.code() + ", " + ce.getMessage(), ce); } catch (Exception e) { throw new ConnectionException("Error connecting to graph database using Bolt", e); } return boltSession; }
private void initializeDriver() { final String serviceUnavailableMessage = "Could not create driver instance"; try { if (credentials != null) { UsernamePasswordCredentials usernameAndPassword = (UsernamePasswordCredentials) this.credentials; AuthToken authToken = AuthTokens.basic(usernameAndPassword.getUsername(), usernameAndPassword.getPassword()); boltDriver = createDriver(configuration, authToken); } else { try { boltDriver = createDriver(configuration, AuthTokens.none()); } catch (ServiceUnavailableException e) { throw new ConnectionException(serviceUnavailableMessage, e); } LOGGER.debug("Bolt Driver credentials not supplied"); } } catch (ServiceUnavailableException e) { throw new ConnectionException(serviceUnavailableMessage, e); } }
private void initializeDriver() { final String serviceUnavailableMessage = "Could not create driver instance"; try { if (credentials != null) { UsernamePasswordCredentials credentials = (UsernamePasswordCredentials) this.credentials; AuthToken authToken = AuthTokens.basic(credentials.getUsername(), credentials.getPassword()); boltDriver = createDriver(configuration, driverConfig, authToken); } else { try { boltDriver = createDriver(configuration, driverConfig, AuthTokens.none()); } catch (ServiceUnavailableException e) { throw new ConnectionException(serviceUnavailableMessage, e); } LOGGER.debug("Bolt Driver credentials not supplied"); } } catch (ServiceUnavailableException e) { throw new ConnectionException(serviceUnavailableMessage, e); } }
throw new HttpRequestException(request, re); } catch (ClientProtocolException uhe) { throw new ConnectionException(request.getURI().toString(), uhe); } catch (IOException ioe) { throw new HttpRequestException(request, ioe);
@Override public synchronized void configure(Configuration config) { super.configure(config); try { String fileStoreUri = config.getURI(); // if no URI is set, create a temporary folder for the graph db // that will persist only for the duration of the JVM // This is effectively what the ImpermanentDatabase does. if (fileStoreUri == null) { fileStoreUri = createTemporaryFileStore(); } else { createPermanentFileStore(fileStoreUri); } File file = new File(new URI(fileStoreUri)); if (!file.exists()) { throw new RuntimeException("Could not create/open filestore: " + fileStoreUri); } GraphDatabaseBuilder graphDatabaseBuilder = getGraphDatabaseFactory(configuration) .newEmbeddedDatabaseBuilder(file); String neo4jConfLocation = config.getNeo4jConfLocation(); if(neo4jConfLocation != null) { URL neo4ConfUrl = ResourceUtils.getResourceUrl(neo4jConfLocation); graphDatabaseBuilder = graphDatabaseBuilder.loadPropertiesFromURL(neo4ConfUrl); } this.graphDatabaseService = graphDatabaseBuilder.newGraphDatabase(); } catch (Exception e) { throw new ConnectionException("Error connecting to embedded graph", e); } }
@Override public synchronized void configure(Configuration newConfiguration) { super.configure(newConfiguration); try { String fileStoreUri = newConfiguration.getURI(); // if no URI is set, create a temporary folder for the graph db // that will persist only for the duration of the JVM // This is effectively what the ImpermanentDatabase does. if (fileStoreUri == null) { fileStoreUri = createTemporaryFileStore(); } else { createPermanentFileStore(fileStoreUri); } File file = new File(new URI(fileStoreUri)); if (!file.exists()) { throw new RuntimeException("Could not create/open filestore: " + fileStoreUri); } GraphDatabaseBuilder graphDatabaseBuilder = getGraphDatabaseFactory(newConfiguration) .newEmbeddedDatabaseBuilder(file); String neo4jConfLocation = newConfiguration.getNeo4jConfLocation(); if (neo4jConfLocation != null) { URL neo4ConfUrl = ResourceUtils.getResourceUrl(neo4jConfLocation); graphDatabaseBuilder = graphDatabaseBuilder.loadPropertiesFromURL(neo4ConfUrl); } this.graphDatabaseService = graphDatabaseBuilder.newGraphDatabase(); } catch (Exception e) { throw new ConnectionException("Error connecting to embedded graph", e); } }
throw new ConnectionException("Unable to build driver configuration", e);
throw new ConnectionException("Unable to build driver configuration", e);
@Override public void commit() { final boolean canCommit = transactionManager.canCommit(); try { if (canCommit) { LOGGER.debug("Committing native transaction: {}", nativeTransaction); if (nativeTransaction.isOpen()) { nativeTransaction.success(); nativeTransaction.close(); nativeSession.close(); } else { throw new IllegalStateException("Transaction is already closed"); } } } catch (ClientException ce) { closeNativeSessionIfPossible(); if (ce.code().startsWith(NEO_CLIENT_ERROR_SECURITY)) { throw new ConnectionException("Security Error: " + ce.code() + ", " + ce.getMessage(), ce); } throw new CypherException(ce.code(), ce.getMessage(), ce); } catch (Exception e) { closeNativeSessionIfPossible(); throw new TransactionException(e.getLocalizedMessage(), e); } finally { super.commit(); if (canCommit) { transactionManager.bookmark(nativeSession.lastBookmark()); } } }
@Override public void commit() { final boolean canCommit = transactionManager.canCommit(); try { if (canCommit) { LOGGER.debug("Committing native transaction: {}", nativeTransaction); if (nativeTransaction.isOpen()) { nativeTransaction.success(); nativeTransaction.close(); nativeSession.close(); } else { throw new IllegalStateException("Transaction is already closed"); } } } catch (ClientException ce) { closeNativeSessionIfPossible(); if (ce.code().startsWith(NEO_CLIENT_ERROR_SECURITY)) { throw new ConnectionException("Security Error: " + ce.code() + ", " + ce.getMessage(), ce); } throw new CypherException(ce.code(), ce.getMessage(), ce); } catch (Exception e) { closeNativeSessionIfPossible(); throw new TransactionException(e.getLocalizedMessage(), e); } finally { super.commit(); if (canCommit) { transactionManager.bookmark(nativeSession.lastBookmark()); } } }