@Bean public org.neo4j.ogm.config.Configuration getConfiguration() { org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration(); config.driverConfiguration() .setDriverClassName ("org.neo4j.ogm.drivers.http.driver.HttpDriver") .setURI(grapheneUrl); return config; }
private void setCredentials() { if (driverConfig.getCredentials() == null && driverConfig.getURI() != null) { try { URI uri = new URI(driverConfig.getURI()); String authInfo = uri.getUserInfo(); if (authInfo != null) { String[] parts = uri.getUserInfo().split(":"); driverConfig.setCredentials(parts[0], parts[1]); } } catch (Exception e) { throw new RuntimeException(e); } } } }
private Neo4jSessionFactory() { try { Configuration configuration = new Configuration("ogm.properties"); sessionFactory = new SessionFactory(configuration, "db"); } catch (Exception ex) { Configuration configuration = new Configuration(); configuration.driverConfiguration().setURI(System.getenv("GRAPHENEDB_URL")); configuration.autoIndexConfiguration().setAutoIndex("assert"); try { sessionFactory = new SessionFactory(configuration, "db"); } catch(Exception ex2) { configuration.driverConfiguration().setURI("http://localhost:7474"); configuration.autoIndexConfiguration().setAutoIndex("assert"); sessionFactory = new SessionFactory("db"); } } }
private String autoCommitUrl() { return transactionEndpoint(driverConfig.getURI()).concat("/commit"); }
@Override public Request request() { String url = requestUrl(); return new HttpRequest(httpClient, url, driverConfig.getCredentials()); }
private String newTransactionUrl() { String url = transactionEndpoint(driverConfig.getURI()); logger.debug("POST {}", url); CloseableHttpResponse response = executeHttpRequest(new HttpPost(url)); Header location = response.getHeaders("Location")[0]; try { response.close(); return location.getValue(); } catch (IOException e) { throw new ResultProcessingException("Failed to execute request: ", e); } }
public CloseableHttpResponse executeHttpRequest(HttpRequestBase request) { try { try(CloseableHttpResponse response = HttpRequest.execute(httpClient, request, driverConfig.getCredentials())) { HttpEntity responseEntity = response.getEntity(); if (responseEntity != null) { String responseText = EntityUtils.toString(responseEntity); logger.debug(responseText); EntityUtils.consume(responseEntity); if (responseText.contains("\"errors\":[{") || responseText.contains("\"errors\": [{")) { throw new ResultErrorsException(responseText); } } return response; } } catch (Exception e) { throw new ResultProcessingException("Failed to execute request: ", e); } finally { request.releaseConnection(); logger.debug("Connection released"); } }
@Override public synchronized void configure(DriverConfiguration config) { super.configure(config); close(); // force any existing graph database to shutdown 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 = createTemporaryEphemeralFileStore(); } File file = new File(new URI(fileStoreUri)); graphDatabaseService = new GraphDatabaseFactory().newEmbeddedDatabase(file); registerShutdownHook(); } catch (Exception e) { throw new RuntimeException(e); } }