use of org.bimserver.database.actions.CreateBaseProjectDatabaseAction 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