use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord 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.PropertyRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method addPropertyBlockToPrimitive.
private PropertyRecord addPropertyBlockToPrimitive(PropertyBlock block, PrimitiveRecord primitive, boolean isNode) {
assert assertPropertyChain(primitive);
int newBlockSizeInBytes = block.getSize();
/*
* Here we could either iterate over the whole chain or just go for the first record
* which is the most likely to be the less full one. Currently we opt for the second
* to perform better.
*/
PropertyRecord host = null;
long firstProp = primitive.getNextProp();
if (firstProp != Record.NO_NEXT_PROPERTY.intValue()) {
// We do not store in map - might not have enough space
PropertyRecord propRecord = getPropertyRecord(firstProp, false, false);
assert propRecord.getPrevProp() == Record.NO_PREVIOUS_PROPERTY.intValue() : propRecord + " for " + primitive;
assert propRecord.inUse() : propRecord;
int propSize = propRecord.size();
assert propSize > 0 : propRecord;
if (propSize + newBlockSizeInBytes <= PropertyType.getPayloadSize()) {
host = propRecord;
host.addPropertyBlock(block);
host.setChanged();
}
}
if (host == null) {
// First record in chain didn't fit, make new one
host = new PropertyRecord(getPropertyStore().nextId());
host.setCreated();
if (primitive.getNextProp() != Record.NO_NEXT_PROPERTY.intValue()) {
PropertyRecord prevProp = getPropertyRecord(primitive.getNextProp(), true, true);
if (isNode) {
addNodeRecord((NodeRecord) primitive);
} else {
addRelationshipRecord((RelationshipRecord) primitive);
}
assert prevProp.getPrevProp() == Record.NO_PREVIOUS_PROPERTY.intValue();
prevProp.setPrevProp(host.getId());
host.setNextProp(prevProp.getId());
prevProp.setChanged();
}
primitive.setNextProp(host.getId());
host.addPropertyBlock(block);
host.setInUse(true);
}
// Ok, here host does for the job. Use it
if (isNode) {
host.setNodeId(primitive.getId());
} else {
host.setRelId(primitive.getId());
}
addPropertyRecord(host);
assert assertPropertyChain(primitive);
return host;
}
use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method assertPropertyChain.
private boolean assertPropertyChain(PrimitiveRecord primitive) {
List<PropertyRecord> toCheck = new LinkedList<PropertyRecord>();
long nextIdToFetch = primitive.getNextProp();
while (nextIdToFetch != Record.NO_NEXT_PROPERTY.intValue()) {
PropertyRecord toAdd = getPropertyRecord(nextIdToFetch, true, false);
toCheck.add(toAdd);
assert toAdd.inUse() : primitive + "->" + Arrays.toString(toCheck.toArray());
nextIdToFetch = toAdd.getNextProp();
}
if (toCheck.isEmpty()) {
assert primitive.getNextProp() == Record.NO_NEXT_PROPERTY.intValue() : primitive;
return true;
}
PropertyRecord first = toCheck.get(0);
PropertyRecord last = toCheck.get(toCheck.size() - 1);
assert first.getPrevProp() == Record.NO_PREVIOUS_PROPERTY.intValue() : primitive + "->" + Arrays.toString(toCheck.toArray());
assert last.getNextProp() == Record.NO_NEXT_PROPERTY.intValue() : primitive + "->" + Arrays.toString(toCheck.toArray());
PropertyRecord current, previous = first;
for (int i = 1; i < toCheck.size(); i++) {
current = toCheck.get(i);
assert current.getPrevProp() == previous.getId() : primitive + "->" + Arrays.toString(toCheck.toArray());
assert previous.getNextProp() == current.getId() : primitive + "->" + Arrays.toString(toCheck.toArray());
previous = current;
}
return true;
}
use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method loadPropertyValue.
@Override
public Object loadPropertyValue(PropertyData propertyData) {
PropertyRecord propertyRecord = propertyRecords.get(propertyData.getId());
if (propertyRecord == null) {
propertyRecord = getPropertyStore().getRecord(propertyData.getId());
}
PropertyBlock block = propertyRecord.getPropertyBlock(propertyData.getIndex());
if (block == null) {
throw new IllegalStateException("Property with index[" + propertyData.getIndex() + "] is not present in property[" + propertyData.getId() + "]");
}
if (block.isLight()) {
getPropertyStore().makeHeavy(block);
}
return block.getType().getValue(block, getPropertyStore());
}
use of org.neo4j.kernel.impl.nioneo.store.PropertyRecord in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method doPrepare.
@Override
protected void doPrepare() throws XAException {
if (committed) {
throw new XAException("Cannot prepare committed transaction[" + getIdentifier() + "]");
}
if (prepared) {
throw new XAException("Cannot prepare prepared transaction[" + getIdentifier() + "]");
}
// generate records then write to logical log via addCommand method
prepared = true;
for (RelationshipTypeRecord record : relTypeRecords.values()) {
Command.RelationshipTypeCommand command = new Command.RelationshipTypeCommand(neoStore.getRelationshipTypeStore(), record);
relTypeCommands.add(command);
addCommand(command);
}
for (NodeRecord record : nodeRecords.values()) {
if (!record.inUse() && record.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
throw new InvalidRecordException("Node record " + record + " still has relationships");
}
Command.NodeCommand command = new Command.NodeCommand(neoStore.getNodeStore(), record);
nodeCommands.add(command);
if (!record.inUse()) {
removeNodeFromCache(record.getId());
}
addCommand(command);
}
for (RelationshipRecord record : relRecords.values()) {
Command.RelationshipCommand command = new Command.RelationshipCommand(neoStore.getRelationshipStore(), record);
relCommands.add(command);
if (!record.inUse()) {
removeRelationshipFromCache(record.getId());
}
addCommand(command);
}
for (PropertyIndexRecord record : propIndexRecords.values()) {
Command.PropertyIndexCommand command = new Command.PropertyIndexCommand(neoStore.getPropertyStore().getIndexStore(), record);
propIndexCommands.add(command);
addCommand(command);
}
for (PropertyRecord record : propertyRecords.values()) {
Command.PropertyCommand command = new Command.PropertyCommand(neoStore.getPropertyStore(), record);
propCommands.add(command);
addCommand(command);
}
}
Aggregations