use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method relationshipCreate.
@Override
public void relationshipCreate(long id, int type, long firstNodeId, long secondNodeId) {
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 neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method relRemoveProperty.
@Override
public void relRemoveProperty(long relId, PropertyData propertyData) {
long propertyId = propertyData.getId();
RelationshipRecord relRecord = getRelationshipRecord(relId);
if (relRecord == null) {
relRecord = getRelationshipStore().getRecord(relId);
}
if (!relRecord.inUse()) {
throw new IllegalStateException("Property remove on relationship[" + relId + "] illegal since it has been deleted.");
}
assert assertPropertyChain(relRecord);
PropertyRecord propRecord = getPropertyRecord(propertyId, false, true);
if (!propRecord.inUse()) {
throw new IllegalStateException("Unable to delete property[" + propertyId + "] since it is already deleted.");
}
propRecord.setRelId(relId);
PropertyBlock block = propRecord.removePropertyBlock(propertyData.getIndex());
if (block == null) {
throw new IllegalStateException("Property with index[" + propertyData.getIndex() + "] is not present in property[" + propertyId + "]");
}
if (block.isLight()) {
getPropertyStore().makeHeavy(block);
}
// TODO: update count on property index record
for (DynamicRecord valueRecord : block.getValueRecords()) {
assert valueRecord.inUse();
valueRecord.setInUse(false, block.getType().intValue());
propRecord.addDeletedRecord(valueRecord);
}
if (propRecord.size() > 0) {
propRecord.setChanged();
assert assertPropertyChain(relRecord);
return;
} else {
if (unlinkPropertyRecord(propRecord, relRecord)) {
addRelationshipRecord(relRecord);
}
}
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method disconnectRelationship.
private void disconnectRelationship(RelationshipRecord rel) {
// update first node prev
if (rel.getFirstPrevRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getFirstPrevRel());
getWriteLock(lockableRel);
RelationshipRecord prevRel = getRelationshipRecord(rel.getFirstPrevRel());
if (prevRel == null) {
prevRel = getRelationshipStore().getRecord(rel.getFirstPrevRel());
addRelationshipRecord(prevRel);
}
boolean changed = false;
if (prevRel.getFirstNode() == rel.getFirstNode()) {
prevRel.setFirstNextRel(rel.getFirstNextRel());
changed = true;
}
if (prevRel.getSecondNode() == rel.getFirstNode()) {
prevRel.setSecondNextRel(rel.getFirstNextRel());
changed = true;
}
if (!changed) {
throw new InvalidRecordException(prevRel + " don't match " + rel);
}
}
// update first node next
if (rel.getFirstNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getFirstNextRel());
getWriteLock(lockableRel);
RelationshipRecord nextRel = getRelationshipRecord(rel.getFirstNextRel());
if (nextRel == null) {
nextRel = getRelationshipStore().getRecord(rel.getFirstNextRel());
addRelationshipRecord(nextRel);
}
boolean changed = false;
if (nextRel.getFirstNode() == rel.getFirstNode()) {
nextRel.setFirstPrevRel(rel.getFirstPrevRel());
changed = true;
}
if (nextRel.getSecondNode() == rel.getFirstNode()) {
nextRel.setSecondPrevRel(rel.getFirstPrevRel());
changed = true;
}
if (!changed) {
throw new InvalidRecordException(nextRel + " don't match " + rel);
}
}
// update second node prev
if (rel.getSecondPrevRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getSecondPrevRel());
getWriteLock(lockableRel);
RelationshipRecord prevRel = getRelationshipRecord(rel.getSecondPrevRel());
if (prevRel == null) {
prevRel = getRelationshipStore().getRecord(rel.getSecondPrevRel());
addRelationshipRecord(prevRel);
}
boolean changed = false;
if (prevRel.getFirstNode() == rel.getSecondNode()) {
prevRel.setFirstNextRel(rel.getSecondNextRel());
changed = true;
}
if (prevRel.getSecondNode() == rel.getSecondNode()) {
prevRel.setSecondNextRel(rel.getSecondNextRel());
changed = true;
}
if (!changed) {
throw new InvalidRecordException(prevRel + " don't match " + rel);
}
}
// update second node next
if (rel.getSecondNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getSecondNextRel());
getWriteLock(lockableRel);
RelationshipRecord nextRel = getRelationshipRecord(rel.getSecondNextRel());
if (nextRel == null) {
nextRel = getRelationshipStore().getRecord(rel.getSecondNextRel());
addRelationshipRecord(nextRel);
}
boolean changed = false;
if (nextRel.getFirstNode() == rel.getSecondNode()) {
nextRel.setFirstPrevRel(rel.getSecondPrevRel());
changed = true;
}
if (nextRel.getSecondNode() == rel.getSecondNode()) {
nextRel.setSecondPrevRel(rel.getSecondPrevRel());
changed = true;
}
if (!changed) {
throw new InvalidRecordException(nextRel + " don't match " + rel);
}
}
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method relAddProperty.
@Override
public PropertyData relAddProperty(long relId, PropertyIndex index, Object value) {
RelationshipRecord relRecord = getRelationshipRecord(relId);
if (relRecord == null) {
relRecord = getRelationshipStore().getRecord(relId);
addRelationshipRecord(relRecord);
}
if (!relRecord.inUse()) {
throw new IllegalStateException("Property add on relationship[" + relId + "] illegal since it has been deleted.");
}
assert assertPropertyChain(relRecord);
PropertyBlock block = new PropertyBlock();
block.setCreated();
getPropertyStore().encodeValue(block, index.getKeyId(), value);
PropertyRecord host = addPropertyBlockToPrimitive(block, relRecord, /*isNode*/
false);
assert assertPropertyChain(relRecord);
return block.newPropertyData(host, value);
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method doRollback.
@Override
public void doRollback() throws XAException {
if (committed) {
throw new XAException("Cannot rollback partialy commited " + "transaction[" + getIdentifier() + "]. Recover and " + "commit");
}
try {
for (RelationshipTypeRecord record : relTypeRecords.values()) {
if (record.isCreated()) {
getRelationshipTypeStore().freeId(record.getId());
for (DynamicRecord dynamicRecord : record.getTypeRecords()) {
if (dynamicRecord.isCreated()) {
getRelationshipTypeStore().freeBlockId((int) dynamicRecord.getId());
}
}
}
removeRelationshipTypeFromCache(record.getId());
}
for (NodeRecord record : nodeRecords.values()) {
if (record.isCreated()) {
getNodeStore().freeId(record.getId());
}
removeNodeFromCache(record.getId());
}
for (RelationshipRecord record : relRecords.values()) {
if (record.isCreated()) {
getRelationshipStore().freeId(record.getId());
}
removeRelationshipFromCache(record.getId());
}
for (PropertyIndexRecord record : propIndexRecords.values()) {
if (record.isCreated()) {
getPropertyStore().getIndexStore().freeId(record.getId());
for (DynamicRecord dynamicRecord : record.getKeyRecords()) {
if (dynamicRecord.isCreated()) {
getPropertyStore().getIndexStore().freeBlockId((int) dynamicRecord.getId());
}
}
}
}
for (PropertyRecord record : propertyRecords.values()) {
if (record.getNodeId() != -1) {
removeNodeFromCache(record.getNodeId());
} else if (record.getRelId() != -1) {
removeRelationshipFromCache(record.getRelId());
}
if (record.isCreated()) {
getPropertyStore().freeId(record.getId());
for (PropertyBlock block : record.getPropertyBlocks()) {
for (DynamicRecord dynamicRecord : block.getValueRecords()) {
if (dynamicRecord.isCreated()) {
if (dynamicRecord.getType() == PropertyType.STRING.intValue()) {
getPropertyStore().freeStringBlockId(dynamicRecord.getId());
} else if (dynamicRecord.getType() == PropertyType.ARRAY.intValue()) {
getPropertyStore().freeArrayBlockId(dynamicRecord.getId());
} else {
throw new InvalidRecordException("Unknown type on " + dynamicRecord);
}
}
}
}
}
}
} finally {
nodeRecords.clear();
propertyRecords.clear();
relRecords.clear();
relTypeRecords.clear();
propIndexRecords.clear();
nodeCommands.clear();
propCommands.clear();
propIndexCommands.clear();
relCommands.clear();
relTypeCommands.clear();
}
}
Aggregations