Search in sources :

Example 6 with NodePropertyDescriptor

use of org.neo4j.kernel.api.schema.NodePropertyDescriptor in project neo4j by neo4j.

the class ResampleIndexProcedureTest method shouldLookUpTheIndexByLabelIdAndPropertyKeyId.

@Test
public void shouldLookUpTheIndexByLabelIdAndPropertyKeyId() throws ProcedureException, SchemaRuleNotFoundException, IndexNotFoundKernelException {
    NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel(0, 0);
    when(operations.labelGetForName(anyString())).thenReturn(123);
    when(operations.propertyKeyGetForName(anyString())).thenReturn(456);
    when(operations.indexGetForLabelAndPropertyKey(anyObject())).thenReturn(index);
    procedure.resampleIndex(":Person(name)");
    verify(operations).indexGetForLabelAndPropertyKey(new NodePropertyDescriptor(123, 456));
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) Test(org.junit.Test)

Example 7 with NodePropertyDescriptor

use of org.neo4j.kernel.api.schema.NodePropertyDescriptor in project neo4j by neo4j.

the class UniquenessConstraintValidationIT method addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup.

@Test
public void addingUniqueNodeWithUnrelatedValueShouldNotAffectLookup() throws Exception {
    // given
    createConstraint("Person", "id");
    long ourNode;
    {
        Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
        ourNode = createLabeledNode(statement, "Person", "id", 1);
        commit();
    }
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    ReadOperations readOps = statement.readOperations();
    int person = readOps.labelGetForName("Person");
    int propId = readOps.propertyKeyGetForName("id");
    NewIndexDescriptor idx = readOps.uniqueIndexGetForLabelAndPropertyKey(new NodePropertyDescriptor(person, propId));
    // when
    createLabeledNode(statement, "Person", "id", 2);
    // then I should find the original node
    assertThat(readOps.nodeGetFromUniqueIndexSeek(idx, exact(propId, 1)), equalTo(ourNode));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 8 with NodePropertyDescriptor

use of org.neo4j.kernel.api.schema.NodePropertyDescriptor in project neo4j by neo4j.

the class UniquenessConstraintValidationIT method unrelatedNodesWithSamePropertyShouldNotInterfereWithUniquenessCheck.

@Test
public void unrelatedNodesWithSamePropertyShouldNotInterfereWithUniquenessCheck() throws Exception {
    // given
    createConstraint("Person", "id");
    long ourNode;
    {
        Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
        ourNode = createLabeledNode(statement, "Person", "id", 1);
        createLabeledNode(statement, "Item", "id", 2);
        commit();
    }
    Statement statement = statementInNewTransaction(AnonymousContext.writeToken());
    ReadOperations readOps = statement.readOperations();
    int person = readOps.labelGetForName("Person");
    int propId = readOps.propertyKeyGetForName("id");
    NewIndexDescriptor idx = readOps.uniqueIndexGetForLabelAndPropertyKey(new NodePropertyDescriptor(person, propId));
    // when
    createLabeledNode(statement, "Item", "id", 2);
    // then I should find the original node
    assertThat(readOps.nodeGetFromUniqueIndexSeek(idx, exact(propId, 1)), equalTo(ourNode));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) Statement(org.neo4j.kernel.api.Statement) Test(org.junit.Test)

Example 9 with NodePropertyDescriptor

use of org.neo4j.kernel.api.schema.NodePropertyDescriptor in project neo4j by neo4j.

the class DbStructureInvocationTracingAcceptanceTest method exerciseVisitor.

private void exerciseVisitor(Function<Object, DbStructureVisitor> visitor) {
    visitor.apply(null).visitLabel(0, "Person");
    visitor.apply(null).visitLabel(1, "Party");
    visitor.apply(null).visitPropertyKey(0, "name");
    visitor.apply(null).visitPropertyKey(1, "age");
    visitor.apply(null).visitRelationshipType(0, "ACCEPTS");
    visitor.apply(null).visitRelationshipType(1, "REJECTS");
    visitor.apply(null).visitIndex(NewIndexDescriptorFactory.forLabel(0, 1), ":Person(age)", 0.5d, 1L);
    visitor.apply(null).visitUniqueIndex(NewIndexDescriptorFactory.forLabel(0, 0), ":Person(name)", 0.5d, 1L);
    visitor.apply(null).visitUniqueConstraint(new UniquenessConstraint(new NodePropertyDescriptor(1, 0)), ":Party(name)");
    visitor.apply(null).visitAllNodesCount(55);
    visitor.apply(null).visitNodeCount(0, "Person", 50);
    visitor.apply(null).visitNodeCount(0, "Party", 5);
    visitor.apply(null).visitRelCount(0, 1, -1, "MATCH (:Person)-[:REJECTS]->() RETURN count(*)", 5);
}
Also used : NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint)

Aggregations

NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)9 Test (org.junit.Test)5 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)3 ReadOperations (org.neo4j.kernel.api.ReadOperations)2 Statement (org.neo4j.kernel.api.Statement)2 UniquenessConstraint (org.neo4j.kernel.api.constraints.UniquenessConstraint)2 Before (org.junit.Before)1 TokenWriteOperations (org.neo4j.kernel.api.TokenWriteOperations)1 NodePropertyConstraint (org.neo4j.kernel.api.constraints.NodePropertyConstraint)1 NodeMultiPropertyDescriptor (org.neo4j.kernel.api.schema.NodeMultiPropertyDescriptor)1 NeoStores (org.neo4j.kernel.impl.store.NeoStores)1