Example usage for org.apache.commons.dbcp BasicDataSource close

List of usage examples for org.apache.commons.dbcp BasicDataSource close

Introduction

In this page you can find the example usage for org.apache.commons.dbcp BasicDataSource close.

Prototype

public synchronized void close() throws SQLException 

Source Link

Document

Close and release all connections that are currently stored in the connection pool associated with our data source.

Usage

From source file:org.jumpmind.metl.ui.views.design.EditRdbmsReaderPanel.java

@Override
public boolean closing() {
    if (queryPanel != null) {
        save();//from   w  w w  . j  a  v  a2s . com
        BasicDataSource dataSource = (BasicDataSource) platform.getDataSource();
        try {
            dataSource.close();
        } catch (SQLException e) {
        }
    }
    if (propertySheet != null) {
        propertySheet.setSource(component);
    }
    return true;
}

From source file:org.jumpmind.symmetric.AbstractCommandLauncher.java

protected void testConnection() {
    try {// ww  w  . jav a2 s.  c om
        BasicDataSource ds = ClientSymmetricEngine.createBasicDataSource(propertiesFile);
        Connection conn = ds.getConnection();
        conn.close();
        ds.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.mentawai.db.DBCPConnectionHandler.java

public void destroy() {

    BasicDataSource dataSource = (BasicDataSource) bds;

    try {/*from   ww  w  . j a  v  a2 s  .com*/

        dataSource.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:org.mzd.shap.sql.FunctionalTable.java

/**
 * @param args//  w  w w  .  ja v a 2s.c  om
 */
public static void main(String[] args) throws Exception {

    if (args.length != 2) {
        throw new Exception("Usage: [func_cat.txt] [cog-to-cat.txt]");
    }

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUrl("jdbc:mysql://localhost/Dummy");
    ds.setUsername("test");
    ds.setPassword("xeno12");

    Connection conn = ds.getConnection();

    // Get the Sequence ID list.
    PreparedStatement insert = null;
    LineNumberReader reader = null;

    try {
        reader = new LineNumberReader(new FileReader(args[0]));

        insert = conn.prepareStatement("INSERT INTO CogCategories (code,function,class) values (?,?,?)");

        while (true) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }

            String[] fields = line.split("\t");
            if (fields.length != 3) {
                throw new Exception("Bad number of fields [" + fields.length + "] for line [" + line + "]");
            }

            insert.setString(1, fields[0]);
            insert.setString(2, fields[1]);
            insert.setString(3, fields[2]);
            insert.executeUpdate();
        }

        insert.close();

        reader.close();

        reader = new LineNumberReader(new FileReader(args[1]));

        insert = conn.prepareStatement("INSERT INTO CogFunctions (accession,code) values (?,?)");

        while (true) {
            String line = reader.readLine();
            if (line == null) {
                break;
            }

            String[] fields = line.split("\\s+");
            if (fields.length != 2) {
                throw new Exception("Bad number of fields [" + fields.length + "] for line [" + line + "]");
            }

            for (char code : fields[1].toCharArray()) {
                insert.setString(1, fields[0]);
                insert.setString(2, String.valueOf(code));
                insert.executeUpdate();
            }
        }

        insert.close();

    } finally {
        if (reader != null) {
            reader.close();
        }

        conn.close();
        ds.close();
    }
}

From source file:org.mzd.shap.sql.UpdateFeatureTable.java

/**
 * @param args// www.  ja  v a  2 s. c  o m
 */
public static void main(String[] args) throws SQLException {

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName("com.mysql.jdbc.Driver");
    ds.setUrl("jdbc:mysql://localhost/BBay01a");
    ds.setUsername("test");
    ds.setPassword("xeno12");

    Connection conn = ds.getConnection();

    // Get the Sequence ID list.
    PreparedStatement select = null;
    PreparedStatement update = null;
    ResultSet result = null;

    select = conn.prepareStatement("SELECT DISTINCT SEQUENCE_ID FROM Features");
    result = select.executeQuery();
    List<Integer> sequenceIds = new ArrayList<Integer>();
    result.beforeFirst();
    while (result.next()) {
        sequenceIds.add(result.getInt(1));
    }
    result.close();
    select.close();

    // Get the list of Feature IDs for this Sequence ID
    select = conn.prepareStatement("SELECT FEATURE_ID FROM Features WHERE SEQUENCE_ID=? ORDER BY start");

    // Update the idx column for this feature id
    update = conn.prepareStatement("UPDATE Features SET featureOrder=? where FEATURE_ID=?");

    for (Integer seqId : sequenceIds) {
        select.setInt(1, seqId);
        result = select.executeQuery();

        int n = 0;
        result.beforeFirst();
        while (result.next()) {
            int featId = result.getInt(1);
            update.setInt(1, n++);
            update.setInt(2, featId);
            if (update.executeUpdate() != 1) {
                System.out.println("Failed update [" + update.toString() + "]");
                throw new SQLException();
            }
        }
        result.close();
    }

    update.close();
    select.close();

    conn.close();
    ds.close();
}

From source file:org.paxml.util.DBUtils.java

public static DataSource getPooledDataSource(String driverClass, String username, String password, String url) {
    String key = driverClass + "::" + url;
    BasicDataSource ds = pooledDataSources.get(key);
    if (ds == null) {
        ds = new BasicDataSource();
        ds.setDriverClassName(driverClass);
        ds.setUsername(username);//from ww w.  ja v  a2  s.  c  o  m
        ds.setPassword(password);
        ds.setUrl(url);
        BasicDataSource existingDs = pooledDataSources.putIfAbsent(key, ds);
        if (existingDs != null) {
            try {
                ds.close();
            } catch (SQLException e) {
                // do nothing
            }
            ds = existingDs;
        }

    }

    return ds;
}

From source file:org.sonar.core.persistence.DryRunDatabaseFactory.java

private void close(BasicDataSource destination) throws SQLException {
    destination.close();
}

From source file:org.wsm.database.tools.util.BaseLoadTestConnectionManager.java

public static synchronized void removeConnectionPoolDataSourceFromBucket(String keyName) {
    log.debug("Removing Connection Pool DataSource from the Bucket");
    if (connectionPoolDataSourceBucket != null) {
        if (!EmptyOrNullStringValidator.isEmpty(keyName)) {
            Object dsObj = connectionPoolDataSourceBucket.get(keyName);
            if (dsObj != null) {
                if (dsObj instanceof PerUserPoolDataSource) {
                    log.debug("DataSource type is PerUserPoolDataSource");
                    PerUserPoolDataSource pupdsTemp = (PerUserPoolDataSource) dsObj;
                    pupdsTemp.close();//w  ww.j av  a2s  .co  m
                    log.debug("Closed DataSource");
                }
                if (dsObj instanceof PoolingDataSource) {
                    log.debug("DataSource type is PoolingDataSource");
                    /*                        PoolingDataSource pds = (PoolingDataSource) dsObj;
                            
                                            pds = null;
                    */ log.debug("Set the Object to null");
                }
                if (dsObj instanceof BasicDataSource) {
                    log.debug("DataSource type is PoolingDataSource");
                    BasicDataSource bds = (BasicDataSource) dsObj;
                    try {
                        bds.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    log.debug("Closed DataSource");
                }
            }
        }
    }
    if (!EmptyOrNullStringValidator.isEmpty(keyName)) {
        if (connectionPoolDataSourceBucket != null) {
            connectionPoolDataSourceBucket.remove(keyName);
            log.debug("Removed the DataSource object from the Bucket.");
        }
    }
}

From source file:org.wso2.carbon.identity.oauth.dao.TestOAuthDAOBase.java

protected void closeH2Base(String databaseName) throws Exception {
    BasicDataSource dataSource = dataSourceMap.get(databaseName);
    if (dataSource != null) {
        dataSource.close();
    }/*www . j a  v  a 2 s.  c o  m*/
}

From source file:org.wso2.carbon.user.core.jdbc.JDBCRealmTest.java

public void initRealmStuff(String dbUrl) throws Exception {

    String dbFolder = "target/BasicJDBCDatabaseTest";
    if ((new File(dbFolder)).exists()) {
        deleteDir(new File(dbFolder));
    }/*  w w w  .  j  av  a2s.  co m*/

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(UserCoreTestConstants.DB_DRIVER);
    ds.setUrl(dbUrl);
    DatabaseCreator creator = new DatabaseCreator(ds);
    creator.createRegistryDatabase();

    realm = new DefaultRealm();
    InputStream inStream = this.getClass().getClassLoader().getResource(JDBCRealmTest.JDBC_TEST_USERMGT_XML)
            .openStream();
    RealmConfiguration realmConfig = TestRealmConfigBuilder.buildRealmConfigWithJDBCConnectionUrl(inStream,
            TEST_URL);
    realm.init(realmConfig, ClaimTestUtil.getClaimTestData(), ClaimTestUtil.getProfileTestData(),
            MultitenantConstants.SUPER_TENANT_ID);
    ds.close();
}