use of org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException 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.kernel.api.exceptions.schema.MalformedSchemaRuleException in project neo4j by neo4j.
the class SchemaRuleSerialization method readConstraintRule.
// READ CONSTRAINT
private static ConstraintRule readConstraintRule(long id, ByteBuffer source) throws MalformedSchemaRuleException {
SchemaDescriptor schema;
byte constraintRuleType = source.get();
String name;
switch(constraintRuleType) {
case EXISTS_CONSTRAINT:
schema = readSchema(source);
name = readRuleName(id, ConstraintRule.class, source);
return ConstraintRule.constraintRule(id, ConstraintDescriptorFactory.existsForSchema(schema), name);
case UNIQUE_CONSTRAINT:
long ownedIndex = source.getLong();
schema = readSchema(source);
UniquenessConstraintDescriptor descriptor = ConstraintDescriptorFactory.uniqueForSchema(schema);
name = readRuleName(id, ConstraintRule.class, source);
return ConstraintRule.constraintRule(id, descriptor, ownedIndex, name);
default:
throw new MalformedSchemaRuleException(format("Got unknown constraint rule type '%d'.", constraintRuleType));
}
}
use of org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException 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;
}
use of org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException in project neo4j by neo4j.
the class PhysicalLogCommandReaderV2_2 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;
}
use of org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException in project neo4j by neo4j.
the class SchemaRecordCheckTest method shouldReportMalformedSchemaRule.
@Test
public void shouldReportMalformedSchemaRule() throws Exception {
// given
DynamicRecord badRecord = inUse(new DynamicRecord(0));
badRecord.setType(RecordAccessStub.SCHEMA_RECORD_TYPE);
when(checker().ruleAccess.loadSingleSchemaRule(0)).thenThrow(new MalformedSchemaRuleException("Bad Record"));
// when
ConsistencyReport.SchemaConsistencyReport report = check(badRecord);
// then
verify(report).malformedSchemaRule();
}
Aggregations