com.mysql.jdbc.Util Java Examples

The following examples show how to use com.mysql.jdbc.Util. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MysqlOldPasswordPlugin.java    From r-course with 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 #2
Source File: ServerStatusDiffInterceptor.java    From r-course with 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 #3
Source File: UtilsTest.java    From Komondor with 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 #4
Source File: WrapperBase.java    From r-course with 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 #5
Source File: UtilsTest.java    From Komondor with 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 #6
Source File: MetaDataRegressionTest.java    From Komondor with GNU General Public License v3.0 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 #7
Source File: MysqlOldPasswordPlugin.java    From Komondor with GNU General Public License v3.0 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 #8
Source File: MetaDataRegressionTest.java    From r-course with 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 #9
Source File: WrapperBase.java    From Komondor with 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 #10
Source File: UtilsTest.java    From r-course with 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 #11
Source File: UtilsTest.java    From r-course with 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 #12
Source File: ServerStatusDiffInterceptor.java    From Komondor with GNU General Public License v3.0 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 #13
Source File: MysqlUtils.java    From clearpool with GNU General Public License v3.0 5 votes vote down vote up
public static XAConnection mysqlXAConnection(Connection con) throws SQLException {
  ConnectionImpl mysqlConn = (ConnectionImpl) con;
  if (mysqlConn.getPinGlobalTxToPhysicalConnection()) {
    if (!Util.isJdbc4()) {
      return new SuspendableXAConnection(mysqlConn);
    }
    return new JDBC4SuspendableXAConnection(mysqlConn);
  }
  return new MysqlXAConnection(mysqlConn, false);
}
 
Example #14
Source File: MysqlXAConnection.java    From Komondor with 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 #15
Source File: SuspendableXAConnection.java    From Komondor with GNU General Public License v3.0 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 #16
Source File: LogUtils.java    From Komondor with 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 #17
Source File: MysqlPooledConnection.java    From Komondor with GNU General Public License v3.0 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 #18
Source File: ConnectionWrapper.java    From Komondor with GNU General Public License v3.0 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 #19
Source File: MetaDataRegressionTest.java    From Komondor with GNU General Public License v3.0 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 #20
Source File: StatementRegressionTest.java    From Komondor with GNU General Public License v3.0 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 #21
Source File: PreparedStatementWrapper.java    From Komondor with GNU General Public License v3.0 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 #22
Source File: ConnectionTest.java    From r-course with 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 #23
Source File: CallableStatementWrapper.java    From Komondor with GNU General Public License v3.0 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 #24
Source File: ConnectionTest.java    From Komondor with 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
Source File: StatementWrapper.java    From Komondor with GNU General Public License v3.0 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 #26
Source File: MetaDataRegressionTest.java    From r-course with 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 #27
Source File: LogUtils.java    From r-course with 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 #28
Source File: SuspendableXAConnection.java    From r-course with 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 #29
Source File: MysqlXAConnection.java    From r-course with 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 #30
Source File: PreparedStatementWrapper.java    From r-course with 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());
}