use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class StreamingCheckinDatabaseAction method fixInverses.
private void fixInverses(PackageMetaData packageMetaData, long newRoid, Map<Long, HashMapVirtualObject> cache, HashMapVirtualObject next, EReference eReference, long refOid) throws JsonParseException, JsonMappingException, IOException, QueryException, BimserverDatabaseException {
HashMapVirtualObject referencedObject = cache.get(refOid);
if (referencedObject == null) {
referencedObject = getByOid(packageMetaData, getDatabaseSession(), newRoid, refOid);
if (referencedObject == null) {
throw new BimserverDatabaseException("Referenced object with oid " + refOid + " (" + getDatabaseSession().getEClassForOid(refOid).getName() + ")" + ", referenced from " + next.eClass().getName() + " not found");
}
cache.put(refOid, referencedObject);
}
EReference oppositeReference = packageMetaData.getInverseOrOpposite(referencedObject.eClass(), eReference);
if (oppositeReference == null) {
if (eReference.getName().equals("RelatedElements") && referencedObject.eClass().getName().equals("IfcSpace")) {
// Ignore, IfcSpace should have a field called RelatedElements, but it doesn't.
} else {
// LOGGER.error("No opposite " + eReference.getName() + " found");
}
} else {
if (oppositeReference.isMany()) {
Object existingList = referencedObject.eGet(oppositeReference);
if (existingList != null) {
int currentSize = ((List<?>) existingList).size();
referencedObject.setListItemReference(oppositeReference, currentSize, next.eClass(), next.getOid(), 0);
} else {
referencedObject.setListItemReference(oppositeReference, 0, next.eClass(), next.getOid(), 0);
}
} else {
referencedObject.setReference(oppositeReference, next.getOid(), 0);
}
}
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method getRecordIterator.
@Override
public RecordIterator getRecordIterator(String tableName, DatabaseSession databaseSession) throws BimserverDatabaseException {
Cursor cursor = null;
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
cursor = tableWrapper.getDatabase().openCursor(getTransaction(databaseSession, tableWrapper), getCursorConfig(tableWrapper));
BerkeleyRecordIterator berkeleyRecordIterator = new BerkeleyRecordIterator(cursor, this, cursorCounter.incrementAndGet());
if (MONITOR_CURSOR_STACK_TRACES) {
openCursors.put(berkeleyRecordIterator.getCursorId(), new Exception().getStackTrace());
}
return berkeleyRecordIterator;
} catch (DatabaseException e) {
LOGGER.error("", e);
}
return null;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method openTable.
public boolean openTable(DatabaseSession databaseSession, String tableName, boolean transactional) throws BimserverDatabaseException {
if (tables.containsKey(tableName)) {
throw new BimserverDatabaseException("Table " + tableName + " already opened");
}
DatabaseConfig databaseConfig = new DatabaseConfig();
databaseConfig.setAllowCreate(false);
boolean finalTransactional = transactional && useTransactions;
// if (!transactional) {
// databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
// }
databaseConfig.setDeferredWrite(!finalTransactional);
databaseConfig.setTransactional(finalTransactional);
databaseConfig.setSortedDuplicates(false);
Database database = environment.openDatabase(null, tableName, databaseConfig);
if (database == null) {
throw new BimserverDatabaseException("Table " + tableName + " not found in database");
}
tables.put(tableName, new TableWrapper(database, finalTransactional));
return true;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method createTable.
public boolean createTable(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;
databaseConfig.setDeferredWrite(!finalTransactional);
// if (!transactional) {
// databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
// }
databaseConfig.setTransactional(finalTransactional);
databaseConfig.setSortedDuplicates(false);
Database database = environment.openDatabase(null, tableName, databaseConfig);
if (database == null) {
return false;
}
tables.put(tableName, new TableWrapper(database, finalTransactional));
return true;
}
use of org.bimserver.BimserverDatabaseException in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method getRecordIterator.
@Override
public SearchingRecordIterator getRecordIterator(String tableName, byte[] mustStartWith, byte[] startSearchingAt, DatabaseSession databaseSession, boolean keysOnly) throws BimserverLockConflictException, BimserverDatabaseException {
Cursor cursor = null;
try {
TableWrapper tableWrapper = getTableWrapper(tableName);
cursor = tableWrapper.getDatabase().openCursor(getTransaction(databaseSession, tableWrapper), getCursorConfig(tableWrapper));
BerkeleySearchingRecordIterator berkeleySearchingRecordIterator = new BerkeleySearchingRecordIterator(cursor, this, cursorCounter.incrementAndGet(), mustStartWith, startSearchingAt, keysOnly);
if (MONITOR_CURSOR_STACK_TRACES) {
openCursors.put(berkeleySearchingRecordIterator.getCursorId(), new Exception().getStackTrace());
}
return berkeleySearchingRecordIterator;
} catch (BimserverLockConflictException e) {
if (cursor != null) {
try {
cursor.close();
throw e;
} catch (DatabaseException e1) {
LOGGER.error("", e1);
}
}
} catch (DatabaseException e1) {
LOGGER.error("", e1);
}
return null;
}
Aggregations