use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project neo4j-mobile-android by neo4j-contrib.
the class BatchInserterImpl method createNewRelationshipType.
private int createNewRelationshipType(String name) {
RelationshipTypeStore typeStore = getRelationshipTypeStore();
int id = (int) typeStore.nextId();
RelationshipTypeRecord record = new RelationshipTypeRecord(id);
record.setInUse(true);
record.setCreated();
int typeBlockId = (int) typeStore.nextBlockId();
record.setTypeBlock(typeBlockId);
Collection<DynamicRecord> typeRecords = typeStore.allocateTypeNameRecords(typeBlockId, encodeString(name));
for (DynamicRecord typeRecord : typeRecords) {
record.addTypeRecord(typeRecord);
}
typeStore.updateRecord(record);
typeHolder.addRelationshipType(name, id);
return id;
}
use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project graphdb by neo4j-attic.
the class Command method readDynamicRecord.
static DynamicRecord readDynamicRecord(ReadableByteChannel byteChannel, ByteBuffer buffer) throws IOException {
// id+type+in_use(byte)+prev_block(long)+nr_of_bytes(int)+next_block(long)
buffer.clear();
buffer.limit(13);
if (byteChannel.read(buffer) != buffer.limit()) {
return null;
}
buffer.flip();
long id = buffer.getLong();
int type = buffer.getInt();
byte inUseFlag = buffer.get();
boolean inUse = false;
if (inUseFlag == Record.IN_USE.byteValue()) {
inUse = true;
buffer.clear();
buffer.limit(20);
if (byteChannel.read(buffer) != buffer.limit()) {
return null;
}
buffer.flip();
} else if (inUseFlag != Record.NOT_IN_USE.byteValue()) {
throw new IOException("Illegal in use flag: " + inUseFlag);
}
DynamicRecord record = new DynamicRecord(id);
record.setInUse(inUse, type);
if (inUse) {
record.setPrevBlock(buffer.getLong());
int nrOfBytes = buffer.getInt();
record.setNextBlock(buffer.getLong());
buffer.clear();
buffer.limit(nrOfBytes);
if (byteChannel.read(buffer) != buffer.limit()) {
return null;
}
buffer.flip();
byte[] data = new byte[nrOfBytes];
buffer.get(data);
record.setData(data);
}
return record;
}
use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project graphdb by neo4j-attic.
the class WriteTransaction method relChangeProperty.
void relChangeProperty(long relId, long propertyId, Object value) {
RelationshipRecord relRecord = getRelationshipRecord(relId);
if (relRecord == null) {
relRecord = getRelationshipStore().getRecord(relId);
}
if (!relRecord.inUse()) {
throw new IllegalStateException("Property change on relationship[" + relId + "] illegal since it has been deleted.");
}
PropertyRecord propertyRecord = getPropertyRecord(propertyId);
if (propertyRecord == null) {
propertyRecord = getPropertyStore().getRecord(propertyId);
addPropertyRecord(propertyRecord);
}
if (!propertyRecord.inUse()) {
throw new IllegalStateException("Unable to change property[" + propertyId + "] since it is deleted.");
}
propertyRecord.setRelId(relId);
if (propertyRecord.isLight()) {
getPropertyStore().makeHeavy(propertyRecord);
}
propertyRecord.setChanged();
if (propertyRecord.getType() == PropertyType.STRING) {
for (DynamicRecord record : propertyRecord.getValueRecords()) {
if (record.inUse()) {
record.setInUse(false, PropertyType.STRING.intValue());
}
}
} else if (propertyRecord.getType() == PropertyType.ARRAY) {
for (DynamicRecord record : propertyRecord.getValueRecords()) {
if (record.inUse()) {
record.setInUse(false, PropertyType.ARRAY.intValue());
}
}
}
getPropertyStore().encodeValue(propertyRecord, value);
addPropertyRecord(propertyRecord);
}
use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord in project graphdb by neo4j-attic.
the class WriteTransaction method relRemoveProperty.
void relRemoveProperty(long relId, long propertyId) {
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.");
}
PropertyRecord propRecord = getPropertyRecord(propertyId);
if (propRecord == null) {
propRecord = getPropertyStore().getRecord(propertyId);
addPropertyRecord(propRecord);
}
if (!propRecord.inUse()) {
throw new IllegalStateException("Unable to delete property[" + propertyId + "] since it is already deleted.");
}
propRecord.setRelId(relId);
if (propRecord.isLight()) {
getPropertyStore().makeHeavy(propRecord);
}
propRecord.setInUse(false);
// TODO: update count on property index record
for (DynamicRecord valueRecord : propRecord.getValueRecords()) {
if (valueRecord.inUse()) {
valueRecord.setInUse(false, propRecord.getType().intValue());
}
}
long prevProp = propRecord.getPrevProp();
long nextProp = propRecord.getNextProp();
if (relRecord.getNextProp() == propertyId) {
relRecord.setNextProp(nextProp);
// re-adding not a problem
addRelationshipRecord(relRecord);
}
if (prevProp != Record.NO_PREVIOUS_PROPERTY.intValue()) {
PropertyRecord prevPropRecord = getPropertyRecord(prevProp);
if (prevPropRecord == null) {
prevPropRecord = getPropertyStore().getLightRecord(prevProp);
addPropertyRecord(prevPropRecord);
}
assert prevPropRecord.inUse();
prevPropRecord.setNextProp(nextProp);
}
if (nextProp != Record.NO_NEXT_PROPERTY.intValue()) {
PropertyRecord nextPropRecord = getPropertyRecord(nextProp);
if (nextPropRecord == null) {
nextPropRecord = getPropertyStore().getLightRecord(nextProp);
addPropertyRecord(nextPropRecord);
}
assert nextPropRecord.inUse();
nextPropRecord.setPrevProp(prevProp);
}
}
use of org.neo4j.kernel.impl.nioneo.store.DynamicRecord 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;
}
Aggregations