com.mysql.cj.protocol.ServerSession Java Examples
The following examples show how to use
com.mysql.cj.protocol.ServerSession.
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: MySQLQueryInterceptor.java From core-ng-project with Apache License 2.0 | 6 votes |
@Override public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { boolean noIndexUsed = serverSession.noIndexUsed(); boolean badIndexUsed = serverSession.noGoodIndexUsed(); if (noIndexUsed || badIndexUsed) { boolean suppress = suppressSlowSQLWarning(); String message = noIndexUsed ? "no index used" : "bad index used"; String sqlValue = sql.get(); if (suppress) { LOGGER.debug("{}, sql={}", message, sqlValue); } else { LOGGER.warn(errorCode("SLOW_SQL"), "{}, sql={}", message, sqlValue); } } return null; }
Example #2
Source File: ExceptionFactory.java From FoxTelem with GNU General Public License v3.0 | 6 votes |
public static CJCommunicationsException createCommunicationsException(PropertySet propertySet, ServerSession serverSession, PacketSentTimeHolder packetSentTimeHolder, PacketReceivedTimeHolder packetReceivedTimeHolder, Throwable cause, ExceptionInterceptor interceptor) { CJCommunicationsException sqlEx = createException(CJCommunicationsException.class, null, cause, interceptor); sqlEx.init(propertySet, serverSession, packetSentTimeHolder, packetReceivedTimeHolder); // TODO: Decide whether we need to intercept exceptions at this level //if (interceptor != null) { // @SuppressWarnings("unchecked") // T interceptedEx = (T) interceptor.interceptException(sqlEx, null); // if (interceptedEx != null) { // return interceptedEx; // } //} return sqlEx; }
Example #3
Source File: ExceptionFactory.java From lams with GNU General Public License v2.0 | 6 votes |
public static CJCommunicationsException createCommunicationsException(PropertySet propertySet, ServerSession serverSession, long lastPacketSentTimeMs, long lastPacketReceivedTimeMs, Throwable cause, ExceptionInterceptor interceptor) { CJCommunicationsException sqlEx = createException(CJCommunicationsException.class, null, cause, interceptor); sqlEx.init(propertySet, serverSession, lastPacketSentTimeMs, lastPacketReceivedTimeMs); // TODO: Decide whether we need to intercept exceptions at this level //if (interceptor != null) { // @SuppressWarnings("unchecked") // T interceptedEx = (T) interceptor.interceptException(sqlEx, null); // if (interceptedEx != null) { // return interceptedEx; // } //} return sqlEx; }
Example #4
Source File: TracingQueryInterceptor.java From brave with Apache License 2.0 | 5 votes |
@Override public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { if (interceptingExceptions && originalResultSet == null) { // Error case, the span will be finished in TracingExceptionInterceptor. return null; } Span span = ThreadLocalSpan.CURRENT_TRACER.remove(); if (span == null || span.isNoop()) return null; span.finish(); return null; }
Example #5
Source File: ResultSetScannerInterceptor.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { // requirement of anonymous class final T finalResultSet = originalResultSet; return (T) Proxy.newProxyInstance(originalResultSet.getClass().getClassLoader(), new Class<?>[] { Resultset.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(Messages.getString("ResultSetScannerInterceptor.2")); } } return invocationResult; } }); }
Example #6
Source File: SocketFactory.java From cloud-sql-jdbc-socket-factory with Apache License 2.0 | 5 votes |
@Override public <T extends Closeable> T performTlsHandshake( SocketConnection socketConnection, ServerSession serverSession) throws IOException { @SuppressWarnings("unchecked") T socket = (T) socketConnection.getMysqlSocket(); return socket; }
Example #7
Source File: NativeProtocol.java From FoxTelem with GNU General Public License v3.0 | 5 votes |
public void checkTransactionState() { int transState = this.serverSession.getTransactionState(); if (transState == ServerSession.TRANSACTION_COMPLETED) { this.transactionManager.transactionCompleted(); } else if (transState == ServerSession.TRANSACTION_STARTED) { this.transactionManager.transactionBegun(); } }
Example #8
Source File: ResultSetScannerInterceptor.java From lams with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { // requirement of anonymous class final T finalResultSet = originalResultSet; return (T) Proxy.newProxyInstance(originalResultSet.getClass().getClassLoader(), new Class<?>[] { Resultset.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(Messages.getString("ResultSetScannerInterceptor.2")); } } return invocationResult; } }); }
Example #9
Source File: NativeProtocol.java From lams with GNU General Public License v2.0 | 5 votes |
public void checkTransactionState() { int transState = this.serverSession.getTransactionState(); if (transState == ServerSession.TRANSACTION_COMPLETED) { this.transactionManager.transactionCompleted(); } else if (transState == ServerSession.TRANSACTION_STARTED) { this.transactionManager.transactionBegun(); } }
Example #10
Source File: MySQLQueryInterceptorTest.java From core-ng-project with Apache License 2.0 | 5 votes |
@Test void postProcess() { ServerSession session = mock(ServerSession.class); when(session.noGoodIndexUsed()).thenReturn(Boolean.TRUE); Database.suppressSlowSQLWarning(true); interceptor.postProcess(() -> "sql", null, null, session); Database.suppressSlowSQLWarning(false); assertThat(actionLog.errorCode()).isNull(); interceptor.postProcess(() -> "sql", null, null, session); assertThat(actionLog.errorCode()).isEqualTo("SLOW_SQL"); }
Example #11
Source File: BaseQueryInterceptor.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { return originalResultSet; }
Example #12
Source File: CoreSession.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
@Override public ServerSession getServerSession() { return this.protocol.getServerSession(); }
Example #13
Source File: NoSubInterceptorWrapper.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { this.underlyingInterceptor.postProcess(sql, interceptedQuery, originalResultSet, serverSession); return null; // don't allow result set substitution }
Example #14
Source File: CJCommunicationsException.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
public void init(PropertySet propertySet, ServerSession serverSession, PacketSentTimeHolder packetSentTimeHolder, PacketReceivedTimeHolder packetReceivedTimeHolder) { this.exceptionMessage = ExceptionFactory.createLinkFailureMessageBasedOnHeuristics(propertySet, serverSession, packetSentTimeHolder, packetReceivedTimeHolder, getCause()); }
Example #15
Source File: CJConnectionFeatureNotAvailableException.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
public CJConnectionFeatureNotAvailableException(PropertySet propertySet, ServerSession serverSession, PacketSentTimeHolder packetSentTimeHolder, Exception underlyingException) { super(underlyingException); init(propertySet, serverSession, packetSentTimeHolder, null); }
Example #16
Source File: AsyncMessageReaderTest.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
@Override public void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException { // TODO Auto-generated method stub }
Example #17
Source File: SimplePacketReaderTest.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
@Override public void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException { // TODO Auto-generated method stub }
Example #18
Source File: XProtocol.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
public ServerSession getServerSession() { return this.serverSession; }
Example #19
Source File: XAuthenticationProvider.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
@Override public void connect(ServerSession serverSession, String userName, String password, String database) { changeUser(serverSession, userName, password, database); }
Example #20
Source File: XAsyncSocketConnection.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
@Override public void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException { this.channel = this.socketFactory.performTlsHandshake(this, serverSession); }
Example #21
Source File: SessionAssociationInterceptor.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
@Override public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { return null; }
Example #22
Source File: LoadBalancedAutoCommitInterceptor.java From FoxTelem with GNU General Public License v3.0 | 4 votes |
@Override @SuppressWarnings("resource") public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { try { // Don't count SETs neither SHOWs. Those are mostly used internally and must not trigger a connection switch. if (!this.countStatements || StringUtils.startsWithIgnoreCase(sql.get(), "SET") || StringUtils.startsWithIgnoreCase(sql.get(), "SHOW")) { return originalResultSet; } // Don't care if auto-commit is not enabled. if (!this.conn.getAutoCommit()) { this.matchingAfterStatementCount = 0; return originalResultSet; } if (this.proxy == null && this.conn.isProxySet()) { JdbcConnection lcl_proxy = this.conn.getMultiHostSafeProxy(); while (lcl_proxy != null && !(lcl_proxy instanceof LoadBalancedMySQLConnection)) { lcl_proxy = lcl_proxy.getMultiHostSafeProxy(); } if (lcl_proxy != null) { this.proxy = ((LoadBalancedMySQLConnection) lcl_proxy).getThisAsProxy(); } } // Connection is not ready to rebalance yet. if (this.proxy == null) { return originalResultSet; } // Increment the match count if no regex specified, or if matches. if (this.matchingAfterStatementRegex == null || sql.get().matches(this.matchingAfterStatementRegex)) { this.matchingAfterStatementCount++; } // Trigger rebalance if count exceeds threshold. if (this.matchingAfterStatementCount >= this.matchingAfterStatementThreshold) { this.matchingAfterStatementCount = 0; try { this.proxy.pickNewConnection(); } catch (SQLException e) { // eat this exception, the auto-commit statement completed, but we could not rebalance for some reason. User may get exception when using // connection next. } } } catch (SQLException ex) { throw ExceptionFactory.createException(ex.getMessage(), ex); } // always return the original result set. return originalResultSet; }
Example #23
Source File: XAsyncSocketConnection.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void performTlsHandshake(ServerSession serverSession) throws SSLParamsException, FeatureNotAvailableException, IOException { this.channel = this.socketFactory.performTlsHandshake(this, serverSession); }
Example #24
Source File: XAuthenticationProvider.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void connect(ServerSession serverSession, String userName, String password, String database) { changeUser(serverSession, userName, password, database); }
Example #25
Source File: XProtocol.java From lams with GNU General Public License v2.0 | 4 votes |
public ServerSession getServerSession() { return this.serverSession; }
Example #26
Source File: NoSubInterceptorWrapper.java From lams with GNU General Public License v2.0 | 4 votes |
public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { this.underlyingInterceptor.postProcess(sql, interceptedQuery, originalResultSet, serverSession); return null; // don't allow result set substitution }
Example #27
Source File: CJConnectionFeatureNotAvailableException.java From lams with GNU General Public License v2.0 | 4 votes |
public CJConnectionFeatureNotAvailableException(PropertySet propertySet, ServerSession serverSession, long lastPacketSentTimeMs, Exception underlyingException) { super(underlyingException); init(propertySet, serverSession, lastPacketSentTimeMs, 0L); }
Example #28
Source File: CJCommunicationsException.java From lams with GNU General Public License v2.0 | 4 votes |
public void init(PropertySet propertySet, ServerSession serverSession, long lastPacketSentTimeMs, long lastPacketReceivedTimeMs) { this.exceptionMessage = ExceptionFactory.createLinkFailureMessageBasedOnHeuristics(propertySet, serverSession, lastPacketSentTimeMs, lastPacketReceivedTimeMs, getCause()); }
Example #29
Source File: LoadBalancedAutoCommitInterceptor.java From lams with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("resource") public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { try { // Don't count SETs neither SHOWs. Those are mostly used internally and must not trigger a connection switch. if (!this.countStatements || StringUtils.startsWithIgnoreCase(sql.get(), "SET") || StringUtils.startsWithIgnoreCase(sql.get(), "SHOW")) { return originalResultSet; } // Don't care if auto-commit is not enabled. if (!this.conn.getAutoCommit()) { this.matchingAfterStatementCount = 0; return originalResultSet; } if (this.proxy == null && this.conn.isProxySet()) { JdbcConnection lcl_proxy = this.conn.getMultiHostSafeProxy(); while (lcl_proxy != null && !(lcl_proxy instanceof LoadBalancedMySQLConnection)) { lcl_proxy = lcl_proxy.getMultiHostSafeProxy(); } if (lcl_proxy != null) { this.proxy = ((LoadBalancedMySQLConnection) lcl_proxy).getThisAsProxy(); } } // Connection is not ready to rebalance yet. if (this.proxy == null) { return originalResultSet; } // Increment the match count if no regex specified, or if matches. if (this.matchingAfterStatementRegex == null || sql.get().matches(this.matchingAfterStatementRegex)) { this.matchingAfterStatementCount++; } // Trigger rebalance if count exceeds threshold. if (this.matchingAfterStatementCount >= this.matchingAfterStatementThreshold) { this.matchingAfterStatementCount = 0; try { this.proxy.pickNewConnection(); } catch (SQLException e) { // eat this exception, the auto-commit statement completed, but we could not rebalance for some reason. User may get exception when using // connection next. } } } catch (SQLException ex) { throw ExceptionFactory.createException(ex.getMessage(), ex); } // always return the original result set. return originalResultSet; }
Example #30
Source File: SessionAssociationInterceptor.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public <T extends Resultset> T postProcess(Supplier<String> sql, Query interceptedQuery, T originalResultSet, ServerSession serverSession) { return null; }