Search in sources :

Example 41 with BimserverDatabaseException

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);
        }
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 42 with BimserverDatabaseException

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;
}
Also used : Cursor(com.sleepycat.je.Cursor) DatabaseException(com.sleepycat.je.DatabaseException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseException(com.sleepycat.je.DatabaseException) IOException(java.io.IOException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) EnvironmentLockedException(com.sleepycat.je.EnvironmentLockedException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 43 with BimserverDatabaseException

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;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 44 with BimserverDatabaseException

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;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 45 with BimserverDatabaseException

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;
}
Also used : Cursor(com.sleepycat.je.Cursor) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseException(com.sleepycat.je.DatabaseException) IOException(java.io.IOException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) EnvironmentLockedException(com.sleepycat.je.EnvironmentLockedException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Aggregations

BimserverDatabaseException (org.bimserver.BimserverDatabaseException)123 DatabaseSession (org.bimserver.database.DatabaseSession)56 UserException (org.bimserver.shared.exceptions.UserException)30 EClass (org.eclipse.emf.ecore.EClass)24 User (org.bimserver.models.store.User)20 ByteBuffer (java.nio.ByteBuffer)19 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)18 ServerSettings (org.bimserver.models.store.ServerSettings)18 IOException (java.io.IOException)16 ServerSettingsSetter (org.bimserver.database.actions.ServerSettingsSetter)16 SetServerSettingDatabaseAction (org.bimserver.database.actions.SetServerSettingDatabaseAction)16 SServerSettings (org.bimserver.interfaces.objects.SServerSettings)16 ServerException (org.bimserver.shared.exceptions.ServerException)15 UserSettings (org.bimserver.models.store.UserSettings)12 ServiceException (org.bimserver.shared.exceptions.ServiceException)11 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)10 ArrayList (java.util.ArrayList)9 IdEObject (org.bimserver.emf.IdEObject)9 Project (org.bimserver.models.store.Project)9 SerializerPluginConfiguration (org.bimserver.models.store.SerializerPluginConfiguration)9