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