Search in sources :

Example 46 with Transaction

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

the class BaseAutoIndexManagerTestClass method executeDrop.

void executeDrop(String... statements) {
    Session session = sessionFactory.openSession();
    for (String statement : statements) {
        try (Transaction transaction = session.beginTransaction()) {
            // it does not clean up the tx resources, leading to deadlock later
            try {
                session.query("DROP " + statement, emptyMap());
                transaction.commit();
            } catch (Exception e) {
                logger.trace("Could not execute drop for statement (this is likely expected) {}", statement, e);
                transaction.rollback();
            }
        }
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) DatabaseException(org.neo4j.driver.exceptions.DatabaseException) IOException(java.io.IOException) Session(org.neo4j.ogm.session.Session)

Example 47 with Transaction

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

the class KnowledgeTest method shouldBeAbleToRollbackObjectWithDifferentKnowledges.

/**
 * @see 351
 */
@Test
public void shouldBeAbleToRollbackObjectWithDifferentKnowledges() {
    Person john = new Person("John");
    Person mary = new Person("Mary");
    Language java = new Language("Java");
    Language scala = new Language("Scala");
    john.knows(mary);
    john.knows(java);
    john.knows(scala);
    try (Transaction tx = session.beginTransaction()) {
        session.save(john);
        tx.rollback();
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction) 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