use of org.bimserver.BimserverDatabaseException 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;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class QueryClassificationsAndTypesStackFrame method getOids.
public List<ObjectIdentifier> getOids(EClass eClass, EStructuralFeature eStructuralFeature, Object value, DatabaseInterface databaseInterface, int pid, int rid) throws BimserverDatabaseException {
if (eStructuralFeature.getEAnnotation("singleindex") != null) {
List<ObjectIdentifier> result = new ArrayList<>();
String indexTableName = eStructuralFeature.getEContainingClass().getEPackage().getName() + "_" + eClass.getName() + "_" + eStructuralFeature.getName();
byte[] queryBytes = null;
if (value instanceof String) {
queryBytes = ((String) value).getBytes(Charsets.UTF_8);
} else if (value instanceof Integer) {
queryBytes = BinUtils.intToByteArray((Integer) value);
} else if (value instanceof Long) {
queryBytes = BinUtils.longToByteArray((Long) value);
} else {
throw new BimserverDatabaseException("Unsupported type " + value);
}
ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8);
valueBuffer.putInt(pid);
valueBuffer.putInt(-rid);
valueBuffer.put(queryBytes);
List<byte[]> duplicates = databaseInterface.getDuplicates(indexTableName, valueBuffer.array());
for (byte[] duplicate : duplicates) {
ByteBuffer buffer = ByteBuffer.wrap(duplicate);
// pid
buffer.getInt();
long oid = buffer.getLong();
result.add(new ObjectIdentifier(oid, (short) oid));
}
return result;
} else {
throw new UnsupportedOperationException();
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class QueryClassificationsAndTypesStackFrame method getOid.
public ObjectIdentifier getOid(EClass eClass, EAttribute attribute, Object value, DatabaseInterface databaseInterface, int pid, int rid) throws BimserverDatabaseException {
if (attribute.getEAnnotation("singleindex") != null) {
String indexTableName = attribute.getEContainingClass().getEPackage().getName() + "_" + eClass.getName() + "_" + attribute.getName();
byte[] queryBytes = null;
if (value instanceof String) {
queryBytes = ((String) value).getBytes(Charsets.UTF_8);
} else if (value instanceof Integer) {
queryBytes = BinUtils.intToByteArray((Integer) value);
} else {
throw new BimserverDatabaseException("Unsupported type " + value);
}
ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8);
valueBuffer.putInt(pid);
valueBuffer.putInt(-rid);
valueBuffer.put(queryBytes);
byte[] firstDuplicate = databaseInterface.get(indexTableName, valueBuffer.array());
if (firstDuplicate != null) {
ByteBuffer buffer = ByteBuffer.wrap(firstDuplicate);
// pid
buffer.getInt();
long oid = buffer.getLong();
return new ObjectIdentifier(oid, (short) oid);
}
} else {
throw new UnsupportedOperationException(eClass.getName() + "." + attribute.getName() + " does not have a singleindex");
}
return null;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method store.
@Override
public void store(String tableName, byte[] key, byte[] value, int offset, int length, DatabaseSession databaseSession) throws BimserverDatabaseException, BimserverLockConflictException {
DatabaseEntry dbKey = new DatabaseEntry(key);
DatabaseEntry dbValue = new DatabaseEntry(value, offset, length);
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
tableWrapper.getDatabase().put(getTransaction(databaseSession, tableWrapper), dbKey, dbValue);
} catch (LockConflictException e) {
throw new BimserverLockConflictException(e);
} catch (DatabaseException e) {
throw new BimserverDatabaseException("", e);
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method createIndexTable.
public boolean createIndexTable(String tableName, DatabaseSession databaseSession, boolean transactional) throws BimserverDatabaseException {
if (tables.containsKey(tableName)) {
throw new BimserverDatabaseException("Table " + tableName + " already created");
}
DatabaseConfig databaseConfig = new DatabaseConfig();
databaseConfig.setAllowCreate(true);
boolean finalTransactional = transactional && useTransactions;
// if (!transactional) {
// databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
// }
databaseConfig.setDeferredWrite(!finalTransactional);
databaseConfig.setTransactional(finalTransactional);
databaseConfig.setSortedDuplicates(true);
Database database = environment.openDatabase(null, tableName, databaseConfig);
if (database == null) {
return false;
}
tables.put(tableName, new TableWrapper(database, finalTransactional));
return true;
}
Aggregations