This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Builder config(Config config) { | |
config.get("authentication.username").asString().ifPresent(this::username); | |
config.get("authentication.password").asString().ifPresent(this::password); | |
config.get("authentication.enabled").asBoolean().ifPresent(this::authenticationEnabled); | |
config.get("uri").asString().ifPresent(this::uri); | |
config.get("encrypted").asBoolean().ifPresent(this::encrypted); | |
//pool | |
config.get("pool.metricsEnabled").asBoolean().ifPresent(this::metricsEnabled); | |
config.get("pool.logLeakedSessions").asBoolean().ifPresent(this::logLeakedSessions); | |
config.get("pool.maxConnectionPoolSize").asInt().ifPresent(this::maxConnectionPoolSize); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.springframework.data</groupId> | |
<artifactId>spring-data-neo4j</artifactId> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
public Builder password(String password) { | |
Objects.requireNonNull(password); | |
this.password = password; | |
return this; | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Neo4j build() { | |
if (driver == null) { | |
driver = initDriver(); | |
} | |
return new Neo4j(this); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Driver initDriver() { | |
AuthToken authToken = AuthTokens.none(); | |
if (authenticationEnabled) { | |
authToken = AuthTokens.basic(username, password); | |
} | |
org.neo4j.driver.Config.ConfigBuilder configBuilder = createBaseConfig(); | |
configureSsl(configBuilder); | |
configurePoolSettings(configBuilder); | |
return GraphDatabase.driver(uri, authToken, configBuilder.build()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Driver driver() { | |
return driver; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Neo4jMetricsSupport.builder() | |
.driver(neo4j.driver()) | |
.build() | |
.initialize(); | |
Driver neo4jDriver = neo4j.driver(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
neo4j: | |
uri: bolt://localhost:7687 | |
authentication: | |
username: neo4j | |
password: secret | |
pool: | |
metricsEnabled: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<Movie> findAll(){ | |
try (var session = driver.session()) { | |
var query = "" | |
+ "match (m:Movie) " | |
+ "match (m) <- [:DIRECTED] - (d:Person) " | |
+ "match (m) <- [r:ACTED_IN] - (a:Person) " | |
+ "return m, collect(d) as directors, collect({name:a.name, roles: r.roles}) as actors"; | |
return session.readTransaction(tx -> tx.run(query).list(r -> { | |
var movieNode = r.get("m").asNode(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Neo4jCdiExtension implements Extension { | |
private static final String NEO4J_METRIC_NAME_PREFIX = "neo4j"; | |
void afterBeanDiscovery(@Observes AfterBeanDiscovery addEvent) { | |
addEvent.addBean() | |
.types(Driver.class) | |
.qualifiers(Default.Literal.INSTANCE, Any.Literal.INSTANCE) | |
.scope(ApplicationScoped.class) | |
.name(Driver.class.getName()) | |
.beanClass(Driver.class) | |
.createWith(creationContext -> { |
OlderNewer