private String autoCommitUrl() { return transactionEndpoint(configuration.getURI()).concat("/commit"); }
private static Driver newConfiguredDriverInstance(Configuration configuration) { String driverClassName = configuration.getDriverClassName(); try { final Class<?> driverClass = Class.forName(driverClassName); final Driver driver = (Driver) driverClass.newInstance(); driver.configure(configuration); return driver; } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { throw new ConfigurationException("Could not load driver class " + driverClassName, 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"); } } }
public AutoIndexManager(MetaData metaData, Configuration configuration, Neo4jSession session) { this.mode = configuration.getAutoIndex(); this.dumpDir = configuration.getDumpDir(); this.dumpFilename = configuration.getDumpFilename(); this.session = session; this.indexes = initialiseAutoIndex(metaData); }
private Driver createDriver(Configuration config, AuthToken authToken) { if (config.getURIS() == null) { return GraphDatabase.driver(config.getURI(), authToken, driverConfig); } else { List<URI> uris = new ArrayList<>(); uris.add(URI.create(config.getURI())); for (String additionalURI : config.getURIS()) { uris.add(URI.create(additionalURI)); } return GraphDatabase.routingDriver(uris, authToken, driverConfig); } }
private BoltConfig getBoltConfiguration(Configuration configuration) { BoltConfig boltConfig = new BoltConfig(); if (configuration.getEncryptionLevel() != null) { try { boltConfig.encryptionLevel = Config.EncryptionLevel .valueOf(configuration.getEncryptionLevel().toUpperCase()); } catch (IllegalArgumentException iae) { LOGGER.debug("Invalid configuration for the Bolt Driver Encryption Level: {}", configuration.getEncryptionLevel()); throw iae; } } boltConfig.sessionPoolSize = configuration.getConnectionPoolSize(); if (configuration.getTrustStrategy() != null) { try { boltConfig.trustStrategy = Config.TrustStrategy.Strategy.valueOf(configuration.getTrustStrategy()); } catch (IllegalArgumentException iae) { LOGGER.debug("Invalid configuration for the Bolt Driver Trust Strategy: {}", configuration.getTrustStrategy()); throw iae; } } if (configuration.getTrustCertFile() != null) { boltConfig.trustCertFile = configuration.getTrustCertFile(); } if (configuration.getConnectionLivenessCheckTimeout() != null) { boltConfig.connectionLivenessCheckTimeout = configuration.getConnectionLivenessCheckTimeout(); } return boltConfig; }
@Test public void shouldConfigureFromNameSpacePropertiesFile() { Configuration configuration = new Configuration.Builder( new ClasspathConfigurationSource("ogm-namespace.properties")).build(); assertThat(configuration.getAutoIndex()).isEqualTo(AutoIndexMode.DUMP); assertThat(configuration.getDumpDir()).isEqualTo("hello"); assertThat(configuration.getDumpFilename()).isEqualTo("generated-indexes2.cql"); assertThat(configuration.getDriverClassName()).isEqualTo("org.neo4j.ogm.drivers.http.driver.HttpDriver"); assertThat(configuration.getCredentials().credentials().toString()).isEqualTo("bmVvNGo6cGFzc3dvcmQ="); assertThat(configuration.getURI()).isEqualTo("http://localhost:7474"); assertThat(configuration.getConnectionPoolSize()).isEqualTo(100); assertThat(configuration.getEncryptionLevel()).isEqualTo("NONE"); assertThat(configuration.getTrustStrategy()).isEqualTo("TRUST_ON_FIRST_USE"); assertThat(configuration.getTrustCertFile()).isEqualTo("/tmp/cert"); }
@Test public void shouldConfigureFromFilesystemPropertiesFileURI() throws Exception { File file = new File(getConfigFileAsRelativePath()); FileConfigurationSource source = new FileConfigurationSource(file.toURI().toString()); Configuration configuration = new Configuration.Builder(source).build(); assertThat(configuration.getAutoIndex()).isEqualTo(AutoIndexMode.NONE); assertThat(configuration.getDriverClassName()).isEqualTo("org.neo4j.ogm.drivers.http.driver.HttpDriver"); assertThat(configuration.getCredentials().credentials().toString()).isEqualTo("bmVvNGo6cGFzc3dvcmQ="); assertThat(configuration.getURI()).isEqualTo("http://localhost:7474"); }
@Test public void shouldConfigureFromSimplePropertiesFile() { Configuration configuration = new Configuration.Builder( new ClasspathConfigurationSource("ogm-simple.properties")).build(); assertThat(configuration.getAutoIndex()).isEqualTo(AutoIndexMode.NONE); assertThat(configuration.getDriverClassName()).isEqualTo("org.neo4j.ogm.drivers.http.driver.HttpDriver"); assertThat(configuration.getCredentials().credentials().toString()).isEqualTo("bmVvNGo6cGFzc3dvcmQ="); assertThat(configuration.getURI()).isEqualTo("http://localhost:7474"); assertThat(configuration.getBasePackages()).isEqualTo(new String[] {"org.neo4j.ogm.domain.bike"}); assertThat(configuration.getUseNativeTypes()).isEqualTo(Boolean.TRUE); }
@Test public void shouldLoadBoltDriverConfigFromPropertiesFile() { Configuration driverConfig = new Configuration.Builder( new ClasspathConfigurationSource("bolt.driver.properties")).build(); assertThat(driverConfig.getURI()).isEqualTo("bolt://localhost"); assertThat(driverConfig.getConnectionPoolSize()).isEqualTo(150); assertThat(driverConfig.getEncryptionLevel()).isEqualTo("NONE"); assertThat(driverConfig.getTrustStrategy()).isEqualTo("TRUST_ON_FIRST_USE"); assertThat(driverConfig.getTrustCertFile()).isEqualTo("/tmp/cert"); }
@Test public void shouldParseEmbeddedUriSchemeCaseInsensitive() { Configuration configuration = new Configuration.Builder() .uri("FILE:///somewhere") .build(); assertThat(configuration.getDriverClassName()) .isEqualTo("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver"); assertThat(configuration.getURI()).isEqualTo("FILE:///somewhere"); }
@Test public void shouldConfigureCredentialsFromURI() { Configuration configuration = new Configuration.Builder().uri("http://fred:flintstone@localhost:8080").build(); // base 64 encoded credentials, e.g. use echo fred:flintstone | base64 assertThat(configuration.getCredentials().credentials().toString()).isEqualTo("ZnJlZDpmbGludHN0b25l"); assertThat(configuration.getURI()).isEqualTo("http://localhost:8080"); }
@Override public void configure(Configuration newConfiguration) { close(); super.configure(newConfiguration); this.driverConfig = buildDriverConfig(); this.credentials = this.configuration.getCredentials(); if (this.configuration.getVerifyConnection()) { checkDriverInitialized(); } }
@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); } }
if (configuration.getTrustStrategy() != null) { if (configuration.getTrustStrategy().equals("ACCEPT_UNSIGNED")) { sslContext = new SSLContextBuilder().loadTrustMaterial(null, (arg0, arg1) -> true).build(); socketFactoryRegistry); Integer connectionPoolSize = configuration.getConnectionPoolSize();
public CloseableHttpResponse executeHttpRequest(HttpRequestBase request) throws HttpRequestException { try (CloseableHttpResponse response = HttpRequest .execute(httpClient(), request, configuration.getCredentials())) { HttpEntity responseEntity = response.getEntity(); if (responseEntity != null) { JsonNode responseNode = mapper.readTree(EntityUtils.toString(responseEntity)); LOGGER.debug("Response: {}", responseNode); JsonNode errors = responseNode.findValue("errors"); if (errors.elements().hasNext()) { JsonNode errorNode = errors.elements().next(); throw new CypherException(errorNode.findValue("code").asText(), errorNode.findValue("message").asText()); } } return response; } catch (IOException ioe) { throw new HttpRequestException(request, ioe); } finally { request.releaseConnection(); LOGGER.debug("Thread: {}, Connection released", Thread.currentThread().getId()); } }
@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; }
/** * Constructs a new {@link SessionFactory} by initialising the object-graph mapping meta-data from the given list of domain * object packages, and also sets the baseConfiguration to be used. * <p> * The package names passed to this constructor should not contain wildcards or trailing full stops, for example, * "org.springframework.data.neo4j.example.domain" would be fine. The default behaviour is for sub-packages to be scanned * and you can also specify fully-qualified class names if you want to cherry pick particular classes. * </p> * Indexes will also be checked or built unless auto index mode is set to <code>NONE</code>. * * @param configuration The baseConfiguration to use * @param packages The packages to scan for domain objects. They will be merged with the configuration. */ public SessionFactory(Configuration configuration, String... packages) { this(newConfiguredDriverInstance(configuration), configuration.mergeBasePackagesWith(packages)); if (configuration.getAutoIndex() != NONE) { runAutoIndexManager(configuration); } }
@Test public void shouldPreserveUpdateConfiguration() { Configuration configuration = getBaseConfiguration().autoIndex("update").build(); assertThat(configuration.getAutoIndex()).isEqualTo(AutoIndexMode.UPDATE); }
public Configuration build() { return new Configuration(this); }