use of org.neo4j.kernel.impl.nioneo.store.PropertyData in project neo4j-mobile-android by neo4j-contrib.
the class Primitive method setProperty.
public void setProperty(NodeManager nodeManager, String key, Object value) {
if (key == null || value == null) {
throw new IllegalArgumentException("Null parameter, " + "key=" + key + ", " + "value=" + value);
}
nodeManager.acquireLock(this, LockType.WRITE);
boolean success = false;
try {
ensureFullProperties(nodeManager);
ArrayMap<Integer, PropertyData> addMap = nodeManager.getCowPropertyAddMap(this, true);
ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this);
PropertyIndex index = null;
PropertyData property = null;
boolean foundInSkipMap = false;
for (PropertyIndex cachedIndex : nodeManager.index(key)) {
if (skipMap != null) {
if (skipMap.remove(cachedIndex.getKeyId()) != null) {
foundInSkipMap = true;
}
}
index = cachedIndex;
property = addMap.get(cachedIndex.getKeyId());
if (property != null) {
break;
}
property = getPropertyForIndex(cachedIndex.getKeyId());
if (property != null) {
break;
}
}
if (property == null && !nodeManager.hasAllPropertyIndexes()) {
for (int keyId : addMap.keySet()) {
if (!nodeManager.hasIndexFor(keyId)) {
PropertyIndex indexToCheck = nodeManager.getIndexFor(keyId);
if (indexToCheck.getKey().equals(key)) {
if (skipMap != null) {
skipMap.remove(indexToCheck.getKeyId());
}
index = indexToCheck;
property = addMap.get(indexToCheck.getKeyId());
if (property != null) {
break;
}
}
}
}
if (property == null) {
for (PropertyData aProperty : properties) {
int keyId = aProperty.getIndex();
if (!nodeManager.hasIndexFor(keyId)) {
PropertyIndex indexToCheck = nodeManager.getIndexFor(keyId);
if (indexToCheck.getKey().equals(key)) {
if (skipMap != null) {
skipMap.remove(indexToCheck.getKeyId());
}
index = indexToCheck;
property = getPropertyForIndex(indexToCheck.getKeyId());
if (property != null) {
break;
}
}
}
}
}
}
if (index == null) {
index = nodeManager.createPropertyIndex(key);
}
if (property != null && !foundInSkipMap) {
property = changeProperty(nodeManager, property, value);
} else {
property = addProperty(nodeManager, index, value);
}
addMap.put(index.getKeyId(), property);
success = true;
} finally {
nodeManager.releaseLock(this, LockType.WRITE);
if (!success) {
nodeManager.setRollbackOnly();
}
}
}
use of org.neo4j.kernel.impl.nioneo.store.PropertyData in project neo4j-mobile-android by neo4j-contrib.
the class Primitive method getPropertyValues.
public Iterable<Object> getPropertyValues(NodeManager nodeManager) {
ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this);
ArrayMap<Integer, PropertyData> addMap = nodeManager.getCowPropertyAddMap(this);
ensureFullProperties(nodeManager);
List<Object> values = new ArrayList<Object>();
for (PropertyData property : properties) {
Integer index = property.getIndex();
if (skipMap != null && skipMap.get(index) != null) {
continue;
}
if (addMap != null && addMap.get(index) != null) {
continue;
}
values.add(property.getValue());
}
if (addMap != null) {
for (PropertyData property : addMap.values()) {
values.add(property.getValue());
}
}
return values;
}
use of org.neo4j.kernel.impl.nioneo.store.PropertyData in project neo4j-mobile-android by neo4j-contrib.
the class Primitive method getPropertyKeys.
public Iterable<String> getPropertyKeys(NodeManager nodeManager) {
ArrayMap<Integer, PropertyData> skipMap = nodeManager.getCowPropertyRemoveMap(this);
ArrayMap<Integer, PropertyData> addMap = nodeManager.getCowPropertyAddMap(this);
ensureFullProperties(nodeManager);
List<String> keys = new ArrayList<String>();
for (PropertyData property : properties) {
Integer index = property.getIndex();
if (skipMap != null && skipMap.get(index) != null) {
continue;
}
if (addMap != null && addMap.get(index) != null) {
continue;
}
keys.add(nodeManager.getIndexFor(index).getKey());
}
if (addMap != null) {
for (Integer index : addMap.keySet()) {
keys.add(nodeManager.getIndexFor(index).getKey());
}
}
return keys;
}
use of org.neo4j.kernel.impl.nioneo.store.PropertyData in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method getAndDeletePropertyChain.
private ArrayMap<Integer, PropertyData> getAndDeletePropertyChain(long startingAt) {
ArrayMap<Integer, PropertyData> result = new ArrayMap<Integer, PropertyData>(9, false, true);
long nextProp = startingAt;
while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
PropertyRecord propRecord = getPropertyRecord(nextProp, false, true);
if (!propRecord.isCreated() && propRecord.isChanged()) {
// Being here means a new value could be on disk. Re-read
propRecord = getPropertyStore().getRecord(propRecord.getId());
}
for (PropertyBlock block : propRecord.getPropertyBlocks()) {
if (block.isLight()) {
getPropertyStore().makeHeavy(block);
}
if (!block.isCreated() && !propRecord.isChanged()) {
result.put(block.getKeyIndexId(), block.newPropertyData(propRecord, propertyGetValueOrNull(block)));
}
// TODO: update count on property index record
for (DynamicRecord valueRecord : block.getValueRecords()) {
assert valueRecord.inUse();
valueRecord.setInUse(false);
propRecord.addDeletedRecord(valueRecord);
}
}
nextProp = propRecord.getNextProp();
propRecord.setInUse(false);
propRecord.setChanged();
// We do not remove them individually, but all together here
propRecord.getPropertyBlocks().clear();
}
return result;
}
use of org.neo4j.kernel.impl.nioneo.store.PropertyData in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method relDelete.
@Override
public 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.");
}
long nextProp = record.getNextProp();
ArrayMap<Integer, PropertyData> propertyMap = getAndDeletePropertyChain(nextProp);
disconnectRelationship(record);
updateNodes(record);
record.setInUse(false);
return propertyMap;
}
Aggregations