Search in sources :

Example 36 with Transaction

use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.

the class BookmarkTest method shouldHaveAvailableBookmark.

@Test
public void shouldHaveAvailableBookmark() {
    when(nativeDriver.session(any(SessionConfig.class))).thenReturn(nativeSession);
    when(nativeSession.beginTransaction().isOpen()).thenReturn(true);
    when(nativeSession.lastBookmark()).thenReturn(Bookmark.from(Collections.singleton("last-bookmark")));
    Transaction transaction = session.beginTransaction(Transaction.Type.READ_WRITE);
    transaction.commit();
    transaction.close();
    String lastBookmark = session.getLastBookmark();
    assertThat(lastBookmark).isEqualTo("last-bookmark");
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) SessionConfig(org.neo4j.driver.SessionConfig) Test(org.junit.Test)

Example 37 with Transaction

use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.

the class DatesBoltTest method shouldUseNativeDateTimeTypesInParameterMaps.

@Override
public void shouldUseNativeDateTimeTypesInParameterMaps() {
    try (Driver driver = GraphDatabase.driver(getBoltUrl())) {
        Session session = sessionFactory.openSession();
        Transaction transaction = session.beginTransaction();
        LocalDate localDate = LocalDate.of(2018, 11, 14);
        LocalDateTime localDateTime = LocalDateTime.of(2018, 10, 11, 15, 24);
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("a", localDate);
        parameters.put("b", localDateTime);
        session.query("CREATE (n:Test {a: $a, b: $b})", parameters);
        transaction.commit();
        Record record = driver.session().run("MATCH (n:Test) RETURN n.a, n.b").single();
        Object a = record.get("n.a").asObject();
        assertThat(a).isInstanceOf(LocalDate.class).isEqualTo(localDate);
        Object b = record.get("n.b").asObject();
        assertThat(b).isInstanceOf(LocalDateTime.class).isEqualTo(localDateTime);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Transaction(org.neo4j.ogm.transaction.Transaction) HashMap(java.util.HashMap) Driver(org.neo4j.driver.Driver) BoltDriver(org.neo4j.ogm.drivers.bolt.driver.BoltDriver) Record(org.neo4j.driver.Record) LocalDate(java.time.LocalDate) Session(org.neo4j.ogm.session.Session)

Example 38 with Transaction

use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.

the class BasicDriverTest method doExtendedCommitCommitRollback.

private void doExtendedCommitCommitRollback() {
    try (Transaction tx = session.beginTransaction()) {
        // commit_deferred
        m2();
        // commit_deferred
        m2();
        tx.rollback();
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction)

Example 39 with Transaction

use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.

the class BasicDriverTest method shouldFindExplicitlyCommittedEntity.

@Test
public void shouldFindExplicitlyCommittedEntity() {
    Transaction tx = session.beginTransaction();
    session.save(new User());
    tx.commit();
    session.clear();
    assertThat(session.loadAll(User.class)).hasSize(1);
}
Also used : User(org.neo4j.ogm.domain.social.User) Transaction(org.neo4j.ogm.transaction.Transaction) Test(org.junit.Test)

Example 40 with Transaction

use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.

the class BasicDriverTest method m3.

private void m3() {
    // inner transaction rolls back (defers rollback)
    try (Transaction tx = session.beginTransaction()) {
        session.save(new User());
        tx.rollback();
    }
}
Also used : User(org.neo4j.ogm.domain.social.User) Transaction(org.neo4j.ogm.transaction.Transaction)

Aggregations

Transaction (org.neo4j.ogm.transaction.Transaction)47 Test (org.junit.Test)30 Session (org.neo4j.ogm.session.Session)10 ArrayList (java.util.ArrayList)5 Neo4jSession (org.neo4j.ogm.session.Neo4jSession)5 SessionConfig (org.neo4j.driver.SessionConfig)4 Result (org.neo4j.ogm.model.Result)4 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 HttpResponseException (org.apache.http.client.HttpResponseException)3 Bike (org.neo4j.ogm.domain.gh817.Bike)3 Studio (org.neo4j.ogm.domain.music.Studio)3 Satellite (org.neo4j.ogm.domain.satellites.Satellite)3 User (org.neo4j.ogm.domain.social.User)3 SessionFactory (org.neo4j.ogm.session.SessionFactory)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2