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();
}
}
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);
}
}
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();
}
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);
}
}
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);
}
}
Aggregations