Search in sources :

Example 1 with SqlDatabase

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);
}
Also used : SqlDatabase(org.molgenis.emx2.sql.SqlDatabase) SqlDatabase(org.molgenis.emx2.sql.SqlDatabase)

Example 2 with SqlDatabase

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());
        }
    };
}
Also used : HttpSessionListener(javax.servlet.http.HttpSessionListener) HttpSessionEvent(javax.servlet.http.HttpSessionEvent) Database(org.molgenis.emx2.Database) SqlDatabase(org.molgenis.emx2.sql.SqlDatabase) SqlDatabase(org.molgenis.emx2.sql.SqlDatabase)

Example 3 with SqlDatabase

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);
}
Also used : Database(org.molgenis.emx2.Database) BeforeClass(org.junit.BeforeClass)

Example 4 with SqlDatabase

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);
}
Also used : SqlDatabase(org.molgenis.emx2.sql.SqlDatabase)

Example 5 with SqlDatabase

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());
    }
}
Also used : MolgenisException(org.molgenis.emx2.MolgenisException) IOException(java.io.IOException)

Aggregations

SqlDatabase (org.molgenis.emx2.sql.SqlDatabase)3 Database (org.molgenis.emx2.Database)2 IOException (java.io.IOException)1 HttpSessionEvent (javax.servlet.http.HttpSessionEvent)1 HttpSessionListener (javax.servlet.http.HttpSessionListener)1 BeforeClass (org.junit.BeforeClass)1 MolgenisException (org.molgenis.emx2.MolgenisException)1