Align with latest Neo4j OGM 3.0 snapshots

See gh-8687
pull/8768/head
Andy Wilkinson 8 years ago
parent ff50331168
commit aaf76e435e

@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.data.neo4j;
import java.util.List; import java.util.List;
import org.neo4j.ogm.config.Components;
import org.neo4j.ogm.session.SessionFactory; import org.neo4j.ogm.session.SessionFactory;
import org.neo4j.ogm.session.event.EventListener; import org.neo4j.ogm.session.event.EventListener;
@ -66,7 +65,6 @@ public class Neo4jDataAutoConfiguration {
public org.neo4j.ogm.config.Configuration configuration(Neo4jProperties properties) { public org.neo4j.ogm.config.Configuration configuration(Neo4jProperties properties) {
org.neo4j.ogm.config.Configuration configuration = properties org.neo4j.ogm.config.Configuration configuration = properties
.createConfiguration(); .createConfiguration();
Components.configure(configuration);
return configuration; return configuration;
} }

@ -16,10 +16,8 @@
package org.springframework.boot.autoconfigure.data.neo4j; package org.springframework.boot.autoconfigure.data.neo4j;
import java.net.URI;
import java.net.URISyntaxException;
import org.neo4j.ogm.config.Configuration; import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.config.Configuration.Builder;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
@ -103,58 +101,28 @@ public class Neo4jProperties implements ApplicationContextAware {
* @return a configuration * @return a configuration
*/ */
public Configuration createConfiguration() { public Configuration createConfiguration() {
Configuration configuration = new Configuration(); Builder builder = new Builder();
configureDriver(configuration); configure(builder);
return configuration; return builder.build();
} }
private void configureDriver(Configuration configuration) { private void configure(Builder builder) {
if (this.uri != null) { if (this.uri != null) {
configureDriverFromUri(configuration, this.uri); builder.uri(this.uri);
} }
else { else {
configureDriverWithDefaults(configuration); configureUriWithDefaults(builder);
} }
if (this.username != null && this.password != null) { if (this.username != null && this.password != null) {
configuration.setCredentials(this.username, this.password); builder.credentials(this.username, this.password);
}
}
private void configureDriverFromUri(Configuration configuration, String uri) {
configuration.setDriverClassName(deduceDriverFromUri());
configuration.setURI(uri);
}
private String deduceDriverFromUri() {
try {
URI uri = new URI(this.uri);
String scheme = uri.getScheme();
if (scheme == null || scheme.equals("file")) {
return EMBEDDED_DRIVER;
}
if ("http".equals(scheme)) {
return HTTP_DRIVER;
}
if ("bolt".equals(scheme)) {
return BOLT_DRIVER;
}
throw new IllegalArgumentException(
"Could not deduce driver to use based on URI '" + uri + "'");
}
catch (URISyntaxException ex) {
throw new IllegalArgumentException(
"Invalid URI for spring.data.neo4j.uri '" + this.uri + "'", ex);
} }
} }
private void configureDriverWithDefaults(Configuration configuration) { private void configureUriWithDefaults(Builder builder) {
if (getEmbedded().isEnabled() if (!getEmbedded().isEnabled()
&& ClassUtils.isPresent(EMBEDDED_DRIVER, this.classLoader)) { || !ClassUtils.isPresent(EMBEDDED_DRIVER, this.classLoader)) {
configuration.setDriverClassName(EMBEDDED_DRIVER); builder.uri(DEFAULT_BOLT_URI);
return;
} }
configuration.setDriverClassName(BOLT_DRIVER);
configuration.setURI(DEFAULT_BOLT_URI);
} }
public static class Embedded { public static class Embedded {

@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.data.neo4j;
import org.assertj.core.api.Assertions; import org.assertj.core.api.Assertions;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.neo4j.ogm.drivers.http.driver.HttpDriver;
import org.neo4j.ogm.session.Session; import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory; import org.neo4j.ogm.session.SessionFactory;
import org.neo4j.ogm.session.event.Event; import org.neo4j.ogm.session.event.Event;
@ -180,9 +179,8 @@ public class Neo4jDataAutoConfigurationTests {
@Bean @Bean
public org.neo4j.ogm.config.Configuration myConfiguration() { public org.neo4j.ogm.config.Configuration myConfiguration() {
org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration(); return new org.neo4j.ogm.config.Configuration.Builder()
configuration.setDriverClassName(HttpDriver.class.getName()); .uri("http://localhost:12345").build();
return configuration;
} }
} }

@ -102,8 +102,7 @@ public class Neo4jPropertiesTests {
Neo4jProperties properties = load(true, Neo4jProperties properties = load(true,
"spring.data.neo4j.uri=http://user:secret@my-server:7474"); "spring.data.neo4j.uri=http://user:secret@my-server:7474");
Configuration configuration = properties.createConfiguration(); Configuration configuration = properties.createConfiguration();
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER, assertDriver(configuration, Neo4jProperties.HTTP_DRIVER, "http://my-server:7474");
"http://user:secret@my-server:7474");
assertCredentials(configuration, "user", "secret"); assertCredentials(configuration, "user", "secret");
} }
@ -119,10 +118,10 @@ public class Neo4jPropertiesTests {
@Test @Test
public void embeddedModeWithRelativeLocation() { public void embeddedModeWithRelativeLocation() {
Neo4jProperties properties = load(true, Neo4jProperties properties = load(true,
"spring.data.neo4j.uri=target/neo4j/my.db"); "spring.data.neo4j.uri=file:target/neo4j/my.db");
Configuration configuration = properties.createConfiguration(); Configuration configuration = properties.createConfiguration();
assertDriver(configuration, Neo4jProperties.EMBEDDED_DRIVER, assertDriver(configuration, Neo4jProperties.EMBEDDED_DRIVER,
"target/neo4j/my.db"); "file:target/neo4j/my.db");
} }
private static void assertDriver(Configuration actual, String driver, String uri) { private static void assertDriver(Configuration actual, String driver, String uri) {

Loading…
Cancel
Save