Example usage for javax.sql ConnectionPoolDataSource setLogWriter

List of usage examples for javax.sql ConnectionPoolDataSource setLogWriter

Introduction

In this page you can find the example usage for javax.sql ConnectionPoolDataSource setLogWriter.

Prototype

@Override
void setLogWriter(java.io.PrintWriter out) throws SQLException;

Source Link

Usage

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

private static void determineDataSource(DBConnectionProperties props)
        throws ConnectionPoolDataSourceCreationException {
    File f = new File(DbUtilConstants.DBUTIL_HOME);
    File f2 = new File(f, "dataSourceLogs.txt");
    PrintWriter pw = null;/*from w  ww.j  a va  2 s  .  c om*/
    try {
        if (!f.exists()) {
            if (f.canWrite()) {
                f2.createNewFile();
            }
        }
        if (f2.exists())
            pw = new PrintWriter(new FileOutputStream(f2));
    } catch (IOException e) {
        e.printStackTrace();
    }
    ConnectionPoolDataSource cpds = null;

    if (DbUtilConstants.DATABASE_TYPE_ORACLE.equals(props.getDatabaseType())) {
        try {
            OracleConnectionPoolDataSource tempOcpds = new OracleConnectionPoolDataSource();
            tempOcpds.setUser(userName);
            tempOcpds.setPassword(password);
            tempOcpds.setURL(connUrl);
            cpds = tempOcpds;
        } catch (SQLException e) {
            e.printStackTrace();
        }
    } else if (DbUtilConstants.DATABASE_TYPE_MYSQL.equals(props.getDatabaseType())) {
        MysqlConnectionPoolDataSource tempCpds = new MysqlConnectionPoolDataSource();
        tempCpds.setUser(userName);
        tempCpds.setPassword(password);
        tempCpds.setURL(connUrl);
        cpds = tempCpds;
    }
    if (pw != null) {
        try {
            if (cpds != null) {
                cpds.setLogWriter(pw);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    if (getPupds() != null) {
        getPupds().close();
    }
    setPupds(null);
    if (getPupds() == null)
        setPupds(new PerUserPoolDataSource());
    if (cpds != null)
        getPupds().setConnectionPoolDataSource(cpds);
    else
        throw new ConnectionPoolDataSourceCreationException("Unable to create Data Source");

}