use of org.neo4j.storageengine.api.schema.SchemaRule in project neo4j by neo4j.
the class PhysicalLogCommandReaderV3_0 method visitSchemaRuleCommand.
private Command visitSchemaRuleCommand(ReadableChannel channel) throws IOException {
Collection<DynamicRecord> recordsBefore = new ArrayList<>();
readDynamicRecords(channel, recordsBefore, COLLECTION_DYNAMIC_RECORD_ADDER);
Collection<DynamicRecord> recordsAfter = new ArrayList<>();
readDynamicRecords(channel, recordsAfter, COLLECTION_DYNAMIC_RECORD_ADDER);
byte isCreated = channel.get();
if (1 == isCreated) {
for (DynamicRecord record : recordsAfter) {
record.setCreated();
}
}
SchemaRule rule = Iterables.first(recordsAfter).inUse() ? readSchemaRule(recordsAfter) : readSchemaRule(recordsBefore);
return new Command.SchemaRuleCommand(recordsBefore, recordsAfter, rule);
}
use of org.neo4j.storageengine.api.schema.SchemaRule in project neo4j by neo4j.
the class SchemaStoreTest method storeAndLoadAllRules.
@Test
public void storeAndLoadAllRules() throws Exception {
// GIVEN
long indexId = store.nextId();
long constraintId = store.nextId();
Collection<SchemaRule> rules = Arrays.asList(uniqueIndexRule(indexId, constraintId, PROVIDER_DESCRIPTOR, 2, 5, 3), constraintUniqueRule(constraintId, indexId, 2, 5, 3), indexRule(store.nextId(), PROVIDER_DESCRIPTOR, 0, 5), indexRule(store.nextId(), PROVIDER_DESCRIPTOR, 1, 6, 10, 99), constraintExistsRule(store.nextId(), 5, 1));
for (SchemaRule rule : rules) {
storeRule(rule);
}
// WHEN
Collection<SchemaRule> readRules = asCollection(store.loadAllSchemaRules());
// THEN
assertEquals(rules, readRules);
}
use of org.neo4j.storageengine.api.schema.SchemaRule 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.storageengine.api.schema.SchemaRule in project neo4j by neo4j.
the class SchemaStorage method loadAllSchemaRules.
<ReturnType extends SchemaRule> Iterator<ReturnType> loadAllSchemaRules(final Predicate<ReturnType> predicate, final Class<ReturnType> returnType, final boolean ignoreMalformed) {
return new PrefetchingIterator<ReturnType>() {
private final long highestId = schemaStore.getHighestPossibleIdInUse();
private long currentId = 1;
/*record 0 contains the block size*/
private final byte[] scratchData = newRecordBuffer();
private final DynamicRecord record = schemaStore.newRecord();
@Override
protected ReturnType fetchNextOrNull() {
while (currentId <= highestId) {
long id = currentId++;
schemaStore.getRecord(id, record, RecordLoad.FORCE);
if (record.inUse() && record.isStartRecord()) {
try {
SchemaRule schemaRule = loadSingleSchemaRuleViaBuffer(id, scratchData);
if (returnType.isInstance(schemaRule)) {
ReturnType returnRule = returnType.cast(schemaRule);
if (predicate.test(returnRule)) {
return returnRule;
}
}
} catch (MalformedSchemaRuleException e) {
if (!ignoreMalformed) {
throw new RuntimeException(e);
}
}
}
}
return null;
}
};
}
use of org.neo4j.storageengine.api.schema.SchemaRule in project neo4j by neo4j.
the class PhysicalLogCommandReaderV2_1 method readSchemaRule.
private SchemaRule readSchemaRule(Collection<DynamicRecord> recordsBefore) {
// TODO: Why was this assertion here?
// assert first(recordsBefore).inUse() : "Asked to deserialize schema records that were not in
// use.";
SchemaRule rule;
ByteBuffer deserialized = AbstractDynamicStore.concatData(recordsBefore, new byte[100]);
try {
rule = SchemaRuleSerialization.deserialize(Iterables.first(recordsBefore).getId(), deserialized);
} catch (MalformedSchemaRuleException e) {
return null;
}
return rule;
}
Aggregations