|
|
@ -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 {
|
|
|
|