Search in sources :

Example 26 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class RelationshipCreator method relationshipCreate.

/**
     * Creates a relationship with the given id, from the nodes identified by id
     * and of type typeId
     *
     * @param id The id of the relationship to create.
     * @param type The id of the relationship type this relationship will
     *            have.
     * @param firstNodeId The id of the start node.
     * @param secondNodeId The id of the end node.
     */
public void relationshipCreate(long id, int type, long firstNodeId, long secondNodeId, RecordAccessSet recordChangeSet, ResourceLocker locks) {
    // TODO could be unnecessary to mark as changed here already, dense nodes may not need to change
    NodeRecord firstNode = recordChangeSet.getNodeRecords().getOrLoad(firstNodeId, null).forChangingLinkage();
    NodeRecord secondNode = recordChangeSet.getNodeRecords().getOrLoad(secondNodeId, null).forChangingLinkage();
    convertNodeToDenseIfNecessary(firstNode, recordChangeSet.getRelRecords(), recordChangeSet.getRelGroupRecords(), locks);
    convertNodeToDenseIfNecessary(secondNode, recordChangeSet.getRelRecords(), recordChangeSet.getRelGroupRecords(), locks);
    RelationshipRecord record = recordChangeSet.getRelRecords().create(id, null).forChangingLinkage();
    record.setLinks(firstNodeId, secondNodeId, type);
    record.setInUse(true);
    record.setCreated();
    connectRelationship(firstNode, secondNode, record, recordChangeSet.getRelRecords(), recordChangeSet.getRelGroupRecords(), locks);
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 27 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class RelationshipDeleter method decrementTotalRelationshipCount.

private boolean decrementTotalRelationshipCount(long nodeId, RelationshipRecord rel, long firstRelId, RecordAccess<Long, RelationshipRecord, Void> relRecords, ResourceLocker locks) {
    if (firstRelId == Record.NO_PREV_RELATIONSHIP.intValue()) {
        return true;
    }
    boolean firstInChain = relIsFirstInChain(nodeId, rel);
    if (!firstInChain) {
        locks.acquireExclusive(LockTracer.NONE, ResourceTypes.RELATIONSHIP, firstRelId);
    }
    RelationshipRecord firstRel = relRecords.getOrLoad(firstRelId, null).forChangingLinkage();
    if (nodeId == firstRel.getFirstNode()) {
        firstRel.setFirstPrevRel(firstInChain ? relCount(nodeId, rel) - 1 : relCount(nodeId, firstRel) - 1);
        firstRel.setFirstInFirstChain(true);
    }
    if (nodeId == firstRel.getSecondNode()) {
        firstRel.setSecondPrevRel(firstInChain ? relCount(nodeId, rel) - 1 : relCount(nodeId, firstRel) - 1);
        firstRel.setFirstInSecondChain(true);
    }
    return false;
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 28 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class RelationshipDeleter method relDelete.

/**
     * Deletes a relationship by its id, returning its properties which are now
     * removed. It is assumed that the nodes it connects have already been
     * deleted in this
     * transaction.
     *
     * @param id The id of the relationship to delete.
     */
public void relDelete(long id, RecordAccessSet recordChanges, ResourceLocker locks) {
    RelationshipRecord record = recordChanges.getRelRecords().getOrLoad(id, null).forChangingLinkage();
    propertyChainDeleter.deletePropertyChain(record, recordChanges.getPropertyRecords());
    disconnectRelationship(record, recordChanges, locks);
    updateNodesForDeletedRelationship(record, recordChanges, locks);
    record.setInUse(false);
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord)

Example 29 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class PhysicalLogCommandReaderV3_0_2 method visitRelationshipCommand.

private Command visitRelationshipCommand(ReadableChannel channel) throws IOException {
    long id = channel.getLong();
    RelationshipRecord before = readRelationshipRecord(id, channel);
    if (before == null) {
        return null;
    }
    RelationshipRecord after = readRelationshipRecord(id, channel);
    if (after == null) {
        return null;
    }
    if (!before.inUse() && after.inUse()) {
        after.setCreated();
    }
    return new Command.RelationshipCommand(before, after);
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) AddRelationshipCommand(org.neo4j.kernel.impl.index.IndexCommand.AddRelationshipCommand)

Example 30 with RelationshipRecord

use of org.neo4j.kernel.impl.store.record.RelationshipRecord in project neo4j by neo4j.

the class NodePropertiesReporter method reportNodeProperties.

public void reportNodeProperties(PrintWriter writer, RecordSet<RelationshipRecord> relationshipRecords) {
    Set<Long> nodeIds = new HashSet<Long>();
    for (RelationshipRecord relationshipRecord : relationshipRecords) {
        nodeIds.add(relationshipRecord.getFirstNode());
        nodeIds.add(relationshipRecord.getSecondNode());
    }
    for (Long nodeId : nodeIds) {
        reportNodeProperties(writer, nodeId);
    }
}
Also used : RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) HashSet(java.util.HashSet)

Aggregations

RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)207 Test (org.junit.Test)73 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)69 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)43 Test (org.junit.jupiter.api.Test)34 RelationshipTypeTokenRecord (org.neo4j.kernel.impl.store.record.RelationshipTypeTokenRecord)30 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)19 RelationshipGroupRecord (org.neo4j.kernel.impl.store.record.RelationshipGroupRecord)19 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)14 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)12 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)12 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)12 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)11 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)11 RecordAccessStub (org.neo4j.consistency.store.RecordAccessStub)9 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)8 RepeatedTest (org.junit.jupiter.api.RepeatedTest)7 IOException (java.io.IOException)6 CursorContext (org.neo4j.io.pagecache.context.CursorContext)6