org.jooq.ExecuteContext Java Examples

The following examples show how to use org.jooq.ExecuteContext. 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: JooqExceptionTranslator.java    From micronaut-sql with Apache License 2.0 5 votes vote down vote up
private SQLExceptionTranslator getTranslator(ExecuteContext context) {
    SQLDialect dialect = context.configuration().dialect();
    if (dialect != null && dialect.thirdParty() != null) {
        String dbName = dialect.thirdParty().springDbName();
        if (dbName != null) {
            return new SQLErrorCodeSQLExceptionTranslator(dbName);
        }
    }
    return new SQLStateSQLExceptionTranslator();
}
 
Example #2
Source File: JooqExecuteListener.java    From micrometer with Apache License 2.0 5 votes vote down vote up
private void stopTimerIfStillRunning(ExecuteContext ctx) {
    Iterable<Tag> queryTags = queryTagsSupplier.get();
    if (queryTags == null) return;

    Timer.Sample sample;
    synchronized (sampleLock) {
        sample = sampleByExecuteContext.remove(ctx);
    }
    if (sample == null) return;

    String exceptionName = "none";
    String exceptionSubclass = "none";

    Exception exception = ctx.exception();
    if (exception != null) {
        if (exception instanceof DataAccessException) {
            DataAccessException dae = (DataAccessException) exception;
            exceptionName = dae.sqlStateClass().name().toLowerCase().replace('_', ' ');
            exceptionSubclass = dae.sqlStateSubclass().name().toLowerCase().replace('_', ' ');
            if (exceptionSubclass.contains("no subclass")) {
                exceptionSubclass = "none";
            }
        } else {
            String simpleName = exception.getClass().getSimpleName();
            exceptionName = StringUtils.isNotBlank(simpleName) ? simpleName : exception.getClass().getName();
        }
    }

    //noinspection unchecked
    sample.stop(Timer.builder("jooq.query")
            .description("Execution time of a SQL query performed with JOOQ")
            .tags(queryTags)
            .tag("type", ctx.type().name().toLowerCase())
            .tag("exception", exceptionName)
            .tag("exception.subclass", exceptionSubclass)
            .tags(tags)
            .register(registry));
}
 
Example #3
Source File: SlowQueryListener.java    From waltz with Apache License 2.0 5 votes vote down vote up
@Override
public void executeEnd(ExecuteContext ctx) {
    super.executeEnd(ctx);
    long split = stopWatch.split();
    if (split > slowQueryThresholdInNanos) {
        DSLContext context = DSL.using(ctx.dialect(),
                // ... and the flag for pretty-printing
                new Settings().withRenderFormatted(true));

        LOG.warn(String.format("Slow SQL executed in %d seconds", TimeUnit.NANOSECONDS.toSeconds(split)), new SQLPerformanceWarning(context.renderInlined(ctx.query())));
    }
}
 
Example #4
Source File: ExceptionTranslator.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public void exception(ExecuteContext context) {
    SQLDialect dialect = context.configuration().dialect();
    SQLExceptionTranslator translator = new SQLErrorCodeSQLExceptionTranslator(dialect.thirdParty().springDbName());

    context.exception(translator.translate("Access database using jOOQ", context.sql(), context.sqlException()));
}
 
Example #5
Source File: JooqExceptionTranslator.java    From micronaut-sql with Apache License 2.0 4 votes vote down vote up
private DataAccessException translate(ExecuteContext context,
        SQLExceptionTranslator translator, SQLException exception) {
    return translator.translate("jOOQ", context.sql(), exception);
}
 
Example #6
Source File: JooqExecuteListener.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
public void start(ExecuteContext ctx) {
    startTimer(ctx);
}
 
Example #7
Source File: JooqExecuteListener.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
public void executeStart(ExecuteContext ctx) {
    startTimer(ctx);
}
 
Example #8
Source File: JooqExecuteListener.java    From micrometer with Apache License 2.0 4 votes vote down vote up
private void startTimer(ExecuteContext ctx) {
    Timer.Sample started = Timer.start(registry);
    synchronized (sampleLock) {
        sampleByExecuteContext.put(ctx, started);
    }
}
 
Example #9
Source File: JooqExecuteListener.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
public void executeEnd(ExecuteContext ctx) {
    stopTimerIfStillRunning(ctx);
}
 
Example #10
Source File: JooqExecuteListener.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
public void end(ExecuteContext ctx) {
    stopTimerIfStillRunning(ctx);
}
 
Example #11
Source File: QueryLogger.java    From curiostack with MIT License 4 votes vote down vote up
@Override
public void executeStart(ExecuteContext ctx) {
  logger.info(ctx.query().getSQL(ParamType.INLINED));
}
 
Example #12
Source File: SlowQueryListener.java    From waltz with Apache License 2.0 4 votes vote down vote up
@Override
public void executeStart(ExecuteContext ctx) {
    super.executeStart(ctx);
    stopWatch = new StopWatch();
}
 
Example #13
Source File: JooqExceptionTranslator.java    From micronaut-sql with Apache License 2.0 3 votes vote down vote up
/**
 * 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 {
        LOG.error("Execution of SQL statement failed.", translated);
    }
}