use of org.neo4j.kernel.impl.nioneo.store.PropertyStore in project neo4j-mobile-android by neo4j-contrib.
the class BatchInserterImpl method createPropertyChain.
private long createPropertyChain(Map<String, Object> properties) {
if (properties == null || properties.isEmpty()) {
return Record.NO_NEXT_PROPERTY.intValue();
}
PropertyStore propStore = getPropertyStore();
List<PropertyRecord> propRecords = new ArrayList<PropertyRecord>();
PropertyRecord currentRecord = new PropertyRecord(propStore.nextId());
currentRecord.setInUse(true);
currentRecord.setCreated();
propRecords.add(currentRecord);
for (Entry<String, Object> entry : properties.entrySet()) {
int keyId = indexHolder.getKeyId(entry.getKey());
if (keyId == -1) {
keyId = createNewPropertyIndex(entry.getKey());
}
PropertyBlock block = new PropertyBlock();
propStore.encodeValue(block, keyId, entry.getValue());
if (currentRecord.size() + block.getSize() > PropertyType.getPayloadSize()) {
// Here it means the current block is done for
PropertyRecord prevRecord = currentRecord;
// Create new record
long propertyId = propStore.nextId();
currentRecord = new PropertyRecord(propertyId);
currentRecord.setInUse(true);
currentRecord.setCreated();
// Set up links
prevRecord.setNextProp(propertyId);
currentRecord.setPrevProp(prevRecord.getId());
propRecords.add(currentRecord);
// Now current is ready to start picking up blocks
}
currentRecord.addPropertyBlock(block);
}
/*
* Add the property records in reverse order, which means largest
* id first. That is to make sure we expand the property store file
* only once.
*/
for (int i = propRecords.size() - 1; i >= 0; i--) {
propStore.updateRecord(propRecords.get(i));
}
/*
* 0 will always exist, if the map was empty we wouldn't be here
* and even one property will create at least one record.
*/
return propRecords.get(0).getId();
}
use of org.neo4j.kernel.impl.nioneo.store.PropertyStore in project neo4j-mobile-android by neo4j-contrib.
the class BatchInserterImpl method deletePropertyChain.
private void deletePropertyChain(long nextProp) {
PropertyStore propStore = getPropertyStore();
while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
PropertyRecord propRecord = propStore.getRecord(nextProp);
for (PropertyBlock propBlock : propRecord.getPropertyBlocks()) {
propStore.makeHeavy(propBlock);
for (DynamicRecord rec : propBlock.getValueRecords()) {
rec.setInUse(false);
propRecord.addDeletedRecord(rec);
}
}
propRecord.setInUse(false);
nextProp = propRecord.getNextProp();
propStore.updateRecord(propRecord);
}
}
use of org.neo4j.kernel.impl.nioneo.store.PropertyStore in project neo4j-mobile-android by neo4j-contrib.
the class BatchInserterImpl method getPropertyChain.
private Map<String, Object> getPropertyChain(long nextProp) {
PropertyStore propStore = getPropertyStore();
Map<String, Object> properties = new HashMap<String, Object>();
while (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
PropertyRecord propRecord = propStore.getRecord(nextProp);
for (PropertyBlock propBlock : propRecord.getPropertyBlocks()) {
String key = indexHolder.getStringKey(propBlock.getKeyIndexId());
PropertyData propertyData = propBlock.newPropertyData(propRecord);
Object value = propertyData.getValue() != null ? propertyData.getValue() : propBlock.getType().getValue(propBlock, getPropertyStore());
properties.put(key, value);
}
nextProp = propRecord.getNextProp();
}
return properties;
}
use of org.neo4j.kernel.impl.nioneo.store.PropertyStore in project graphdb by neo4j-attic.
the class BatchInserterImpl method deletePropertyChain.
private void deletePropertyChain(long propertyId) {
PropertyStore propStore = getPropertyStore();
PropertyRecord propertyRecord = propStore.getRecord(propertyId);
propertyRecord.setInUse(false);
for (DynamicRecord record : propertyRecord.getValueRecords()) {
record.setInUse(false);
}
propStore.updateRecord(propertyRecord);
}
use of org.neo4j.kernel.impl.nioneo.store.PropertyStore in project graphdb by neo4j-attic.
the class BatchInserterImpl method createPropertyChain.
private long createPropertyChain(Map<String, Object> properties) {
if (properties == null) {
return Record.NO_NEXT_PROPERTY.intValue();
}
PropertyStore propStore = getPropertyStore();
List<PropertyRecord> propRecords = new ArrayList<PropertyRecord>();
PropertyRecord prevRecord = null;
for (Entry<String, Object> entry : properties.entrySet()) {
int keyId = indexHolder.getKeyId(entry.getKey());
if (keyId == -1) {
keyId = createNewPropertyIndex(entry.getKey());
}
long propertyId = propStore.nextId();
PropertyRecord propertyRecord = new PropertyRecord(propertyId);
propertyRecord.setInUse(true);
propertyRecord.setCreated();
propertyRecord.setKeyIndexId(keyId);
propStore.encodeValue(propertyRecord, entry.getValue());
if (prevRecord != null) {
prevRecord.setPrevProp(propertyId);
propertyRecord.setNextProp(prevRecord.getId());
}
propRecords.add(propertyRecord);
prevRecord = propertyRecord;
}
// reverse order results in forward update to store
for (int i = propRecords.size() - 1; i >= 0; i--) {
propStore.updateRecord(propRecords.get(i));
}
if (prevRecord != null) {
return prevRecord.getId();
}
return Record.NO_NEXT_PROPERTY.intValue();
}
Aggregations