Search in sources :

Example 16 with Transaction

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

the class BasicDriverTest method m2.

private void m2() {
    // inner transaction commits (defers commit)
    try (Transaction tx = session.beginTransaction()) {
        session.save(new User());
        tx.commit();
    }
}
Also used : User(org.neo4j.ogm.domain.social.User) Transaction(org.neo4j.ogm.transaction.Transaction)

Example 17 with Transaction

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

the class BasicDriverTest method doExtendedRollbackCommitCommit.

private void doExtendedRollbackCommitCommit() throws TransactionException {
    try (Transaction tx = session.beginTransaction()) {
        // rollback_deferred
        m3();
        // commit_deferred
        m2();
        // cannot commit outer transaction
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction)

Example 18 with Transaction

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

the class BasicDriverTest method doExtendedCommitRollbackCommit.

private void doExtendedCommitRollbackCommit() throws TransactionException {
    try (Transaction tx = session.beginTransaction()) {
        // commit_deferred
        m2();
        // rollback_deferred
        m3();
        // cannot commit outer transaction
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction)

Example 19 with Transaction

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

the class BasicDriverTest method doExtendedRollbackRollbackRollback.

private void doExtendedRollbackRollbackRollback() {
    try (Transaction tx = session.beginTransaction()) {
        // rollback_deferred
        m3();
        // rollback_deferred
        m3();
        // won't commit outer transaction
        tx.rollback();
    }
}
Also used : Transaction(org.neo4j.ogm.transaction.Transaction)

Example 20 with Transaction

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

the class CyclicStructureTest method testCyclicStructure.

/**
 * This issue was introduced by #407
 *
 * @see org.neo4j.ogm.persistence.examples.social.SocialIntegrationTest#shouldSaveObjectsToCorrectDepth
 * @see org.neo4j.ogm.persistence.examples.social.SocialIntegrationTest#shouldSaveAllDirectedRelationships
 */
// GH-609
@Test
public void testCyclicStructure() throws Exception {
    long numberOfNodes = 10;
    long numberOfRefFields = 100;
    List<CyclicNodeType> nodes = new ArrayList<>();
    for (long i = 0; i < numberOfNodes; ++i) {
        nodes.add(new CyclicNodeType());
    }
    List<RefField> refFields = new ArrayList<>();
    for (long i = 0; i < numberOfRefFields; i++) {
        RefField field = new RefField().setNodeTypes(nodes);
        refFields.add(field);
    }
    for (CyclicNodeType nodeType : nodes) {
        nodeType.setSubordinateNodeTypes(nodes);
        nodeType.setRefFields(refFields);
    }
    Session session = sessionFactory.openSession();
    // Make sure the number of builders fits the number of expected relationships
    MultiStatementCypherCompiler compiler = (MultiStatementCypherCompiler) mapAndCompile((Neo4jSession) session, nodes.get(0), -1);
    List<RelationshipBuilder> newRelationshipBuilders = extractRelationshipBuilder(compiler);
    assertThat(newRelationshipBuilders).size().isEqualTo(numberOfNodes * numberOfNodes + (numberOfNodes * numberOfRefFields * 2));
    // Make sure the session saves all relationships accordingly
    Transaction transaction = session.beginTransaction();
    session.save(nodes.get(0), -1);
    session.clear();
    transaction.commit();
    session = sessionFactory.openSession();
    Result result = session.query("" + " MATCH (c1:CyclicNodeType) - [s:SUBORDINATE] - (c2:CyclicNodeType)," + "       (c1) - [f:HAS_FIELD] -> (r:RefField)" + " RETURN count(distinct c1) as numberOfNodes, count(distinct s) as countRelCyc, " + "        count(distinct r)  as numberOfRefFields, count(distinct f) as countRelHasField", Collections.emptyMap());
    assertThat(result).hasSize(1);
    result.queryResults().forEach(record -> {
        assertThat(record.get("numberOfNodes")).isEqualTo(numberOfNodes);
        assertThat(record.get("numberOfRefFields")).isEqualTo(numberOfRefFields);
        assertThat(record.get("countRelCyc")).isEqualTo(numberOfNodes * numberOfNodes);
        assertThat(record.get("countRelHasField")).isEqualTo(numberOfNodes * numberOfRefFields);
    });
}
Also used : ArrayList(java.util.ArrayList) RefField(org.neo4j.ogm.domain.gh609.RefField) Result(org.neo4j.ogm.model.Result) Transaction(org.neo4j.ogm.transaction.Transaction) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) CyclicNodeType(org.neo4j.ogm.domain.gh609.CyclicNodeType) Session(org.neo4j.ogm.session.Session) Neo4jSession(org.neo4j.ogm.session.Neo4jSession) 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