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

The following examples show how to use org.javalite.activejdbc.Base#open() . 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: PubmedDatabaseAE.java    From bluima with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(UimaContext context)
        throws ResourceInitializationException {
    super.initialize(context);
    Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://" + db_connection[0]
            + "/" + db_connection[1] + "", db_connection[2],
            db_connection[3]);
    processed = 0;
    inserted = 0;
}
 
Example 2
Source File: ProductUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
public void givenSavedProduct_WhenFindFirst_ThenSavedProductIsReturned() {
    //Open DB connection
    Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/dbname", "user", "password");

    //Create a product and save it
    Product toSaveProduct = new Product();
    toSaveProduct.set("name", "Bread");
    toSaveProduct.saveIt();

    //Find product
    Product savedProduct = Product.findFirst("name = ?", "Bread");

    Assert.assertEquals(toSaveProduct.get("name"), savedProduct.get("name"));
}
 
Example 3
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 4
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 5
Source File: Tools.java    From flowchat with GNU General Public License v3.0 4 votes vote down vote up
public static final void dbInit() {
    Base.open(hikariDataSource); // get connection from pool
}
 
Example 6
Source File: PubmedArticleEntity.java    From bluima with Apache License 2.0 4 votes vote down vote up
public static void connect(String[] db_connection) {
    Base.open("com.mysql.jdbc.Driver", "jdbc:mysql://" + db_connection[0]
            + "/" + db_connection[1] + "", db_connection[2],
            db_connection[3]);
}
 
Example 7
Source File: Main.java    From javalite with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args){
    DBConfiguration.loadConfiguration("/database.properties");
    Base.open();
}
 
Example 8
Source File: DefaultDBReset.java    From javalite with Apache License 2.0 4 votes vote down vote up
protected static void before() throws SQLException {
    Base.open(driver(), url(), user(), password());
    tryGenSchema();
    Base.connection().setAutoCommit(false);
}
 
Example 9
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 10
Source File: AbstractDbMigrationMojo.java    From javalite with Apache License 2.0 4 votes vote down vote up
/**
 * @param root open connection to root URL
 */
protected void openConnection(boolean root){
    String url = root? DbUtils.extractServerUrl(getUrl()): getUrl();
    Base.open(getDriver(), url, getUsername(), getPassword());
}
 
Example 11
Source File: H2MigrationSpec.java    From javalite with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
    Base.open("org.h2.Driver", "jdbc:h2:mem:h2-migration-test;DB_CLOSE_DELAY=-1", "sa", "");
    migrationManager = new MigrationManager("src/test/resources/test_migrations/h2/");
}
 
Example 12
Source File: SimpleVersionStrategySpec.java    From javalite with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
    strategy = new VersionStrategy();
    Base.open("org.h2.Driver", "jdbc:h2:mem:h2-migration-test;DB_CLOSE_DELAY=-1", "sa", "");
    try {exec("drop table " + VersionStrategy.VERSION_TABLE);} catch (Exception e) {/* ignore*/}
}
 
Example 13
Source File: HSQLMigrationSpec.java    From javalite with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
    Base.open("org.hsqldb.jdbcDriver", "jdbc:hsqldb:file:./target/tmp/hsql-migration-test", "sa", "");
    migrationManager = new MigrationManager("src/test/resources/test_migrations/hsql/");
}