Search in sources :

Example 91 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class GraphDbHelper method getPropertyUniquenessConstraints.

public Iterable<ConstraintDefinition> getPropertyUniquenessConstraints(String labelName, final String propertyKey) {
    try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.read())) {
        Iterable<ConstraintDefinition> definitions = Iterables.filter(item -> {
            if (item.isConstraintType(ConstraintType.UNIQUENESS)) {
                Iterable<String> keys = item.getPropertyKeys();
                return single(keys).equals(propertyKey);
            } else {
                return false;
            }
        }, database.getGraph().schema().getConstraints(label(labelName)));
        tx.success();
        return definitions;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 92 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class GraphDbHelper method getFirstNode.

public long getFirstNode() {
    try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.write())) {
        try {
            Node referenceNode = database.getGraph().getNodeById(0L);
            tx.success();
            return referenceNode.getId();
        } catch (NotFoundException e) {
            Node newNode = database.getGraph().createNode();
            tx.success();
            return newNode.getId();
        }
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Node(org.neo4j.graphdb.Node) NotFoundException(org.neo4j.graphdb.NotFoundException)

Example 93 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class RelationshipExpanderBuilderTest method createSomeData.

private Node createSomeData() {
    try (Transaction tx = db.beginTx()) {
        Node node = db.createNode();
        node.createRelationshipTo(db.createNode(), MyRelTypes.TEST);
        node.createRelationshipTo(db.createNode(), MyRelTypes.TEST2);
        tx.success();
        return node;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Example 94 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class RelationshipExpanderBuilderTest method shouldInterpretNoSpecifiedRelationshipsAsAll.

@Test
public void shouldInterpretNoSpecifiedRelationshipsAsAll() throws Exception {
    // GIVEN
    Node node = createSomeData();
    PathExpander expander = RelationshipExpanderBuilder.describeRelationships(map());
    // WHEN
    Set<Relationship> expanded;
    try (Transaction tx = db.beginTx()) {
        expanded = asSet(expander.expand(singleNodePath(node), NO_STATE));
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        // THEN
        assertEquals(asSet(node.getRelationships()), expanded);
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) PathExpander(org.neo4j.graphdb.PathExpander) Test(org.junit.Test)

Example 95 with Transaction

use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.

the class PagedTraverserIT method createLinkedList.

private Node createLinkedList(final int listLength, final Database db) {
    Node startNode = null;
    try (Transaction tx = db.getGraph().beginTx()) {
        Node previous = null;
        for (int i = 0; i < listLength; i++) {
            Node current = db.getGraph().createNode();
            current.setProperty("name", String.valueOf(i));
            if (previous != null) {
                previous.createRelationshipTo(current, RelationshipType.withName("NEXT"));
            } else {
                startNode = current;
            }
            previous = current;
        }
        tx.success();
        return startNode;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node)

Aggregations

Transaction (org.neo4j.graphdb.Transaction)2409 Node (org.neo4j.graphdb.Node)1086 Test (org.junit.jupiter.api.Test)751 Test (org.junit.Test)607 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)352 Relationship (org.neo4j.graphdb.Relationship)307 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)302 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)241 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)177 Label (org.neo4j.graphdb.Label)154 Result (org.neo4j.graphdb.Result)142 HashMap (java.util.HashMap)105 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)104 MethodSource (org.junit.jupiter.params.provider.MethodSource)103 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)86 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)77 File (java.io.File)74 ArrayList (java.util.ArrayList)73 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)67 Path (java.nio.file.Path)64