Search in sources :

Example 11 with Statement

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

the class IndexStatisticsTest method dropIndex.

private void dropIndex(NewIndexDescriptor index) throws KernelException {
    try (Transaction tx = db.beginTx()) {
        Statement statement = bridge.get();
        statement.schemaWriteOperations().indexDrop(index);
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Statement(org.neo4j.kernel.api.Statement)

Example 12 with Statement

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

the class IndexIT method committedAndTransactionalIndexRulesShouldBeMerged.

@Test
public void committedAndTransactionalIndexRulesShouldBeMerged() throws Exception {
    // GIVEN
    SchemaWriteOperations schemaWriteOperations = schemaWriteOperationsInNewTransaction();
    NewIndexDescriptor existingRule = schemaWriteOperations.indexCreate(SchemaBoundary.map(descriptor));
    commit();
    // WHEN
    Statement statement = statementInNewTransaction(AnonymousContext.AUTH_DISABLED);
    NewIndexDescriptor addedRule = statement.schemaWriteOperations().indexCreate(SchemaDescriptorFactory.forLabel(labelId, 10));
    Set<NewIndexDescriptor> indexRulesInTx = asSet(statement.readOperations().indexesGetForLabel(labelId));
    commit();
    // THEN
    assertEquals(asSet(existingRule, addedRule), indexRulesInTx);
}
Also used : SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 13 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 14 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 15 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)

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