use of org.molgenis.emx2.sql.SqlDatabase in project molgenis-emx2 by molgenis.
the class RunMolgenisEmx2 method main.
public static void main(String[] args) {
logger.info("Starting MOLGENIS EMX2 Software Version=" + Version.getVersion());
Integer port = (Integer) EnvironmentProperty.getParameter(Constants.MOLGENIS_HTTP_PORT, "8080", INT);
logger.info("with " + org.molgenis.emx2.Constants.MOLGENIS_HTTP_PORT + "=" + port + " (change either via java properties or via ENV variables)");
// setup database
Database db = new SqlDatabase(true);
if (db.getSchema("pet store") == null) {
Schema schema = db.createSchema("pet store");
PetStoreExample.create(schema.getMetadata());
PetStoreExample.populate(schema);
}
// start
MolgenisWebservice.start(port);
}
use of org.molgenis.emx2.sql.SqlDatabase in project molgenis-emx2 by molgenis.
the class MolgenisSessionManager method createSessionListener.
/**
* takes care of creating and destroying session attributes when Jetty creates/destroys sessions
*/
private EventListener createSessionListener() {
MolgenisSessionManager _this = this;
return new HttpSessionListener() {
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
logger.info("Initializing session");
// create private database wrapper to session
Database database = new SqlDatabase(false);
// set default use to "anonymous"
database.setActiveUser("anonymous");
// create session and add to sessions lists so we can also access all active
// sessions
MolgenisSession molgenisSession = new MolgenisSession(database);
sessions.put(httpSessionEvent.getSession().getId(), molgenisSession);
logger.info("session created: " + httpSessionEvent.getSession().getId());
// create listener
database.setListener(new MolgenisSessionManagerDatabaseListener(_this, molgenisSession));
}
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
// remove from session pool
sessions.remove(httpSessionEvent.getSession().getId());
logger.info("session destroyed: " + httpSessionEvent.getSession().getId());
}
};
}
use of org.molgenis.emx2.sql.SqlDatabase in project molgenis-emx2 by molgenis.
the class InitTestDatabaseAndRunNonParallelTests method createDatabase.
@BeforeClass
public static void createDatabase() {
// we want this run only once and NOT parallel for total test suite
// AND we want run all other tests in parallel
// so tests are in molgenis-emx2-sql-it ('integration test')
// and 'init' only happence once, here
Database db = new SqlDatabase(true);
assertTrue(db.getDatabaseVersion() > 0);
}
use of org.molgenis.emx2.sql.SqlDatabase in project molgenis-emx2 by molgenis.
the class AToolToCleanDatabase method deleteAll.
public static void deleteAll() {
SqlDatabase db = new SqlDatabase(true);
jooq = db.getJooq();
jooq.dropSchemaIfExists("MOLGENIS").cascade().execute();
deleteAllForeignKeyConstraints();
deleteAllSchemas();
deleteAllRoles();
db = new SqlDatabase(true);
}
use of org.molgenis.emx2.sql.SqlDatabase in project molgenis-emx2 by molgenis.
the class Migrations method executeMigrationFile.
static void executeMigrationFile(Database db, String sqlFile, String message) {
try {
String sql = new String(Migrations.class.getResourceAsStream(sqlFile).readAllBytes());
((SqlDatabase) db).getJooq().execute(sql);
logger.debug(message + "(file = " + sqlFile);
} catch (IOException e) {
throw new MolgenisException(e.getMessage());
}
}
Aggregations