use of org.neo4j.kernel.impl.nioneo.store.Buffer in project neo4j-mobile-android by neo4j-contrib.
the class LegacyDynamicStoreReader method getRecord.
private LegacyDynamicRecord getRecord(long blockId, PersistenceWindow window) {
LegacyDynamicRecord record = new LegacyDynamicRecord(blockId);
Buffer buffer = window.getOffsettedBuffer(blockId);
// [ , x] in use
// [xxxx, ] high bits for prev block
long inUseByte = buffer.get();
boolean inUse = (inUseByte & 0x1) == Record.IN_USE.intValue();
if (!inUse) {
throw new InvalidRecordException("Not in use, blockId[" + blockId + "]");
}
long prevBlock = buffer.getUnsignedInt();
long prevModifier = (inUseByte & 0xF0L) << 28;
int dataSize = blockSize - BLOCK_HEADER_SIZE;
// [ , ][xxxx,xxxx][xxxx,xxxx][xxxx,xxxx] number of bytes
// [ ,xxxx][ , ][ , ][ , ] higher bits for next block
long nrOfBytesInt = buffer.getInt();
int nrOfBytes = (int) (nrOfBytesInt & 0xFFFFFF);
long nextBlock = buffer.getUnsignedInt();
long nextModifier = (nrOfBytesInt & 0xF000000L) << 8;
long longNextBlock = LegacyStore.longFromIntAndMod(nextBlock, nextModifier);
if (longNextBlock != Record.NO_NEXT_BLOCK.intValue() && nrOfBytes < dataSize || nrOfBytes > dataSize) {
throw new InvalidRecordException("Next block set[" + nextBlock + "] current block illegal size[" + nrOfBytes + "/" + dataSize + "]");
}
record.setInUse(true);
record.setLength(nrOfBytes);
record.setPrevBlock(LegacyStore.longFromIntAndMod(prevBlock, prevModifier));
record.setNextBlock(longNextBlock);
byte[] byteArrayElement = new byte[nrOfBytes];
buffer.get(byteArrayElement);
record.setData(byteArrayElement);
return record;
}
use of org.neo4j.kernel.impl.nioneo.store.Buffer in project neo4j-mobile-android by neo4j-contrib.
the class LegacyPropertyStoreReader method readPropertyRecord.
public LegacyPropertyRecord readPropertyRecord(long id) throws IOException {
PersistenceWindow persistenceWindow = windowPool.acquire(id, OperationType.READ);
try {
Buffer buffer = persistenceWindow.getOffsettedBuffer(id);
// [ , x] in use
// [xxxx, ] high prev prop bits
long inUseByte = buffer.get();
boolean inUse = (inUseByte & 0x1) == Record.IN_USE.intValue();
if (!inUse) {
throw new IllegalArgumentException(MessageFormat.format("Record {0} not in use", id));
}
LegacyPropertyRecord record = new LegacyPropertyRecord(id);
// [ , ][ , ][xxxx,xxxx][xxxx,xxxx] type
// [ , ][ ,xxxx][ , ][ , ] high next prop bits
long typeInt = buffer.getInt();
record.setType(getEnumType((int) typeInt & 0xFFFF));
record.setInUse(true);
record.setKeyIndexId(buffer.getInt());
record.setPropBlock(buffer.getLong());
long prevProp = buffer.getUnsignedInt();
long prevModifier = (inUseByte & 0xF0L) << 28;
long nextProp = buffer.getUnsignedInt();
long nextModifier = (typeInt & 0xF0000L) << 16;
record.setPrevProp(LegacyStore.longFromIntAndMod(prevProp, prevModifier));
record.setNextProp(LegacyStore.longFromIntAndMod(nextProp, nextModifier));
return record;
} finally {
windowPool.release(persistenceWindow);
}
}
Aggregations