@Override public void renderEnd(ExecuteContext ctx) { // Only join traces, don't start them. This prevents LocalCollector's thread from amplifying. if (brave.serverSpanThreadBinder().getCurrentServerSpan() == null || brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() == null) { return; } brave.clientTracer().startNewSpan(ctx.type().toString().toLowerCase()); String[] batchSQL = ctx.batchSQL(); if (!StringUtils.isBlank(ctx.sql())) { brave.clientTracer().submitBinaryAnnotation(SQL_QUERY, ctx.sql()); } else if (batchSQL.length > 0 && batchSQL[batchSQL.length - 1] != null) { brave.clientTracer().submitBinaryAnnotation(SQL_QUERY, StringUtils.join(batchSQL, '\n')); } brave.clientTracer() .setClientSent(mysqlEndpoint.ipv4, mysqlEndpoint.port, mysqlEndpoint.serviceName); }
@Override public void executeEnd(ExecuteContext ctx) { if (brave.serverSpanThreadBinder().getCurrentServerSpan() == null || brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() == null) { return; } brave.clientTracer().setClientReceived(); }
private SQLExceptionTranslator getTranslator(ExecuteContext context) { SQLDialect dialect = context.configuration().dialect(); if (dialect != null && dialect.thirdParty() != null) { return new SQLErrorCodeSQLExceptionTranslator( dialect.thirdParty().springDbName()); } return new SQLStateSQLExceptionTranslator(); }
/** * Handle a single exception in the chain. SQLExceptions might be nested multiple * levels deep. The outermost exception is usually the least interesting one ( * "Call getNextException to see the cause."). Therefore the innermost exception is * propagated and all other exceptions are logged. * @param context the execute context * @param translator the exception translator * @param exception the exception */ private void handle(ExecuteContext context, SQLExceptionTranslator translator, SQLException exception) { DataAccessException translated = translate(context, translator, exception); if (exception.getNextException() == null) { context.exception(translated); } else { logger.error("Execution of SQL statement failed.", translated); } }
@Test public void exceptionTranslation() { ExecuteContext context = mock(ExecuteContext.class); Configuration configuration = mock(Configuration.class); given(context.configuration()).willReturn(configuration); given(configuration.dialect()).willReturn(this.dialect); given(context.sqlException()).willReturn(this.sqlException); this.exceptionTranslator.exception(context); ArgumentCaptor<RuntimeException> captor = ArgumentCaptor .forClass(RuntimeException.class); verify(context).exception(captor.capture()); assertThat(captor.getValue()).isInstanceOf(BadSqlGrammarException.class); }
@Override public void fetchEnd(ExecuteContext ctx) { super.fetchEnd(ctx); Pair<Long, Integer> stopWatchIntegerPair = timing.get(ctx.query().toString()); long duration = System.nanoTime() - stopWatchIntegerPair.getValue0(); timing.put(ctx.query().toString(), new Pair<>(duration, ctx.result().size())); }
@Override public void fetchStart(ExecuteContext ctx) { super.start(ctx); StopWatch stopWatch = new StopWatch(); timing.put(ctx.query().toString(), new Pair<>(System.nanoTime(), 0)); stopWatch.start(); }
private SQLExceptionTranslator getTranslator(ExecuteContext context) { SQLDialect dialect = context.configuration().dialect(); if (dialect != null) { return new SQLErrorCodeSQLExceptionTranslator(dialect.name()); } return new SQLStateSQLExceptionTranslator(); }
@Override public void renderEnd(ExecuteContext ctx) { if (database.getDatabaseConfig().logDatabaseQueries) { database.getLog().debug(ctx.query().getSQL()); } }
@Override public void start(final ExecuteContext ctx) { System.err.println("Query: " + ctx.query().getSQL()); }
private DataAccessException translate(ExecuteContext context, SQLExceptionTranslator translator, SQLException exception) { return translator.translate("jOOQ", context.sql(), exception); }