Search in sources :

Example 96 with Transaction

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

the class SchemaConstraintsIT method createLabelUniquenessPropertyConstraint.

private ConstraintDefinition createLabelUniquenessPropertyConstraint(String labelName, String propertyKey) {
    try (Transaction tx = graphdb().beginTx()) {
        ConstraintDefinition constraintDefinition = graphdb().schema().constraintFor(label(labelName)).assertPropertyIsUnique(propertyKey).create();
        tx.success();
        return constraintDefinition;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 97 with Transaction

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

the class GraphDbHelper method getRelationship.

public Relationship getRelationship(long relationshipId) {
    try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.read())) {
        Relationship relationship = database.getGraph().getRelationshipById(relationshipId);
        tx.success();
        return relationship;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Relationship(org.neo4j.graphdb.Relationship)

Example 98 with Transaction

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

the class GraphDbHelper method getIndexedRelationships.

public Collection<Long> getIndexedRelationships(String indexName, String key, Object value) {
    try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.write())) {
        Collection<Long> result = new ArrayList<>();
        for (Relationship relationship : database.getGraph().index().forRelationships(indexName).get(key, value)) {
            result.add(relationship.getId());
        }
        tx.success();
        return result;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Relationship(org.neo4j.graphdb.Relationship) ArrayList(java.util.ArrayList)

Example 99 with Transaction

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

the class GraphDbHelper method createPropertyUniquenessConstraint.

public ConstraintDefinition createPropertyUniquenessConstraint(String labelName, List<String> propertyKeys) {
    try (Transaction tx = database.getGraph().beginTransaction(implicit, AUTH_DISABLED)) {
        ConstraintCreator creator = database.getGraph().schema().constraintFor(label(labelName));
        for (String propertyKey : propertyKeys) {
            creator = creator.assertPropertyIsUnique(propertyKey);
        }
        ConstraintDefinition result = creator.create();
        tx.success();
        return result;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ConstraintCreator(org.neo4j.graphdb.schema.ConstraintCreator) ConstraintDefinition(org.neo4j.graphdb.schema.ConstraintDefinition)

Example 100 with Transaction

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

the class GraphDbHelper method addRelationshipToIndex.

public void addRelationshipToIndex(String indexName, String key, String value, long relationshipId) {
    try (Transaction tx = database.getGraph().beginTransaction(implicit, AUTH_DISABLED)) {
        Index<Relationship> index = database.getGraph().index().forRelationships(indexName);
        index.add(database.getGraph().getRelationshipById(relationshipId), key, value);
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Relationship(org.neo4j.graphdb.Relationship)

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