use of org.bimserver.database.migrations.MigrationException 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) {
}
}
use of org.bimserver.database.migrations.MigrationException in project BIMserver by opensourceBIM.
the class Database method init.
public void init() throws DatabaseInitException, DatabaseRestartRequiredException, InconsistentModelsException {
DatabaseSession databaseSession = createSession();
try {
if (getKeyValueStore().isNew()) {
keyValueStore.createTable(CLASS_LOOKUP_TABLE, null, true);
keyValueStore.createTable(Database.STORE_PROJECT_NAME, null, true);
keyValueStore.createTable(Registry.REGISTRY_TABLE, null, true);
setDatabaseVersion(-1, databaseSession);
created = new Date();
registry.save(DATE_CREATED, created, databaseSession);
} else {
keyValueStore.openTable(databaseSession, CLASS_LOOKUP_TABLE, true);
keyValueStore.openTable(databaseSession, Database.STORE_PROJECT_NAME, true);
keyValueStore.openTable(databaseSession, Registry.REGISTRY_TABLE, true);
created = registry.readDate(DATE_CREATED, databaseSession);
if (created == null) {
created = new Date();
registry.save(DATE_CREATED, created, databaseSession);
}
}
databaseSchemaVersion = registry.readInt(SCHEMA_VERSION, databaseSession, -1);
migrator = new Migrator(this);
if (getKeyValueStore().isNew()) {
try {
migrator.migrate(databaseSession);
} catch (MigrationException e) {
LOGGER.error("", e);
}
registry.save("isnew", true, databaseSession);
databaseSession.commit();
databaseSession.close();
throw new DatabaseRestartRequiredException();
} else if (registry.readBoolean("isnew", true, databaseSession)) {
initInternalStructure(databaseSession);
initCounters(databaseSession);
ServerSettings settings = createDefaultSettings(databaseSession);
databaseSession.store(settings);
new CreateBaseProjectDatabaseAction(databaseSession, AccessMethod.INTERNAL).execute();
AddUserDatabaseAction addUserDatabaseAction = new AddUserDatabaseAction(bimServer, databaseSession, AccessMethod.INTERNAL, "system", "system", "System", UserType.SYSTEM, new SystemAuthorization(1, TimeUnit.HOURS), false, null);
addUserDatabaseAction.setCreateSystemUser();
User systemUser = addUserDatabaseAction.execute();
systemUser.setCreatedBy(systemUser);
databaseSession.store(systemUser);
DatabaseCreated databaseCreated = databaseSession.create(DatabaseCreated.class);
databaseCreated.setAccessMethod(AccessMethod.INTERNAL);
databaseCreated.setExecutor(systemUser);
databaseCreated.setDate(new Date());
databaseCreated.setPath(getKeyValueStore().getLocation());
databaseCreated.setVersion(databaseSchemaVersion);
databaseSession.store(databaseCreated);
registry.save("isnew", false, databaseSession);
} else {
initInternalStructure(databaseSession);
initCounters(databaseSession);
}
for (EClass eClass : cidToEclass) {
if (eClass != null) {
if (eClass.getEPackage() == Ifc2x3tc1Package.eINSTANCE || eClass.getEPackage() == Ifc4Package.eINSTANCE) {
realClasses.add(eClass.getName());
}
}
}
databaseSession.commit();
} catch (UserException e) {
LOGGER.error("", e);
close();
throw new DatabaseInitException(e.getMessage());
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
close();
throw new DatabaseInitException(e.getMessage());
} catch (DatabaseRestartRequiredException e) {
throw e;
} catch (Exception e) {
throw new DatabaseInitException(e);
} finally {
databaseSession.close();
}
}
Aggregations