use of org.neo4j.kernel.impl.nioneo.store.InvalidRecordException in project neo4j-mobile-android by neo4j-contrib.
the class BatchInserterImpl method getRelationshipIds.
public Iterable<Long> getRelationshipIds(long nodeId) {
NodeRecord nodeRecord = getNodeRecord(nodeId);
long nextRel = nodeRecord.getNextRel();
List<Long> ids = new ArrayList<Long>();
while (nextRel != Record.NO_NEXT_RELATIONSHIP.intValue()) {
RelationshipRecord relRecord = getRelationshipRecord(nextRel);
ids.add(relRecord.getId());
long firstNode = relRecord.getFirstNode();
long secondNode = relRecord.getSecondNode();
if (firstNode == nodeId) {
nextRel = relRecord.getFirstNextRel();
} else if (secondNode == nodeId) {
nextRel = relRecord.getSecondNextRel();
} else {
throw new InvalidRecordException("Node[" + nodeId + "] not part of firstNode[" + firstNode + "] or secondNode[" + secondNode + "]");
}
}
return ids;
}
use of org.neo4j.kernel.impl.nioneo.store.InvalidRecordException 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.InvalidRecordException in project neo4j-mobile-android by neo4j-contrib.
the class BatchGraphDatabaseImpl method getRelationshipById.
public Relationship getRelationshipById(long id) {
RelationshipBatchImpl rel = rels.get(id);
if (rel == null) {
try {
SimpleRelationship simpleRel = batchInserter.getRelationshipById(id);
Map<String, Object> props = batchInserter.getRelationshipProperties(id);
rel = new RelationshipBatchImpl(simpleRel, this, props);
rels.put(id, rel);
} catch (InvalidRecordException e) {
throw new NotFoundException(e);
}
}
return rel;
}
use of org.neo4j.kernel.impl.nioneo.store.InvalidRecordException in project neo4j-mobile-android by neo4j-contrib.
the class LegacyDynamicStoreReader method getRightArray.
public static Object getRightArray(byte[] bArray) {
ByteBuffer buf = ByteBuffer.wrap(bArray);
byte type = buf.get();
if (type == ArrayType.INT.byteValue()) {
int size = (bArray.length - 1) / 4;
assert (bArray.length - 1) % 4 == 0;
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = buf.getInt();
}
return array;
}
if (type == ArrayType.STRING.byteValue()) {
String[] array = new String[buf.getInt()];
for (int i = 0; i < array.length; i++) {
int charLength = buf.getInt() / 2;
char[] charBuffer = new char[charLength];
for (int j = 0; j < charLength; j++) {
charBuffer[j] = buf.getChar();
}
array[i] = new String(charBuffer);
}
return array;
}
if (type == ArrayType.BOOL.byteValue()) {
boolean[] array = new boolean[buf.getInt()];
int byteItr = 1;
byte currentValue = buf.get();
for (int i = 0; i < array.length; i++) {
array[i] = (currentValue & byteItr) > 0 ? true : false;
byteItr *= 2;
if (byteItr == 256) {
byteItr = 0;
currentValue = buf.get();
}
}
return array;
}
if (type == ArrayType.DOUBLE.byteValue()) {
int size = (bArray.length - 1) / 8;
assert (bArray.length - 1) % 8 == 0;
double[] array = new double[size];
for (int i = 0; i < size; i++) {
array[i] = buf.getDouble();
}
return array;
}
if (type == ArrayType.FLOAT.byteValue()) {
int size = (bArray.length - 1) / 4;
assert (bArray.length - 1) % 4 == 0;
float[] array = new float[size];
for (int i = 0; i < size; i++) {
array[i] = buf.getFloat();
}
return array;
}
if (type == ArrayType.LONG.byteValue()) {
int size = (bArray.length - 1) / 8;
assert (bArray.length - 1) % 8 == 0;
long[] array = new long[size];
for (int i = 0; i < size; i++) {
array[i] = buf.getLong();
}
return array;
}
if (type == ArrayType.BYTE.byteValue()) {
int size = (bArray.length - 1);
byte[] array = new byte[size];
buf.get(array);
return array;
}
if (type == ArrayType.CHAR.byteValue()) {
int size = (bArray.length - 1) / 2;
assert (bArray.length - 1) % 2 == 0;
char[] array = new char[size];
for (int i = 0; i < size; i++) {
array[i] = buf.getChar();
}
return array;
}
if (type == ArrayType.SHORT.byteValue()) {
int size = (bArray.length - 1) / 2;
assert (bArray.length - 1) % 2 == 0;
short[] array = new short[size];
for (short i = 0; i < size; i++) {
array[i] = buf.getShort();
}
return array;
}
throw new InvalidRecordException("Unknown array type[" + type + "]");
}
use of org.neo4j.kernel.impl.nioneo.store.InvalidRecordException in project neo4j-mobile-android by neo4j-contrib.
the class WriteTransaction method disconnectRelationship.
private void disconnectRelationship(RelationshipRecord rel) {
// update first node prev
if (rel.getFirstPrevRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getFirstPrevRel());
getWriteLock(lockableRel);
RelationshipRecord prevRel = getRelationshipRecord(rel.getFirstPrevRel());
if (prevRel == null) {
prevRel = getRelationshipStore().getRecord(rel.getFirstPrevRel());
addRelationshipRecord(prevRel);
}
boolean changed = false;
if (prevRel.getFirstNode() == rel.getFirstNode()) {
prevRel.setFirstNextRel(rel.getFirstNextRel());
changed = true;
}
if (prevRel.getSecondNode() == rel.getFirstNode()) {
prevRel.setSecondNextRel(rel.getFirstNextRel());
changed = true;
}
if (!changed) {
throw new InvalidRecordException(prevRel + " don't match " + rel);
}
}
// update first node next
if (rel.getFirstNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getFirstNextRel());
getWriteLock(lockableRel);
RelationshipRecord nextRel = getRelationshipRecord(rel.getFirstNextRel());
if (nextRel == null) {
nextRel = getRelationshipStore().getRecord(rel.getFirstNextRel());
addRelationshipRecord(nextRel);
}
boolean changed = false;
if (nextRel.getFirstNode() == rel.getFirstNode()) {
nextRel.setFirstPrevRel(rel.getFirstPrevRel());
changed = true;
}
if (nextRel.getSecondNode() == rel.getFirstNode()) {
nextRel.setSecondPrevRel(rel.getFirstPrevRel());
changed = true;
}
if (!changed) {
throw new InvalidRecordException(nextRel + " don't match " + rel);
}
}
// update second node prev
if (rel.getSecondPrevRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getSecondPrevRel());
getWriteLock(lockableRel);
RelationshipRecord prevRel = getRelationshipRecord(rel.getSecondPrevRel());
if (prevRel == null) {
prevRel = getRelationshipStore().getRecord(rel.getSecondPrevRel());
addRelationshipRecord(prevRel);
}
boolean changed = false;
if (prevRel.getFirstNode() == rel.getSecondNode()) {
prevRel.setFirstNextRel(rel.getSecondNextRel());
changed = true;
}
if (prevRel.getSecondNode() == rel.getSecondNode()) {
prevRel.setSecondNextRel(rel.getSecondNextRel());
changed = true;
}
if (!changed) {
throw new InvalidRecordException(prevRel + " don't match " + rel);
}
}
// update second node next
if (rel.getSecondNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
Relationship lockableRel = new LockableRelationship(rel.getSecondNextRel());
getWriteLock(lockableRel);
RelationshipRecord nextRel = getRelationshipRecord(rel.getSecondNextRel());
if (nextRel == null) {
nextRel = getRelationshipStore().getRecord(rel.getSecondNextRel());
addRelationshipRecord(nextRel);
}
boolean changed = false;
if (nextRel.getFirstNode() == rel.getSecondNode()) {
nextRel.setFirstPrevRel(rel.getSecondPrevRel());
changed = true;
}
if (nextRel.getSecondNode() == rel.getSecondNode()) {
nextRel.setSecondPrevRel(rel.getSecondPrevRel());
changed = true;
}
if (!changed) {
throw new InvalidRecordException(nextRel + " don't match " + rel);
}
}
}
Aggregations