Search in sources :

Example 1 with MalformedSchemaRuleException

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;
        }
    };
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) PrefetchingIterator(org.neo4j.helpers.collection.PrefetchingIterator) MalformedSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule)

Example 2 with MalformedSchemaRuleException

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));
    }
}
Also used : RelationTypeSchemaDescriptor(org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) SchemaDescriptor(org.neo4j.kernel.api.schema_new.SchemaDescriptor) MalformedSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)

Example 3 with MalformedSchemaRuleException

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;
}
Also used : MalformedSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) ByteBuffer(java.nio.ByteBuffer)

Example 4 with MalformedSchemaRuleException

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;
}
Also used : MalformedSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) ByteBuffer(java.nio.ByteBuffer)

Example 5 with MalformedSchemaRuleException

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();
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) MalformedSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException) ConsistencyReport(org.neo4j.consistency.report.ConsistencyReport) Test(org.junit.Test)

Aggregations

MalformedSchemaRuleException (org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException)11 SchemaRule (org.neo4j.storageengine.api.schema.SchemaRule)8 ByteBuffer (java.nio.ByteBuffer)7 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)2 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)2 Test (org.junit.Test)1 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)1 PrefetchingIterator (org.neo4j.helpers.collection.PrefetchingIterator)1 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)1 RelationTypeSchemaDescriptor (org.neo4j.kernel.api.schema_new.RelationTypeSchemaDescriptor)1 SchemaDescriptor (org.neo4j.kernel.api.schema_new.SchemaDescriptor)1 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)1 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1