Java Code Examples for com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource#getPooledConnection()

The following examples show how to use com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource#getPooledConnection() . 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: ConnectionRegressionTest.java    From r-course with MIT License 6 votes vote down vote up
/**
 * Tests fix for BUG#62452 - NPE thrown in JDBC4MySQLPooledException when statement is closed.
 * 
 * @throws Exception
 */
public void testBug62452() throws Exception {
    PooledConnection con = null;

    MysqlConnectionPoolDataSource pds = new MysqlConnectionPoolDataSource();
    pds.setUrl(dbUrl);
    con = pds.getPooledConnection();
    assertTrue(con instanceof JDBC4MysqlPooledConnection);
    testBug62452WithConnection(con);

    MysqlXADataSource xads = new MysqlXADataSource();
    xads.setUrl(dbUrl);

    xads.setPinGlobalTxToPhysicalConnection(false);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4MysqlXAConnection);
    testBug62452WithConnection(con);

    xads.setPinGlobalTxToPhysicalConnection(true);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4SuspendableXAConnection);
    testBug62452WithConnection(con);

}
 
Example 2
Source File: ConnectionRegressionTest.java    From Komondor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests fix for BUG#62452 - NPE thrown in JDBC4MySQLPooledException when statement is closed.
 * 
 * @throws Exception
 */
public void testBug62452() throws Exception {
    PooledConnection con = null;

    MysqlConnectionPoolDataSource pds = new MysqlConnectionPoolDataSource();
    pds.setUrl(dbUrl);
    con = pds.getPooledConnection();
    assertTrue(con instanceof JDBC4MysqlPooledConnection);
    testBug62452WithConnection(con);

    MysqlXADataSource xads = new MysqlXADataSource();
    xads.setUrl(dbUrl);

    xads.setPinGlobalTxToPhysicalConnection(false);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4MysqlXAConnection);
    testBug62452WithConnection(con);

    xads.setPinGlobalTxToPhysicalConnection(true);
    con = xads.getXAConnection();
    assertTrue(con instanceof JDBC4SuspendableXAConnection);
    testBug62452WithConnection(con);

}
 
Example 3
Source File: DataSourceRegressionTest.java    From r-course with MIT License 5 votes vote down vote up
/**
 * Tests fix for BUG#4808- Calling .close() twice on a PooledConnection
 * causes NPE.
 * 
 * @throws Exception
 *             if an error occurs.
 */
public void testBug4808() throws Exception {
    MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
    ds.setURL(BaseTestCase.dbUrl);
    PooledConnection closeMeTwice = ds.getPooledConnection();
    closeMeTwice.close();
    closeMeTwice.close();

}
 
Example 4
Source File: DataSourceRegressionTest.java    From r-course with MIT License 5 votes vote down vote up
/**
 * Tests fix for BUG#32101 - When using a connection from our ConnectionPoolDataSource,
 * some Connection.prepareStatement() methods would return null instead of
 * a prepared statement.
 * 
 * @throws Exception
 */
public void testBug32101() throws Exception {
    MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
    ds.setURL(BaseTestCase.dbUrl);
    PooledConnection pc = ds.getPooledConnection();
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1"));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", Statement.RETURN_GENERATED_KEYS));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", new int[0]));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", new String[0]));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
    assertNotNull(
            pc.getConnection().prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT));
}
 
Example 5
Source File: DataSourceRegressionTest.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tests fix for BUG#4808- Calling .close() twice on a PooledConnection
 * causes NPE.
 * 
 * @throws Exception
 *             if an error occurs.
 */
public void testBug4808() throws Exception {
    MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
    ds.setURL(BaseTestCase.dbUrl);
    PooledConnection closeMeTwice = ds.getPooledConnection();
    closeMeTwice.close();
    closeMeTwice.close();

}
 
Example 6
Source File: DataSourceRegressionTest.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tests fix for BUG#32101 - When using a connection from our ConnectionPoolDataSource,
 * some Connection.prepareStatement() methods would return null instead of
 * a prepared statement.
 * 
 * @throws Exception
 */
public void testBug32101() throws Exception {
    MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
    ds.setURL(BaseTestCase.dbUrl);
    PooledConnection pc = ds.getPooledConnection();
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1"));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", Statement.RETURN_GENERATED_KEYS));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", new int[0]));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", new String[0]));
    assertNotNull(pc.getConnection().prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY));
    assertNotNull(
            pc.getConnection().prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT));
}
 
Example 7
Source File: DataSourceTest.java    From r-course with MIT License 4 votes vote down vote up
/**
 * Tests whether Connection.changeUser() (and thus pooled connections)
 * restore character set information correctly.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testChangeUserAndCharsets() throws Exception {
    if (versionMeetsMinimum(4, 1)) {
        MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
        ds.setURL(BaseTestCase.dbUrl);
        ds.setCharacterEncoding("utf-8");
        PooledConnection pooledConnection = ds.getPooledConnection();

        Connection connToMySQL = pooledConnection.getConnection();
        this.rs = connToMySQL.createStatement().executeQuery("SELECT @@character_set_results");
        assertTrue(this.rs.next());

        String toCheck = null;

        if (versionMeetsMinimum(4, 1, 15)) {
            if (versionMeetsMinimum(5, 0)) {
                if (versionMeetsMinimum(5, 0, 13)) {
                    toCheck = null;
                } else {
                    toCheck = "NULL";
                }
            } else {
                toCheck = null;
            }
        } else {
            toCheck = "NULL";
        }

        assertEquals(toCheck, this.rs.getString(1));

        this.rs = connToMySQL.createStatement().executeQuery("SHOW SESSION VARIABLES LIKE 'character_set_client'");
        assertTrue(this.rs.next());

        //Cause of utf8mb4
        assertEquals(0, this.rs.getString(2).indexOf("utf8"));

        connToMySQL.close();

        connToMySQL = pooledConnection.getConnection();
        this.rs = connToMySQL.createStatement().executeQuery("SELECT @@character_set_results");
        assertTrue(this.rs.next());
        assertEquals(toCheck, this.rs.getString(1));

        this.rs = connToMySQL.createStatement().executeQuery("SHOW SESSION VARIABLES LIKE 'character_set_client'");
        assertTrue(this.rs.next());

        //Cause of utf8mb4
        assertEquals(0, this.rs.getString(2).indexOf("utf8"));

        pooledConnection.getConnection().close();
    }
}
 
Example 8
Source File: DataSourceTest.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Tests whether Connection.changeUser() (and thus pooled connections)
 * restore character set information correctly.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testChangeUserAndCharsets() throws Exception {
    if (versionMeetsMinimum(4, 1)) {
        MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
        ds.setURL(BaseTestCase.dbUrl);
        ds.setCharacterEncoding("utf-8");
        PooledConnection pooledConnection = ds.getPooledConnection();

        Connection connToMySQL = pooledConnection.getConnection();
        this.rs = connToMySQL.createStatement().executeQuery("SELECT @@character_set_results");
        assertTrue(this.rs.next());

        String toCheck = null;

        if (versionMeetsMinimum(4, 1, 15)) {
            if (versionMeetsMinimum(5, 0)) {
                if (versionMeetsMinimum(5, 0, 13)) {
                    toCheck = null;
                } else {
                    toCheck = "NULL";
                }
            } else {
                toCheck = null;
            }
        } else {
            toCheck = "NULL";
        }

        assertEquals(toCheck, this.rs.getString(1));

        this.rs = connToMySQL.createStatement().executeQuery("SHOW SESSION VARIABLES LIKE 'character_set_client'");
        assertTrue(this.rs.next());

        //Cause of utf8mb4
        assertEquals(0, this.rs.getString(2).indexOf("utf8"));

        connToMySQL.close();

        connToMySQL = pooledConnection.getConnection();
        this.rs = connToMySQL.createStatement().executeQuery("SELECT @@character_set_results");
        assertTrue(this.rs.next());
        assertEquals(toCheck, this.rs.getString(1));

        this.rs = connToMySQL.createStatement().executeQuery("SHOW SESSION VARIABLES LIKE 'character_set_client'");
        assertTrue(this.rs.next());

        //Cause of utf8mb4
        assertEquals(0, this.rs.getString(2).indexOf("utf8"));

        pooledConnection.getConnection().close();
    }
}