Example usage for org.apache.commons.dbcp2 BasicDataSource setDefaultTransactionIsolation

List of usage examples for org.apache.commons.dbcp2 BasicDataSource setDefaultTransactionIsolation

Introduction

In this page you can find the example usage for org.apache.commons.dbcp2 BasicDataSource setDefaultTransactionIsolation.

Prototype

public void setDefaultTransactionIsolation(int defaultTransactionIsolation) 

Source Link

Document

Sets the default transaction isolation state for returned connections.

Note: this method currently has no effect once the pool has been initialized.

Usage

From source file:ws.rocket.sqlstore.test.SqlStoreTest.java

@BeforeClass
public void setUp() throws SQLException, IOException {
    ResourceBundle bundle = ResourceBundle.getBundle("ws.rocket.sqlstore.test.test");

    File dbPath = new File(bundle.getString("jdbc.dbPath"));
    if (!dbPath.exists()) {
        dbPath.mkdirs();//from w ww. j a v a2s .c om
    }

    System.setProperty("derby.system.home", dbPath.getCanonicalPath());

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(bundle.getString("jdbc.driver"));
    ds.setUrl(bundle.getString("jdbc.url"));
    ds.setDefaultReadOnly(true);
    ds.setDefaultAutoCommit(false);
    ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    ds.setInitialSize(Integer.parseInt(bundle.getString("jdbc.initialConnections")));

    this.dataSource = ds;

    boolean tableExists;
    try (Connection c = this.dataSource.getConnection()) {
        DatabaseMetaData meta = c.getMetaData();
        try (ResultSet rs = meta.getTables(null, "SQLSTORE", "PERSON", new String[] { "TABLE" })) {
            tableExists = rs.next();
        }
    }

    if (tableExists) {
        dropTables();
    }
}