com.mysql.jdbc.ResultSetInternalMethods Java Examples

The following examples show how to use com.mysql.jdbc.ResultSetInternalMethods. 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: ConnectionTest.java    From r-course with MIT License 6 votes vote down vote up
@Override
public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection)
        throws SQLException {
    if (sql == null && interceptedStatement instanceof com.mysql.jdbc.PreparedStatement) {
        sql = ((com.mysql.jdbc.PreparedStatement) interceptedStatement).asSql();
    }

    int p;
    if (sql != null && (p = sql.indexOf("testEnableEscapeProcessing:")) != -1) {
        int tst = Integer.parseInt(sql.substring(sql.indexOf('(', p) + 1, sql.indexOf(')', p)));
        boolean enableEscapeProcessing = (tst & 0x1) != 0;
        boolean processEscapeCodesForPrepStmts = (tst & 0x2) != 0;
        boolean useServerPrepStmts = (tst & 0x4) != 0;
        boolean isPreparedStatement = interceptedStatement instanceof PreparedStatement;

        String testCase = String.format("Case: %d [ %s | %s | %s ]/%s", tst, enableEscapeProcessing ? "enEscProc" : "-",
                processEscapeCodesForPrepStmts ? "procEscProcPS" : "-", useServerPrepStmts ? "useSSPS" : "-",
                isPreparedStatement ? "PreparedStatement" : "Statement");

        boolean escapeProcessingDone = sql.indexOf('{') == -1;
        assertTrue(testCase, isPreparedStatement && processEscapeCodesForPrepStmts == escapeProcessingDone
                || !isPreparedStatement && enableEscapeProcessing == escapeProcessingDone);
    }
    return super.preProcess(sql, interceptedStatement, connection);
}
 
Example #2
Source File: ConnectionTest.java    From Komondor with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection)
        throws SQLException {
    if (sql == null && interceptedStatement instanceof com.mysql.jdbc.PreparedStatement) {
        sql = ((com.mysql.jdbc.PreparedStatement) interceptedStatement).asSql();
    }

    int p;
    if (sql != null && (p = sql.indexOf("testEnableEscapeProcessing:")) != -1) {
        int tst = Integer.parseInt(sql.substring(sql.indexOf('(', p) + 1, sql.indexOf(')', p)));
        boolean enableEscapeProcessing = (tst & 0x1) != 0;
        boolean processEscapeCodesForPrepStmts = (tst & 0x2) != 0;
        boolean useServerPrepStmts = (tst & 0x4) != 0;
        boolean isPreparedStatement = interceptedStatement instanceof PreparedStatement;

        String testCase = String.format("Case: %d [ %s | %s | %s ]/%s", tst, enableEscapeProcessing ? "enEscProc" : "-",
                processEscapeCodesForPrepStmts ? "procEscProcPS" : "-", useServerPrepStmts ? "useSSPS" : "-",
                isPreparedStatement ? "PreparedStatement" : "Statement");

        boolean escapeProcessingDone = sql.indexOf('{') == -1;
        assertTrue(testCase, isPreparedStatement && processEscapeCodesForPrepStmts == escapeProcessingDone
                || !isPreparedStatement && enableEscapeProcessing == escapeProcessingDone);
    }
    return super.preProcess(sql, interceptedStatement, connection);
}
 
Example #3
Source File: ServerStatusDiffInterceptor.java    From r-course with MIT License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {

        if (connection.versionMeetsMinimum(5, 0, 2)) {
            populateMapWithSessionStatusValues(connection, this.preExecuteValues);
        }

        return null; // we don't actually modify a result set
    }
 
Example #4
Source File: TracingStatementInterceptor.java    From brave with Apache License 2.0 6 votes vote down vote up
/**
 * Uses {@link ThreadLocalSpan} as there's no attribute namespace shared between callbacks, but
 * all callbacks happen on the same thread.
 *
 * <p>Uses {@link ThreadLocalSpan#CURRENT_TRACER} and this interceptor initializes before
 * tracing.
 */
@Override
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement,
  Connection connection) {
  // Gets the next span (and places it in scope) so code between here and postProcess can read it
  Span span = ThreadLocalSpan.CURRENT_TRACER.next();
  if (span == null || span.isNoop()) return null;

  // When running a prepared statement, sql will be null and we must fetch the sql from the statement itself
  if (interceptedStatement instanceof PreparedStatement) {
    sql = ((PreparedStatement) interceptedStatement).getPreparedSql();
  }
  int spaceIndex = sql.indexOf(' '); // Allow span names of single-word statements like COMMIT
  span.kind(CLIENT).name(spaceIndex == -1 ? sql : sql.substring(0, spaceIndex));
  span.tag("sql.query", sql);
  parseServerIpAndPort(connection, span);
  span.start();
  return null;
}
 
Example #5
Source File: SessionAssociationInterceptor.java    From Komondor with GNU General Public License v3.0 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example #6
Source File: SessionAssociationInterceptor.java    From r-course with MIT License 6 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    String key = getSessionKey();

    if (key != null && !key.equals(this.currentSessionKey)) {
        PreparedStatement pstmt = connection.clientPrepareStatement("SET @mysql_proxy_session=?");

        try {
            pstmt.setString(1, key);
            pstmt.execute();
        } finally {
            pstmt.close();
        }

        this.currentSessionKey = key;
    }

    return null;
}
 
Example #7
Source File: MetaDataRegressionTest.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection conn)
        throws SQLException {
    if (interceptedStatement instanceof com.mysql.jdbc.PreparedStatement) {
        sql = ((com.mysql.jdbc.PreparedStatement) interceptedStatement).getPreparedSql();
        assertTrue("Assereet failed on: " + sql,
                StringUtils.indexOfIgnoreCase(0, sql, "WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME LIKE ?") > -1);
    }
    return null;
}
 
Example #8
Source File: CharsetRegressionTest.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection)
        throws SQLException {
    if (sql.contains("SET NAMES utf8") && !sql.contains("utf8mb4")) {
        throw new SQLException("Character set statement issued: " + sql);
    }
    return null;
}
 
Example #9
Source File: ResultSetScannerInterceptor.java    From r-course with MIT License 5 votes vote down vote up
public ResultSetInternalMethods postProcess(String sql, Statement interceptedStatement, ResultSetInternalMethods originalResultSet, Connection connection)
        throws SQLException {

    // requirement of anonymous class
    final ResultSetInternalMethods finalResultSet = originalResultSet;

    return (ResultSetInternalMethods) Proxy.newProxyInstance(originalResultSet.getClass().getClassLoader(), new Class[] { ResultSetInternalMethods.class },
            new InvocationHandler() {

                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

                    if ("equals".equals(method.getName())) {
                        // Let args[0] "unwrap" to its InvocationHandler if it is a proxy.
                        return args[0].equals(this);
                    }

                    Object invocationResult = method.invoke(finalResultSet, args);

                    String methodName = method.getName();

                    if (invocationResult != null && invocationResult instanceof String || "getString".equals(methodName) || "getObject".equals(methodName)
                            || "getObjectStoredProc".equals(methodName)) {
                        Matcher matcher = ResultSetScannerInterceptor.this.regexP.matcher(invocationResult.toString());

                        if (matcher.matches()) {
                            throw new SQLException("value disallowed by filter");
                        }
                    }

                    return invocationResult;
                }
            });

}
 
Example #10
Source File: ResultSetScannerInterceptor.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
public ResultSetInternalMethods postProcess(String sql, Statement interceptedStatement, ResultSetInternalMethods originalResultSet, Connection connection)
        throws SQLException {

    // requirement of anonymous class
    final ResultSetInternalMethods finalResultSet = originalResultSet;

    return (ResultSetInternalMethods) Proxy.newProxyInstance(originalResultSet.getClass().getClassLoader(), new Class[] { ResultSetInternalMethods.class },
            new InvocationHandler() {

                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

                    if ("equals".equals(method.getName())) {
                        // Let args[0] "unwrap" to its InvocationHandler if it is a proxy.
                        return args[0].equals(this);
                    }

                    Object invocationResult = method.invoke(finalResultSet, args);

                    String methodName = method.getName();

                    if (invocationResult != null && invocationResult instanceof String || "getString".equals(methodName) || "getObject".equals(methodName)
                            || "getObjectStoredProc".equals(methodName)) {
                        Matcher matcher = ResultSetScannerInterceptor.this.regexP.matcher(invocationResult.toString());

                        if (matcher.matches()) {
                            throw new SQLException("value disallowed by filter");
                        }
                    }

                    return invocationResult;
                }
            });

}
 
Example #11
Source File: ServerStatusDiffInterceptor.java    From Komondor with GNU General Public License v3.0 5 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {

        if (connection.versionMeetsMinimum(5, 0, 2)) {
            populateMapWithSessionStatusValues(connection, this.preExecuteValues);
        }

        return null; // we don't actually modify a result set
    }
 
Example #12
Source File: MetaDataRegressionTest.java    From r-course with MIT License 5 votes vote down vote up
@Override
public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection conn)
        throws SQLException {
    if (interceptedStatement instanceof com.mysql.jdbc.PreparedStatement) {
        sql = ((com.mysql.jdbc.PreparedStatement) interceptedStatement).getPreparedSql();
        assertTrue("Assereet failed on: " + sql,
                StringUtils.indexOfIgnoreCase(0, sql, "WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME LIKE ?") > -1);
    }
    return null;
}
 
Example #13
Source File: CharsetRegressionTest.java    From r-course with MIT License 5 votes vote down vote up
@Override
public ResultSetInternalMethods preProcess(String sql, com.mysql.jdbc.Statement interceptedStatement, com.mysql.jdbc.Connection connection)
        throws SQLException {
    if (sql.contains("SET NAMES utf8") && !sql.contains("utf8mb4")) {
        throw new SQLException("Character set statement issued: " + sql);
    }
    return null;
}
 
Example #14
Source File: TracingStatementInterceptor.java    From brave with Apache License 2.0 5 votes vote down vote up
@Override
public ResultSetInternalMethods postProcess(String sql, Statement interceptedStatement,
  ResultSetInternalMethods originalResultSet, Connection connection, int warningCount,
  boolean noIndexUsed, boolean noGoodIndexUsed, SQLException statementException) {
  Span span = ThreadLocalSpan.CURRENT_TRACER.remove();
  if (span == null || span.isNoop()) return null;

  if (statementException != null) {
    span.error(statementException);
    span.tag("error", Integer.toString(statementException.getErrorCode()));
  }
  span.finish();

  return null;
}
 
Example #15
Source File: ResultSetScannerInterceptor.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    // we don't care about this event

    return null;
}
 
Example #16
Source File: SessionAssociationInterceptor.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
public ResultSetInternalMethods postProcess(String sql, Statement interceptedStatement, ResultSetInternalMethods originalResultSet, Connection connection)
        throws SQLException {
    return null;
}
 
Example #17
Source File: FabricMySQLConnectionProxy.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
public void initializeResultsMetadataFromCache(String sql, CachedResultSetMetaData cachedMetaData, ResultSetInternalMethods resultSet) throws SQLException {
}
 
Example #18
Source File: FabricMySQLConnectionProxy.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
public ResultSetInternalMethods execSQL(StatementImpl callingStatement, String sql, int maxRows, Buffer packet, int resultSetType, int resultSetConcurrency,
        boolean streamResults, String catalog, Field[] cachedMetadata, boolean isBatch) throws SQLException {
    return getActiveMySQLConnectionChecked().execSQL(callingStatement, sql, maxRows, packet, resultSetType, resultSetConcurrency, streamResults, catalog,
            cachedMetadata, isBatch);
}
 
Example #19
Source File: BaseStatementInterceptor.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
public ResultSetInternalMethods postProcess(String sql, Statement interceptedStatement, ResultSetInternalMethods originalResultSet, Connection connection,
        int warningCount, boolean noIndexUsed, boolean noGoodIndexUsed, SQLException statementException) throws SQLException {
    return originalResultSet;
}
 
Example #20
Source File: FabricMySQLConnectionProxy.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
public ResultSetInternalMethods execSQL(StatementImpl callingStatement, String sql, int maxRows, Buffer packet, int resultSetType, int resultSetConcurrency,
        boolean streamResults, String catalog, Field[] cachedMetadata) throws SQLException {
    return getActiveMySQLConnectionChecked().execSQL(callingStatement, sql, maxRows, packet, resultSetType, resultSetConcurrency, streamResults, catalog,
            cachedMetadata);
}
 
Example #21
Source File: BaseStatementInterceptor.java    From r-course with MIT License 4 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    return null;
}
 
Example #22
Source File: BaseStatementInterceptor.java    From Komondor with GNU General Public License v3.0 4 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    return null;
}
 
Example #23
Source File: ResultSetScannerInterceptor.java    From r-course with MIT License 4 votes vote down vote up
public ResultSetInternalMethods preProcess(String sql, Statement interceptedStatement, Connection connection) throws SQLException {
    // we don't care about this event

    return null;
}
 
Example #24
Source File: SessionAssociationInterceptor.java    From r-course with MIT License 4 votes vote down vote up
public ResultSetInternalMethods postProcess(String sql, Statement interceptedStatement, ResultSetInternalMethods originalResultSet, Connection connection)
        throws SQLException {
    return null;
}
 
Example #25
Source File: FabricMySQLConnectionProxy.java    From r-course with MIT License 4 votes vote down vote up
public void initializeResultsMetadataFromCache(String sql, CachedResultSetMetaData cachedMetaData, ResultSetInternalMethods resultSet) throws SQLException {
}
 
Example #26
Source File: FabricMySQLConnectionProxy.java    From r-course with MIT License 4 votes vote down vote up
public ResultSetInternalMethods execSQL(StatementImpl callingStatement, String sql, int maxRows, Buffer packet, int resultSetType, int resultSetConcurrency,
        boolean streamResults, String catalog, Field[] cachedMetadata, boolean isBatch) throws SQLException {
    return getActiveMySQLConnectionChecked().execSQL(callingStatement, sql, maxRows, packet, resultSetType, resultSetConcurrency, streamResults, catalog,
            cachedMetadata, isBatch);
}
 
Example #27
Source File: FabricMySQLConnectionProxy.java    From r-course with MIT License 4 votes vote down vote up
public ResultSetInternalMethods execSQL(StatementImpl callingStatement, String sql, int maxRows, Buffer packet, int resultSetType, int resultSetConcurrency,
        boolean streamResults, String catalog, Field[] cachedMetadata) throws SQLException {
    return getActiveMySQLConnectionChecked().execSQL(callingStatement, sql, maxRows, packet, resultSetType, resultSetConcurrency, streamResults, catalog,
            cachedMetadata);
}
 
Example #28
Source File: BaseStatementInterceptor.java    From r-course with MIT License 4 votes vote down vote up
public ResultSetInternalMethods postProcess(String sql, Statement interceptedStatement, ResultSetInternalMethods originalResultSet, Connection connection,
        int warningCount, boolean noIndexUsed, boolean noGoodIndexUsed, SQLException statementException) throws SQLException {
    return originalResultSet;
}
 
Example #29
Source File: ServerStatusDiffInterceptor.java    From r-course with MIT License 3 votes vote down vote up
public ResultSetInternalMethods postProcess(String sql, Statement interceptedStatement, ResultSetInternalMethods originalResultSet, Connection connection)
        throws SQLException {

    if (connection.versionMeetsMinimum(5, 0, 2)) {
        populateMapWithSessionStatusValues(connection, this.postExecuteValues);

        connection.getLog().logInfo("Server status change for statement:\n" + Util.calculateDifferences(this.preExecuteValues, this.postExecuteValues));
    }

    return null; // we don't actually modify a result set

}
 
Example #30
Source File: ServerStatusDiffInterceptor.java    From Komondor with GNU General Public License v3.0 3 votes vote down vote up
public ResultSetInternalMethods postProcess(String sql, Statement interceptedStatement, ResultSetInternalMethods originalResultSet, Connection connection)
        throws SQLException {

    if (connection.versionMeetsMinimum(5, 0, 2)) {
        populateMapWithSessionStatusValues(connection, this.postExecuteValues);

        connection.getLog().logInfo("Server status change for statement:\n" + Util.calculateDifferences(this.preExecuteValues, this.postExecuteValues));
    }

    return null; // we don't actually modify a result set

}