Search in sources :

Example 1 with SchemaStore

use of org.neo4j.kernel.impl.store.SchemaStore in project neo4j by neo4j.

the class BatchInsertTest method shouldCreateConsistentUniquenessConstraint.

@Test
public void shouldCreateConsistentUniquenessConstraint() throws Exception {
    // given
    BatchInserter inserter = newBatchInserter();
    // when
    inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
    // then
    GraphDatabaseAPI graphdb = (GraphDatabaseAPI) switchToEmbeddedGraphDatabaseService(inserter);
    try {
        NeoStores neoStores = graphdb.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
        SchemaStore store = neoStores.getSchemaStore();
        SchemaStorage storage = new SchemaStorage(store);
        List<Long> inUse = new ArrayList<>();
        DynamicRecord record = store.nextRecord();
        for (long i = 1, high = store.getHighestPossibleIdInUse(); i <= high; i++) {
            store.getRecord(i, record, RecordLoad.FORCE);
            if (record.inUse() && record.isStartRecord()) {
                inUse.add(i);
            }
        }
        assertEquals("records in use", 2, inUse.size());
        SchemaRule rule0 = storage.loadSingleSchemaRule(inUse.get(0));
        SchemaRule rule1 = storage.loadSingleSchemaRule(inUse.get(1));
        IndexRule indexRule;
        ConstraintRule constraintRule;
        if (rule0 instanceof IndexRule) {
            indexRule = (IndexRule) rule0;
            constraintRule = (ConstraintRule) rule1;
        } else {
            constraintRule = (ConstraintRule) rule0;
            indexRule = (IndexRule) rule1;
        }
        assertEquals("index should reference constraint", constraintRule.getId(), indexRule.getOwningConstraint().longValue());
        assertEquals("constraint should reference index", indexRule.getId(), constraintRule.getOwnedIndex());
    } finally {
        graphdb.shutdown();
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) ArrayList(java.util.ArrayList) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Matchers.anyLong(org.mockito.Matchers.anyLong) Test(org.junit.Test)

Example 2 with SchemaStore

use of org.neo4j.kernel.impl.store.SchemaStore in project neo4j by neo4j.

the class FullCheckIntegrationTest method createRelationshipPropertyExistenceConstraint.

private void createRelationshipPropertyExistenceConstraint(int relTypeId, int propertyKeyId) {
    SchemaStore schemaStore = (SchemaStore) fixture.directStoreAccess().nativeStores().getSchemaStore();
    ConstraintRule rule = relPropertyExistenceConstraintRule(schemaStore.nextId(), relTypeId, propertyKeyId);
    Collection<DynamicRecord> records = schemaStore.allocateFrom(rule);
    for (DynamicRecord record : records) {
        schemaStore.updateRecord(record);
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) SchemaRuleUtil.uniquenessConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule) SchemaRuleUtil.relPropertyExistenceConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.relPropertyExistenceConstraintRule) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) SchemaRuleUtil.nodePropertyExistenceConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.nodePropertyExistenceConstraintRule)

Example 3 with SchemaStore

use of org.neo4j.kernel.impl.store.SchemaStore in project neo4j by neo4j.

the class IndexLookupTest method setUp.

@BeforeClass
public static void setUp() {
    api = dbRule.getGraphDatabaseAPI();
    String notUsedIndexPropKey = "notUsed";
    String usedIndexPropKey = "used";
    Label usedLabel = Label.label("UsedLabel");
    Label notUsedLabel = Label.label("NotUsedLabel");
    try (Transaction transaction = api.beginTx()) {
        api.schema().indexFor(usedLabel).on(usedIndexPropKey).create();
        transaction.success();
    }
    try (Transaction transaction = api.beginTx()) {
        api.schema().awaitIndexesOnline(10, TimeUnit.SECONDS);
        indexedNodePropertyValue = "value1";
        notIndexedNodePropertyValue = "value2";
        Node nodeA = api.createNode(usedLabel);
        nodeA.setProperty(usedIndexPropKey, indexedNodePropertyValue);
        nodeA.setProperty(notUsedIndexPropKey, notIndexedNodePropertyValue);
        indexedNode = nodeA.getId();
        Node nodeB = api.createNode(notUsedLabel);
        nodeB.setProperty(usedIndexPropKey, notIndexedNodePropertyValue);
        nodeB.setProperty(notUsedIndexPropKey, indexedNodePropertyValue);
        notIndexedNode = nodeB.getId();
        transaction.success();
    }
    DependencyResolver resolver = api.getDependencyResolver();
    NeoStores neoStores = resolver.resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
    SchemaStore schemaStore = neoStores.getSchemaStore();
    SchemaIndexProvider schemaIndexProvider = resolver.resolveDependency(SchemaIndexProvider.class);
    indexLookup = new IndexLookup(schemaStore, schemaIndexProvider);
    LabelTokenStore labelTokenStore = neoStores.getLabelTokenStore();
    notUsedLabelId = findTokenFor(labelTokenStore, notUsedLabel.name()).id();
    usedLabelId = findTokenFor(labelTokenStore, usedLabel.name()).id();
    PropertyKeyTokenStore propertyKeyTokenStore = neoStores.getPropertyKeyTokenStore();
    notUsedPropertyId = findTokenFor(propertyKeyTokenStore, notUsedIndexPropKey).id();
    usedPropertyId = findTokenFor(propertyKeyTokenStore, usedIndexPropKey).id();
}
Also used : LabelTokenStore(org.neo4j.kernel.impl.store.LabelTokenStore) PropertyKeyTokenStore(org.neo4j.kernel.impl.store.PropertyKeyTokenStore) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) Transaction(org.neo4j.graphdb.Transaction) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) Node(org.neo4j.graphdb.Node) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Label(org.neo4j.graphdb.Label) DependencyResolver(org.neo4j.graphdb.DependencyResolver) BeforeClass(org.junit.BeforeClass)

Example 4 with SchemaStore

use of org.neo4j.kernel.impl.store.SchemaStore in project neo4j by neo4j.

the class DumpStore method dumpSchemaStore.

private static void dumpSchemaStore(NeoStores neoStores, long[] ids) throws Exception {
    try (SchemaStore store = neoStores.getSchemaStore()) {
        final SchemaStorage storage = new SchemaStorage(store);
        new DumpStore<DynamicRecord, SchemaStore>(System.out) {

            @Override
            protected Object transform(DynamicRecord record) throws Exception {
                return record.inUse() && record.isStartRecord() ? storage.loadSingleSchemaRule(record.getId()) : null;
            }
        }.dump(store, ids);
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore)

Example 5 with SchemaStore

use of org.neo4j.kernel.impl.store.SchemaStore in project neo4j by neo4j.

the class FullCheckIntegrationTest method createNodePropertyExistenceConstraint.

private void createNodePropertyExistenceConstraint(int labelId, int propertyKeyId) {
    SchemaStore schemaStore = (SchemaStore) fixture.directStoreAccess().nativeStores().getSchemaStore();
    ConstraintRule rule = nodePropertyExistenceConstraintRule(schemaStore.nextId(), labelId, propertyKeyId);
    Collection<DynamicRecord> records = schemaStore.allocateFrom(rule);
    for (DynamicRecord record : records) {
        schemaStore.updateRecord(record);
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) SchemaRuleUtil.uniquenessConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule) SchemaRuleUtil.relPropertyExistenceConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.relPropertyExistenceConstraintRule) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) SchemaRuleUtil.nodePropertyExistenceConstraintRule(org.neo4j.consistency.checking.SchemaRuleUtil.nodePropertyExistenceConstraintRule)

Aggregations

SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)7 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)4 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)3 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 SchemaRuleUtil.nodePropertyExistenceConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.nodePropertyExistenceConstraintRule)2 SchemaRuleUtil.relPropertyExistenceConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.relPropertyExistenceConstraintRule)2 SchemaRuleUtil.uniquenessConstraintRule (org.neo4j.consistency.checking.SchemaRuleUtil.uniquenessConstraintRule)2 RecordStorageEngine (org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine)2 SchemaStorage (org.neo4j.kernel.impl.store.SchemaStorage)2 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)2 List (java.util.List)1 BeforeClass (org.junit.BeforeClass)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 Label (org.neo4j.graphdb.Label)1 Node (org.neo4j.graphdb.Node)1 Transaction (org.neo4j.graphdb.Transaction)1 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)1