Search in sources :

Example 31 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class SchemaImpl method getConstraints.

@Override
public Iterable<ConstraintDefinition> getConstraints(RelationshipType type) {
    actions.assertInOpenTransaction();
    try (Statement statement = statementContextSupplier.get()) {
        int typeId = statement.readOperations().relationshipTypeGetForName(type.name());
        if (typeId == KeyReadOperations.NO_SUCH_RELATIONSHIP_TYPE) {
            return emptyList();
        }
        Iterator<ConstraintDescriptor> constraints = statement.readOperations().constraintsGetForRelationshipType(typeId);
        return asConstraintDefinitions(constraints, statement.readOperations());
    }
}
Also used : Statement(org.neo4j.kernel.api.Statement) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) PropertyConstraint(org.neo4j.kernel.api.constraints.PropertyConstraint) NodePropertyExistenceConstraint(org.neo4j.kernel.api.constraints.NodePropertyExistenceConstraint) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint) RelationshipPropertyConstraint(org.neo4j.kernel.api.constraints.RelationshipPropertyConstraint) NodePropertyConstraint(org.neo4j.kernel.api.constraints.NodePropertyConstraint) RelationshipPropertyExistenceConstraint(org.neo4j.kernel.api.constraints.RelationshipPropertyExistenceConstraint)

Example 32 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class SchemaImpl method getIndexes.

@Override
public Iterable<IndexDefinition> getIndexes() {
    try (Statement statement = statementContextSupplier.get()) {
        List<IndexDefinition> definitions = new ArrayList<>();
        addDefinitions(definitions, statement.readOperations(), statement.readOperations().indexesGetAll(), false);
        addDefinitions(definitions, statement.readOperations(), statement.readOperations().uniqueIndexesGetAll(), true);
        return definitions;
    }
}
Also used : IndexDefinition(org.neo4j.graphdb.schema.IndexDefinition) Statement(org.neo4j.kernel.api.Statement) ArrayList(java.util.ArrayList)

Example 33 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class GraphDatabaseFacade method nodesByLabelAndProperty.

private ResourceIterator<Node> nodesByLabelAndProperty(Label myLabel, String key, Object value) {
    Statement statement = spi.currentStatement();
    ReadOperations readOps = statement.readOperations();
    int propertyId = readOps.propertyKeyGetForName(key);
    int labelId = readOps.labelGetForName(myLabel.name());
    if (propertyId == NO_SUCH_PROPERTY_KEY || labelId == NO_SUCH_LABEL) {
        statement.close();
        return emptyIterator();
    }
    NewIndexDescriptor descriptor = findAnyIndexByLabelAndProperty(readOps, propertyId, labelId);
    try {
        if (null != descriptor) {
            // Ha! We found an index - let's use it to find matching nodes
            IndexQuery.ExactPredicate query = IndexQuery.exact(descriptor.schema().getPropertyId(), value);
            return map2nodes(readOps.indexQuery(descriptor, query), statement);
        }
    } catch (KernelException e) {
    // weird at this point but ignore and fallback to a label scan
    }
    return getNodesByLabelAndPropertyWithoutIndex(propertyId, value, statement, labelId);
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) KeyReadOperations(org.neo4j.kernel.impl.api.operations.KeyReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) Statement(org.neo4j.kernel.api.Statement) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) InvalidTransactionTypeKernelException(org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) SchemaKernelException(org.neo4j.kernel.api.exceptions.schema.SchemaKernelException)

Example 34 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class Neo4jTransactionalContextFactory method create.

@Deprecated
public static TransactionalContextFactory create(GraphDatabaseQueryService queryService, PropertyContainerLocker locker) {
    DependencyResolver resolver = queryService.getDependencyResolver();
    ThreadToStatementContextBridge txBridge = resolver.resolveDependency(ThreadToStatementContextBridge.class);
    Guard guard = resolver.resolveDependency(Guard.class);
    Neo4jTransactionalContext.Creator contextCreator = (Supplier<Statement> statementSupplier, InternalTransaction tx, Statement initialStatement, ExecutingQuery executingQuery) -> new Neo4jTransactionalContext(queryService, statementSupplier, guard, txBridge, locker, tx, initialStatement, executingQuery);
    return new Neo4jTransactionalContextFactory(txBridge, contextCreator);
}
Also used : ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) Statement(org.neo4j.kernel.api.Statement) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) Guard(org.neo4j.kernel.guard.Guard) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 35 with Statement

use of org.neo4j.kernel.api.Statement in project neo4j by neo4j.

the class Neo4jTransactionalContextFactory method newContext.

@Override
public final Neo4jTransactionalContext newContext(ClientConnectionInfo clientConnection, InternalTransaction tx, String queryText, Map<String, Object> queryParameters) {
    Statement initialStatement = statementSupplier.get();
    ClientConnectionInfo connectionWithUserName = clientConnection.withUsername(tx.securityContext().subject().username());
    ExecutingQuery executingQuery = initialStatement.queryRegistration().startQueryExecution(connectionWithUserName, queryText, queryParameters);
    return contextCreator.create(statementSupplier, tx, initialStatement, executingQuery);
}
Also used : ClientConnectionInfo(org.neo4j.kernel.impl.query.clientconnection.ClientConnectionInfo) ExecutingQuery(org.neo4j.kernel.api.query.ExecutingQuery) Statement(org.neo4j.kernel.api.Statement)

Aggregations

Statement (org.neo4j.kernel.api.Statement)158 Test (org.junit.Test)76 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)56 Transaction (org.neo4j.graphdb.Transaction)44 ReadOperations (org.neo4j.kernel.api.ReadOperations)40 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)30 EntityNotFoundException (org.neo4j.kernel.api.exceptions.EntityNotFoundException)23 NotFoundException (org.neo4j.graphdb.NotFoundException)21 Node (org.neo4j.graphdb.Node)20 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)19 PropertyNotFoundException (org.neo4j.kernel.api.exceptions.PropertyNotFoundException)13 KeyReadOperations (org.neo4j.kernel.impl.api.operations.KeyReadOperations)11 ArrayList (java.util.ArrayList)10 DependencyResolver (org.neo4j.graphdb.DependencyResolver)10 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 Label (org.neo4j.graphdb.Label)9 KernelAPI (org.neo4j.kernel.api.KernelAPI)9 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)9 InvalidTransactionTypeKernelException (org.neo4j.kernel.api.exceptions.InvalidTransactionTypeKernelException)8 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)8