Search in sources :

Example 1 with NodePropertyDescriptor

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

the class IndexIT method createLabelAndProperty.

@Before
public void createLabelAndProperty() throws Exception {
    TokenWriteOperations tokenWrites = tokenWriteOperationsInNewTransaction();
    labelId = tokenWrites.labelGetOrCreateForName(LABEL);
    propertyKeyId = tokenWrites.propertyKeyGetOrCreateForName(PROPERTY_KEY);
    descriptor = new NodePropertyDescriptor(labelId, propertyKeyId);
    commit();
}
Also used : TokenWriteOperations(org.neo4j.kernel.api.TokenWriteOperations) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) Before(org.junit.Before)

Example 2 with NodePropertyDescriptor

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

the class IndexingAcceptanceTest method indexDescriptor.

private NewIndexDescriptor indexDescriptor(ReadOperations readOperations, IndexDefinition index) throws SchemaRuleNotFoundException {
    int labelId = readOperations.labelGetForName(index.getLabel().name());
    int[] propertyKeyIds = getPropertyKeyIds(readOperations, index.getPropertyKeys());
    NodePropertyDescriptor descriptor = new NodeMultiPropertyDescriptor(labelId, propertyKeyIds);
    return readOperations.indexGetForLabelAndPropertyKey(descriptor);
}
Also used : NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) NodeMultiPropertyDescriptor(org.neo4j.kernel.api.schema.NodeMultiPropertyDescriptor)

Example 3 with NodePropertyDescriptor

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

the class HighIdTransactionApplierTest method shouldUpdateHighIdsOnExternalTransaction.

@Test
public void shouldUpdateHighIdsOnExternalTransaction() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    HighIdTransactionApplier tracker = new HighIdTransactionApplier(neoStores);
    // WHEN
    // Nodes
    tracker.visitNodeCommand(Commands.createNode(10, 2, 3));
    tracker.visitNodeCommand(Commands.createNode(20, 4, 5));
    // Relationships
    tracker.visitRelationshipCommand(Commands.createRelationship(4, 10, 20, 0));
    tracker.visitRelationshipCommand(Commands.createRelationship(45, 10, 20, 1));
    // Label tokens
    tracker.visitLabelTokenCommand(Commands.createLabelToken(3, 0));
    tracker.visitLabelTokenCommand(Commands.createLabelToken(5, 1));
    // Property tokens
    tracker.visitPropertyKeyTokenCommand(Commands.createPropertyKeyToken(3, 0));
    tracker.visitPropertyKeyTokenCommand(Commands.createPropertyKeyToken(5, 1));
    // Relationship type tokens
    tracker.visitRelationshipTypeTokenCommand(Commands.createRelationshipTypeToken(3, 0));
    tracker.visitRelationshipTypeTokenCommand(Commands.createRelationshipTypeToken(5, 1));
    // Relationship groups
    tracker.visitRelationshipGroupCommand(Commands.createRelationshipGroup(10, 1));
    tracker.visitRelationshipGroupCommand(Commands.createRelationshipGroup(20, 2));
    // Schema rules
    tracker.visitSchemaRuleCommand(Commands.createIndexRule(NO_INDEX_PROVIDER.getProviderDescriptor(), 10, new NodePropertyDescriptor(0, 1)));
    tracker.visitSchemaRuleCommand(Commands.createIndexRule(NO_INDEX_PROVIDER.getProviderDescriptor(), 20, new NodePropertyDescriptor(1, 2)));
    // Properties
    tracker.visitPropertyCommand(Commands.createProperty(10, PropertyType.STRING, 0, 6, 7));
    tracker.visitPropertyCommand(Commands.createProperty(20, PropertyType.ARRAY, 1, 8, 9));
    tracker.close();
    // THEN
    assertEquals("NodeStore", 20 + 1, neoStores.getNodeStore().getHighId());
    assertEquals("DynamicNodeLabelStore", 5 + 1, neoStores.getNodeStore().getDynamicLabelStore().getHighId());
    assertEquals("RelationshipStore", 45 + 1, neoStores.getRelationshipStore().getHighId());
    assertEquals("RelationshipTypeStore", 5 + 1, neoStores.getRelationshipTypeTokenStore().getHighId());
    assertEquals("RelationshipType NameStore", 1 + 1, neoStores.getRelationshipTypeTokenStore().getNameStore().getHighId());
    assertEquals("PropertyKeyStore", 5 + 1, neoStores.getPropertyKeyTokenStore().getHighId());
    assertEquals("PropertyKey NameStore", 1 + 1, neoStores.getPropertyKeyTokenStore().getNameStore().getHighId());
    assertEquals("LabelStore", 5 + 1, neoStores.getLabelTokenStore().getHighId());
    assertEquals("Label NameStore", 1 + 1, neoStores.getLabelTokenStore().getNameStore().getHighId());
    assertEquals("PropertyStore", 20 + 1, neoStores.getPropertyStore().getHighId());
    assertEquals("PropertyStore DynamicStringStore", 7 + 1, neoStores.getPropertyStore().getStringStore().getHighId());
    assertEquals("PropertyStore DynamicArrayStore", 9 + 1, neoStores.getPropertyStore().getArrayStore().getHighId());
    assertEquals("SchemaStore", 20 + 1, neoStores.getSchemaStore().getHighId());
}
Also used : NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Test(org.junit.Test)

Example 4 with NodePropertyDescriptor

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

the class DbStructureCollectorTest method collectsDbStructure.

@Test
public void collectsDbStructure() {
    // GIVEN
    DbStructureCollector collector = new DbStructureCollector();
    collector.visitLabel(1, "Person");
    collector.visitLabel(2, "City");
    collector.visitPropertyKey(1, "name");
    collector.visitPropertyKey(2, "income");
    collector.visitRelationshipType(1, "LIVES_IN");
    collector.visitRelationshipType(2, "FRIEND");
    collector.visitUniqueIndex(NewIndexDescriptorFactory.forLabel(1, 1), ":Person(name)", 1.0d, 1L);
    collector.visitUniqueConstraint(new UniquenessConstraint(new NodePropertyDescriptor(2, 1)), ":Person(name)");
    collector.visitIndex(NewIndexDescriptorFactory.forLabel(2, 2), ":City(income)", 0.2d, 1L);
    collector.visitAllNodesCount(50);
    collector.visitNodeCount(1, "Person", 20);
    collector.visitNodeCount(2, "City", 30);
    collector.visitRelCount(1, 2, -1, "(:Person)-[:FRIEND]->()", 500);
    // WHEN
    DbStructureLookup lookup = collector.lookup();
    // THEN
    assertEquals(asList(of(1, "Person"), of(2, "City")), Iterators.asList(lookup.labels()));
    assertEquals(asList(of(1, "name"), of(2, "income")), Iterators.asList(lookup.properties()));
    assertEquals(asList(of(1, "LIVES_IN"), of(2, "FRIEND")), Iterators.asList(lookup.relationshipTypes()));
    assertEquals(asList(of("City", "name")), Iterators.asList(lookup.knownUniqueConstraints()));
    assertEquals(asList(of("Person", "name")), Iterators.asList(lookup.knownUniqueIndices()));
    assertEquals(asList(of("City", "income")), Iterators.asList(lookup.knownIndices()));
    assertEquals(50, lookup.nodesWithLabelCardinality(-1));
    assertEquals(20, lookup.nodesWithLabelCardinality(1));
    assertEquals(30, lookup.nodesWithLabelCardinality(2));
    assertEquals(500, lookup.cardinalityByLabelsAndRelationshipType(1, 2, -1));
    assertEquals(1.0d, lookup.indexSelectivity(1, 1), 0.01d);
    assertEquals(0.2d, lookup.indexSelectivity(2, 2), 0.01d);
}
Also used : NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor) UniquenessConstraint(org.neo4j.kernel.api.constraints.UniquenessConstraint) Test(org.junit.Test)

Example 5 with NodePropertyDescriptor

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

the class AlreadyConstrainedException method constructUserMessage.

private static String constructUserMessage(OperationContext context, TokenNameLookup tokenNameLookup, PropertyConstraint constraint) {
    switch(context) {
        case INDEX_CREATION:
            // is is safe to cast here because we only support indexes on nodes atm
            NodePropertyConstraint nodePropertyConstraint = (NodePropertyConstraint) constraint;
            NodePropertyDescriptor descriptor = nodePropertyConstraint.descriptor();
            return messageWithLabelAndPropertyName(tokenNameLookup, INDEX_CONTEXT_FORMAT, descriptor);
        case CONSTRAINT_CREATION:
            return ALREADY_CONSTRAINED_MESSAGE_PREFIX + constraint.userDescription(tokenNameLookup);
        default:
            return format(NO_CONTEXT_FORMAT, constraint);
    }
}
Also used : NodePropertyConstraint(org.neo4j.kernel.api.constraints.NodePropertyConstraint) NodePropertyDescriptor(org.neo4j.kernel.api.schema.NodePropertyDescriptor)

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