Search in sources :

Example 21 with SchemaRule

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

the class PhysicalLogCommandReaderV3_0_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 22 with SchemaRule

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

the class PhysicalLogCommandReaderV2_2 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);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ArrayList(java.util.ArrayList) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule)

Example 23 with SchemaRule

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

the class PhysicalLogCommandReaderV3_0 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 24 with SchemaRule

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

the class PhysicalLogCommandReaderV2_2_10 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);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ArrayList(java.util.ArrayList) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule)

Example 25 with SchemaRule

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

the class BatchInserterImpl method createRelTypePropertyExistenceConstraintRule.

private void createRelTypePropertyExistenceConstraintRule(int relTypeId, int... propertyKeyIds) {
    SchemaRule rule = ConstraintRule.constraintRule(schemaStore.nextId(), ConstraintDescriptorFactory.existsForRelType(relTypeId, propertyKeyIds));
    for (DynamicRecord record : schemaStore.allocateFrom(rule)) {
        schemaStore.updateRecord(record);
    }
    schemaCache.addSchemaRule(rule);
    flushStrategy.forceFlush();
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule)

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