Search in sources :

Example 6 with Transaction

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

the class TransactionManagerTest method shouldRollbackManagedTransaction.

@Test
public void shouldRollbackManagedTransaction() {
    DefaultTransactionManager transactionManager = new DefaultTransactionManager(session, getDriver().getTransactionFactorySupplier());
    assertThat(session.getLastBookmark()).isNull();
    try (Transaction tx = transactionManager.openTransaction()) {
        assertThat(tx.status()).isEqualTo(Transaction.Status.OPEN);
        tx.rollback();
        assertThat(tx.status()).isEqualTo(Transaction.Status.ROLLEDBACK);
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) DefaultTransactionManager(org.neo4j.ogm.session.transaction.DefaultTransactionManager) Test(org.junit.Test)

Example 7 with Transaction

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

the class TransactionManagerTest method shouldBeAbleToCreateManagedTransaction.

@Test
public void shouldBeAbleToCreateManagedTransaction() {
    DefaultTransactionManager transactionManager = new DefaultTransactionManager(session, getDriver().getTransactionFactorySupplier());
    assertThat(session.getLastBookmark()).isNull();
    try (Transaction tx = transactionManager.openTransaction()) {
        assertThat(tx.status()).isEqualTo(Transaction.Status.OPEN);
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) DefaultTransactionManager(org.neo4j.ogm.session.transaction.DefaultTransactionManager) Test(org.junit.Test)

Example 8 with Transaction

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

the class TransactionTest method defaultTransactionShouldWorkAfterManagedTransaction.

@Test
public void defaultTransactionShouldWorkAfterManagedTransaction() {
    Transaction tx = session.beginTransaction();
    Studio emi = new Studio("EMI Studios, London");
    session.save(emi);
    tx.commit();
    tx.close();
    session.purgeDatabase();
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) Studio(org.neo4j.ogm.domain.music.Studio) Test(org.junit.Test)

Example 9 with Transaction

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

the class TransactionTest method shouldBeAbleToRetrySaveOnTransactionRollback.

// GH-126
@Test
public void shouldBeAbleToRetrySaveOnTransactionRollback() {
    Transaction tx = session.beginTransaction();
    Studio emi = new Studio("EMI Studios, London");
    Artist theBeatles = new Artist("The Beatles");
    Album please = new Album("Please Please Me");
    Recording pleaseRecording = new Recording(please, emi, 1963);
    please.setRecording(pleaseRecording);
    theBeatles.getAlbums().add(please);
    please.setArtist(theBeatles);
    session.save(theBeatles);
    tx.rollback();
    session.save(theBeatles);
    session.clear();
    theBeatles = session.loadAll(Artist.class, -1).iterator().next();
    assertThat(theBeatles.getName()).isEqualTo("The Beatles");
    assertThat(theBeatles.getAlbums()).hasSize(1);
    assertThat(theBeatles.getAlbums().iterator().next().getName()).isEqualTo("Please Please Me");
    assertThat(theBeatles.getAlbums().iterator().next().getRecording().getStudio().getName()).isEqualTo("EMI Studios, London");
}
Also used : Artist(org.neo4j.ogm.domain.music.Artist) Transaction(org.neo4j.ogm.transaction.Transaction) Album(org.neo4j.ogm.domain.music.Album) Recording(org.neo4j.ogm.domain.music.Recording) Studio(org.neo4j.ogm.domain.music.Studio) Test(org.junit.Test)

Example 10 with Transaction

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

the class BookmarkTest method shouldDealWithMultiValueBookmarks.

/**
 * Make sure a bookmark containing multiple values is treated as one, not multiple bookmarks
 */
@Test
public void shouldDealWithMultiValueBookmarks() {
    Set<String> multipleBookmarks = new LinkedHashSet<>();
    multipleBookmarks.addAll(Arrays.asList("bookmark-part1", "bookmark-part2"));
    when(nativeDriver.session(any(SessionConfig.class))).thenReturn(nativeSession);
    when(nativeSession.beginTransaction().isOpen()).thenReturn(true);
    when(nativeSession.lastBookmark()).thenReturn(Bookmark.from(multipleBookmarks));
    Transaction transaction = session.beginTransaction(Transaction.Type.READ_WRITE);
    transaction.commit();
    transaction.close();
    String lastBookmark = session.getLastBookmark();
    assertThat(lastBookmark).isEqualTo("bookmark-part1/_BS_/bookmark-part2");
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Transaction(org.neo4j.ogm.transaction.Transaction) SessionConfig(org.neo4j.driver.SessionConfig) Test(org.junit.Test)

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