Search in sources :

Example 21 with BimserverLockConflictException

use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.

the class BerkeleySearchingRecordIterator method getFirstNext.

private Record getFirstNext(byte[] startSearchingAt) throws BimserverLockConflictException {
    this.nextStartSearchingAt = null;
    DatabaseEntry key = new DatabaseEntry(startSearchingAt);
    DatabaseEntry value = new DatabaseEntry();
    if (onlyKeys) {
        value.setPartial(0, 0, true);
    }
    try {
        OperationStatus next = cursor.getSearchKeyRange(key, value, LockMode.DEFAULT);
        if (next == OperationStatus.SUCCESS) {
            byte[] firstBytes = new byte[mustStartWith.length];
            System.arraycopy(key.getData(), 0, firstBytes, 0, mustStartWith.length);
            if (Arrays.equals(firstBytes, mustStartWith)) {
                return new BerkeleyRecord(key, value);
            }
        }
    } catch (LockConflictException e) {
        throw new BimserverLockConflictException(e);
    } catch (DatabaseException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException)

Example 22 with BimserverLockConflictException

use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.

the class BerkeleyKeyValueStore method delete.

public void delete(String tableName, byte[] key, DatabaseSession databaseSession) throws BimserverLockConflictException {
    DatabaseEntry entry = new DatabaseEntry(key);
    try {
        TableWrapper tableWrapper = getTableWrapper(tableName);
        tableWrapper.getDatabase().delete(getTransaction(databaseSession, tableWrapper), entry);
    } catch (LockConflictException e) {
        throw new BimserverLockConflictException(e);
    } catch (DatabaseException e) {
        LOGGER.error("", e);
    } catch (UnsupportedOperationException e) {
        LOGGER.error("", e);
    } catch (IllegalArgumentException e) {
        LOGGER.error("", e);
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) LockConflictException(com.sleepycat.je.LockConflictException) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseException(com.sleepycat.je.DatabaseException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 23 with BimserverLockConflictException

use of org.bimserver.database.BimserverLockConflictException in project BIMserver by opensourceBIM.

the class BimServer method initDatabaseDependantItems.

private void initDatabaseDependantItems() throws BimserverDatabaseException {
    notificationsManager.init();
    getSerializerFactory().init(pluginManager, bimDatabase, this);
    try {
        DatabaseSession session = bimDatabase.createSession();
        try {
            updatePlugins(session);
            session.commit();
        } catch (ServiceException e) {
            LOGGER.error("", e);
        } finally {
            session.close();
        }
        session = bimDatabase.createSession();
        // createDatabaseObjects(session);
        ServerSettings serverSettings = serverSettingsCache.getServerSettings();
        for (Entry<PluginContext, WebModulePlugin> entry : pluginManager.getAllWebPlugins(true).entrySet()) {
            WebModulePluginConfiguration webPluginConfiguration = find(serverSettings.getWebModules(), entry.getKey().getIdentifier());
            if (webPluginConfiguration == null) {
                webPluginConfiguration = session.create(WebModulePluginConfiguration.class);
                serverSettings.getWebModules().add(webPluginConfiguration);
                PluginDescriptor pluginDescriptor = getPluginDescriptor(session, entry.getKey().getIdentifier());
                if (pluginDescriptor == null) {
                    throw new BimserverDatabaseException("No plugin descriptor found: " + entry.getKey().getIdentifier());
                }
                genericPluginConversion(entry.getKey(), session, webPluginConfiguration, pluginDescriptor);
            } else {
                if (webPluginConfiguration == serverSettings.getWebModule()) {
                    setDefaultWebModule(entry.getValue());
                }
            }
        }
        // Set the default
        // if (serverSettings.getWebModule() == null) {
        // WebModulePluginConfiguration bimviewsWebModule = findWebModule(serverSettings, "BIM Views");
        // if (bimviewsWebModule != null) {
        // serverSettings.setWebModule(bimviewsWebModule);
        // setDefaultWebModule(pluginManager.getWebModulePlugin(bimviewsWebModule.getPluginDescriptor().getPluginClassName(), true));
        // } else {
        // WebModulePluginConfiguration defaultWebModule = findWebModule(serverSettings, "org.bimserver.defaultwebmodule.DefaultWebModulePlugin");
        // if (defaultWebModule != null) {
        // serverSettings.setWebModule(defaultWebModule);
        // setDefaultWebModule(pluginManager.getWebModulePlugin(defaultWebModule.getPluginDescriptor().getPluginClassName(), true));
        // }
        // }
        // }
        session.store(serverSettings);
        Condition condition = new AttributeCondition(StorePackage.eINSTANCE.getUser_Username(), new StringLiteral("system"));
        User systemUser = session.querySingle(condition, User.class, OldQuery.getDefault());
        ServerStarted serverStarted = session.create(ServerStarted.class);
        serverStarted.setDate(new Date());
        serverStarted.setAccessMethod(AccessMethod.INTERNAL);
        serverStarted.setExecutor(systemUser);
        try {
            session.store(serverStarted);
            session.commit();
        } catch (BimserverLockConflictException e) {
            throw new BimserverDatabaseException(e);
        } catch (ServiceException e) {
            throw new BimserverDatabaseException(e);
        } finally {
            session.close();
        }
        webModules = new HashMap<String, WebModulePlugin>();
        DatabaseSession ses = bimDatabase.createSession();
        try {
            List<WebModulePluginConfiguration> webModuleConfigurations = serverSettingsCache.getServerSettings().getWebModules();
            for (WebModulePluginConfiguration webModulePluginConfiguration : webModuleConfigurations) {
                String contextPath = "";
                for (Parameter parameter : webModulePluginConfiguration.getSettings().getParameters()) {
                    if (parameter.getName().equals("contextPath")) {
                        contextPath = ((StringType) parameter.getValue()).getValue();
                    }
                }
                String identifier = webModulePluginConfiguration.getPluginDescriptor().getIdentifier();
                webModules.put(contextPath, (WebModulePlugin) pluginManager.getPlugin(identifier, true));
            }
        // if (serverSettingsCache.getServerSettings().getWebModule() !=
        // null) {
        // defaultWebModule = (WebModulePlugin)
        // pluginManager.getPlugin(serverSettingsCache.getServerSettings().getWebModule().getPluginDescriptor().getPluginClassName(),
        // true);
        // }
        } finally {
            ses.close();
        }
        Integer protocolBuffersPort = getServerSettingsCache().getServerSettings().getProtocolBuffersPort();
        if (protocolBuffersPort >= 1 && protocolBuffersPort <= 65535) {
            try {
                protocolBuffersServer = new ProtocolBuffersServer(protocolBuffersMetaData, serviceFactory, servicesMap, protocolBuffersPort);
                protocolBuffersServer.start();
            } catch (Exception e) {
                LOGGER.error("", e);
            }
        }
        bimServerClientFactory = new DirectBimServerClientFactory<ServiceInterface>(serverSettingsCache.getServerSettings().getSiteAddress(), serviceFactory, servicesMap, pluginManager, metaDataManager);
        pluginManager.setBimServerClientFactory(bimServerClientFactory);
        try (DatabaseSession session2 = bimDatabase.createSession()) {
            IfcModelInterface pluginBundleVersions = session2.getAllOfType(StorePackage.eINSTANCE.getPluginBundleVersion(), OldQuery.getDefault());
            for (PluginBundleVersion pluginBundleVersion : pluginBundleVersions.getAll(PluginBundleVersion.class)) {
                if (pluginBundleVersion.getType() == PluginBundleType.MAVEN || pluginBundleVersion.getType() == PluginBundleType.LOCAL) {
                    PluginBundleVersionIdentifier pluginBundleVersionIdentifier = new PluginBundleVersionIdentifier(pluginBundleVersion.getGroupId(), pluginBundleVersion.getArtifactId(), pluginBundleVersion.getVersion());
                    IfcModelInterface pluginDescriptors = session2.getAllOfType(StorePackage.eINSTANCE.getPluginDescriptor(), OldQuery.getDefault());
                    List<SPluginInformation> plugins = new ArrayList<>();
                    for (PluginDescriptor pluginDescriptor : pluginDescriptors.getAll(PluginDescriptor.class)) {
                        if (pluginDescriptor.getPluginBundleVersion() == pluginBundleVersion && pluginDescriptor.getEnabled()) {
                            SPluginInformation sPluginInformation = new SPluginInformation();
                            sPluginInformation.setEnabled(true);
                            sPluginInformation.setDescription(pluginDescriptor.getDescription());
                            sPluginInformation.setIdentifier(pluginDescriptor.getIdentifier());
                            sPluginInformation.setInstallForAllUsers(pluginDescriptor.isInstallForNewUsers());
                            sPluginInformation.setInstallForNewUsers(pluginDescriptor.isInstallForNewUsers());
                            sPluginInformation.setName(pluginDescriptor.getName());
                            sPluginInformation.setType(pluginManager.getPluginTypeFromClass(pluginDescriptor.getPluginClassName()));
                            plugins.add(sPluginInformation);
                        }
                    }
                    try {
                        pluginManager.loadFromPluginDir(pluginBundleVersionIdentifier, getSConverter().convertToSObject(pluginBundleVersion), plugins, serverSettingsCache.getServerSettings().isPluginStrictVersionChecking());
                    } catch (Exception e) {
                        LOGGER.error("", e);
                    }
                }
            }
        } catch (Exception e) {
            throw new BimserverDatabaseException(e);
        }
    } catch (BimserverLockConflictException e) {
        throw new BimserverDatabaseException(e);
    // } catch (PluginException e) {
    // throw new BimserverDatabaseException(e);
    }
}
Also used : User(org.bimserver.models.store.User) DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) ArrayList(java.util.ArrayList) PluginBundleVersionIdentifier(org.bimserver.plugins.PluginBundleVersionIdentifier) ServerSettings(org.bimserver.models.store.ServerSettings) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) WebModulePlugin(org.bimserver.plugins.web.WebModulePlugin) PluginBundleVersion(org.bimserver.models.store.PluginBundleVersion) SPluginBundleVersion(org.bimserver.interfaces.objects.SPluginBundleVersion) Condition(org.bimserver.database.query.conditions.Condition) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) PluginContext(org.bimserver.plugins.PluginContext) WebModulePluginConfiguration(org.bimserver.models.store.WebModulePluginConfiguration) SPluginInformation(org.bimserver.interfaces.objects.SPluginInformation) AttributeCondition(org.bimserver.database.query.conditions.AttributeCondition) Date(java.util.Date) ServiceException(org.bimserver.shared.exceptions.ServiceException) IOException(java.io.IOException) ServerException(org.bimserver.shared.exceptions.ServerException) PluginException(org.bimserver.shared.exceptions.PluginException) InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) DatabaseRestartRequiredException(org.bimserver.database.DatabaseRestartRequiredException) DatabaseInitException(org.bimserver.database.berkeley.DatabaseInitException) ProtocolBuffersServer(org.bimserver.pb.server.ProtocolBuffersServer) PluginDescriptor(org.bimserver.models.store.PluginDescriptor) ServerStarted(org.bimserver.models.log.ServerStarted) ServiceException(org.bimserver.shared.exceptions.ServiceException) StringLiteral(org.bimserver.database.query.literals.StringLiteral) Parameter(org.bimserver.models.store.Parameter) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException)

Aggregations

BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)23 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)17 DatabaseException (com.sleepycat.je.DatabaseException)8 LockConflictException (com.sleepycat.je.LockConflictException)8 UserException (org.bimserver.shared.exceptions.UserException)7 DatabaseEntry (com.sleepycat.je.DatabaseEntry)6 ByteBuffer (java.nio.ByteBuffer)5 EClass (org.eclipse.emf.ecore.EClass)5 OperationStatus (com.sleepycat.je.OperationStatus)4 IOException (java.io.IOException)4 KeyValueStore (org.bimserver.database.KeyValueStore)4 Record (org.bimserver.database.Record)4 RecordIterator (org.bimserver.database.RecordIterator)4 User (org.bimserver.models.store.User)4 ServerException (org.bimserver.shared.exceptions.ServerException)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 DatabaseSession (org.bimserver.database.DatabaseSession)3 SPluginInformation (org.bimserver.interfaces.objects.SPluginInformation)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2