Search in sources :

Example 16 with SchemaRule

use of org.neo4j.storageengine.api.schema.SchemaRule in project neo4j by neo4j.

the class IndexLookup method buildIndexRuleIndex.

private PrimitiveIntObjectMap<List<IndexRule>> buildIndexRuleIndex(SchemaStore schemaStore) {
    final PrimitiveIntObjectMap<List<IndexRule>> indexRuleIndex = Primitive.intObjectMap();
    for (SchemaRule schemaRule : schemaStore) {
        if (schemaRule instanceof IndexRule) {
            IndexRule rule = (IndexRule) schemaRule;
            // assuming 1 property always
            int propertyId = rule.schema().getPropertyId();
            List<IndexRule> ruleList = indexRuleIndex.get(propertyId);
            if (ruleList == null) {
                ruleList = new LinkedList<>();
                indexRuleIndex.put(propertyId, ruleList);
            }
            ruleList.add(rule);
        }
    }
    return indexRuleIndex;
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 17 with SchemaRule

use of org.neo4j.storageengine.api.schema.SchemaRule in project neo4j by neo4j.

the class PhysicalLogCommandReaderV2_0 method readSchemaRule.

private SchemaRule readSchemaRule(Collection<DynamicRecord> recordsBefore) {
    assert Iterables.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) {
        // TODO This is bad. We should probably just shut down if that happens
        throw launderedException(e);
    }
    return rule;
}
Also used : MalformedSchemaRuleException(org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) ByteBuffer(java.nio.ByteBuffer)

Example 18 with SchemaRule

use of org.neo4j.storageengine.api.schema.SchemaRule in project neo4j by neo4j.

the class PhysicalLogCommandReaderV2_1 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();
        }
    }
    // txId - ignored
    channel.getLong();
    SchemaRule rule = Iterables.first(recordsAfter).inUse() ? readSchemaRule(recordsAfter) : readSchemaRule(recordsBefore);
    return new Command.SchemaRuleCommand(recordsBefore, recordsAfter, rule);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ArrayList(java.util.ArrayList) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule)

Example 19 with SchemaRule

use of org.neo4j.storageengine.api.schema.SchemaRule in project neo4j by neo4j.

the class PhysicalLogCommandReaderV2_2_10 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 20 with SchemaRule

use of org.neo4j.storageengine.api.schema.SchemaRule in project neo4j by neo4j.

the class PhysicalLogCommandReaderV2_2_4 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)

Aggregations

SchemaRule (org.neo4j.storageengine.api.schema.SchemaRule)27 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)13 ArrayList (java.util.ArrayList)9 MalformedSchemaRuleException (org.neo4j.kernel.api.exceptions.schema.MalformedSchemaRuleException)8 ByteBuffer (java.nio.ByteBuffer)7 Test (org.junit.Test)4 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)4 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 LinkedList (java.util.LinkedList)2 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)2 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)2 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)2 PrimitiveRecord (org.neo4j.kernel.impl.store.record.PrimitiveRecord)2 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)2 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)2 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)2 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)2 RelationshipTypeTokenRecord (org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord)2 List (java.util.List)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1