Java Code Examples for org.javalite.activejdbc.Base#close()

The following examples show how to use org.javalite.activejdbc.Base#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckMojo.java    From javalite with Apache License 2.0 6 votes vote down vote up
public void executeMojo() throws MojoExecutionException {
    getLog().info("Checking " + getUrl() + " using migrations from " + getMigrationsPath());

    List<Migration> pendingMigrations;
    try {
        openConnection();
        MigrationManager manager = new MigrationManager(getMigrationsPath());
        pendingMigrations = manager.getPendingMigrations();
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to check " + getUrl(), e);
    }finally {
        Base.close();
    }

    if (pendingMigrations.isEmpty()) return;

    getLog().warn("Pending migration(s): ");
    for (Migration migration : pendingMigrations)
        getLog().warn("Migration: " + migration.getName());

    getLog().warn("Run db-migrator:migrate to apply pending migrations.");
    throw new MojoExecutionException("Pending migration(s) exist, migrate your db and try again.");
}
 
Example 2
Source File: ValidateMojo.java    From javalite with Apache License 2.0 6 votes vote down vote up
public void executeMojo() throws MojoExecutionException {
    getLog().info("Validating " + getUrl() + " using migrations from " + getMigrationsPath());
    try {
        openConnection();
        MigrationManager manager = new MigrationManager(getMigrationsPath());
        List<Migration> pendingMigrations = manager.getPendingMigrations();

        getLog().info("Database: " + getUrl());
        getLog().info("Up-to-date: " + pendingMigrations.isEmpty());
        if (!pendingMigrations.isEmpty()) {
            getLog().info("Pending Migrations: ");
            for (Migration migration : pendingMigrations) {
                getLog().info(migration.getName());
            }
        }else{
            getLog().info("No pending migrations found");
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Failed to validate " + getUrl(), e);
    }finally {
        Base.close();
    }
}
 
Example 3
Source File: PubmedDatabaseAE.java    From bluima with Apache License 2.0 5 votes vote down vote up
@Override
public void destroy() {
    try {
        Base.close();
    } catch (Exception e) {
        LOG.warn("could not close conn", e);
    }
}
 
Example 4
Source File: PubmedArticleEntity.java    From bluima with Apache License 2.0 5 votes vote down vote up
public static void reConnect(String[] db_connection) {
    try {
        Base.close();
    } catch (Exception e) {// nope
    }
    connect(db_connection);
}
 
Example 5
Source File: ActiveJDBCApp.java    From tutorials with MIT License 5 votes vote down vote up
public static void main( String[] args )
{
    try {
        Base.open();
        ActiveJDBCApp app = new ActiveJDBCApp();
        app.create();
        app.update();
        app.delete();
        app.deleteCascade();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        Base.close();
    }
}
 
Example 6
Source File: DefaultDBReset.java    From javalite with Apache License 2.0 5 votes vote down vote up
public static void after() {

        try {
            Base.connection().rollback();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        Base.close();
    }
 
Example 7
Source File: MigrateMojo.java    From javalite with Apache License 2.0 5 votes vote down vote up
public void executeMojo() throws MojoExecutionException {
    getLog().info("Migrating " + getUrl() + " using migrations at " + getMigrationsPath());
    try {
        openConnection();
        new MigrationManager(getMigrationsPath()).migrate(getLog(), getEncoding());
    } catch(SQLException e){
        throw new MojoExecutionException("Failed to migrate database " + getUrl(), e);
    } finally {
        Base.close();
    }
}
 
Example 8
Source File: DropMojo.java    From javalite with Apache License 2.0 5 votes vote down vote up
public void executeMojo() throws MojoExecutionException {
    try {
        String dropSql = blank(getDropSql()) ? "drop database %s" : getDropSql();
        openConnection(true);
        exec(format(dropSql, DbUtils.extractDatabaseName(getUrl())));
        getLog().info("Dropped database " + getUrl());
    } finally {
        Base.close();
    }
}
 
Example 9
Source File: MySQLMigrationSpec.java    From javalite with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {

    Base.open(driver(), url(), user(), password());
    try {
        exec("drop database mysql_migration_test");
    } catch (Exception e) {/*ignore*/}
    exec("create database mysql_migration_test");
    Base.close();
    Base.open(driver(), "jdbc:mysql://localhost/mysql_migration_test", user(), password());
    migrationManager = new MigrationManager("src/test/resources/test_migrations/mysql/");
}
 
Example 10
Source File: MySQLMigrationSpec.java    From javalite with Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
    try {
        exec("drop database mysql_migration_test");
    } catch (Exception e) {/*ignore*/}
    Base.close();
}
 
Example 11
Source File: Tools.java    From flowchat with GNU General Public License v3.0 4 votes vote down vote up
public static final void dbClose() {
    Base.close();
}
 
Example 12
Source File: MojoIntegrationSpec.java    From javalite with Apache License 2.0 4 votes vote down vote up
private void run(String dir, String val) throws IOException, InterruptedException {
    // drop
    execute(dir, "db-migrator:drop");

    // create database
    String output = execute(dir, "db-migrator:create");
    the(output).shouldContain("Created database jdbc:mysql://localhost/test_project");
    the(output).shouldContain("BUILD SUCCESS");

    // migrate
    output = execute(dir, "db-migrator:migrate");
    the(output).shouldContain("BUILD SUCCESS");

    if(val != null){
        the(output).shouldContain(val);
    }

    Base.open(driver(), "jdbc:mysql://localhost/test_project", user(), password());
    the(countRows("books")).shouldBeEqual(9);
    the(countRows("authors")).shouldBeEqual(2);
    Base.close();

    // drop, create and validate
    output = execute(dir, "db-migrator:drop");
    the(output).shouldContain("Dropped database jdbc:mysql://localhost/test_project");
    the(output).shouldContain("BUILD SUCCESS");

    output = execute(dir, "db-migrator:create");
    the(output).shouldContain("Created database jdbc:mysql://localhost/test_project");
    the(output).shouldContain("BUILD SUCCESS");

    output = execute(dir, "db-migrator:validate");
    the(output).shouldContain("BUILD SUCCESS");

    // now migrate and validate again
    output = execute(dir, "db-migrator:migrate");
    the(output).shouldContain("BUILD SUCCESS");

    output = execute(dir, "db-migrator:validate");
    the(output).shouldContain("No pending migrations found");
    the(output).shouldContain("BUILD SUCCESS");

    // creation of new migration
    execute(dir, "db-migrator:new", "-Dname=add_people");
    File migrationsDir = new File(dir, "src/migrations");
    String migrationFile = findMigrationFile(migrationsDir, "add_people");
    assertNotNull(migrationFile);
    assertTrue(new File(migrationsDir, migrationFile).delete());
}
 
Example 13
Source File: H2MigrationSpec.java    From javalite with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown(){
    Base.close();
}
 
Example 14
Source File: SimpleVersionStrategySpec.java    From javalite with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() {
    Base.close();
}
 
Example 15
Source File: HSQLMigrationSpec.java    From javalite with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
    Base.close();
}