Search in sources :

Example 1 with Applier

use of org.neo4j.consistency.checking.GraphStoreFixture.Applier in project neo4j by neo4j.

the class FullCheckIntegrationTest method chainOfDynamicRecordsWithLabelsForANode.

private Pair<List<DynamicRecord>, List<Integer>> chainOfDynamicRecordsWithLabelsForANode(int labelCount) throws TransactionFailureException {
    // allocate enough labels to need three records
    final long[] labels = new long[labelCount + 1];
    final List<Integer> createdLabels = new ArrayList<>();
    try (Applier applier = fixture.createApplier()) {
        for (int i = 1; /*leave space for the node id*/
        i < labels.length; i++) {
            final int offset = i;
            applier.apply(new GraphStoreFixture.Transaction() {

                // Neo4j can create no more than one label per transaction...
                @Override
                protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
                    Integer label = next.label();
                    tx.nodeLabel((int) (labels[offset] = label), "label:" + offset);
                    createdLabels.add(label);
                }
            });
        }
    }
    final List<DynamicRecord> chain = new ArrayList<>();
    fixture.apply(new GraphStoreFixture.Transaction() {

        @Override
        protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
            NodeRecord nodeRecord = new NodeRecord(next.node(), false, -1, -1);
            DynamicRecord record1 = inUse(new DynamicRecord(next.nodeLabel()));
            DynamicRecord record2 = inUse(new DynamicRecord(next.nodeLabel()));
            DynamicRecord record3 = inUse(new DynamicRecord(next.nodeLabel()));
            // the first id should not be a label id, but the id of the node
            labels[0] = nodeRecord.getId();
            ReusableRecordsAllocator allocator = new ReusableRecordsAllocator(60, record1, record2, record3);
            allocateFromNumbers(chain, labels, allocator);
            nodeRecord.setLabelField(dynamicPointer(chain), chain);
            tx.create(nodeRecord);
        }
    });
    return Pair.of(chain, createdLabels);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) ArrayList(java.util.ArrayList) ReusableRecordsAllocator(org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) TransactionDataBuilder(org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder) IdGenerator(org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator) Applier(org.neo4j.consistency.checking.GraphStoreFixture.Applier) GraphStoreFixture(org.neo4j.consistency.checking.GraphStoreFixture)

Aggregations

ArrayList (java.util.ArrayList)1 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)1 Applier (org.neo4j.consistency.checking.GraphStoreFixture.Applier)1 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)1 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)1 ReusableRecordsAllocator (org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator)1 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)1 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)1