use of org.bimserver.database.SearchingRecordIterator in project BIMserver by opensourceBIM.
the class DatabaseReadingStackFrame method getByOid.
public HashMapVirtualObject getByOid(long oid, boolean useCache) throws BimserverDatabaseException {
HashMapVirtualObject byOid = getQueryObjectProvider().getFromCache((long) oid);
if (byOid != null) {
return byOid;
}
EClass eClass = getQueryObjectProvider().getDatabaseSession().getEClassForOid(oid);
ByteBuffer mustStartWith = ByteBuffer.wrap(new byte[12]);
mustStartWith.putInt(reusable.getPid());
mustStartWith.putLong(oid);
ByteBuffer startSearchWith = ByteBuffer.wrap(new byte[16]);
startSearchWith.putInt(reusable.getPid());
startSearchWith.putLong(oid);
startSearchWith.putInt(-reusable.getRid());
SearchingRecordIterator recordIterator = getQueryObjectProvider().getDatabaseSession().getKeyValueStore().getRecordIterator(eClass.getEPackage().getName() + "_" + eClass.getName(), mustStartWith.array(), startSearchWith.array(), getQueryObjectProvider().getDatabaseSession());
try {
Record record = recordIterator.next();
if (record == null) {
return null;
}
getQueryObjectProvider().incReads();
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
// pid
keyBuffer.getInt();
long keyOid = keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
if (keyRid <= reusable.getRid()) {
if (valueBuffer.capacity() == 1 && valueBuffer.get(0) == -1) {
valueBuffer.position(valueBuffer.position() + 1);
return null;
// deleted entity
} else {
byOid = convertByteArrayToObject(eClass, keyOid, valueBuffer, keyRid);
if (byOid != null && useCache) {
getQueryObjectProvider().cache(byOid);
}
return byOid;
}
} else {
return null;
}
} finally {
recordIterator.close();
}
}
use of org.bimserver.database.SearchingRecordIterator in project BIMserver by opensourceBIM.
the class FollowReferenceStackFrame method process.
@Override
public boolean process() throws BimserverDatabaseException, QueryException {
if (getQueryObjectProvider().hasRead(oid)) {
processPossibleIncludes(currentObject, null, include);
return true;
}
if (hasRun) {
return true;
}
hasRun = true;
if (oid == -1) {
throw new BimserverDatabaseException("Cannot get object for oid " + oid);
}
EClass eClass = getQueryObjectProvider().getDatabaseSession().getEClassForOid(oid);
ByteBuffer mustStartWith = ByteBuffer.wrap(new byte[12]);
mustStartWith.putInt(getReusable().getPid());
mustStartWith.putLong(oid);
ByteBuffer startSearchWith = ByteBuffer.wrap(new byte[16]);
startSearchWith.putInt(getReusable().getPid());
startSearchWith.putLong(oid);
startSearchWith.putInt(-getReusable().getRid());
SearchingRecordIterator recordIterator = getQueryObjectProvider().getDatabaseSession().getKeyValueStore().getRecordIterator(eClass.getEPackage().getName() + "_" + eClass.getName(), mustStartWith.array(), startSearchWith.array(), getQueryObjectProvider().getDatabaseSession());
try {
Record record = recordIterator.next();
if (record == null) {
return true;
}
getQueryObjectProvider().incReads();
ByteBuffer keyBuffer = ByteBuffer.wrap(record.getKey());
ByteBuffer valueBuffer = ByteBuffer.wrap(record.getValue());
// pid
keyBuffer.getInt();
long keyOid = keyBuffer.getLong();
int keyRid = -keyBuffer.getInt();
if (keyRid <= getReusable().getRid()) {
if (valueBuffer.capacity() == 1 && valueBuffer.get(0) == -1) {
valueBuffer.position(valueBuffer.position() + 1);
return true;
// deleted entity
} else {
currentObject = convertByteArrayToObject(eClass, keyOid, valueBuffer, keyRid);
if (currentObject != null) {
EReference opposite = getPackageMetaData().getInverseOrOpposite(currentObject.eClass(), fromReference);
if (opposite != null) {
Object x = currentObject.get(opposite.getName());
if (x instanceof List) {
List<Long> list = (List<Long>) x;
int index = list.indexOf(fromOid);
currentObject.addUseForSerialization(opposite, index);
} else {
currentObject.addUseForSerialization(opposite);
}
}
}
processPossibleIncludes(currentObject, null, include);
}
} else {
return true;
}
} finally {
recordIterator.close();
}
return true;
}
Aggregations