use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.
the class SatelliteIntegrationTest method shouldUseLongTransaction.
@Test
public void shouldUseLongTransaction() {
try (Transaction tx = session.beginTransaction()) {
// load all
Collection<Satellite> satellites = session.loadAll(Satellite.class);
assertThat(satellites).hasSize(11);
Satellite satellite = satellites.iterator().next();
Long id = satellite.getId();
satellite.setName("Updated satellite");
// update
session.save(satellite);
// refetch
Satellite updatedSatellite = session.load(Satellite.class, id);
assertThat(updatedSatellite.getName()).isEqualTo("Updated satellite");
}
// transaction will be rolled back
}
use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.
the class SatelliteIntegrationTest method shouldRollbackClosedAndUnCommittedTransaction.
@Test
public void shouldRollbackClosedAndUnCommittedTransaction() {
Long id;
String name;
try (Transaction tx = session.beginTransaction()) {
// load all
Collection<Satellite> satellites = session.loadAll(Satellite.class);
assertThat(satellites).hasSize(11);
Satellite satellite = satellites.iterator().next();
id = satellite.getId();
name = satellite.getName();
satellite.setName("Updated satellite");
// update
session.save(satellite);
session.clear();
// refetch
Satellite updatedSatellite = session.load(Satellite.class, id);
assertThat(updatedSatellite.getName()).isEqualTo("Updated satellite");
}
session.clear();
// fetch - after rollback should not be changed
// note, that because we aren't starting a new tx, we will be given an autocommit one.
Satellite reloadedSatellite = session.load(Satellite.class, id);
assertThat(reloadedSatellite.getName()).isEqualTo(name);
}
use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.
the class FriendsInLongTransactionTest method createPersonAndFriendsInLongTransaction.
/**
* @see DATAGRAPH-703
*/
@Test
public void createPersonAndFriendsInLongTransaction() {
try (Transaction tx = session.beginTransaction()) {
assertThat(tx.status()).isEqualTo(Transaction.Status.OPEN);
Person john = new Person("John");
session.save(john);
Person bob = new Person("Bob");
session.save(bob);
Person bill = new Person("Bill");
session.save(bill);
john = session.load(Person.class, john.getId());
bob = session.load(Person.class, bob.getId());
john.addFriend(bob);
session.save(john);
john = session.load(Person.class, john.getId());
bill = session.load(Person.class, bill.getId());
john.addFriend(bill);
session.save(john);
session.clear();
session.load(Person.class, john.getId());
assertThat(john.getFriends()).hasSize(2);
}
}
use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.
the class BidirectionalMappingTest method shouldHandleSelfReferencingObjectOnRollback.
@Test
public void shouldHandleSelfReferencingObjectOnRollback() {
Item item = new Item();
item.next = item;
item.previous = item;
try (Transaction tx = session.beginTransaction()) {
session.save(item);
session.deleteAll(Item.class);
}
}
use of org.neo4j.ogm.transaction.Transaction in project neo4j-ogm by neo4j.
the class AuthenticatingHttpDriverTest method testAuthorizedDriver.
@Test
public void testAuthorizedDriver() {
try {
session = new SessionFactory(getDriver(), "dummy").openSession();
Transaction ignored = session.beginTransaction();
assertThat(ignored).isNotNull();
} catch (Exception rpe) {
fail("'" + rpe.getLocalizedMessage() + "' was not expected here");
}
}
Aggregations