mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Align with latest Neo4j OGM 3.0 snapshots
See gh-8687
This commit is contained in:
parent
ff50331168
commit
aaf76e435e
@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.data.neo4j;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.neo4j.ogm.config.Components;
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
import org.neo4j.ogm.session.event.EventListener;
|
||||
|
||||
@ -66,7 +65,6 @@ public class Neo4jDataAutoConfiguration {
|
||||
public org.neo4j.ogm.config.Configuration configuration(Neo4jProperties properties) {
|
||||
org.neo4j.ogm.config.Configuration configuration = properties
|
||||
.createConfiguration();
|
||||
Components.configure(configuration);
|
||||
return configuration;
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,8 @@
|
||||
|
||||
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.Builder;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@ -103,58 +101,28 @@ public class Neo4jProperties implements ApplicationContextAware {
|
||||
* @return a configuration
|
||||
*/
|
||||
public Configuration createConfiguration() {
|
||||
Configuration configuration = new Configuration();
|
||||
configureDriver(configuration);
|
||||
return configuration;
|
||||
Builder builder = new Builder();
|
||||
configure(builder);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private void configureDriver(Configuration configuration) {
|
||||
private void configure(Builder builder) {
|
||||
if (this.uri != null) {
|
||||
configureDriverFromUri(configuration, this.uri);
|
||||
builder.uri(this.uri);
|
||||
}
|
||||
else {
|
||||
configureDriverWithDefaults(configuration);
|
||||
configureUriWithDefaults(builder);
|
||||
}
|
||||
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 + "'");
|
||||
private void configureUriWithDefaults(Builder builder) {
|
||||
if (!getEmbedded().isEnabled()
|
||||
|| !ClassUtils.isPresent(EMBEDDED_DRIVER, this.classLoader)) {
|
||||
builder.uri(DEFAULT_BOLT_URI);
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid URI for spring.data.neo4j.uri '" + this.uri + "'", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void configureDriverWithDefaults(Configuration configuration) {
|
||||
if (getEmbedded().isEnabled()
|
||||
&& ClassUtils.isPresent(EMBEDDED_DRIVER, this.classLoader)) {
|
||||
configuration.setDriverClassName(EMBEDDED_DRIVER);
|
||||
return;
|
||||
}
|
||||
configuration.setDriverClassName(BOLT_DRIVER);
|
||||
configuration.setURI(DEFAULT_BOLT_URI);
|
||||
}
|
||||
|
||||
public static class Embedded {
|
||||
|
@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.data.neo4j;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.neo4j.ogm.drivers.http.driver.HttpDriver;
|
||||
import org.neo4j.ogm.session.Session;
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
import org.neo4j.ogm.session.event.Event;
|
||||
@ -180,9 +179,8 @@ public class Neo4jDataAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public org.neo4j.ogm.config.Configuration myConfiguration() {
|
||||
org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration();
|
||||
configuration.setDriverClassName(HttpDriver.class.getName());
|
||||
return configuration;
|
||||
return new org.neo4j.ogm.config.Configuration.Builder()
|
||||
.uri("http://localhost:12345").build();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -102,8 +102,7 @@ public class Neo4jPropertiesTests {
|
||||
Neo4jProperties properties = load(true,
|
||||
"spring.data.neo4j.uri=http://user:secret@my-server:7474");
|
||||
Configuration configuration = properties.createConfiguration();
|
||||
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER,
|
||||
"http://user:secret@my-server:7474");
|
||||
assertDriver(configuration, Neo4jProperties.HTTP_DRIVER, "http://my-server:7474");
|
||||
assertCredentials(configuration, "user", "secret");
|
||||
}
|
||||
|
||||
@ -119,10 +118,10 @@ public class Neo4jPropertiesTests {
|
||||
@Test
|
||||
public void embeddedModeWithRelativeLocation() {
|
||||
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();
|
||||
assertDriver(configuration, Neo4jProperties.EMBEDDED_DRIVER,
|
||||
"target/neo4j/my.db");
|
||||
"file:target/neo4j/my.db");
|
||||
}
|
||||
|
||||
private static void assertDriver(Configuration actual, String driver, String uri) {
|
||||
|
Loading…
Reference in New Issue
Block a user