Java 类com.mysql.jdbc.MySQLConnection 实例源码

项目:the-vigilantes    文件:StatementsTest.java   
public void testLocalInfileHooked() throws Exception {
    createTable("localInfileHooked", "(field1 int, field2 varchar(255))");
    String streamData = "1\tabcd\n2\tefgh\n3\tijkl";
    InputStream stream = new ByteArrayInputStream(streamData.getBytes());
    try {
        ((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(stream);
        this.stmt.execute("LOAD DATA LOCAL INFILE 'bogusFileName' INTO TABLE localInfileHooked CHARACTER SET "
                + CharsetMapping.getMysqlCharsetForJavaEncoding(((MySQLConnection) this.conn).getEncoding(), (com.mysql.jdbc.Connection) this.conn));
        assertEquals(-1, stream.read());
        this.rs = this.stmt.executeQuery("SELECT field2 FROM localInfileHooked ORDER BY field1 ASC");
        this.rs.next();
        assertEquals("abcd", this.rs.getString(1));
        this.rs.next();
        assertEquals("efgh", this.rs.getString(1));
        this.rs.next();
        assertEquals("ijkl", this.rs.getString(1));
    } finally {
        ((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(null);
    }
}
项目:BibliotecaPS    文件:ConnectionRegressionTest.java   
public void run() {
    System.out.println(this.num + ". Start cancelling at " + new Date().getTime());

    if (Proxy.isProxyClass(this.c.getClass())) {
        try {
            if (this.num == 7 || this.num == 10) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, Connection.class.getMethod("close", new Class[] {}), null);
            } else if (this.num == 8 || this.num == 11) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, MySQLConnection.class.getMethod("abortInternal", new Class[] {}), null);
            } else if (this.num == 9 || this.num == 12) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, com.mysql.jdbc.Connection.class.getMethod("abort", new Class[] { Executor.class }),
                        new Object[] { new ThreadPerTaskExecutor() });
            }

            ConnectionRegressionTest.this.testServerPrepStmtDeadlockCounter++;
            System.out.println(this.num + ". Done!");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
项目:the-vigilantes    文件:ConnectionRegressionTest.java   
public void run() {
    System.out.println(this.num + ". Start cancelling at " + new Date().getTime());

    if (Proxy.isProxyClass(this.c.getClass())) {
        try {
            if (this.num == 7 || this.num == 10) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, Connection.class.getMethod("close", new Class[] {}), null);
            } else if (this.num == 8 || this.num == 11) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, MySQLConnection.class.getMethod("abortInternal", new Class[] {}), null);
            } else if (this.num == 9 || this.num == 12) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, com.mysql.jdbc.Connection.class.getMethod("abort", new Class[] { Executor.class }),
                        new Object[] { new ThreadPerTaskExecutor() });
            }

            ConnectionRegressionTest.this.testServerPrepStmtDeadlockCounter++;
            System.out.println(this.num + ". Done!");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
项目:BibliotecaPS    文件:ConnectionRegressionTest.java   
/**
 * Tests fix for BUG#19354014 - CHANGEUSER() CALL RESULTS IN "PACKETS OUT OF ORDER" ERROR
 * 
 * @throws Exception
 */
public void testBug19354014() throws Exception {
    if (versionMeetsMinimum(5, 5, 7)) {
        Connection con = null;
        createUser("'bug19354014user'@'%'", "identified WITH mysql_native_password");
        this.stmt.executeUpdate("grant all on *.* to 'bug19354014user'@'%'");
        this.stmt.executeUpdate(versionMeetsMinimum(5, 7, 6) ? "ALTER USER 'bug19354014user'@'%' IDENTIFIED BY 'pwd'"
                : "set password for 'bug19354014user'@'%' = PASSWORD('pwd')");
        this.stmt.executeUpdate("flush privileges");

        try {
            Properties props = new Properties();
            props.setProperty("useCompression", "true");

            con = getConnectionWithProps(props);
            ((MySQLConnection) con).changeUser("bug19354014user", "pwd");
        } finally {
            this.stmt.executeUpdate("flush privileges");

            if (con != null) {
                con.close();
            }
        }
    }
}
项目:BibliotecaPS    文件:CharsetRegressionTest.java   
/**
 * Tests fix for Bug#73663 (19479242), utf8mb4 does not work for connector/j >=5.1.13
 * 
 * This test is only run when character_set_server=utf8mb4 and collation-server set to one of utf8mb4 collations (it's better to test two configurations:
 * with default utf8mb4_general_ci and one of non-default, say utf8mb4_bin)
 * 
 * @throws Exception
 */
public void testBug73663() throws Exception {

    this.rs = this.stmt.executeQuery("show variables like 'collation_server'");
    this.rs.next();
    String collation = this.rs.getString(2);

    if (collation != null && collation.startsWith("utf8mb4") && "utf8mb4".equals(((MySQLConnection) this.conn).getServerVariable("character_set_server"))) {
        Properties p = new Properties();
        p.setProperty("characterEncoding", "UTF-8");
        p.setProperty("statementInterceptors", Bug73663StatementInterceptor.class.getName());

        getConnectionWithProps(p);
        // exception will be thrown from the statement interceptor if any "SET NAMES utf8" statement is issued instead of "SET NAMES utf8mb4"
    } else {
        System.out.println(
                "testBug73663 was skipped: This test is only run when character_set_server=utf8mb4 and collation-server set to one of utf8mb4 collations.");
    }
}
项目:OpenVertretung    文件:StatementsTest.java   
public void testLocalInfileHooked() throws Exception {
    createTable("localInfileHooked", "(field1 int, field2 varchar(255))");
    String streamData = "1\tabcd\n2\tefgh\n3\tijkl";
    InputStream stream = new ByteArrayInputStream(streamData.getBytes());
    try {
        ((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(stream);
        this.stmt.execute("LOAD DATA LOCAL INFILE 'bogusFileName' INTO TABLE localInfileHooked CHARACTER SET "
                + CharsetMapping.getMysqlCharsetForJavaEncoding(((MySQLConnection) this.conn).getEncoding(), (com.mysql.jdbc.Connection) this.conn));
        assertEquals(-1, stream.read());
        this.rs = this.stmt.executeQuery("SELECT field2 FROM localInfileHooked ORDER BY field1 ASC");
        this.rs.next();
        assertEquals("abcd", this.rs.getString(1));
        this.rs.next();
        assertEquals("efgh", this.rs.getString(1));
        this.rs.next();
        assertEquals("ijkl", this.rs.getString(1));
    } finally {
        ((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(null);
    }
}
项目:OpenVertretung    文件:ConnectionRegressionTest.java   
/**
 * Tests fix for BUG#12218, properties shared between master and slave with
 * replication connection.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug12218() throws Exception {
    if (runMultiHostTests()) {
        Connection replConn = null;

        try {
            replConn = getMasterSlaveReplicationConnection();
            assertTrue(!((MySQLConnection) ((ReplicationConnection) replConn).getMasterConnection())
                    .hasSameProperties(((ReplicationConnection) replConn).getSlavesConnection()));
        } finally {
            if (replConn != null) {
                replConn.close();
            }
        }
    }
}
项目:OpenVertretung    文件:ConnectionRegressionTest.java   
public void run() {
    System.out.println(this.num + ". Start cancelling at " + new Date().getTime());

    if (Proxy.isProxyClass(this.c.getClass())) {
        try {
            if (this.num == 7 || this.num == 10) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, Connection.class.getMethod("close", new Class[] {}), null);
            } else if (this.num == 8 || this.num == 11) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, MySQLConnection.class.getMethod("abortInternal", new Class[] {}), null);
            } else if (this.num == 9 || this.num == 12) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, com.mysql.jdbc.Connection.class.getMethod("abort", new Class[] { Executor.class }),
                        new Object[] { new ThreadPerTaskExecutor() });
            }

            ConnectionRegressionTest.this.testServerPrepStmtDeadlockCounter++;
            System.out.println(this.num + ". Done!");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
项目:ProyectoPacientes    文件:StatementRegressionTest.java   
/**
 * Tests fix for Bug#78961 - Can't call MySQL procedure with InOut parameters in Fabric environment.
 * 
 * Although this is a Fabric related bug we are able reproduce it using a couple of multi-host connections.
 */
public void testBug78961() throws Exception {
    createProcedure("testBug78961", "(IN c1 FLOAT, IN c2 FLOAT, OUT h FLOAT, INOUT t FLOAT) BEGIN SET h = SQRT(c1 * c1 + c2 * c2); SET t = t + h; END;");

    Connection highLevelConn = getLoadBalancedConnection(null);
    assertTrue(highLevelConn.getClass().getName().startsWith("com.sun.proxy") || highLevelConn.getClass().getName().startsWith("$Proxy"));

    Connection lowLevelConn = getMasterSlaveReplicationConnection(null);
    // This simulates the behavior from Fabric connections that are causing the problem.
    ((ReplicationConnection) lowLevelConn).setProxy((MySQLConnection) highLevelConn);

    CallableStatement cstmt = lowLevelConn.prepareCall("{CALL testBug78961 (?, ?, ?, ?)}");
    cstmt.setFloat(1, 3.0f);
    cstmt.setFloat(2, 4.0f);
    cstmt.setFloat(4, 5.0f);
    cstmt.registerOutParameter(3, Types.FLOAT);
    cstmt.registerOutParameter(4, Types.FLOAT);
    cstmt.execute();

    assertEquals(5.0f, cstmt.getFloat(3));
    assertEquals(10.0f, cstmt.getFloat(4));
}
项目:OpenVertretung    文件:StatementRegressionTest.java   
/**
 * Tests fix for Bug#78961 - Can't call MySQL procedure with InOut parameters in Fabric environment.
 * 
 * Although this is a Fabric related bug we are able reproduce it using a couple of multi-host connections.
 */
public void testBug78961() throws Exception {
    createProcedure("testBug78961", "(IN c1 FLOAT, IN c2 FLOAT, OUT h FLOAT, INOUT t FLOAT) BEGIN SET h = SQRT(c1 * c1 + c2 * c2); SET t = t + h; END;");

    Connection highLevelConn = getLoadBalancedConnection(null);
    assertTrue(highLevelConn.getClass().getName().startsWith("com.sun.proxy") || highLevelConn.getClass().getName().startsWith("$Proxy"));

    Connection lowLevelConn = getMasterSlaveReplicationConnection(null);
    // This simulates the behavior from Fabric connections that are causing the problem.
    ((ReplicationConnection) lowLevelConn).setProxy((MySQLConnection) highLevelConn);

    CallableStatement cstmt = lowLevelConn.prepareCall("{CALL testBug78961 (?, ?, ?, ?)}");
    cstmt.setFloat(1, 3.0f);
    cstmt.setFloat(2, 4.0f);
    cstmt.setFloat(4, 5.0f);
    cstmt.registerOutParameter(3, Types.FLOAT);
    cstmt.registerOutParameter(4, Types.FLOAT);
    cstmt.execute();

    assertEquals(5.0f, cstmt.getFloat(3));
    assertEquals(10.0f, cstmt.getFloat(4));
}
项目:ProyectoPacientes    文件:StatementsTest.java   
public void testLocalInfileHooked() throws Exception {
    createTable("localInfileHooked", "(field1 int, field2 varchar(255))");
    String streamData = "1\tabcd\n2\tefgh\n3\tijkl";
    InputStream stream = new ByteArrayInputStream(streamData.getBytes());
    try {
        ((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(stream);
        this.stmt.execute("LOAD DATA LOCAL INFILE 'bogusFileName' INTO TABLE localInfileHooked CHARACTER SET "
                + CharsetMapping.getMysqlCharsetForJavaEncoding(((MySQLConnection) this.conn).getEncoding(), (com.mysql.jdbc.Connection) this.conn));
        assertEquals(-1, stream.read());
        this.rs = this.stmt.executeQuery("SELECT field2 FROM localInfileHooked ORDER BY field1 ASC");
        this.rs.next();
        assertEquals("abcd", this.rs.getString(1));
        this.rs.next();
        assertEquals("efgh", this.rs.getString(1));
        this.rs.next();
        assertEquals("ijkl", this.rs.getString(1));
    } finally {
        ((com.mysql.jdbc.Statement) this.stmt).setLocalInfileInputStream(null);
    }
}
项目:ProyectoPacientes    文件:ConnectionRegressionTest.java   
/**
 * Tests fix for BUG#12218, properties shared between master and slave with
 * replication connection.
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug12218() throws Exception {
    if (runMultiHostTests()) {
        Connection replConn = null;

        try {
            replConn = getMasterSlaveReplicationConnection();
            assertTrue(!((MySQLConnection) ((ReplicationConnection) replConn).getMasterConnection())
                    .hasSameProperties(((ReplicationConnection) replConn).getSlavesConnection()));
        } finally {
            if (replConn != null) {
                replConn.close();
            }
        }
    }
}
项目:ProyectoPacientes    文件:ConnectionRegressionTest.java   
public void run() {
    System.out.println(this.num + ". Start cancelling at " + new Date().getTime());

    if (Proxy.isProxyClass(this.c.getClass())) {
        try {
            if (this.num == 7 || this.num == 10) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, Connection.class.getMethod("close", new Class[] {}), null);
            } else if (this.num == 8 || this.num == 11) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, MySQLConnection.class.getMethod("abortInternal", new Class[] {}), null);
            } else if (this.num == 9 || this.num == 12) {
                Proxy.getInvocationHandler(this.c).invoke(this.c, com.mysql.jdbc.Connection.class.getMethod("abort", new Class[] { Executor.class }),
                        new Object[] { new ThreadPerTaskExecutor() });
            }

            ConnectionRegressionTest.this.testServerPrepStmtDeadlockCounter++;
            System.out.println(this.num + ". Done!");
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
项目:the-vigilantes    文件:ConnectionRegressionTest.java   
public void testBug37570() throws Exception {
    Properties props = new Properties();
    props.setProperty("characterEncoding", "utf-8");
    props.setProperty("passwordCharacterEncoding", "utf-8");

    // TODO enable for usual connection?
    Connection adminConn = getAdminConnectionWithProps(props);

    if (adminConn != null) {

        String unicodePassword = "\u0430\u0431\u0432"; // Cyrillic string
        String user = "bug37570";
        Statement adminStmt = adminConn.createStatement();

        adminStmt.executeUpdate("create user '" + user + "'@'127.0.0.1' identified by 'foo'");
        adminStmt.executeUpdate("grant usage on *.* to '" + user + "'@'127.0.0.1'");
        adminStmt.executeUpdate("update mysql.user set password=PASSWORD('" + unicodePassword + "') where user = '" + user + "'");
        adminStmt.executeUpdate("flush privileges");

        try {
            ((MySQLConnection) adminConn).changeUser(user, unicodePassword);
        } catch (SQLException sqle) {
            assertTrue("Connection with non-latin1 password failed", false);
        }

    }
}
项目:the-vigilantes    文件:ConnectionRegressionTest.java   
/**
 * Tests fix for BUG#44587, provide last packet sent/received timing in all
 * connection failure errors.
 */
public void testBug44587() throws Exception {
    Exception e = null;
    String msg = SQLError.createLinkFailureMessageBasedOnHeuristics((MySQLConnection) this.conn, System.currentTimeMillis() - 1000,
            System.currentTimeMillis() - 2000, e);
    assertTrue(containsMessage(msg, "CommunicationsException.ServerPacketTimingInfo"));
}
项目:the-vigilantes    文件:ConnectionRegressionTest.java   
/**
 * Tests fix for BUG#45419, ensure that time is not converted to seconds
 * before being reported as milliseconds.
 */
public void testBug45419() throws Exception {
    Exception e = null;
    String msg = SQLError.createLinkFailureMessageBasedOnHeuristics((MySQLConnection) this.conn, System.currentTimeMillis() - 1000,
            System.currentTimeMillis() - 2000, e);
    Matcher m = Pattern.compile("([\\d\\,\\.]+)", Pattern.MULTILINE).matcher(msg);
    assertTrue(m.find());
    assertTrue(Long.parseLong(m.group(0).replaceAll("[,.]", "")) >= 2000);
    assertTrue(Long.parseLong(m.group(1).replaceAll("[,.]", "")) >= 1000);
}
项目:the-vigilantes    文件:ConnectionRegressionTest.java   
private void assertCurrentUser(String url, Properties props, String expectedUser, boolean sslRequired) throws SQLException {
    Connection connection = url == null ? getConnectionWithProps(props) : getConnectionWithProps(url, props);
    if (sslRequired) {
        assertTrue("SSL connection isn't actually established!", ((MySQLConnection) connection).getIO().isSSLEstablished());
    }
    Statement st = connection.createStatement();
    ResultSet rset = st.executeQuery("select USER(),CURRENT_USER()");
    rset.next();
    assertEquals(expectedUser, rset.getString(1).split("@")[0]);
    assertEquals(expectedUser, rset.getString(2).split("@")[0]);
    connection.close();
}
项目:BibliotecaPS    文件:Sha256PasswordPlugin.java   
private static byte[] encryptPassword(String password, String seed, Connection connection, String key) throws SQLException {
    byte[] input = null;
    try {
        input = password != null ? StringUtils.getBytesNullTerminated(password, connection.getPasswordCharacterEncoding()) : new byte[] { 0 };
    } catch (UnsupportedEncodingException e) {
        throw SQLError.createSQLException(Messages.getString("Sha256PasswordPlugin.3", new Object[] { connection.getPasswordCharacterEncoding() }),
                SQLError.SQL_STATE_GENERAL_ERROR, null);
    }
    byte[] mysqlScrambleBuff = new byte[input.length];
    Security.xorString(input, mysqlScrambleBuff, seed.getBytes(), input.length);
    return ExportControlled.encryptWithRSAPublicKey(mysqlScrambleBuff,
            ExportControlled.decodeRSAPublicKey(key, ((MySQLConnection) connection).getExceptionInterceptor()),
            ((MySQLConnection) connection).getExceptionInterceptor());
}
项目:the-vigilantes    文件:ConnectionRegressionTest.java   
/**
 * Test for Bug#72712 - SET NAMES issued unnecessarily.
 * 
 * Using a statement interceptor, ensure that SET NAMES is not
 * called if the encoding requested by the client application
 * matches that of character_set_server.
 * 
 * Also test that character_set_results is not set unnecessarily.
 */
public void testBug72712() throws Exception {
    // this test is only run when character_set_server=latin1
    if (!((MySQLConnection) this.conn).getServerVariable("character_set_server").equals("latin1")) {
        return;
    }

    Properties p = new Properties();
    p.setProperty("characterEncoding", "cp1252");
    p.setProperty("characterSetResults", "cp1252");
    p.setProperty("statementInterceptors", Bug72712StatementInterceptor.class.getName());

    getConnectionWithProps(p);
    // exception will be thrown from the statement interceptor if any SET statements are issued
}
项目:the-vigilantes    文件:ConnectionRegressionTest.java   
private void testBug18869381WithProperties(Properties props) throws Exception {
    Connection testConn = null;
    Statement testSt = null;
    ResultSet testRs = null;

    try {
        testConn = getConnectionWithProps(sha256Url, props);

        ((MySQLConnection) testConn).changeUser("bug18869381user1", "LongLongLongLongLongLongLongLongLongLongLongLongPwd1");
        testSt = testConn.createStatement();
        testRs = testSt.executeQuery("select USER(),CURRENT_USER()");
        testRs.next();
        assertEquals("bug18869381user1", testRs.getString(1).split("@")[0]);
        assertEquals("bug18869381user1", testRs.getString(2).split("@")[0]);
        testSt.close();

        ((MySQLConnection) testConn).changeUser("bug18869381user2", "pwd2");
        testSt = testConn.createStatement();
        testRs = testSt.executeQuery("select USER(),CURRENT_USER()");
        testRs.next();
        assertEquals("bug18869381user2", testRs.getString(1).split("@")[0]);
        assertEquals("bug18869381user2", testRs.getString(2).split("@")[0]);
        testSt.close();

        ((MySQLConnection) testConn).changeUser("bug18869381user3", "pwd3");
        testSt = testConn.createStatement();
        testRs = testSt.executeQuery("select USER(),CURRENT_USER()");
        testRs.next();
        assertEquals("bug18869381user3", testRs.getString(1).split("@")[0]);
        assertEquals("bug18869381user3", testRs.getString(2).split("@")[0]);

    } finally {
        if (testConn != null) {
            testConn.close();
        }
    }
}
项目:ProyectoPacientes    文件:FabricMySQLConnectionProxy.java   
public MySQLConnection getActiveMySQLConnection() {
    try {
        return getActiveMySQLConnectionChecked();
    } catch (SQLException ex) {
        throw new IllegalStateException("Unable to determine active connection", ex);
    }
}
项目:the-vigilantes    文件:FabricMySQLConnectionProxy.java   
public MySQLConnection getActiveMySQLConnection() {
    try {
        return getActiveMySQLConnectionChecked();
    } catch (SQLException ex) {
        throw new IllegalStateException("Unable to determine active connection", ex);
    }
}
项目:the-vigilantes    文件:ErrorReportingExceptionInterceptor.java   
public SQLException interceptException(SQLException sqlEx, Connection conn) {
    MySQLConnection mysqlConn = (MySQLConnection) conn;

    // don't intercept exceptions during initialization, before the proxy has a chance to setProxy() on the physical connection
    if (ConnectionImpl.class.isAssignableFrom(mysqlConn.getMultiHostSafeProxy().getClass())) {
        return null;
    }

    FabricMySQLConnectionProxy fabricProxy = (FabricMySQLConnectionProxy) mysqlConn.getMultiHostSafeProxy();
    try {
        return fabricProxy.interceptException(sqlEx, conn, this.fabricHaGroup, this.hostname, this.port);
    } catch (FabricCommunicationException ex) {
        return SQLError.createSQLException("Failed to report error to Fabric.", SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE, ex, null);
    }
}
项目:the-vigilantes    文件:Sha256PasswordPlugin.java   
private static byte[] encryptPassword(String password, String seed, Connection connection, String key) throws SQLException {
    byte[] input = null;
    try {
        input = password != null ? StringUtils.getBytesNullTerminated(password, connection.getPasswordCharacterEncoding()) : new byte[] { 0 };
    } catch (UnsupportedEncodingException e) {
        throw SQLError.createSQLException(Messages.getString("Sha256PasswordPlugin.3", new Object[] { connection.getPasswordCharacterEncoding() }),
                SQLError.SQL_STATE_GENERAL_ERROR, null);
    }
    byte[] mysqlScrambleBuff = new byte[input.length];
    Security.xorString(input, mysqlScrambleBuff, seed.getBytes(), input.length);
    return ExportControlled.encryptWithRSAPublicKey(mysqlScrambleBuff,
            ExportControlled.decodeRSAPublicKey(key, ((MySQLConnection) connection).getExceptionInterceptor()),
            ((MySQLConnection) connection).getExceptionInterceptor());
}
项目:BibliotecaPS    文件:ConnectionRegressionTest.java   
/**
 * Test for Bug#72712 - SET NAMES issued unnecessarily.
 * 
 * Using a statement interceptor, ensure that SET NAMES is not
 * called if the encoding requested by the client application
 * matches that of character_set_server.
 * 
 * Also test that character_set_results is not set unnecessarily.
 */
public void testBug72712() throws Exception {
    // this test is only run when character_set_server=latin1
    if (!((MySQLConnection) this.conn).getServerVariable("character_set_server").equals("latin1")) {
        return;
    }

    Properties p = new Properties();
    p.setProperty("characterEncoding", "cp1252");
    p.setProperty("characterSetResults", "cp1252");
    p.setProperty("statementInterceptors", Bug72712StatementInterceptor.class.getName());

    getConnectionWithProps(p);
    // exception will be thrown from the statement interceptor if any SET statements are issued
}
项目:OpenVertretung    文件:ConnectionRegressionTest.java   
public void testBug37570() throws Exception {
    Properties props = new Properties();
    props.setProperty("characterEncoding", "utf-8");
    props.setProperty("passwordCharacterEncoding", "utf-8");

    // TODO enable for usual connection?
    Connection adminConn = getAdminConnectionWithProps(props);

    if (adminConn != null) {

        String unicodePassword = "\u0430\u0431\u0432"; // Cyrillic string
        String user = "bug37570";
        Statement adminStmt = adminConn.createStatement();

        adminStmt.executeUpdate("create user '" + user + "'@'127.0.0.1' identified by 'foo'");
        adminStmt.executeUpdate("grant usage on *.* to '" + user + "'@'127.0.0.1'");
        adminStmt.executeUpdate("update mysql.user set password=PASSWORD('" + unicodePassword + "') where user = '" + user + "'");
        adminStmt.executeUpdate("flush privileges");

        try {
            ((MySQLConnection) adminConn).changeUser(user, unicodePassword);
        } catch (SQLException sqle) {
            assertTrue("Connection with non-latin1 password failed", false);
        }

    }
}
项目:OpenVertretung    文件:ConnectionRegressionTest.java   
/**
 * Tests fix for BUG#44587, provide last packet sent/received timing in all
 * connection failure errors.
 */
public void testBug44587() throws Exception {
    Exception e = null;
    String msg = SQLError.createLinkFailureMessageBasedOnHeuristics((MySQLConnection) this.conn, System.currentTimeMillis() - 1000,
            System.currentTimeMillis() - 2000, e);
    assertTrue(containsMessage(msg, "CommunicationsException.ServerPacketTimingInfo"));
}
项目:OpenVertretung    文件:ConnectionRegressionTest.java   
/**
 * Tests fix for BUG#45419, ensure that time is not converted to seconds
 * before being reported as milliseconds.
 */
public void testBug45419() throws Exception {
    Exception e = null;
    String msg = SQLError.createLinkFailureMessageBasedOnHeuristics((MySQLConnection) this.conn, System.currentTimeMillis() - 1000,
            System.currentTimeMillis() - 2000, e);
    Matcher m = Pattern.compile("([\\d\\,\\.]+)", Pattern.MULTILINE).matcher(msg);
    assertTrue(m.find());
    assertTrue(Long.parseLong(m.group(0).replaceAll("[,.]", "")) >= 2000);
    assertTrue(Long.parseLong(m.group(1).replaceAll("[,.]", "")) >= 1000);
}
项目:OpenVertretung    文件:ConnectionRegressionTest.java   
private void assertCurrentUser(String url, Properties props, String expectedUser, boolean sslRequired) throws SQLException {
    Connection connection = url == null ? getConnectionWithProps(props) : getConnectionWithProps(url, props);
    if (sslRequired) {
        assertTrue("SSL connection isn't actually established!", ((MySQLConnection) connection).getIO().isSSLEstablished());
    }
    Statement st = connection.createStatement();
    ResultSet rset = st.executeQuery("select USER(),CURRENT_USER()");
    rset.next();
    assertEquals(expectedUser, rset.getString(1).split("@")[0]);
    assertEquals(expectedUser, rset.getString(2).split("@")[0]);
    connection.close();
}
项目:OpenVertretung    文件:ConnectionRegressionTest.java   
/**
 * Test for Bug#72712 - SET NAMES issued unnecessarily.
 * 
 * Using a statement interceptor, ensure that SET NAMES is not
 * called if the encoding requested by the client application
 * matches that of character_set_server.
 * 
 * Also test that character_set_results is not set unnecessarily.
 */
public void testBug72712() throws Exception {
    // this test is only run when character_set_server=latin1
    if (!((MySQLConnection) this.conn).getServerVariable("character_set_server").equals("latin1")) {
        return;
    }

    Properties p = new Properties();
    p.setProperty("characterEncoding", "cp1252");
    p.setProperty("characterSetResults", "cp1252");
    p.setProperty("statementInterceptors", Bug72712StatementInterceptor.class.getName());

    getConnectionWithProps(p);
    // exception will be thrown from the statement interceptor if any SET statements are issued
}
项目:BibliotecaPS    文件:CommunicationsException.java   
public CommunicationsException(MySQLConnection conn, long lastPacketSentTimeMs, long lastPacketReceivedTimeMs, Exception underlyingException) {
    this.exceptionMessage = SQLError.createLinkFailureMessageBasedOnHeuristics(conn, lastPacketSentTimeMs, lastPacketReceivedTimeMs, underlyingException);

    if (underlyingException != null) {
        initCause(underlyingException);
    }
}
项目:OpenVertretung    文件:CommunicationsException.java   
public CommunicationsException(MySQLConnection conn, long lastPacketSentTimeMs, long lastPacketReceivedTimeMs, Exception underlyingException) {
    this.exceptionMessage = SQLError.createLinkFailureMessageBasedOnHeuristics(conn, lastPacketSentTimeMs, lastPacketReceivedTimeMs, underlyingException);

    if (underlyingException != null) {
        initCause(underlyingException);
    }
}
项目:OpenVertretung    文件:Sha256PasswordPlugin.java   
private static byte[] encryptPassword(String password, String seed, Connection connection, String key) throws SQLException {
    byte[] input = null;
    try {
        input = password != null ? StringUtils.getBytesNullTerminated(password, connection.getPasswordCharacterEncoding()) : new byte[] { 0 };
    } catch (UnsupportedEncodingException e) {
        throw SQLError.createSQLException(Messages.getString("Sha256PasswordPlugin.3", new Object[] { connection.getPasswordCharacterEncoding() }),
                SQLError.SQL_STATE_GENERAL_ERROR, null);
    }
    byte[] mysqlScrambleBuff = new byte[input.length];
    Security.xorString(input, mysqlScrambleBuff, seed.getBytes(), input.length);
    return ExportControlled.encryptWithRSAPublicKey(mysqlScrambleBuff,
            ExportControlled.decodeRSAPublicKey(key, ((MySQLConnection) connection).getExceptionInterceptor()),
            ((MySQLConnection) connection).getExceptionInterceptor());
}
项目:lams    文件:FabricMySQLConnectionProxy.java   
protected MySQLConnection getActiveMySQLConnectionPassive() {
    try {
        return getActiveMySQLConnection();
    } catch (SQLException ex) {
        throw new IllegalStateException("Unable to determine active connection", ex);
    }
}
项目:lams    文件:ErrorReportingExceptionInterceptor.java   
public SQLException interceptException(SQLException sqlEx, Connection conn) {
    MySQLConnection mysqlConn = (MySQLConnection) conn;

    // don't intercept exceptions during initialization, before the proxy has a chance to setProxy() on the physical connection
    if (ConnectionImpl.class.isAssignableFrom(mysqlConn.getMultiHostSafeProxy().getClass())) {
        return null;
    }

    FabricMySQLConnectionProxy fabricProxy = (FabricMySQLConnectionProxy) mysqlConn.getMultiHostSafeProxy();
    try {
        return fabricProxy.interceptException(sqlEx, conn, this.fabricHaGroup, this.hostname, this.port);
    } catch (FabricCommunicationException ex) {
        return SQLError.createSQLException("Failed to report error to Fabric.", SQLError.SQL_STATE_COMMUNICATION_LINK_FAILURE, ex, null);
    }
}
项目:lams    文件:CommunicationsException.java   
public CommunicationsException(MySQLConnection conn, long lastPacketSentTimeMs, long lastPacketReceivedTimeMs, Exception underlyingException) {
    this.exceptionMessage = SQLError.createLinkFailureMessageBasedOnHeuristics(conn, lastPacketSentTimeMs, lastPacketReceivedTimeMs, underlyingException);

    if (underlyingException != null) {
        initCause(underlyingException);
    }
}
项目:lams    文件:Sha256PasswordPlugin.java   
private static byte[] encryptPassword(String password, String seed, Connection connection, String key) throws SQLException {
    byte[] input = null;
    try {
        input = password != null ? StringUtils.getBytesNullTerminated(password, connection.getPasswordCharacterEncoding()) : new byte[] { 0 };
    } catch (UnsupportedEncodingException e) {
        throw SQLError.createSQLException(Messages.getString("Sha256PasswordPlugin.3", new Object[] { connection.getPasswordCharacterEncoding() }),
                SQLError.SQL_STATE_GENERAL_ERROR, null);
    }
    byte[] mysqlScrambleBuff = new byte[input.length];
    Security.xorString(input, mysqlScrambleBuff, seed.getBytes(), input.length);
    return ExportControlled.encryptWithRSAPublicKey(mysqlScrambleBuff,
            ExportControlled.decodeRSAPublicKey(key, ((MySQLConnection) connection).getExceptionInterceptor()),
            ((MySQLConnection) connection).getExceptionInterceptor());
}
项目:ProyectoPacientes    文件:ConnectionRegressionTest.java   
public void testBug37570() throws Exception {
    Properties props = new Properties();
    props.setProperty("characterEncoding", "utf-8");
    props.setProperty("passwordCharacterEncoding", "utf-8");

    // TODO enable for usual connection?
    Connection adminConn = getAdminConnectionWithProps(props);

    if (adminConn != null) {

        String unicodePassword = "\u0430\u0431\u0432"; // Cyrillic string
        String user = "bug37570";
        Statement adminStmt = adminConn.createStatement();

        adminStmt.executeUpdate("create user '" + user + "'@'127.0.0.1' identified by 'foo'");
        adminStmt.executeUpdate("grant usage on *.* to '" + user + "'@'127.0.0.1'");
        adminStmt.executeUpdate("update mysql.user set password=PASSWORD('" + unicodePassword + "') where user = '" + user + "'");
        adminStmt.executeUpdate("flush privileges");

        try {
            ((MySQLConnection) adminConn).changeUser(user, unicodePassword);
        } catch (SQLException sqle) {
            assertTrue("Connection with non-latin1 password failed", false);
        }

    }
}
项目:BibliotecaPS    文件:ConnectionRegressionTest.java   
/**
 * Tests fix for BUG#45419, ensure that time is not converted to seconds
 * before being reported as milliseconds.
 */
public void testBug45419() throws Exception {
    Exception e = null;
    String msg = SQLError.createLinkFailureMessageBasedOnHeuristics((MySQLConnection) this.conn, System.currentTimeMillis() - 1000,
            System.currentTimeMillis() - 2000, e);
    Matcher m = Pattern.compile("([\\d\\,\\.]+)", Pattern.MULTILINE).matcher(msg);
    assertTrue(m.find());
    assertTrue(Long.parseLong(m.group(0).replaceAll("[,.]", "")) >= 2000);
    assertTrue(Long.parseLong(m.group(1).replaceAll("[,.]", "")) >= 1000);
}
项目:BibliotecaPS    文件:FabricMySQLConnectionProxy.java   
public MySQLConnection getActiveMySQLConnection() {
    try {
        return getActiveMySQLConnectionChecked();
    } catch (SQLException ex) {
        throw new IllegalStateException("Unable to determine active connection", ex);
    }
}