Search in sources :

Example 1 with ScriptRunner

use of com.linkedin.thirdeye.datalayer.ScriptRunner in project pinot by linkedin.

the class AbstractManagerTestBase method initializeDs.

private void initializeDs(PersistenceConfig configuration) throws Exception {
    ds = new DataSource();
    dbUrlId = configuration.getDatabaseConfiguration().getUrl() + System.currentTimeMillis() + "" + Math.random();
    ds.setUrl(dbUrlId);
    System.out.println("Creating db with connection url : " + ds.getUrl());
    ds.setPassword(configuration.getDatabaseConfiguration().getPassword());
    ds.setUsername(configuration.getDatabaseConfiguration().getUser());
    ds.setDriverClassName(configuration.getDatabaseConfiguration().getProperties().get("hibernate.connection.driver_class"));
    // pool size configurations
    ds.setMaxActive(200);
    ds.setMinIdle(10);
    ds.setInitialSize(10);
    // when returning connection to pool
    ds.setTestOnReturn(true);
    ds.setRollbackOnReturn(true);
    // Timeout before an abandoned(in use) connection can be removed.
    ds.setRemoveAbandonedTimeout(600_000);
    ds.setRemoveAbandoned(true);
    Connection conn = ds.getConnection();
    // create schema
    URL createSchemaUrl = getClass().getResource("/schema/create-schema.sql");
    ScriptRunner scriptRunner = new ScriptRunner(conn, false, false);
    scriptRunner.setDelimiter(";", true);
    scriptRunner.runScript(new FileReader(createSchemaUrl.getFile()));
}
Also used : Connection(java.sql.Connection) FileReader(java.io.FileReader) ScriptRunner(com.linkedin.thirdeye.datalayer.ScriptRunner) URL(java.net.URL) DataSource(org.apache.tomcat.jdbc.pool.DataSource)

Example 2 with ScriptRunner

use of com.linkedin.thirdeye.datalayer.ScriptRunner in project pinot by linkedin.

the class AbstractManagerTestBase method cleanUpJDBC.

private void cleanUpJDBC() throws Exception {
    System.out.println("Cleaning database: start");
    try (Connection conn = ds.getConnection()) {
        URL deleteSchemaUrl = getClass().getResource("/schema/drop-tables.sql");
        ScriptRunner scriptRunner = new ScriptRunner(conn, false, false);
        scriptRunner.runScript(new FileReader(deleteSchemaUrl.getFile()));
    }
    new File(dbUrlId).delete();
    System.out.println("Cleaning database: done!");
}
Also used : Connection(java.sql.Connection) FileReader(java.io.FileReader) ScriptRunner(com.linkedin.thirdeye.datalayer.ScriptRunner) File(java.io.File) URL(java.net.URL)

Example 3 with ScriptRunner

use of com.linkedin.thirdeye.datalayer.ScriptRunner in project pinot by linkedin.

the class TestDBResources method cleanUpJDBC.

private void cleanUpJDBC() throws Exception {
    System.out.println("Cleaning database: start");
    try (Connection conn = ds.getConnection()) {
        URL deleteSchemaUrl = getClass().getResource("/schema/drop-tables.sql");
        ScriptRunner scriptRunner = new ScriptRunner(conn, false, false);
        scriptRunner.runScript(new FileReader(deleteSchemaUrl.getFile()));
    }
    System.out.println("Cleaning database: done!");
}
Also used : Connection(java.sql.Connection) FileReader(java.io.FileReader) ScriptRunner(com.linkedin.thirdeye.datalayer.ScriptRunner) URL(java.net.URL)

Example 4 with ScriptRunner

use of com.linkedin.thirdeye.datalayer.ScriptRunner in project pinot by linkedin.

the class TestDBResources method initDB.

private void initDB() throws Exception {
    try (Connection conn = ds.getConnection()) {
        // create schema
        URL createSchemaUrl = getClass().getResource("/schema/create-schema.sql");
        ScriptRunner scriptRunner = new ScriptRunner(conn, false, false);
        scriptRunner.setDelimiter(";", true);
        scriptRunner.runScript(new FileReader(createSchemaUrl.getFile()));
    }
}
Also used : Connection(java.sql.Connection) FileReader(java.io.FileReader) ScriptRunner(com.linkedin.thirdeye.datalayer.ScriptRunner) URL(java.net.URL)

Aggregations

ScriptRunner (com.linkedin.thirdeye.datalayer.ScriptRunner)4 FileReader (java.io.FileReader)4 URL (java.net.URL)4 Connection (java.sql.Connection)4 File (java.io.File)1 DataSource (org.apache.tomcat.jdbc.pool.DataSource)1