Search in sources :

Example 26 with Transaction

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
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) Satellite(org.neo4j.ogm.domain.satellites.Satellite) Test(org.junit.Test)

Example 27 with Transaction

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);
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) Satellite(org.neo4j.ogm.domain.satellites.Satellite) Test(org.junit.Test)

Example 28 with Transaction

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);
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) Person(org.neo4j.ogm.domain.friendships.Person) Test(org.junit.Test)

Example 29 with Transaction

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);
    }
}
Also used : Item(org.neo4j.ogm.domain.linkedlist.Item) Transaction(org.neo4j.ogm.transaction.Transaction) Test(org.junit.Test)

Example 30 with Transaction

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");
    }
}
Also used : SessionFactory(org.neo4j.ogm.session.SessionFactory) Transaction(org.neo4j.ogm.transaction.Transaction) HttpResponseException(org.apache.http.client.HttpResponseException) 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