Search in sources :

Example 31 with Transaction

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

the class SessionAndMappingContextTest method shouldNotThrowConcurrentModificationException.

@Test
public void shouldNotThrowConcurrentModificationException() {
    try (Transaction tx = session.beginTransaction()) {
        session.save(new Actor("Mary"));
        session.deleteAll(Actor.class);
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) Actor(org.neo4j.ogm.domain.cineasts.annotated.Actor) Test(org.junit.Test)

Example 32 with Transaction

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

the class SessionAndMappingContextTest method shouldFlushSessionWithoutReturningNodes.

// GH-817
@Test
public void shouldFlushSessionWithoutReturningNodes() {
    sessionFactory.openSession().purgeDatabase();
    Session sessionForCreation = sessionFactory.openSession();
    try (Transaction tx = sessionForCreation.beginTransaction()) {
        Stream.of(new Bike("Bike1"), new Bike("Bike2")).forEach(sessionForCreation::save);
        tx.commit();
    }
    Session sessionForLoadingAndUpdate = sessionFactory.openSession();
    Iterable<Bike> loadedBikes = sessionForLoadingAndUpdate.loadAll(Bike.class);
    assertThat(loadedBikes).hasSize(2).extracting(Bike::isDamaged).containsOnly(false);
    sessionForLoadingAndUpdate.query("MATCH (c:Bike) SET c.damaged = true", Collections.emptyMap());
    loadedBikes = sessionForLoadingAndUpdate.loadAll(Bike.class);
    assertThat(loadedBikes).hasSize(2).extracting(Bike::isDamaged).containsOnly(true);
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) Bike(org.neo4j.ogm.domain.gh817.Bike) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 33 with Transaction

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

the class SessionAndMappingContextTest method shouldRefreshUpdatedEntities.

// GH-817
@Test
public void shouldRefreshUpdatedEntities() {
    sessionFactory.openSession().purgeDatabase();
    Session sessionForCreation = sessionFactory.openSession();
    try (Transaction tx = sessionForCreation.beginTransaction()) {
        Stream.of(new Bike("Bike1"), new Bike("Bike2")).forEach(sessionForCreation::save);
        tx.commit();
    }
    Session sessionForLoadingAndUpdate = sessionFactory.openSession();
    Iterable<Bike> loadedBikes = sessionForLoadingAndUpdate.loadAll(Bike.class);
    assertThat(loadedBikes).hasSize(2).extracting(Bike::isDamaged).containsOnly(false);
    Iterable<Bike> updatedBikes = sessionForLoadingAndUpdate.query(Bike.class, "MATCH (c:Bike) SET c.damaged = true RETURN c", Collections.emptyMap());
    assertThat(updatedBikes).hasSize(2).extracting(Bike::isDamaged).containsOnly(true);
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) Bike(org.neo4j.ogm.domain.gh817.Bike) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) Session(org.neo4j.ogm.session.Session) Test(org.junit.Test)

Example 34 with Transaction

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

the class TransactionTest method shouldNotCommitWhenTransactionIsManaged.

@Test
public void shouldNotCommitWhenTransactionIsManaged() {
    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);
    // the previous saves shouldn't have been committed
    tx.rollback();
    assertThat(session.countEntitiesOfType(Artist.class)).isEqualTo(0);
}
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 35 with Transaction

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

the class BookmarkTest method shouldPassMultiValueBookmarksToDriver.

@Test
public void shouldPassMultiValueBookmarksToDriver() {
    Set<String> bookmarkStringRepresentation = new HashSet<>(Arrays.asList("bookmark1", "bookmark2", "bookmark3-part1/_BS_/bookmark3-part2"));
    Transaction transaction = session.beginTransaction(Transaction.Type.READ_ONLY, bookmarkStringRepresentation);
    ArgumentCaptor<SessionConfig> argumentCaptor = ArgumentCaptor.forClass(SessionConfig.class);
    verify(nativeDriver).session(argumentCaptor.capture());
    Set<String> multipleBookmarks = new HashSet<>();
    multipleBookmarks.addAll(Arrays.asList("bookmark3-part1", "bookmark3-part2"));
    SessionConfig sessionConfig = argumentCaptor.getValue();
    assertThat(sessionConfig.defaultAccessMode()).isEqualTo(AccessMode.READ);
    assertThat(sessionConfig.bookmarks()).contains(Bookmark.from(Collections.singleton("bookmark1")), Bookmark.from(Collections.singleton("bookmark2")), Bookmark.from(multipleBookmarks));
    transaction.rollback();
    transaction.close();
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) SessionConfig(org.neo4j.driver.SessionConfig) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) 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