Java Code Examples for com.mysql.jdbc.Util

The following examples show how to use com.mysql.jdbc.Util. These examples are extracted from open source projects. 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 Project: r-course   Source File: UtilsTest.java    License: MIT License 6 votes vote down vote up
/**
 * Tests Util.isJdbcInterface()
 * 
 * @throws Exception
 */
public void testIsJdbcInterface() throws Exception {
    // Classes directly or indirectly implementing JDBC interfaces.
    assertTrue(Util.isJdbcInterface(PreparedStatement.class));
    assertTrue(Util.isJdbcInterface(StatementImpl.class));
    assertTrue(Util.isJdbcInterface(Statement.class));
    assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
    Statement s = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { Statement.class }, new InvocationHandler() {
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return null;
        }
    });
    assertTrue(Util.isJdbcInterface(s.getClass()));

    // Classes not implementing JDBC interfaces.
    assertFalse(Util.isJdbcInterface(Util.class));
    assertFalse(Util.isJdbcInterface(UtilsTest.class));

}
 
Example 2
Source Project: r-course   Source File: UtilsTest.java    License: MIT License 6 votes vote down vote up
/**
 * Tests Util.isJdbcPackage()
 * 
 * @throws Exception
 */
public void testIsJdbcPackage() throws Exception {
    // JDBC packages.
    assertTrue(Util.isJdbcPackage("java.sql"));
    assertTrue(Util.isJdbcPackage("javax.sql"));
    assertTrue(Util.isJdbcPackage("javax.sql.rowset"));
    assertTrue(Util.isJdbcPackage("com.mysql.jdbc"));
    assertTrue(Util.isJdbcPackage("com.mysql.jdbc"));
    assertTrue(Util.isJdbcPackage("com.mysql.jdbc.jdbc2.optional"));

    // Non-JDBC packages.
    assertFalse(Util.isJdbcPackage("java"));
    assertFalse(Util.isJdbcPackage("java.lang"));
    assertFalse(Util.isJdbcPackage("com"));
    assertFalse(Util.isJdbcPackage("com.mysql"));
}
 
Example 3
Source Project: r-course   Source File: MetaDataRegressionTest.java    License: MIT License 6 votes vote down vote up
public void testReservedWords() throws Exception {
    if (Util.isJdbc4()) {
        // there is a specific JCDB4 test for this
        return;
    }
    final String mysqlKeywords = "ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB,CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR,"
            + "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED,DETERMINISTIC,DISTINCTROW,DIV,DUAL,EACH,ELSEIF,ENCLOSED,ESCAPED,EXIT,EXPLAIN,FLOAT4,FLOAT8,"
            + "FORCE,FULLTEXT,GENERATED,HIGH_PRIORITY,HOUR_MICROSECOND,HOUR_MINUTE,HOUR_SECOND,IF,IGNORE,INDEX,INFILE,INOUT,INT1,INT2,INT3,INT4,INT8,"
            + "IO_AFTER_GTIDS,IO_BEFORE_GTIDS,ITERATE,KEYS,KILL,LEAVE,LIMIT,LINEAR,LINES,LOAD,LOCALTIME,LOCALTIMESTAMP,LOCK,LONG,LONGBLOB,LONGTEXT,LOOP,"
            + "LOW_PRIORITY,MASTER_BIND,MASTER_SSL_VERIFY_SERVER_CERT,MAXVALUE,MEDIUMBLOB,MEDIUMINT,MEDIUMTEXT,MIDDLEINT,MINUTE_MICROSECOND,MINUTE_SECOND,"
            + "MOD,MODIFIES,NO_WRITE_TO_BINLOG,OPTIMIZE,OPTIMIZER_COSTS,OPTIONALLY,OUT,OUTFILE,PARTITION,PURGE,RANGE,READS,READ_WRITE,REGEXP,RELEASE,"
            + "RENAME,REPEAT,REPLACE,REQUIRE,RESIGNAL,RETURN,RLIKE,SCHEMAS,SECOND_MICROSECOND,SENSITIVE,SEPARATOR,SHOW,SIGNAL,SPATIAL,SPECIFIC,"
            + "SQLEXCEPTION,SQLWARNING,SQL_BIG_RESULT,SQL_CALC_FOUND_ROWS,SQL_SMALL_RESULT,SSL,STARTING,STORED,STRAIGHT_JOIN,TERMINATED,TINYBLOB,TINYINT,"
            + "TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED,USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY,VARCHARACTER,VIRTUAL,WHILE,XOR,YEAR_MONTH,ZEROFILL";
    assertEquals("MySQL keywords don't match expected.", mysqlKeywords, this.conn.getMetaData().getSQLKeywords());
}
 
Example 4
Source Project: r-course   Source File: MysqlOldPasswordPlugin.java    License: MIT License 6 votes vote down vote up
public boolean nextAuthenticationStep(Buffer fromServer, List<Buffer> toServer) throws SQLException {
    toServer.clear();

    Buffer bresp = null;

    String pwd = this.password;

    if (fromServer == null || pwd == null || pwd.length() == 0) {
        bresp = new Buffer(new byte[0]);
    } else {
        bresp = new Buffer(
                StringUtils.getBytes(Util.newCrypt(pwd, fromServer.readString().substring(0, 8), this.connection.getPasswordCharacterEncoding())));

        bresp.setPosition(bresp.getBufLength());
        int oldBufLength = bresp.getBufLength();

        bresp.writeByte((byte) 0);

        bresp.setBufLength(oldBufLength + 1);
        bresp.setPosition(0);
    }
    toServer.add(bresp);

    return true;
}
 
Example 5
Source Project: r-course   Source File: WrapperBase.java    License: MIT License 6 votes vote down vote up
/**
 * Recursively checks for interfaces on the given object to determine
 * if it implements a java.sql interface, and if so, proxies the
 * instance so that we can catch and fire SQL errors.
 * 
 * @param toProxy
 * @param clazz
 */
private Object proxyIfInterfaceIsJdbc(Object toProxy, Class<?> clazz) {
    Class<?>[] interfaces = clazz.getInterfaces();

    for (Class<?> iclass : interfaces) {
        String packageName = Util.getPackageName(iclass);

        if ("java.sql".equals(packageName) || "javax.sql".equals(packageName)) {
            return Proxy.newProxyInstance(toProxy.getClass().getClassLoader(), interfaces, new ConnectionErrorFiringInvocationHandler(toProxy));
        }

        return proxyIfInterfaceIsJdbc(toProxy, iclass);
    }

    return toProxy;
}
 
Example 6
Source Project: r-course   Source File: ServerStatusDiffInterceptor.java    License: MIT License 6 votes vote down vote up
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 7
Source Project: Komondor   Source File: UtilsTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests Util.isJdbcInterface()
 * 
 * @throws Exception
 */
public void testIsJdbcInterface() throws Exception {
    // Classes directly or indirectly implementing JDBC interfaces.
    assertTrue(Util.isJdbcInterface(PreparedStatement.class));
    assertTrue(Util.isJdbcInterface(StatementImpl.class));
    assertTrue(Util.isJdbcInterface(Statement.class));
    assertTrue(Util.isJdbcInterface(ResultSetImpl.class));
    Statement s = (Statement) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { Statement.class }, new InvocationHandler() {
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return null;
        }
    });
    assertTrue(Util.isJdbcInterface(s.getClass()));

    // Classes not implementing JDBC interfaces.
    assertFalse(Util.isJdbcInterface(Util.class));
    assertFalse(Util.isJdbcInterface(UtilsTest.class));

}
 
Example 8
Source Project: Komondor   Source File: UtilsTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests Util.isJdbcPackage()
 * 
 * @throws Exception
 */
public void testIsJdbcPackage() throws Exception {
    // JDBC packages.
    assertTrue(Util.isJdbcPackage("java.sql"));
    assertTrue(Util.isJdbcPackage("javax.sql"));
    assertTrue(Util.isJdbcPackage("javax.sql.rowset"));
    assertTrue(Util.isJdbcPackage("com.mysql.jdbc"));
    assertTrue(Util.isJdbcPackage("com.mysql.jdbc"));
    assertTrue(Util.isJdbcPackage("com.mysql.jdbc.jdbc2.optional"));

    // Non-JDBC packages.
    assertFalse(Util.isJdbcPackage("java"));
    assertFalse(Util.isJdbcPackage("java.lang"));
    assertFalse(Util.isJdbcPackage("com"));
    assertFalse(Util.isJdbcPackage("com.mysql"));
}
 
Example 9
public void testReservedWords() throws Exception {
    if (Util.isJdbc4()) {
        // there is a specific JCDB4 test for this
        return;
    }
    final String mysqlKeywords = "ACCESSIBLE,ANALYZE,ASENSITIVE,BEFORE,BIGINT,BINARY,BLOB,CALL,CHANGE,CONDITION,DATABASE,DATABASES,DAY_HOUR,"
            + "DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DELAYED,DETERMINISTIC,DISTINCTROW,DIV,DUAL,EACH,ELSEIF,ENCLOSED,ESCAPED,EXIT,EXPLAIN,FLOAT4,FLOAT8,"
            + "FORCE,FULLTEXT,GENERATED,HIGH_PRIORITY,HOUR_MICROSECOND,HOUR_MINUTE,HOUR_SECOND,IF,IGNORE,INDEX,INFILE,INOUT,INT1,INT2,INT3,INT4,INT8,"
            + "IO_AFTER_GTIDS,IO_BEFORE_GTIDS,ITERATE,KEYS,KILL,LEAVE,LIMIT,LINEAR,LINES,LOAD,LOCALTIME,LOCALTIMESTAMP,LOCK,LONG,LONGBLOB,LONGTEXT,LOOP,"
            + "LOW_PRIORITY,MASTER_BIND,MASTER_SSL_VERIFY_SERVER_CERT,MAXVALUE,MEDIUMBLOB,MEDIUMINT,MEDIUMTEXT,MIDDLEINT,MINUTE_MICROSECOND,MINUTE_SECOND,"
            + "MOD,MODIFIES,NO_WRITE_TO_BINLOG,OPTIMIZE,OPTIMIZER_COSTS,OPTIONALLY,OUT,OUTFILE,PARTITION,PURGE,RANGE,READS,READ_WRITE,REGEXP,RELEASE,"
            + "RENAME,REPEAT,REPLACE,REQUIRE,RESIGNAL,RETURN,RLIKE,SCHEMAS,SECOND_MICROSECOND,SENSITIVE,SEPARATOR,SHOW,SIGNAL,SPATIAL,SPECIFIC,"
            + "SQLEXCEPTION,SQLWARNING,SQL_BIG_RESULT,SQL_CALC_FOUND_ROWS,SQL_SMALL_RESULT,SSL,STARTING,STORED,STRAIGHT_JOIN,TERMINATED,TINYBLOB,TINYINT,"
            + "TINYTEXT,TRIGGER,UNDO,UNLOCK,UNSIGNED,USE,UTC_DATE,UTC_TIME,UTC_TIMESTAMP,VARBINARY,VARCHARACTER,VIRTUAL,WHILE,XOR,YEAR_MONTH,ZEROFILL";
    assertEquals("MySQL keywords don't match expected.", mysqlKeywords, this.conn.getMetaData().getSQLKeywords());
}
 
Example 10
public boolean nextAuthenticationStep(Buffer fromServer, List<Buffer> toServer) throws SQLException {
    toServer.clear();

    Buffer bresp = null;

    String pwd = this.password;

    if (fromServer == null || pwd == null || pwd.length() == 0) {
        bresp = new Buffer(new byte[0]);
    } else {
        bresp = new Buffer(
                StringUtils.getBytes(Util.newCrypt(pwd, fromServer.readString().substring(0, 8), this.connection.getPasswordCharacterEncoding())));

        bresp.setPosition(bresp.getBufLength());
        int oldBufLength = bresp.getBufLength();

        bresp.writeByte((byte) 0);

        bresp.setBufLength(oldBufLength + 1);
        bresp.setPosition(0);
    }
    toServer.add(bresp);

    return true;
}
 
Example 11
Source Project: Komondor   Source File: WrapperBase.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Recursively checks for interfaces on the given object to determine
 * if it implements a java.sql interface, and if so, proxies the
 * instance so that we can catch and fire SQL errors.
 * 
 * @param toProxy
 * @param clazz
 */
private Object proxyIfInterfaceIsJdbc(Object toProxy, Class<?> clazz) {
    Class<?>[] interfaces = clazz.getInterfaces();

    for (Class<?> iclass : interfaces) {
        String packageName = Util.getPackageName(iclass);

        if ("java.sql".equals(packageName) || "javax.sql".equals(packageName)) {
            return Proxy.newProxyInstance(toProxy.getClass().getClassLoader(), interfaces, new ConnectionErrorFiringInvocationHandler(toProxy));
        }

        return proxyIfInterfaceIsJdbc(toProxy, iclass);
    }

    return toProxy;
}
 
Example 12
private void populateMapWithSessionStatusValues(Connection connection, Map<String, String> toPopulate) throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
        toPopulate.clear();

        stmt = connection.createStatement();
        rs = stmt.executeQuery("SHOW SESSION STATUS");
        Util.resultSetToMap(toPopulate, rs);
    } finally {
        if (rs != null) {
            rs.close();
        }

        if (stmt != null) {
            stmt.close();
        }
    }
}
 
Example 13
Source Project: r-course   Source File: ConnectionTest.java    License: MIT License 5 votes vote down vote up
/**
 * Checks if setting useCursorFetch to "true" automatically enables
 * server-side prepared statements.
 */

public void testCouplingOfCursorFetch() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    Connection fetchConn = null;

    try {
        Properties props = new Properties();
        props.setProperty("useServerPrepStmts", "false"); // force the issue
        props.setProperty("useCursorFetch", "true");
        fetchConn = getConnectionWithProps(props);

        String classname = "com.mysql.jdbc.ServerPreparedStatement";

        if (Util.isJdbc42()) {
            classname = "com.mysql.jdbc.JDBC42ServerPreparedStatement";
        } else if (Util.isJdbc4()) {
            classname = "com.mysql.jdbc.JDBC4ServerPreparedStatement";
        }

        assertEquals(classname, fetchConn.prepareStatement("SELECT 1").getClass().getName());
    } finally {
        if (fetchConn != null) {
            fetchConn.close();
        }
    }
}
 
Example 14
Source Project: r-course   Source File: StatementRegressionTest.java    License: MIT License 5 votes vote down vote up
/**
 * Tests fix for BUG#73163 - IndexOutOfBoundsException thrown preparing statement.
 * 
 * This bug occurs only if running with Java6+. Duplicated in testsuite.regression.StatementRegressionTest.testBug73163().
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug73163() throws Exception {
    try {
        stmt = conn.prepareStatement("LOAD DATA INFILE ? INTO TABLE testBug73163");
    } catch (SQLException e) {
        if (e.getCause() instanceof IndexOutOfBoundsException && Util.isJdbc4()) {
            fail("IOOBE thrown in Java6+ while preparing a LOAD DATA statement with placeholders.");
        } else {
            throw e;
        }
    }
}
 
Example 15
Source Project: r-course   Source File: MetaDataRegressionTest.java    License: MIT License 5 votes vote down vote up
/**
 * Tests fix for BUG#17248345 - GETFUNCTIONCOLUMNS() METHOD RETURNS COLUMNS OF PROCEDURE. (this happens when
 * functions and procedures have a common name)
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug17248345() throws Exception {
    if (Util.isJdbc4()) {
        // there is a specific JCDB4 test for this
        return;
    }

    Connection testConn;

    // create one stored procedure and one function with same name
    createFunction("testBug17248345", "(funccol INT) RETURNS INT DETERMINISTIC RETURN 1");
    createProcedure("testBug17248345", "(IN proccol INT) SELECT 1");

    // test with standard connection (getProceduresReturnsFunctions=true & useInformationSchema=false)
    assertFalse("Property useInformationSchema should be false", ((ConnectionProperties) this.conn).getUseInformationSchema());
    assertTrue("Property getProceduresReturnsFunctions should be true", ((ConnectionProperties) this.conn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(this.conn);

    // test with property useInformationSchema=true (getProceduresReturnsFunctions=true)
    testConn = getConnectionWithProps("useInformationSchema=true");
    assertTrue("Property useInformationSchema should be true", ((ConnectionProperties) testConn).getUseInformationSchema());
    assertTrue("Property getProceduresReturnsFunctions should be true", ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(testConn);
    testConn.close();

    // test with property getProceduresReturnsFunctions=false (useInformationSchema=false)
    testConn = getConnectionWithProps("getProceduresReturnsFunctions=false");
    assertFalse("Property useInformationSchema should be false", ((ConnectionProperties) testConn).getUseInformationSchema());
    assertFalse("Property getProceduresReturnsFunctions should be false", ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(testConn);
    testConn.close();

    // test with property useInformationSchema=true & getProceduresReturnsFunctions=false
    testConn = getConnectionWithProps("useInformationSchema=true,getProceduresReturnsFunctions=false");
    assertTrue("Property useInformationSchema should be true", ((ConnectionProperties) testConn).getUseInformationSchema());
    assertFalse("Property getProceduresReturnsFunctions should be false", ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(testConn);
    testConn.close();
}
 
Example 16
Source Project: r-course   Source File: LogUtils.java    License: MIT License 5 votes vote down vote up
public static String findCallingClassAndMethod(Throwable t) {
    String stackTraceAsString = Util.stackTraceToString(t);

    String callingClassAndMethod = CALLER_INFORMATION_NOT_AVAILABLE;

    int endInternalMethods = stackTraceAsString.lastIndexOf("com.mysql.jdbc");

    if (endInternalMethods != -1) {
        int endOfLine = -1;
        int compliancePackage = stackTraceAsString.indexOf("com.mysql.jdbc.compliance", endInternalMethods);

        if (compliancePackage != -1) {
            endOfLine = compliancePackage - LINE_SEPARATOR_LENGTH;
        } else {
            endOfLine = stackTraceAsString.indexOf(LINE_SEPARATOR, endInternalMethods);
        }

        if (endOfLine != -1) {
            int nextEndOfLine = stackTraceAsString.indexOf(LINE_SEPARATOR, endOfLine + LINE_SEPARATOR_LENGTH);

            if (nextEndOfLine != -1) {
                callingClassAndMethod = stackTraceAsString.substring(endOfLine + LINE_SEPARATOR_LENGTH, nextEndOfLine);
            } else {
                callingClassAndMethod = stackTraceAsString.substring(endOfLine + LINE_SEPARATOR_LENGTH);
            }
        }
    }

    if (!callingClassAndMethod.startsWith("\tat ") && !callingClassAndMethod.startsWith("at ")) {
        return "at " + callingClassAndMethod;
    }

    return callingClassAndMethod;
}
 
Example 17
Source Project: r-course   Source File: SuspendableXAConnection.java    License: MIT License 5 votes vote down vote up
protected static SuspendableXAConnection getInstance(Connection mysqlConnection) throws SQLException {
    if (!Util.isJdbc4()) {
        return new SuspendableXAConnection(mysqlConnection);
    }

    return (SuspendableXAConnection) Util.handleNewInstance(JDBC_4_XA_CONNECTION_WRAPPER_CTOR, new Object[] { mysqlConnection },
            mysqlConnection.getExceptionInterceptor());
}
 
Example 18
Source Project: r-course   Source File: MysqlXAConnection.java    License: MIT License 5 votes vote down vote up
protected static MysqlXAConnection getInstance(com.mysql.jdbc.Connection mysqlConnection, boolean logXaCommands) throws SQLException {
    if (!Util.isJdbc4()) {
        return new MysqlXAConnection(mysqlConnection, logXaCommands);
    }

    return (MysqlXAConnection) Util.handleNewInstance(JDBC_4_XA_CONNECTION_WRAPPER_CTOR, new Object[] { mysqlConnection, Boolean.valueOf(logXaCommands) },
            mysqlConnection.getExceptionInterceptor());
}
 
Example 19
Source Project: r-course   Source File: PreparedStatementWrapper.java    License: MIT License 5 votes vote down vote up
protected static PreparedStatementWrapper getInstance(ConnectionWrapper c, MysqlPooledConnection conn, PreparedStatement toWrap) throws SQLException {
    if (!Util.isJdbc4()) {
        return new PreparedStatementWrapper(c, conn, toWrap);
    }

    return (PreparedStatementWrapper) Util.handleNewInstance(JDBC_4_PREPARED_STATEMENT_WRAPPER_CTOR, new Object[] { c, conn, toWrap },
            conn.getExceptionInterceptor());
}
 
Example 20
Source Project: r-course   Source File: CallableStatementWrapper.java    License: MIT License 5 votes vote down vote up
protected static CallableStatementWrapper getInstance(ConnectionWrapper c, MysqlPooledConnection conn, CallableStatement toWrap) throws SQLException {
    if (!Util.isJdbc4()) {
        return new CallableStatementWrapper(c, conn, toWrap);
    }

    return (CallableStatementWrapper) Util.handleNewInstance(JDBC_4_CALLABLE_STATEMENT_WRAPPER_CTOR, new Object[] { c, conn, toWrap },
            conn.getExceptionInterceptor());
}
 
Example 21
Source Project: r-course   Source File: StatementWrapper.java    License: MIT License 5 votes vote down vote up
protected static StatementWrapper getInstance(ConnectionWrapper c, MysqlPooledConnection conn, Statement toWrap) throws SQLException {
    if (!Util.isJdbc4()) {
        return new StatementWrapper(c, conn, toWrap);
    }

    return (StatementWrapper) Util.handleNewInstance(JDBC_4_STATEMENT_WRAPPER_CTOR, new Object[] { c, conn, toWrap }, conn.getExceptionInterceptor());
}
 
Example 22
Source Project: r-course   Source File: MysqlPooledConnection.java    License: MIT License 5 votes vote down vote up
protected static MysqlPooledConnection getInstance(com.mysql.jdbc.Connection connection) throws SQLException {
    if (!Util.isJdbc4()) {
        return new MysqlPooledConnection(connection);
    }

    return (MysqlPooledConnection) Util.handleNewInstance(JDBC_4_POOLED_CONNECTION_WRAPPER_CTOR, new Object[] { connection },
            connection.getExceptionInterceptor());
}
 
Example 23
Source Project: r-course   Source File: ConnectionWrapper.java    License: MIT License 5 votes vote down vote up
protected static ConnectionWrapper getInstance(MysqlPooledConnection mysqlPooledConnection, Connection mysqlConnection, boolean forXa) throws SQLException {
    if (!Util.isJdbc4()) {
        return new ConnectionWrapper(mysqlPooledConnection, mysqlConnection, forXa);
    }

    return (ConnectionWrapper) Util.handleNewInstance(JDBC_4_CONNECTION_WRAPPER_CTOR,
            new Object[] { mysqlPooledConnection, mysqlConnection, Boolean.valueOf(forXa) }, mysqlPooledConnection.getExceptionInterceptor());
}
 
Example 24
Source Project: Komondor   Source File: ConnectionTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if setting useCursorFetch to "true" automatically enables
 * server-side prepared statements.
 */

public void testCouplingOfCursorFetch() throws Exception {
    if (!versionMeetsMinimum(5, 0)) {
        return;
    }

    Connection fetchConn = null;

    try {
        Properties props = new Properties();
        props.setProperty("useServerPrepStmts", "false"); // force the issue
        props.setProperty("useCursorFetch", "true");
        fetchConn = getConnectionWithProps(props);

        String classname = "com.mysql.jdbc.ServerPreparedStatement";

        if (Util.isJdbc42()) {
            classname = "com.mysql.jdbc.JDBC42ServerPreparedStatement";
        } else if (Util.isJdbc4()) {
            classname = "com.mysql.jdbc.JDBC4ServerPreparedStatement";
        }

        assertEquals(classname, fetchConn.prepareStatement("SELECT 1").getClass().getName());
    } finally {
        if (fetchConn != null) {
            fetchConn.close();
        }
    }
}
 
Example 25
/**
 * Tests fix for BUG#73163 - IndexOutOfBoundsException thrown preparing statement.
 * 
 * This bug occurs only if running with Java6+. Duplicated in testsuite.regression.StatementRegressionTest.testBug73163().
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug73163() throws Exception {
    try {
        stmt = conn.prepareStatement("LOAD DATA INFILE ? INTO TABLE testBug73163");
    } catch (SQLException e) {
        if (e.getCause() instanceof IndexOutOfBoundsException && Util.isJdbc4()) {
            fail("IOOBE thrown in Java6+ while preparing a LOAD DATA statement with placeholders.");
        } else {
            throw e;
        }
    }
}
 
Example 26
/**
 * Tests fix for BUG#17248345 - GETFUNCTIONCOLUMNS() METHOD RETURNS COLUMNS OF PROCEDURE. (this happens when
 * functions and procedures have a common name)
 * 
 * @throws Exception
 *             if the test fails.
 */
public void testBug17248345() throws Exception {
    if (Util.isJdbc4()) {
        // there is a specific JCDB4 test for this
        return;
    }

    Connection testConn;

    // create one stored procedure and one function with same name
    createFunction("testBug17248345", "(funccol INT) RETURNS INT DETERMINISTIC RETURN 1");
    createProcedure("testBug17248345", "(IN proccol INT) SELECT 1");

    // test with standard connection (getProceduresReturnsFunctions=true & useInformationSchema=false)
    assertFalse("Property useInformationSchema should be false", ((ConnectionProperties) this.conn).getUseInformationSchema());
    assertTrue("Property getProceduresReturnsFunctions should be true", ((ConnectionProperties) this.conn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(this.conn);

    // test with property useInformationSchema=true (getProceduresReturnsFunctions=true)
    testConn = getConnectionWithProps("useInformationSchema=true");
    assertTrue("Property useInformationSchema should be true", ((ConnectionProperties) testConn).getUseInformationSchema());
    assertTrue("Property getProceduresReturnsFunctions should be true", ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(testConn);
    testConn.close();

    // test with property getProceduresReturnsFunctions=false (useInformationSchema=false)
    testConn = getConnectionWithProps("getProceduresReturnsFunctions=false");
    assertFalse("Property useInformationSchema should be false", ((ConnectionProperties) testConn).getUseInformationSchema());
    assertFalse("Property getProceduresReturnsFunctions should be false", ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(testConn);
    testConn.close();

    // test with property useInformationSchema=true & getProceduresReturnsFunctions=false
    testConn = getConnectionWithProps("useInformationSchema=true,getProceduresReturnsFunctions=false");
    assertTrue("Property useInformationSchema should be true", ((ConnectionProperties) testConn).getUseInformationSchema());
    assertFalse("Property getProceduresReturnsFunctions should be false", ((ConnectionProperties) testConn).getGetProceduresReturnsFunctions());
    checkMetaDataInfoForBug17248345(testConn);
    testConn.close();
}
 
Example 27
Source Project: Komondor   Source File: LogUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static String findCallingClassAndMethod(Throwable t) {
    String stackTraceAsString = Util.stackTraceToString(t);

    String callingClassAndMethod = CALLER_INFORMATION_NOT_AVAILABLE;

    int endInternalMethods = stackTraceAsString.lastIndexOf("com.mysql.jdbc");

    if (endInternalMethods != -1) {
        int endOfLine = -1;
        int compliancePackage = stackTraceAsString.indexOf("com.mysql.jdbc.compliance", endInternalMethods);

        if (compliancePackage != -1) {
            endOfLine = compliancePackage - LINE_SEPARATOR_LENGTH;
        } else {
            endOfLine = stackTraceAsString.indexOf(LINE_SEPARATOR, endInternalMethods);
        }

        if (endOfLine != -1) {
            int nextEndOfLine = stackTraceAsString.indexOf(LINE_SEPARATOR, endOfLine + LINE_SEPARATOR_LENGTH);

            if (nextEndOfLine != -1) {
                callingClassAndMethod = stackTraceAsString.substring(endOfLine + LINE_SEPARATOR_LENGTH, nextEndOfLine);
            } else {
                callingClassAndMethod = stackTraceAsString.substring(endOfLine + LINE_SEPARATOR_LENGTH);
            }
        }
    }

    if (!callingClassAndMethod.startsWith("\tat ") && !callingClassAndMethod.startsWith("at ")) {
        return "at " + callingClassAndMethod;
    }

    return callingClassAndMethod;
}
 
Example 28
protected static SuspendableXAConnection getInstance(Connection mysqlConnection) throws SQLException {
    if (!Util.isJdbc4()) {
        return new SuspendableXAConnection(mysqlConnection);
    }

    return (SuspendableXAConnection) Util.handleNewInstance(JDBC_4_XA_CONNECTION_WRAPPER_CTOR, new Object[] { mysqlConnection },
            mysqlConnection.getExceptionInterceptor());
}
 
Example 29
Source Project: Komondor   Source File: MysqlXAConnection.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected static MysqlXAConnection getInstance(com.mysql.jdbc.Connection mysqlConnection, boolean logXaCommands) throws SQLException {
    if (!Util.isJdbc4()) {
        return new MysqlXAConnection(mysqlConnection, logXaCommands);
    }

    return (MysqlXAConnection) Util.handleNewInstance(JDBC_4_XA_CONNECTION_WRAPPER_CTOR, new Object[] { mysqlConnection, Boolean.valueOf(logXaCommands) },
            mysqlConnection.getExceptionInterceptor());
}
 
Example 30
protected static PreparedStatementWrapper getInstance(ConnectionWrapper c, MysqlPooledConnection conn, PreparedStatement toWrap) throws SQLException {
    if (!Util.isJdbc4()) {
        return new PreparedStatementWrapper(c, conn, toWrap);
    }

    return (PreparedStatementWrapper) Util.handleNewInstance(JDBC_4_PREPARED_STATEMENT_WRAPPER_CTOR, new Object[] { c, conn, toWrap },
            conn.getExceptionInterceptor());
}