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