org.neo4j.driver.AccessMode Java Examples

The following examples show how to use org.neo4j.driver.AccessMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveDataNeo4jTestIT.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void testTemplate() {

	Mono
		.just(new ExampleEntity("Look, new @ReactiveDataNeo4jTest!"))
		.flatMap(neo4jTemplate::save)
		.as(StepVerifier::create)
		.expectNextCount(1)
		.verifyComplete();

	try (Session session = driver
		.session(SessionConfig.builder().withDefaultAccessMode(AccessMode.READ).build())) {
		long cnt = session.run("MATCH (n:ExampleEntity) RETURN count(n) as cnt").single().get("cnt").asLong();
		assertThat(cnt).isEqualTo(1L);
	}
}
 
Example #2
Source File: Neo4JGraph.java    From neo4j-gremlin-bolt with Apache License 2.0 6 votes vote down vote up
Neo4JSession currentSession() {
    // get current session
    Neo4JSession session = this.session.get();
    if (session == null) {
        // session config
        SessionConfig.Builder config = SessionConfig.builder()
            .withDefaultAccessMode(readonly ? AccessMode.READ : AccessMode.WRITE)
            .withBookmarks(bookmarks);
        // set database if needed
        if (database != null)
            config.withDatabase(database);
        // create new session
        session = new Neo4JSession(this, driver.session(config.build()), vertexIdProvider, edgeIdProvider, readonly);
        // attach it to current thread
        this.session.set(session);
    }
    return session;
}
 
Example #3
Source File: DataNeo4jTestIT.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void testRepository() {
	ExampleEntity entity = new ExampleEntity("Look, new @DataNeo4jTest!");
	assertThat(entity.getId()).isNull();
	ExampleEntity persistedEntity = this.exampleRepository.save(entity);
	assertThat(persistedEntity.getId()).isNotNull();

	try (Session session = driver
		.session(SessionConfig.builder().withDefaultAccessMode(AccessMode.READ).build())) {
		long cnt = session.run("MATCH (n:ExampleEntity) RETURN count(n) as cnt").single().get("cnt").asLong();
		assertThat(cnt).isEqualTo(1L);
	}
}
 
Example #4
Source File: Neo4jTransactionUtils.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
public static SessionConfig sessionConfig(boolean readOnly, Collection<Bookmark> bookmarks,
	@Nullable String databaseName) {
	SessionConfig.Builder builder = SessionConfig.builder()
		.withDefaultAccessMode(readOnly ? AccessMode.READ : AccessMode.WRITE)
		.withBookmarks(bookmarks);

	if (databaseName != null) {
		builder.withDatabase(databaseName);
	}

	return builder.build();
}
 
Example #5
Source File: Neo4jExtension.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
String getEdition() {
	String edition = "n/a";
	SessionConfig sessionConfig = SessionConfig.builder().withDefaultAccessMode(AccessMode.READ).build();
	try (Session session = getDriver().session(
		sessionConfig)) {
		edition = session.run("call dbms.components() yield edition").single().get("edition").asString();
	}
	return edition.toLowerCase(Locale.ENGLISH);
}