Search in sources :

Example 6 with DatabaseSession

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

the class CommandLine method run.

@Override
public void run() {
    reader = new BufferedReader(new InputStreamReader(System.in));
    running = true;
    try {
        while (running) {
            try {
                String line = reader.readLine();
                if (line == null) {
                    Thread.sleep(50);
                    continue;
                }
                if (line.equalsIgnoreCase("exit")) {
                    bimServer.stop();
                    return;
                } else if (line.startsWith("dumpmodel")) {
                    try {
                        long roid = Long.parseLong(line.substring(9).trim());
                        DatabaseSession databaseSession = bimServer.getDatabase().createSession();
                        try {
                            DownloadDatabaseAction downloadDatabaseAction = new DownloadDatabaseAction(bimServer, databaseSession, AccessMethod.INTERNAL, roid, -1, -1, new SystemAuthorization(1, TimeUnit.HOURS), null);
                            IfcModelInterface model = downloadDatabaseAction.execute();
                            LOGGER.info("Model size: " + model.size());
                            List<IfcWall> walls = model.getAll(IfcWall.class);
                            List<IfcProject> projects = model.getAll(IfcProject.class);
                            List<IfcSlab> slabs = model.getAll(IfcSlab.class);
                            List<IfcWindow> windows = model.getAll(IfcWindow.class);
                            LOGGER.info("Walls: " + walls.size());
                            LOGGER.info("Windows: " + windows.size());
                            LOGGER.info("Projects: " + projects.size());
                            LOGGER.info("Slabs: " + slabs.size());
                        } catch (UserException e) {
                            LOGGER.error("", e);
                        } catch (BimserverLockConflictException e) {
                            LOGGER.error("", e);
                        } catch (BimserverDatabaseException e) {
                            LOGGER.error("", e);
                        } finally {
                            databaseSession.close();
                        }
                    } catch (Exception e) {
                        LOGGER.error("", e);
                    }
                } else if (line.equalsIgnoreCase("dump")) {
                    LOGGER.info("Dumping all thread's track traces...");
                    LOGGER.info("");
                    Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
                    for (Thread t : allStackTraces.keySet()) {
                        LOGGER.info(t.getName());
                        StackTraceElement[] stackTraceElements = allStackTraces.get(t);
                        for (StackTraceElement stackTraceElement : stackTraceElements) {
                            LOGGER.info("\t" + stackTraceElement.getClassName() + ":" + stackTraceElement.getLineNumber() + "." + stackTraceElement.getMethodName());
                        }
                        LOGGER.info("");
                    }
                    LOGGER.info("Done printing stack traces");
                    LOGGER.info("");
                    Thread.sleep(10000);
                } else if (line.equals("migrate")) {
                    try {
                        bimServer.getDatabase().getMigrator().migrate();
                        bimServer.getServerInfoManager().update();
                    } catch (MigrationException e) {
                        LOGGER.error("", e);
                    } catch (InconsistentModelsException e) {
                        LOGGER.error("", e);
                    }
                } else if (line.equals("clearendpoints")) {
                    bimServer.getEndPointManager().clear();
                } else if (line.startsWith("showall")) {
                    KeyValueStore keyValueStore = ((Database) bimServer.getDatabase()).getKeyValueStore();
                    Set<String> allTableNames = keyValueStore.getAllTableNames();
                    long total = 0;
                    for (String tableName : allTableNames) {
                        long size = keyValueStore.count(tableName);
                        total += size;
                        if (size != 0) {
                            LOGGER.info(tableName + " " + size);
                        }
                    }
                    LOGGER.info("total: " + total);
                } else {
                    LOGGER.info("Unknown command");
                }
            } catch (IOException e) {
                LOGGER.error("", e);
            }
        }
    } catch (InterruptedException e) {
    }
}
Also used : InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) Set(java.util.Set) DatabaseSession(org.bimserver.database.DatabaseSession) IfcModelInterface(org.bimserver.emf.IfcModelInterface) KeyValueStore(org.bimserver.database.KeyValueStore) SystemAuthorization(org.bimserver.webservices.authorization.SystemAuthorization) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) DownloadDatabaseAction(org.bimserver.database.actions.DownloadDatabaseAction) IfcWall(org.bimserver.models.ifc2x3tc1.IfcWall) IfcProject(org.bimserver.models.ifc2x3tc1.IfcProject) IfcWindow(org.bimserver.models.ifc2x3tc1.IfcWindow) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) IOException(java.io.IOException) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException) MigrationException(org.bimserver.database.migrations.MigrationException) UserException(org.bimserver.shared.exceptions.UserException) InconsistentModelsException(org.bimserver.database.migrations.InconsistentModelsException) IfcSlab(org.bimserver.models.ifc2x3tc1.IfcSlab) MigrationException(org.bimserver.database.migrations.MigrationException) BufferedReader(java.io.BufferedReader) BimserverLockConflictException(org.bimserver.database.BimserverLockConflictException)

Example 7 with DatabaseSession

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

the class TestDatabase method checkLists3.

private void checkLists3() {
    DatabaseSession session = database.createSession();
    long xid = -1;
    try {
        User user = session.create(User.class);
        UserSettings userSettings = session.create(UserSettings.class);
        SerializerPluginConfiguration serializerPluginConfiguration1 = session.create(SerializerPluginConfiguration.class);
        SerializerPluginConfiguration serializerPluginConfiguration2 = session.create(SerializerPluginConfiguration.class);
        xid = serializerPluginConfiguration2.getOid();
        user.setUserSettings(userSettings);
        serializerPluginConfiguration1.setUserSettings(userSettings);
        serializerPluginConfiguration2.setUserSettings(userSettings);
        session.commit();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (ServiceException e) {
        e.printStackTrace();
    } finally {
        session.close();
        session = database.createSession();
        try {
            SerializerPluginConfiguration p1 = session.get(xid, OldQuery.getDefault());
            UserSettings userSettings = p1.getUserSettings();
            for (SerializerPluginConfiguration p2 : userSettings.getSerializers()) {
                System.out.println(p2.getOid() + " - " + p2);
            }
        } catch (BimserverDatabaseException e) {
            e.printStackTrace();
        } finally {
            session.close();
        }
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) User(org.bimserver.models.store.User) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseSession(org.bimserver.database.DatabaseSession) UserSettings(org.bimserver.models.store.UserSettings) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration)

Example 8 with DatabaseSession

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

the class TestDatabase method checkWithAllOfType.

private void checkWithAllOfType() {
    DatabaseSession session = database.createSession();
    try {
        List<User> users = session.getAllOfType(StorePackage.eINSTANCE.getUser(), User.class, OldQuery.getDefault());
        for (User user : users) {
            if (user.getName().equals("testuser")) {
                System.out.println(user.getName() + ": " + user.getHasRightsOn());
            }
        }
        List<Project> projects = session.getAllOfType(StorePackage.eINSTANCE.getProject(), Project.class, OldQuery.getDefault());
        for (Project project : projects) {
            if (project.getName().equals("testproject")) {
                System.out.println(project.getName() + ": " + project.getHasAuthorizedUsers());
            }
        }
        session.commit();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (ServiceException e) {
        e.printStackTrace();
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) User(org.bimserver.models.store.User) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseSession(org.bimserver.database.DatabaseSession)

Example 9 with DatabaseSession

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

the class TestDatabase method removeWithOid.

private void removeWithOid() {
    DatabaseSession session = database.createSession();
    try {
        Project p = session.get(StorePackage.eINSTANCE.getProject(), poid, OldQuery.getDefault());
        User u = session.get(StorePackage.eINSTANCE.getUser(), uoid, OldQuery.getDefault());
        if (!u.getHasRightsOn().remove(p)) {
            System.err.println("Not removed");
        }
        session.store(u);
        session.store(p);
        session.commit();
    } catch (BimserverDatabaseException e) {
        e.printStackTrace();
    } catch (ServiceException e) {
        e.printStackTrace();
    } finally {
        session.close();
    }
}
Also used : Project(org.bimserver.models.store.Project) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) User(org.bimserver.models.store.User) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseSession(org.bimserver.database.DatabaseSession)

Example 10 with DatabaseSession

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

the class SerializerFactory method createMessagingSerializer.

public MessagingSerializer createMessagingSerializer(String username, IfcModelInterface model, DownloadParameters downloadParameters) throws SerializerException {
    DatabaseSession session = bimDatabase.createSession();
    try {
        MessagingSerializerPluginConfiguration serializerPluginConfiguration = session.get(StorePackage.eINSTANCE.getMessagingSerializerPluginConfiguration(), downloadParameters.getSerializerOid(), OldQuery.getDefault());
        if (serializerPluginConfiguration != null) {
            MessagingSerializerPlugin serializerPlugin = (MessagingSerializerPlugin) pluginManager.getPlugin(serializerPluginConfiguration.getPluginDescriptor().getPluginClassName(), true);
            if (serializerPlugin != null) {
                ObjectType settings = serializerPluginConfiguration.getSettings();
                MessagingSerializer serializer = serializerPlugin.createSerializer(new PluginConfiguration(settings));
                if (serializer != null) {
                    try {
                        serializer.init(model, null, pluginManager, model.getPackageMetaData(), true);
                        return serializer;
                    } catch (NullPointerException e) {
                        LOGGER.error("", e);
                    }
                }
            }
        }
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    } finally {
        session.close();
    }
    return null;
}
Also used : MessagingSerializerPlugin(org.bimserver.plugins.serializers.MessagingSerializerPlugin) MessagingSerializer(org.bimserver.plugins.serializers.MessagingSerializer) ObjectType(org.bimserver.models.store.ObjectType) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration) SerializerPluginConfiguration(org.bimserver.models.store.SerializerPluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) MessagingSerializerPluginConfiguration(org.bimserver.models.store.MessagingSerializerPluginConfiguration)

Aggregations

DatabaseSession (org.bimserver.database.DatabaseSession)279 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)258 UserException (org.bimserver.shared.exceptions.UserException)228 ServerException (org.bimserver.shared.exceptions.ServerException)217 IOException (java.io.IOException)194 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)105 SerializerException (org.bimserver.plugins.serializers.SerializerException)105 UnsupportedEncodingException (java.io.UnsupportedEncodingException)103 MalformedURLException (java.net.MalformedURLException)103 MessagingException (javax.mail.MessagingException)103 AddressException (javax.mail.internet.AddressException)103 CannotBeScheduledException (org.bimserver.longaction.CannotBeScheduledException)103 BcfException (org.opensourcebim.bcf.BcfException)103 User (org.bimserver.models.store.User)34 ArrayList (java.util.ArrayList)29 UserSettings (org.bimserver.models.store.UserSettings)29 Project (org.bimserver.models.store.Project)25 ServerSettings (org.bimserver.models.store.ServerSettings)21 ServerSettingsSetter (org.bimserver.database.actions.ServerSettingsSetter)18 SetServerSettingDatabaseAction (org.bimserver.database.actions.SetServerSettingDatabaseAction)18