Search in sources :

Example 26 with JdbcConnection

use of com.mysql.cj.jdbc.JdbcConnection in project JavaSegundasQuintas by ecteruel.

the class MetaDataRegressionTest method testBug69290.

/**
 * Tests fix for BUG#69290 - JDBC Table type "SYSTEM TABLE" is used inconsistently.
 *
 * Tests DatabaseMetaData.getTableTypes() and DatabaseMetaData.getTables() against schemas: mysql, information_schema, performance_schema, test.
 *
 * @throws Exception
 */
@Test
public void testBug69290() throws Exception {
    String[] testStepDescription = new String[] { "MySQL MetaData", "I__S MetaData" };
    Properties props = new Properties();
    props.setProperty(PropertyKey.useSSL.getKeyName(), "false");
    props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
    props.setProperty(PropertyKey.useInformationSchema.getKeyName(), "true");
    Connection connUseIS = getConnectionWithProps(props);
    props.setProperty(PropertyKey.nullDatabaseMeansCurrent.getKeyName(), "false");
    Connection connUseISAndNullAll = getConnectionWithProps(props);
    props.remove(PropertyKey.useInformationSchema.getKeyName());
    Connection connNullAll = getConnectionWithProps(props);
    boolean dbMapsToSchema = ((JdbcConnection) this.conn).getPropertySet().<DatabaseTerm>getEnumProperty(PropertyKey.databaseTerm).getValue() == DatabaseTerm.SCHEMA;
    final String testDb = dbMapsToSchema ? this.conn.getSchema() : this.conn.getCatalog();
    Connection[] testConnections = new Connection[] { this.conn, connUseIS };
    // check table types returned in getTableTypes()
    final List<String> tableTypes = Arrays.asList(new String[] { "LOCAL TEMPORARY", "SYSTEM TABLE", "SYSTEM VIEW", "TABLE", "VIEW" });
    for (int i = 0; i < testStepDescription.length; i++) {
        DatabaseMetaData testDbMetaData = testConnections[i].getMetaData();
        this.rs = testDbMetaData.getTableTypes();
        int idx = 0;
        while (this.rs.next()) {
            String message = testStepDescription[i] + ", table type '" + this.rs.getString("TABLE_TYPE") + "'";
            assertFalse(idx >= tableTypes.size(), message + " not expected.");
            assertEquals(tableTypes.get(idx++), this.rs.getString("TABLE_TYPE"), message);
        }
    }
    // create table and view in '(test)' schema
    createTable("testBug69290_table", "(c1 INT)");
    createView("testBug69290_view", "AS SELECT * FROM testBug69290_table WHERE c1 > 1");
    int[][] countResults = new int[][] { { 0, 0, 0 }, { 0, 0, 0 } };
    // check table types returned in getTables() for each catalog/schema
    for (int i = 0; i < testStepDescription.length; i++) {
        DatabaseMetaData testDbMetaData = testConnections[i].getMetaData();
        // check catalog/schema 'information_schema'
        this.rs = dbMapsToSchema ? testDbMetaData.getTables(null, "information_schema", "%", null) : testDbMetaData.getTables("information_schema", null, "%", null);
        while (this.rs.next()) {
            assertEquals("SYSTEM VIEW", this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", 'information_schema' catalog/schema, wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
            countResults[i][0]++;
        }
        // check catalog/schema 'mysql'
        this.rs = dbMapsToSchema ? testDbMetaData.getTables(null, "mysql", "%", null) : testDbMetaData.getTables("mysql", null, "%", null);
        while (this.rs.next()) {
            assertEquals("SYSTEM TABLE", this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", 'mysql' catalog/schema, wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
            countResults[i][1]++;
        }
        // check catalog/schema 'performance_schema'
        this.rs = dbMapsToSchema ? testDbMetaData.getTables(null, "performance_schema", "%", null) : testDbMetaData.getTables("performance_schema", null, "%", null);
        while (this.rs.next()) {
            assertEquals("SYSTEM TABLE", this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", 'performance_schema' catalog/schema, wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
            countResults[i][2]++;
        }
        // check catalog/schema '(test)'
        this.rs = dbMapsToSchema ? testDbMetaData.getTables(null, testDb, "testBug69290_%", null) : testDbMetaData.getTables(testDb, null, "testBug69290_%", null);
        assertTrue(this.rs.next(), testStepDescription[i] + ", '" + testDb + "' catalog/schema, expected row from getTables().");
        assertEquals("TABLE", this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", '" + testDb + "' catalog/schema, wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
        assertTrue(this.rs.next(), testStepDescription[i] + ", '" + testDb + "' catalog/schema, expected row from getTables().");
        assertEquals("VIEW", this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", '" + testDb + "' catalog/schema, wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
    }
    // compare results count
    assertTrue(countResults[0][0] == countResults[1][0], "The number of results from getTables() MySQl(" + countResults[0][0] + ") and I__S(" + countResults[1][0] + ") should be the same for 'information_schema' catalog/schema.");
    assertTrue(countResults[0][1] == countResults[1][1], "The number of results from getTables() MySQl(" + countResults[0][1] + ") and I__S(" + countResults[1][1] + ") should be the same for 'mysql' catalog/schema.");
    assertTrue(countResults[0][2] == countResults[1][2], "The number of results from getTables() MySQl(" + countResults[0][2] + ") and I__S(" + countResults[1][2] + ") should be the same for 'performance_schema' catalog/schema.");
    testConnections = new Connection[] { connNullAll, connUseISAndNullAll };
    countResults = new int[][] { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 } };
    // check table types returned in getTables() for all catalogs/schemas and filter by table type (tested with property nullCatalogMeansCurrent=false)
    for (int i = 0; i < testStepDescription.length; i++) {
        DatabaseMetaData testDbMetaData = testConnections[i].getMetaData();
        int j = 0;
        // check table type filters
        for (String tableType : tableTypes) {
            this.rs = testDbMetaData.getTables(null, null, "%", new String[] { tableType });
            while (this.rs.next()) {
                assertEquals(tableType, this.rs.getString("TABLE_TYPE"), testStepDescription[i] + ", table type filter '" + tableType + "', wrong table type for '" + this.rs.getString("TABLE_NAME") + "'.");
                countResults[i][j]++;
            }
            j++;
        }
    }
    // compare results count
    int i = 0;
    for (String tableType : tableTypes) {
        assertTrue(countResults[0][i] == countResults[1][i], "The number of results from getTables() MySQl(" + countResults[0][i] + ") and I__S(" + countResults[1][i] + ") should be the same for '" + tableType + "' table type filter.");
        i++;
    }
}
Also used : DatabaseTerm(com.mysql.cj.conf.PropertyDefinitions.DatabaseTerm) Connection(java.sql.Connection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) MysqlConnection(com.mysql.cj.MysqlConnection) Properties(java.util.Properties) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.jupiter.api.Test)

Example 27 with JdbcConnection

use of com.mysql.cj.jdbc.JdbcConnection in project JavaSegundasQuintas by ecteruel.

the class MetaDataRegressionTest method checkMetaDataInfoForBug17248345.

private void checkMetaDataInfoForBug17248345(Connection testConn) throws Exception {
    DatabaseMetaData testDbMetaData = testConn.getMetaData();
    ResultSet rsMD;
    boolean useInfoSchema = ((JdbcConnection) testConn).getPropertySet().getBooleanProperty(PropertyKey.useInformationSchema).getValue();
    boolean getProcRetFunc = ((JdbcConnection) testConn).getPropertySet().getBooleanProperty(PropertyKey.getProceduresReturnsFunctions).getValue();
    String stepDescription = "Prop. useInfoSchema(" + (useInfoSchema ? 1 : 0) + ") + getProcRetFunc(" + (getProcRetFunc ? 1 : 0) + "):";
    String sd;
    // getFunctions() must return 1 record.
    sd = stepDescription + " getFunctions() ";
    rsMD = testDbMetaData.getFunctions(null, null, "testBug17248345");
    assertTrue(rsMD.next(), sd + "one row expected.");
    assertEquals("testBug17248345", rsMD.getString("FUNCTION_NAME"), sd + " -> FUNCTION_NAME");
    assertFalse(rsMD.next(), sd + "no more rows expected.");
    // getFunctionColumns() must return 2 records (func return + func param).
    sd = stepDescription + " getFunctionColumns() ";
    rsMD = testDbMetaData.getFunctionColumns(null, null, "testBug17248345", "%");
    assertTrue(rsMD.next(), sd + "1st of 2 rows expected.");
    assertEquals("testBug17248345", rsMD.getString("FUNCTION_NAME"), sd + " -> FUNCTION_NAME");
    assertEquals("", rsMD.getString("COLUMN_NAME"), sd + " -> COLUMN_NAME");
    assertTrue(rsMD.next(), sd + "2nd of 2 rows expected.");
    assertEquals("testBug17248345", rsMD.getString("FUNCTION_NAME"), sd + " -> FUNCTION_NAME");
    assertEquals("funccol", rsMD.getString("COLUMN_NAME"), sd + " -> COLUMN_NAME");
    assertFalse(rsMD.next(), sd + "no more rows expected.");
    // getProcedures() must return 1 or 2 records, depending on if getProceduresReturnsFunctions is false or true
    // respectively. When exists a procedure and a function with same name, function is returned first.
    sd = stepDescription + " getProcedures() ";
    rsMD = testDbMetaData.getProcedures(null, null, "testBug17248345");
    if (getProcRetFunc) {
        assertTrue(rsMD.next(), sd + "1st of 2 rows expected.");
        assertEquals("testBug17248345", rsMD.getString("PROCEDURE_NAME"), sd + " -> PROCEDURE_NAME");
        assertTrue(rsMD.next(), sd + "2nd of 2 rows expected.");
    } else {
        assertTrue(rsMD.next(), sd + "one row expected.");
    }
    assertEquals("testBug17248345", rsMD.getString("PROCEDURE_NAME"), sd + " -> PROCEDURE_NAME");
    assertFalse(rsMD.next(), sd + "no more rows expected.");
    // getProcedureColumns() must return 1 or 3 records, depending on if getProceduresReturnsFunctions is false or
    // true respectively. When exists a procedure and a function with same name, function is returned first.
    sd = stepDescription + " getProcedureColumns() ";
    rsMD = testDbMetaData.getProcedureColumns(null, null, "testBug17248345", "%");
    if (getProcRetFunc) {
        assertTrue(rsMD.next(), sd + "1st of 3 rows expected.");
        assertEquals("testBug17248345", rsMD.getString("PROCEDURE_NAME"), sd + " -> PROCEDURE_NAME");
        assertEquals("", rsMD.getString("COLUMN_NAME"), sd + " -> COLUMN_NAME");
        assertTrue(rsMD.next(), sd + "2nd of 3 rows expected.");
        assertEquals("testBug17248345", rsMD.getString("PROCEDURE_NAME"), sd + " -> PROCEDURE_NAME");
        assertEquals("funccol", rsMD.getString("COLUMN_NAME"), sd + " -> COLUMN_NAME");
        assertTrue(rsMD.next(), sd + "3rd of 3 rows expected.");
    } else {
        assertTrue(rsMD.next(), sd + "one row expected.");
    }
    assertEquals("testBug17248345", rsMD.getString("PROCEDURE_NAME"), sd + " -> PROCEDURE_NAME");
    assertEquals("proccol", rsMD.getString("COLUMN_NAME"), sd + " -> COLUMN_NAME");
    assertFalse(rsMD.next(), sd + "no more rows expected.");
}
Also used : ResultSet(java.sql.ResultSet) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 28 with JdbcConnection

use of com.mysql.cj.jdbc.JdbcConnection in project JavaSegundasQuintas by ecteruel.

the class MetaDataRegressionTest method checkGetProcedureColumnsForBug69298.

private void checkGetProcedureColumnsForBug69298(String stepDescription, Connection testConn) throws Exception {
    DatabaseMetaData testDbMetaData = testConn.getMetaData();
    boolean dbMapsToSchema = ((JdbcConnection) testConn).getPropertySet().<DatabaseTerm>getEnumProperty(PropertyKey.databaseTerm).getValue() == DatabaseTerm.SCHEMA;
    ResultSet procColsMD = testDbMetaData.getProcedureColumns(null, null, "testBug69298_%", "%");
    String sd = stepDescription + " getProcedureColumns() ";
    boolean isGetProceduresReturnsFunctions = ((JdbcConnection) testConn).getPropertySet().getBooleanProperty(PropertyKey.getProceduresReturnsFunctions).getValue();
    if (isGetProceduresReturnsFunctions) {
        assertTrue(procColsMD.next(), sd + "1st of 3 rows expected.");
        // function column: testBug69298_func return
        assertEquals(dbMapsToSchema ? "def" : testConn.getCatalog(), procColsMD.getString("PROCEDURE_CAT"), sd + "-> PROCEDURE_CAT");
        assertEquals(dbMapsToSchema ? testConn.getSchema() : null, procColsMD.getString("PROCEDURE_SCHEM"), sd + "-> PROCEDURE_SCHEM");
        assertEquals("testBug69298_func", procColsMD.getString("PROCEDURE_NAME"), sd + "-> PROCEDURE_NAME");
        assertEquals("", procColsMD.getString("COLUMN_NAME"), sd + "-> COLUMN_NAME");
        assertEquals(DatabaseMetaData.procedureColumnReturn, procColsMD.getShort("COLUMN_TYPE"), sd + "-> COLUMN_TYPE");
        assertEquals(Types.INTEGER, procColsMD.getInt("DATA_TYPE"), sd + "-> DATA_TYPE");
        assertEquals("INT", procColsMD.getString("TYPE_NAME"), sd + "-> TYPE_NAME");
        assertEquals(10, procColsMD.getInt("PRECISION"), sd + "-> PRECISION");
        assertEquals(10, procColsMD.getInt("LENGTH"), sd + "-> LENGTH");
        assertEquals(0, procColsMD.getShort("SCALE"), sd + "-> SCALE");
        assertEquals(10, procColsMD.getShort("RADIX"), sd + "-> RADIX");
        assertEquals(DatabaseMetaData.procedureNullable, procColsMD.getShort("NULLABLE"), sd + "-> NULLABLE");
        assertEquals(null, procColsMD.getString("REMARKS"), sd + "-> REMARKS");
        assertEquals(null, procColsMD.getString("COLUMN_DEF"), sd + "-> COLUMN_DEF");
        assertEquals(0, procColsMD.getInt("SQL_DATA_TYPE"), sd + "-> SQL_DATA_TYPE");
        assertEquals(0, procColsMD.getInt("SQL_DATETIME_SUB"), sd + "-> SQL_DATETIME_SUB");
        assertEquals(0, procColsMD.getInt("CHAR_OCTET_LENGTH"), sd + "-> CHAR_OCTET_LENGTH");
        assertEquals(0, procColsMD.getInt("ORDINAL_POSITION"), sd + "-> ORDINAL_POSITION");
        assertEquals("YES", procColsMD.getString("IS_NULLABLE"), sd + "-> IS_NULLABLE");
        assertEquals("testBug69298_func", procColsMD.getString("SPECIFIC_NAME"), sd + "-> SPECIFIC_NAME");
        assertTrue(procColsMD.next(), sd + "2nd of 3 rows expected.");
        // function column: testBug69298_func.param_func
        assertEquals(dbMapsToSchema ? "def" : testConn.getCatalog(), procColsMD.getString("PROCEDURE_CAT"), sd + "-> PROCEDURE_CAT");
        assertEquals(dbMapsToSchema ? testConn.getSchema() : null, procColsMD.getString("PROCEDURE_SCHEM"), sd + "-> PROCEDURE_SCHEM");
        assertEquals("testBug69298_func", procColsMD.getString("PROCEDURE_NAME"), sd + "-> PROCEDURE_NAME");
        assertEquals("param_func", procColsMD.getString("COLUMN_NAME"), sd + "-> COLUMN_NAME");
        assertEquals(DatabaseMetaData.procedureColumnIn, procColsMD.getShort("COLUMN_TYPE"), sd + "-> COLUMN_TYPE");
        assertEquals(Types.INTEGER, procColsMD.getInt("DATA_TYPE"), sd + "-> DATA_TYPE");
        assertEquals("INT", procColsMD.getString("TYPE_NAME"), sd + "-> TYPE_NAME");
        assertEquals(10, procColsMD.getInt("PRECISION"), sd + "-> PRECISION");
        assertEquals(10, procColsMD.getInt("LENGTH"), sd + "-> LENGTH");
        assertEquals(0, procColsMD.getShort("SCALE"), sd + "-> SCALE");
        assertEquals(10, procColsMD.getShort("RADIX"), sd + "-> RADIX");
        assertEquals(DatabaseMetaData.procedureNullable, procColsMD.getShort("NULLABLE"), sd + "-> NULLABLE");
        assertEquals(null, procColsMD.getString("REMARKS"), sd + "-> REMARKS");
        assertEquals(null, procColsMD.getString("COLUMN_DEF"), sd + "-> COLUMN_DEF");
        assertEquals(0, procColsMD.getInt("SQL_DATA_TYPE"), sd + "-> SQL_DATA_TYPE");
        assertEquals(0, procColsMD.getInt("SQL_DATETIME_SUB"), sd + "-> SQL_DATETIME_SUB");
        assertEquals(0, procColsMD.getInt("CHAR_OCTET_LENGTH"), sd + "-> CHAR_OCTET_LENGTH");
        assertEquals(1, procColsMD.getInt("ORDINAL_POSITION"), sd + "-> ORDINAL_POSITION");
        assertEquals("YES", procColsMD.getString("IS_NULLABLE"), sd + "-> IS_NULLABLE");
        assertEquals("testBug69298_func", procColsMD.getString("SPECIFIC_NAME"), sd + "-> SPECIFIC_NAME");
        assertTrue(procColsMD.next(), sd + "3rd of 3 rows expected.");
    } else {
        assertTrue(procColsMD.next(), sd + "one row expected.");
    }
    // procedure column: testBug69298_proc.param_proc
    assertEquals(dbMapsToSchema ? "def" : testConn.getCatalog(), procColsMD.getString("PROCEDURE_CAT"), sd + "-> PROCEDURE_CAT");
    assertEquals(dbMapsToSchema ? testConn.getSchema() : null, procColsMD.getString("PROCEDURE_SCHEM"), sd + "-> PROCEDURE_SCHEM");
    assertEquals("testBug69298_proc", procColsMD.getString("PROCEDURE_NAME"), sd + "-> PROCEDURE_NAME");
    assertEquals("param_proc", procColsMD.getString("COLUMN_NAME"), sd + "-> COLUMN_NAME");
    assertEquals(DatabaseMetaData.procedureColumnIn, procColsMD.getShort("COLUMN_TYPE"), sd + "-> COLUMN_TYPE");
    assertEquals(Types.INTEGER, procColsMD.getInt("DATA_TYPE"), sd + "-> DATA_TYPE");
    assertEquals("INT", procColsMD.getString("TYPE_NAME"), sd + "-> TYPE_NAME");
    assertEquals(10, procColsMD.getInt("PRECISION"), sd + "-> PRECISION");
    assertEquals(10, procColsMD.getInt("LENGTH"), sd + "-> LENGTH");
    assertEquals(0, procColsMD.getShort("SCALE"), sd + "-> SCALE");
    assertEquals(10, procColsMD.getShort("RADIX"), sd + "-> RADIX");
    assertEquals(DatabaseMetaData.procedureNullable, procColsMD.getShort("NULLABLE"), sd + "-> NULLABLE");
    assertEquals(null, procColsMD.getString("REMARKS"), sd + "-> REMARKS");
    assertEquals(null, procColsMD.getString("COLUMN_DEF"), sd + "-> COLUMN_DEF");
    assertEquals(0, procColsMD.getInt("SQL_DATA_TYPE"), sd + "-> SQL_DATA_TYPE");
    assertEquals(0, procColsMD.getInt("SQL_DATETIME_SUB"), sd + "-> SQL_DATETIME_SUB");
    assertEquals(0, procColsMD.getInt("CHAR_OCTET_LENGTH"), sd + "-> CHAR_OCTET_LENGTH");
    assertEquals(1, procColsMD.getInt("ORDINAL_POSITION"), sd + "-> ORDINAL_POSITION");
    assertEquals("YES", procColsMD.getString("IS_NULLABLE"), sd + "-> IS_NULLABLE");
    assertEquals("testBug69298_proc", procColsMD.getString("SPECIFIC_NAME"), sd + "-> SPECIFIC_NAME");
    assertFalse(procColsMD.next(), sd + "no more rows expected.");
}
Also used : DatabaseTerm(com.mysql.cj.conf.PropertyDefinitions.DatabaseTerm) ResultSet(java.sql.ResultSet) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 29 with JdbcConnection

use of com.mysql.cj.jdbc.JdbcConnection in project JavaSegundasQuintas by ecteruel.

the class PooledConnectionRegressionTest method checkConnectionReturnedToPool.

@SuppressWarnings("deprecation")
private void checkConnectionReturnedToPool(ConnectionWrapper cw) throws Exception {
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.clientPrepare("SELECT 1");
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.clientPrepare("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.clientPrepareStatement("SELECT 1");
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.clientPrepareStatement("SELECT 1", Statement.RETURN_GENERATED_KEYS);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.clientPrepareStatement("SELECT 1", new int[] { 1 });
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.clientPrepareStatement("SELECT 1", new String[] { "1" });
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.clientPrepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.clientPrepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.serverPrepareStatement("SELECT 1");
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.serverPrepareStatement("SELECT 1", Statement.RETURN_GENERATED_KEYS);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.serverPrepareStatement("SELECT 1", new int[] { 1 });
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.serverPrepareStatement("SELECT 1", new String[] { "1" });
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.serverPrepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.serverPrepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.prepareStatement("SELECT 1");
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.prepareStatement("SELECT 1", Statement.RETURN_GENERATED_KEYS);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.prepareStatement("SELECT 1", new int[] { 1 });
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.prepareStatement("SELECT 1", new String[] { "1" });
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.prepareCall("SELECT 1");
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.createStatement();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.createArrayOf(String.class.getName(), new Object[] {}).getClass();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.createStruct(String.class.getName(), new Object[] {}).getClass();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.createBlob();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.createClob();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.createNClob();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.createSQLXML();
            return null;
        }
    });
    assertEquals(ConnectionImpl.class, cw.getActiveMySQLConnection().getClass());
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.getAutoCommit();
            return null;
        }
    });
    assertEquals(((JdbcConnection) this.conn).getAutoIncrementIncrement(), cw.getAutoIncrementIncrement());
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.getCatalog();
            return null;
        }
    });
    assertEquals(((JdbcConnection) this.conn).getCharacterSetMetadata(), cw.getCharacterSetMetadata());
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.getHoldability();
            return null;
        }
    });
    assertEquals(((JdbcConnection) this.conn).getHost(), cw.getHost());
    assertEquals(((JdbcConnection) this.conn).getHostPortPair(), cw.getHostPortPair());
    assertEquals(Properties.class, cw.getProperties().getClass());
    assertEquals(JdbcPropertySetImpl.class, cw.getPropertySet().getClass());
    assertEquals(((JdbcConnection) this.conn).getSchema(), cw.getSchema());
    assertEquals(((JdbcConnection) this.conn).getServerVersion().toString(), cw.getServerVersion().toString());
    assertEquals(NativeSession.class, cw.getSession().getClass());
    assertEquals(((JdbcConnection) this.conn).getSessionMaxRows(), cw.getSessionMaxRows());
    assertEquals(((JdbcConnection) this.conn).getURL(), cw.getURL());
    assertEquals(((JdbcConnection) this.conn).getUser(), cw.getUser());
    assertFalse(cw.hasTriedMaster());
    assertTrue(cw.isClosed());
    assertFalse(cw.isInGlobalTx());
    assertFalse(cw.isSourceConnection());
    assertFalse(cw.isProxySet());
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.isReadOnly();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.isReadOnly(false);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.isReadOnly(true);
            return null;
        }
    });
    assertEquals(isMysqlRunningLocally(), cw.isServerLocal());
    assertTrue(cw.isValid(10));
    assertTrue(cw.isWrapperFor(Connection.class));
    assertEquals(((JdbcConnection) this.conn).lowerCaseTableNames(), cw.lowerCaseTableNames());
    assertEquals(CommentClientInfoProvider.class, cw.getClientInfoProviderImpl().getClass());
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            Properties ci1 = new Properties();
            ci1.setProperty("k1", "v1");
            cw.setClientInfo(ci1);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.setClientInfo("k4", "v4");
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.getClientInfo();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.getClientInfo("k1");
            return null;
        }
    });
    assertEquals(ConnectionImpl.class, cw.getConnectionMutex().getClass());
    assertNull(cw.getExceptionInterceptor());
    assertEquals(((JdbcConnection) this.conn).getNetworkTimeout(), cw.getNetworkTimeout());
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.getTypeMap();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.getWarnings();
            return null;
        }
    });
    // testsuite is built upon non-SSL default connection with additional useSSL=false&allowPublicKeyRetrieval=true properties
    assertFalse(cw.hasSameProperties((JdbcConnection) this.conn));
    assertTrue(cw.isSameResource((JdbcConnection) this.conn));
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.nativeSQL("SELECT 1");
            return null;
        }
    });
    String comment = cw.getStatementComment();
    assertEquals("Test comment", comment);
    cw.setStatementComment("Test comment 2");
    assertNotEquals(((JdbcConnection) this.conn).getStatementComment(), cw.getStatementComment());
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.getMetaData();
            return null;
        }
    });
    // TODO find a way to test following methods
    // cw.getId();
    // cw.getIdleFor();
    // cw.getMetadataSafeStatement();
    // cw.getMultiHostSafeProxy();
    // cw.resetServerState();
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        @SuppressWarnings("synthetic-access")
        public Void call() throws Exception {
            cw.setCatalog(PooledConnectionRegressionTest.this.dbName);
            return null;
        }
    });
    cw.setFailedOver(false);
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
            return null;
        }
    });
    cw.setInGlobalTx(false);
    // TODO find a way to test following methods
    // cw.setNetworkTimeout(executor, milliseconds);
    // cw.setProxy(this.conn);
    // cw.setReadOnly(readOnly);
    // cw.setReadOnlyInternal(readOnlyFlag);
    // cw.setSchema(schema);
    // cw.setSessionMaxRows(max);
    // cw.setTypeMap(map);
    assertEquals(((JdbcConnection) this.conn).storesLowerCaseTableName(), cw.storesLowerCaseTableName());
    // TODO find a way to test following methods
    // cw.getQueryInterceptorsInstances();
    // cw.initializeSafeQueryInterceptors();
    // cw.unSafeQueryInterceptors();
    // cw.unwrap(iface);
    // cw.initializeResultsMetadataFromCache(sql, cachedMetaData, resultSet);
    // cw.getCachedMetaData(sql);
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.setAutoCommit(false);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.getTransactionIsolation();
            return null;
        }
    });
    cw.transactionBegun();
    cw.transactionCompleted();
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.commit();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.rollback();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.rollback(null);
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.setSavepoint();
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.setSavepoint("SP1");
            return null;
        }
    });
    assertThrows(SQLNonTransientConnectionException.class, "Logical handle no longer valid", new Callable<Void>() {

        public Void call() throws Exception {
            cw.releaseSavepoint(null);
            return null;
        }
    });
// TODO find a way to test following methods
// cw.registerStatement(this.stmt);
// cw.unregisterStatement(this.stmt);
// cw.decachePreparedStatement(this.pstmt);
// cw.recachePreparedStatement(this.pstmt);
// cw.clearHasTriedMaster();
// cw.clearWarnings();
// cw.ping();
// cw.pingInternal(checkForClosedConnection, timeoutMillis);
// cw.createNewIO(isForReconnect);
// cw.changeUser(userName, newPassword);
// cw.checkClosed();
// cw.realClose(calledExplicitly, issueRollback, skipLocalTeardown, reason);
// cw.cleanup(whyCleanedUp);
// cw.abort(executor);
// cw.abortInternal();
}
Also used : Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) Properties(java.util.Properties) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException)

Example 30 with JdbcConnection

use of com.mysql.cj.jdbc.JdbcConnection in project JavaSegundasQuintas by ecteruel.

the class PooledConnectionRegressionTest method testConnectionWrapperMethods.

@SuppressWarnings("deprecation")
@Test
public void testConnectionWrapperMethods() throws Exception {
    PooledConnection pc = null;
    pc = this.cpds.getPooledConnection();
    ConnectionWrapper cw = (ConnectionWrapper) pc.getConnection();
    assertEquals(PreparedStatementWrapper.class, cw.clientPrepare("SELECT 1").getClass());
    assertEquals(PreparedStatementWrapper.class, cw.clientPrepare("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.clientPrepareStatement("SELECT 1").getClass());
    assertEquals(PreparedStatementWrapper.class, cw.clientPrepareStatement("SELECT 1", Statement.RETURN_GENERATED_KEYS).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.clientPrepareStatement("SELECT 1", new int[] { 1 }).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.clientPrepareStatement("SELECT 1", new String[] { "1" }).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.clientPrepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.clientPrepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.serverPrepareStatement("SELECT 1").getClass());
    assertEquals(PreparedStatementWrapper.class, cw.serverPrepareStatement("SELECT 1", Statement.RETURN_GENERATED_KEYS).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.serverPrepareStatement("SELECT 1", new int[] { 1 }).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.serverPrepareStatement("SELECT 1", new String[] { "1" }).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.serverPrepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.serverPrepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.prepareStatement("SELECT 1").getClass());
    assertEquals(PreparedStatementWrapper.class, cw.prepareStatement("SELECT 1", Statement.RETURN_GENERATED_KEYS).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.prepareStatement("SELECT 1", new int[] { 1 }).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.prepareStatement("SELECT 1", new String[] { "1" }).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY).getClass());
    assertEquals(PreparedStatementWrapper.class, cw.prepareStatement("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT).getClass());
    assertEquals(CallableStatementWrapper.class, cw.prepareCall("SELECT 1").getClass());
    assertEquals(CallableStatementWrapper.class, cw.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY).getClass());
    assertEquals(CallableStatementWrapper.class, cw.prepareCall("SELECT 1", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT).getClass());
    assertEquals(StatementWrapper.class, cw.createStatement().getClass());
    assertEquals(StatementWrapper.class, cw.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY).getClass());
    assertEquals(StatementWrapper.class, cw.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT).getClass());
    assertEquals(26, cw.getActiveStatementCount());
    assertThrows(SQLFeatureNotSupportedException.class, new Callable<Void>() {

        public Void call() throws Exception {
            cw.createArrayOf(String.class.getName(), new Object[] {}).getClass();
            return null;
        }
    });
    assertThrows(SQLFeatureNotSupportedException.class, new Callable<Void>() {

        public Void call() throws Exception {
            cw.createStruct(String.class.getName(), new Object[] {}).getClass();
            return null;
        }
    });
    assertEquals(Blob.class, cw.createBlob().getClass());
    assertEquals(Clob.class, cw.createClob().getClass());
    assertEquals(NClob.class, cw.createNClob().getClass());
    assertEquals(MysqlSQLXML.class, cw.createSQLXML().getClass());
    assertEquals(ConnectionImpl.class, cw.getActiveMySQLConnection().getClass());
    assertEquals(this.conn.getAutoCommit(), cw.getAutoCommit());
    assertEquals(((JdbcConnection) this.conn).getAutoIncrementIncrement(), cw.getAutoIncrementIncrement());
    assertEquals(((JdbcConnection) this.conn).getCatalog(), cw.getCatalog());
    assertEquals(((JdbcConnection) this.conn).getCharacterSetMetadata(), cw.getCharacterSetMetadata());
    assertEquals(((JdbcConnection) this.conn).getHoldability(), cw.getHoldability());
    assertEquals(((JdbcConnection) this.conn).getHost(), cw.getHost());
    assertEquals(((JdbcConnection) this.conn).getHostPortPair(), cw.getHostPortPair());
    assertEquals(Properties.class, cw.getProperties().getClass());
    assertEquals(JdbcPropertySetImpl.class, cw.getPropertySet().getClass());
    assertEquals(((JdbcConnection) this.conn).getSchema(), cw.getSchema());
    assertEquals(((JdbcConnection) this.conn).getServerVersion().toString(), cw.getServerVersion().toString());
    assertEquals(NativeSession.class, cw.getSession().getClass());
    assertEquals(((JdbcConnection) this.conn).getSessionMaxRows(), cw.getSessionMaxRows());
    assertEquals(((JdbcConnection) this.conn).getURL(), cw.getURL());
    assertEquals(((JdbcConnection) this.conn).getUser(), cw.getUser());
    assertFalse(cw.hasTriedMaster());
    assertFalse(cw.isClosed());
    assertFalse(cw.isInGlobalTx());
    assertFalse(cw.isSourceConnection());
    assertFalse(cw.isProxySet());
    assertFalse(cw.isReadOnly());
    assertFalse(cw.isReadOnly(false));
    assertFalse(cw.isReadOnly(true));
    assertEquals(isMysqlRunningLocally(), cw.isServerLocal());
    assertTrue(cw.isValid(10));
    assertTrue(cw.isWrapperFor(Connection.class));
    assertEquals(((JdbcConnection) this.conn).lowerCaseTableNames(), cw.lowerCaseTableNames());
    assertEquals(CommentClientInfoProvider.class, cw.getClientInfoProviderImpl().getClass());
    Properties ci1 = new Properties();
    ci1.setProperty("k1", "v1");
    ci1.setProperty("k2", "v2");
    cw.setClientInfo(ci1);
    cw.setClientInfo("k3", "v3");
    Properties ci2 = cw.getClientInfo();
    assertFalse(ci1.equals(ci2));
    assertEquals("v1", cw.getClientInfo("k1"));
    assertEquals("v2", cw.getClientInfo("k2"));
    assertEquals("v3", cw.getClientInfo("k3"));
    String comment = cw.getStatementComment();
    assertEquals("k3=v3, k2=v2, k1=v1", comment);
    cw.setStatementComment("Test comment");
    assertNotEquals(((JdbcConnection) this.conn).getStatementComment(), cw.getStatementComment());
    assertEquals(ConnectionImpl.class, cw.getConnectionMutex().getClass());
    assertNull(cw.getExceptionInterceptor());
    assertEquals(((JdbcConnection) this.conn).getNetworkTimeout(), cw.getNetworkTimeout());
    assertEquals(((JdbcConnection) this.conn).getTypeMap(), cw.getTypeMap());
    assertNull(cw.getWarnings());
    // testsuite is built upon non-SSL default connection with additional useSSL=false&allowPublicKeyRetrieval=true properties
    assertFalse(cw.hasSameProperties((JdbcConnection) this.conn));
    assertTrue(cw.isSameResource((JdbcConnection) this.conn));
    assertEquals(((JdbcConnection) this.conn).nativeSQL("SELECT 1"), cw.nativeSQL("SELECT 1"));
    assertEquals(cw.getServerVersion().meetsMinimum(new ServerVersion(8, 0, 3)) ? DatabaseMetaDataUsingInfoSchema.class : DatabaseMetaData.class, cw.getMetaData().getClass());
    // TODO find a way to test following methods
    // cw.getId();
    // cw.getIdleFor();
    // cw.getMetadataSafeStatement();
    // cw.getMultiHostSafeProxy();
    // cw.resetServerState();
    cw.setCatalog(this.dbName);
    cw.setFailedOver(false);
    cw.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
    cw.setInGlobalTx(false);
    // TODO find a way to test following methods
    // cw.setNetworkTimeout(executor, milliseconds);
    // cw.setProxy(this.conn);
    // cw.setReadOnly(readOnly);
    // cw.setReadOnlyInternal(readOnlyFlag);
    // cw.setSchema(schema);
    // cw.setSessionMaxRows(max);
    // cw.setTypeMap(map);
    assertEquals(((JdbcConnection) this.conn).storesLowerCaseTableName(), cw.storesLowerCaseTableName());
    // TODO find a way to test following methods
    // cw.getQueryInterceptorsInstances();
    // cw.initializeSafeQueryInterceptors();
    // cw.unSafeQueryInterceptors();
    // cw.unwrap(iface);
    // cw.initializeResultsMetadataFromCache(sql, cachedMetaData, resultSet);
    // cw.getCachedMetaData(sql);
    cw.setAutoCommit(false);
    cw.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
    assertEquals(Connection.TRANSACTION_READ_UNCOMMITTED, cw.getTransactionIsolation());
    cw.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
    assertEquals(Connection.TRANSACTION_READ_COMMITTED, cw.getTransactionIsolation());
    // TODO find a way to test following methods
    // cw.transactionBegun();
    // cw.transactionCompleted();
    // cw.commit();
    // cw.rollback();
    // cw.rollback(arg0);
    // cw.setSavepoint();
    // cw.setSavepoint(arg0);
    // cw.releaseSavepoint(arg0);
    cw.setAutoCommit(true);
    // TODO find a way to test following methods
    // cw.registerStatement(this.stmt);
    // cw.unregisterStatement(this.stmt);
    // cw.decachePreparedStatement(this.pstmt);
    // cw.recachePreparedStatement(this.pstmt);
    // TODO find a way to test following methods
    // cw.clearHasTriedMaster();
    // cw.clearWarnings();
    // cw.ping();
    // cw.pingInternal(checkForClosedConnection, timeoutMillis);
    // cw.createNewIO(isForReconnect);
    // cw.changeUser(userName, newPassword);
    // cw.checkClosed();
    cw.close();
    // TODO why are they still active? Active statements should be cleaned when connection is returned to pool.
    assertEquals(26, cw.getActiveStatementCount());
    checkConnectionReturnedToPool(cw);
    cw.normalClose();
    assertEquals(0, cw.getActiveStatementCount());
    checkReallyClosedConnection(cw);
// TODO find a way to test following methods
// cw.realClose(calledExplicitly, issueRollback, skipLocalTeardown, reason);
// cw.cleanup(whyCleanedUp);
// cw.abort(executor);
// cw.abortInternal();
}
Also used : PooledConnection(javax.sql.PooledConnection) ServerVersion(com.mysql.cj.ServerVersion) DatabaseMetaDataUsingInfoSchema(com.mysql.cj.jdbc.DatabaseMetaDataUsingInfoSchema) ConnectionWrapper(com.mysql.cj.jdbc.ConnectionWrapper) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) JdbcConnection(com.mysql.cj.jdbc.JdbcConnection) Properties(java.util.Properties) DatabaseMetaData(com.mysql.cj.jdbc.DatabaseMetaData) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLException(java.sql.SQLException) CommunicationsException(com.mysql.cj.jdbc.exceptions.CommunicationsException) PacketTooBigException(com.mysql.cj.jdbc.exceptions.PacketTooBigException) SQLNonTransientConnectionException(java.sql.SQLNonTransientConnectionException) Test(org.junit.jupiter.api.Test)

Aggregations

JdbcConnection (com.mysql.cj.jdbc.JdbcConnection)280 Properties (java.util.Properties)216 Test (org.junit.jupiter.api.Test)207 Connection (java.sql.Connection)175 MysqlConnection (com.mysql.cj.MysqlConnection)149 XAConnection (javax.sql.XAConnection)100 SQLException (java.sql.SQLException)97 ReplicationConnection (com.mysql.cj.jdbc.ha.ReplicationConnection)96 PooledConnection (javax.sql.PooledConnection)90 MysqlPooledConnection (com.mysql.cj.jdbc.MysqlPooledConnection)81 MysqlXAConnection (com.mysql.cj.jdbc.MysqlXAConnection)79 SuspendableXAConnection (com.mysql.cj.jdbc.SuspendableXAConnection)78 Statement (java.sql.Statement)77 ServerPreparedStatement (com.mysql.cj.jdbc.ServerPreparedStatement)66 PreparedStatement (java.sql.PreparedStatement)66 ResultSet (java.sql.ResultSet)65 ClientPreparedStatement (com.mysql.cj.jdbc.ClientPreparedStatement)60 CommunicationsException (com.mysql.cj.jdbc.exceptions.CommunicationsException)60 IOException (java.io.IOException)54 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)45