use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project graphdb by neo4j-attic.
the class WriteTransaction method relDelete.
ArrayMap<Integer, PropertyData> relDelete(long id) {
RelationshipRecord record = getRelationshipRecord(id);
if (record == null) {
record = getRelationshipStore().getRecord(id);
addRelationshipRecord(record);
}
if (!record.inUse()) {
throw new IllegalStateException("Unable to delete relationship[" + id + "] since it is already deleted.");
}
ArrayMap<Integer, PropertyData> propertyMap = new ArrayMap<Integer, PropertyData>(9, false, true);
long nextProp = record.getNextProp();
while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
PropertyRecord propRecord = getPropertyRecord(nextProp);
if (propRecord == null) {
propRecord = getPropertyStore().getRecord(nextProp);
addPropertyRecord(propRecord);
}
if (propRecord.isLight()) {
getPropertyStore().makeHeavy(propRecord);
}
if (!propRecord.isCreated()) {
if (!propRecord.isChanged()) {
propertyMap.put(propRecord.getKeyIndexId(), new PropertyData(propRecord.getId(), propertyGetValueOrNull(propRecord)));
} else {
// we have to re-read committed value since property has
// changed and old value is erased in memory
PropertyRecord diskValue = getPropertyStore().getRecord(propRecord.getId());
getPropertyStore().makeHeavy(diskValue);
propertyMap.put(diskValue.getKeyIndexId(), new PropertyData(diskValue.getId(), propertyGetValueOrNull(diskValue)));
}
}
nextProp = propRecord.getNextProp();
propRecord.setInUse(false);
// TODO: update count on property index record
for (DynamicRecord valueRecord : propRecord.getValueRecords()) {
valueRecord.setInUse(false);
}
}
disconnectRelationship(record);
updateNodes(record);
record.setInUse(false);
return propertyMap;
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project graphdb by neo4j-attic.
the class WriteTransaction method relationshipCreate.
void relationshipCreate(long id, long firstNodeId, long secondNodeId, int type) {
NodeRecord firstNode = getNodeRecord(firstNodeId);
if (firstNode == null) {
firstNode = getNodeStore().getRecord(firstNodeId);
addNodeRecord(firstNode);
}
if (!firstNode.inUse()) {
throw new IllegalStateException("First node[" + firstNodeId + "] is deleted and cannot be used to create a relationship");
}
NodeRecord secondNode = getNodeRecord(secondNodeId);
if (secondNode == null) {
secondNode = getNodeStore().getRecord(secondNodeId);
addNodeRecord(secondNode);
}
if (!secondNode.inUse()) {
throw new IllegalStateException("Second node[" + secondNodeId + "] is deleted and cannot be used to create a relationship");
}
RelationshipRecord record = new RelationshipRecord(id, firstNodeId, secondNodeId, type);
record.setInUse(true);
record.setCreated();
addRelationshipRecord(record);
connectRelationship(firstNode, secondNode, record);
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project graphdb by neo4j-attic.
the class WriteTransaction method relationshipLoad.
public RelationshipData relationshipLoad(long id) {
RelationshipRecord relRecord = getRelationshipRecord(id);
if (relRecord != null) {
// }
return new RelationshipData(id, relRecord.getFirstNode(), relRecord.getSecondNode(), relRecord.getType());
}
relRecord = getRelationshipStore().getLightRel(id);
if (relRecord != null) {
return new RelationshipData(id, relRecord.getFirstNode(), relRecord.getSecondNode(), relRecord.getType());
}
return null;
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class ReadTransaction method getMoreRelationships.
static Pair<Map<DirectionWrapper, Iterable<RelationshipRecord>>, Long> getMoreRelationships(long nodeId, long position, int grabSize, RelationshipStore relStore) {
// initialCapacity=grabSize saves the lists the trouble of resizing
List<RelationshipRecord> out = new ArrayList<RelationshipRecord>();
List<RelationshipRecord> in = new ArrayList<RelationshipRecord>();
List<RelationshipRecord> loop = null;
Map<DirectionWrapper, Iterable<RelationshipRecord>> result = new EnumMap<DirectionWrapper, Iterable<RelationshipRecord>>(DirectionWrapper.class);
result.put(DirectionWrapper.OUTGOING, out);
result.put(DirectionWrapper.INCOMING, in);
for (int i = 0; i < grabSize && position != Record.NO_NEXT_RELATIONSHIP.intValue(); i++) {
RelationshipRecord relRecord = relStore.getChainRecord(position);
if (relRecord == null) {
// return what we got so far
return Pair.of(result, position);
}
long firstNode = relRecord.getFirstNode();
long secondNode = relRecord.getSecondNode();
if (relRecord.inUse()) {
if (firstNode == secondNode) {
if (loop == null) {
// This is done lazily because loops are probably quite
// rarely encountered
loop = new ArrayList<RelationshipRecord>();
result.put(DirectionWrapper.BOTH, loop);
}
loop.add(relRecord);
} else if (firstNode == nodeId) {
out.add(relRecord);
} else if (secondNode == nodeId) {
in.add(relRecord);
}
} else {
i--;
}
if (firstNode == nodeId) {
position = relRecord.getFirstNextRel();
} else if (secondNode == nodeId) {
position = relRecord.getSecondNextRel();
} else {
throw new InvalidRecordException("Node[" + nodeId + "] is neither firstNode[" + firstNode + "] nor secondNode[" + secondNode + "] for Relationship[" + relRecord.getId() + "]");
}
}
return Pair.of(result, position);
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method relLoadProperties.
@Override
public ArrayMap<Integer, PropertyData> relLoadProperties(long relId, boolean light) {
RelationshipRecord relRecord = getRelationshipRecord(relId);
if (relRecord != null && relRecord.isCreated()) {
return null;
}
if (relRecord != null) {
if (!relRecord.inUse() && !light) {
throw new IllegalStateException("Relationship[" + relId + "] has been deleted in this tx");
}
}
relRecord = getRelationshipStore().getRecord(relId);
if (!relRecord.inUse()) {
throw new InvalidRecordException("Relationship[" + relId + "] not in use");
}
return ReadTransaction.loadProperties(getPropertyStore(), relRecord.getNextProp());
}
Aggregations