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);
}
}
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);
}
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);
}
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);
}
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();
}
Aggregations