use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class BatchInserterImpl method connect.
private void connect(NodeRecord node, RelationshipRecord rel) {
if (node.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
RelationshipRecord nextRel = getRelationshipStore().getRecord(node.getNextRel());
boolean changed = false;
if (nextRel.getFirstNode() == node.getId()) {
nextRel.setFirstPrevRel(rel.getId());
changed = true;
}
if (nextRel.getSecondNode() == node.getId()) {
nextRel.setSecondPrevRel(rel.getId());
changed = true;
}
if (!changed) {
throw new InvalidRecordException(node + " dont match " + nextRel);
}
getRelationshipStore().updateRecord(nextRel);
}
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class BatchInserterImpl method getRelationshipById.
public SimpleRelationship getRelationshipById(long relId) {
RelationshipRecord record = getRelationshipRecord(relId);
RelationshipType type = new RelationshipTypeImpl(typeHolder.getName(record.getType()));
return new SimpleRelationship(record.getId(), record.getFirstNode(), record.getSecondNode(), type);
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class NodeManager method getRelationshipById.
public Relationship getRelationshipById(long relId) throws NotFoundException {
RelationshipImpl relationship = relCache.get(relId);
if (relationship != null) {
return new RelationshipProxy(relId, this);
}
ReentrantLock loadLock = lockId(relId);
try {
relationship = relCache.get(relId);
if (relationship != null) {
return new RelationshipProxy(relId, this);
}
RelationshipRecord data = persistenceManager.loadLightRelationship(relId);
if (data == null) {
throw new NotFoundException("Relationship[" + relId + "]");
}
int typeId = data.getType();
RelationshipType type = getRelationshipTypeById(typeId);
if (type == null) {
throw new NotFoundException("Relationship[" + data.getId() + "] exist but relationship type[" + typeId + "] not found.");
}
final long startNodeId = data.getFirstNode();
final long endNodeId = data.getSecondNode();
relationship = newRelationshipImpl(relId, startNodeId, endNodeId, type, typeId, false);
relCache.put(relId, relationship);
return new RelationshipProxy(relId, this);
} finally {
loadLock.unlock();
}
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class NodeManager method getRelForProxy.
RelationshipImpl getRelForProxy(long relId) {
RelationshipImpl relationship = relCache.get(relId);
if (relationship != null) {
return relationship;
}
ReentrantLock loadLock = lockId(relId);
try {
relationship = relCache.get(relId);
if (relationship != null) {
return relationship;
}
RelationshipRecord data = persistenceManager.loadLightRelationship(relId);
if (data == null) {
throw new NotFoundException("Relationship[" + relId + "] not found.");
}
int typeId = data.getType();
RelationshipType type = getRelationshipTypeById(typeId);
if (type == null) {
throw new NotFoundException("Relationship[" + data.getId() + "] exist but relationship type[" + typeId + "] not found.");
}
relationship = newRelationshipImpl(relId, data.getFirstNode(), data.getSecondNode(), type, typeId, false);
relCache.put(relId, relationship);
return relationship;
} finally {
loadLock.unlock();
}
}
use of org.neo4j.kernel.impl.nioneo.store.RelationshipRecord in project neo4j-mobile-android by neo4j-contrib.
the class LegacyRelationshipStoreReader method readRelationshipStore.
public Iterable<RelationshipRecord> readRelationshipStore() throws IOException {
final ByteBuffer buffer = ByteBuffer.allocateDirect(RECORD_LENGTH);
return new Iterable<RelationshipRecord>() {
@Override
public Iterator<RelationshipRecord> iterator() {
return new PrefetchingIterator<RelationshipRecord>() {
long id = 0;
@Override
protected RelationshipRecord fetchNextOrNull() {
RelationshipRecord record = null;
while (record == null && id <= maxId) {
buffer.clear();
try {
fileChannel.read(buffer);
} catch (IOException e) {
throw new RuntimeException(e);
}
buffer.flip();
long inUseByte = buffer.get();
boolean inUse = (inUseByte & 0x1) == Record.IN_USE.intValue();
if (inUse) {
long firstNode = LegacyStore.getUnsignedInt(buffer);
long firstNodeMod = (inUseByte & 0xEL) << 31;
long secondNode = LegacyStore.getUnsignedInt(buffer);
// [ xxx, ][ , ][ , ][ , ] second node high order bits, 0x70000000
// [ ,xxx ][ , ][ , ][ , ] first prev rel high order bits, 0xE000000
// [ , x][xx , ][ , ][ , ] first next rel high order bits, 0x1C00000
// [ , ][ xx,x ][ , ][ , ] second prev rel high order bits, 0x380000
// [ , ][ , xxx][ , ][ , ] second next rel high order bits, 0x70000
// [ , ][ , ][xxxx,xxxx][xxxx,xxxx] type
long typeInt = buffer.getInt();
long secondNodeMod = (typeInt & 0x70000000L) << 4;
int type = (int) (typeInt & 0xFFFF);
record = new RelationshipRecord(id, LegacyStore.longFromIntAndMod(firstNode, firstNodeMod), LegacyStore.longFromIntAndMod(secondNode, secondNodeMod), type);
record.setInUse(inUse);
long firstPrevRel = LegacyStore.getUnsignedInt(buffer);
long firstPrevRelMod = (typeInt & 0xE000000L) << 7;
record.setFirstPrevRel(LegacyStore.longFromIntAndMod(firstPrevRel, firstPrevRelMod));
long firstNextRel = LegacyStore.getUnsignedInt(buffer);
long firstNextRelMod = (typeInt & 0x1C00000L) << 10;
record.setFirstNextRel(LegacyStore.longFromIntAndMod(firstNextRel, firstNextRelMod));
long secondPrevRel = LegacyStore.getUnsignedInt(buffer);
long secondPrevRelMod = (typeInt & 0x380000L) << 13;
record.setSecondPrevRel(LegacyStore.longFromIntAndMod(secondPrevRel, secondPrevRelMod));
long secondNextRel = LegacyStore.getUnsignedInt(buffer);
long secondNextRelMod = (typeInt & 0x70000L) << 16;
record.setSecondNextRel(LegacyStore.longFromIntAndMod(secondNextRel, secondNextRelMod));
long nextProp = LegacyStore.getUnsignedInt(buffer);
long nextPropMod = (inUseByte & 0xF0L) << 28;
record.setNextProp(LegacyStore.longFromIntAndMod(nextProp, nextPropMod));
} else {
record = new RelationshipRecord(id, -1, -1, -1);
record.setInUse(false);
}
id++;
}
return record;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
Aggregations