All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.crosstreelabs.testing.DataSourceResource Maven / Gradle / Ivy

There is a newer version: 0.5.0
Show newest version
package com.crosstreelabs.testing;

import javax.sql.DataSource;
import org.hsqldb.jdbc.JDBCDataSource;
import org.junit.rules.ExternalResource;

/**
 * 
 */
public class DataSourceResource extends ExternalResource {
    public static DataSource datasource;

    //~ ExternalResource implementation ~~~~~~~~~~~~~~~~~~~~
    @Override
    protected void before() throws Throwable {
        if(datasource == null) {
            datasource = new JDBCDataSource();
            ((JDBCDataSource)datasource).setUrl("jdbc:hsqldb:mem:"+getSchema());
            ((JDBCDataSource)datasource).setUser("SA");
        }
    }

    @Override
    protected void after() {
        datasource = null;
    }
    
    //~ Datasource necessities ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    public String getSchema() {
        return "PUBLIC";
    }
    public DataSource getDataSource() {
        return datasource;
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy