ThreadContextImpl implements ThreadContextPlus { @Override public QueryEntry startQueryEntry(String queryType, String queryText, QueryMessageSupplier queryMessageSupplier, TimerName timerName) { if (queryType == null) { logger.error("startQueryEntry(): argument 'queryType' must be non-null"); return NopTransactionService.QUERY_ENTRY; } if (queryText == null) { logger.error("startQueryEntry(): argument 'queryText' must be non-null"); return NopTransactionService.QUERY_ENTRY; } if (queryMessageSupplier == null) { logger.error("startQueryEntry(): argument 'queryMessageSupplier' must be non-null"); return NopTransactionService.QUERY_ENTRY; } if (timerName == null) { logger.error("startQueryEntry(): argument 'timerName' must be non-null"); return NopTransactionService.QUERY_ENTRY; } long startTick = ticker.read(); TimerImpl timer = startTimer(timerName, startTick); if (transaction.allowAnotherEntry()) { SyncQueryData queryData = getOrCreateQueryData(queryType, queryText, true); return traceEntryComponent.pushEntry(startTick, queryMessageSupplier, timer, null, queryData, 1); } else { SyncQueryData queryData = getOrCreateQueryData(queryType, queryText, false); return new DummyTraceEntryOrQuery(timer, null, startTick, queryMessageSupplier, queryData, 1); } } ThreadContextImpl(Transaction transaction, @Nullable TraceEntryImpl parentTraceEntry,
            @Nullable TraceEntryImpl parentThreadContextPriorEntry, MessageSupplier messageSupplier,
            TimerName rootTimerName, long startTick, boolean captureThreadStats,
            int maxQueryAggregates, int maxServiceCallAggregates,
            @Nullable ThreadAllocatedBytes threadAllocatedBytes,
            boolean limitExceededAuxThreadContext, Ticker ticker,
            ThreadContextThreadLocal.Holder threadContextHolder,
            @Nullable ServletRequestInfo servletRequestInfo, int rootNestingGroupId,
            int rootSuppressionKeyId); Transaction getTransaction(); long getThreadId(); boolean isActive(); @Nullable TimerImpl getCurrentTimer(); @Override int getCurrentNestingGroupId(); @Override void setCurrentNestingGroupId(int nestingGroupId); @Override int getCurrentSuppressionKeyId(); @Override void setCurrentSuppressionKeyId(int suppressionKeyId); @Override AuxThreadContext createAuxThreadContext(); @Override boolean isInTransaction(); @Override TraceEntry startTransaction(String transactionType, String transactionName,
            MessageSupplier messageSupplier, TimerName timerName); @Override TraceEntry startTransaction(String transactionType, String transactionName,
            MessageSupplier messageSupplier, TimerName timerName,
            AlreadyInTransactionBehavior alreadyInTransactionBehavior); @Override TraceEntry startTraceEntry(MessageSupplier messageSupplier, TimerName timerName); @Override AsyncTraceEntry startAsyncTraceEntry(MessageSupplier messageSupplier,
            TimerName timerName); @Override QueryEntry startQueryEntry(String queryType, String queryText,
            QueryMessageSupplier queryMessageSupplier, TimerName timerName); @Override QueryEntry startQueryEntry(String queryType, String queryText, long queryExecutionCount,
            QueryMessageSupplier queryMessageSupplier, TimerName timerName); @Override AsyncQueryEntry startAsyncQueryEntry(String queryType, String queryText,
            QueryMessageSupplier queryMessageSupplier, TimerName timerName); @Override TraceEntry startServiceCallEntry(String serviceCallType, String serviceCallText,
            MessageSupplier messageSupplier, TimerName timerName); @Override AsyncTraceEntry startAsyncServiceCallEntry(String serviceCallType,
            String serviceCallText, MessageSupplier messageSupplier, TimerName timerName); @Override Timer startTimer(TimerName timerName); @Override void setTransactionAsync(); @Override void setTransactionAsyncComplete(); @Override void setTransactionOuter(); @Override void setTransactionType(@Nullable String transactionType, int priority); @Override void setTransactionName(@Nullable String transactionName, int priority); @Override void setTransactionUser(@Nullable String user, int priority); @Override void addTransactionAttribute(String name, @Nullable String value); @Override void setTransactionSlowThreshold(long threshold, TimeUnit unit, int priority); @Override void setTransactionError(Throwable t); @Override void setTransactionError(@Nullable String message); @Override void setTransactionError(@Nullable String message, @Nullable Throwable t); @Override void addErrorEntry(Throwable t); @Override void addErrorEntry(@Nullable String message); @Override void addErrorEntry(@Nullable String message, Throwable t); @Override void trackResourceAcquired(Object resource, boolean withLocationStackTrace); @Override void trackResourceReleased(Object resource); @Override @Nullable ServletRequestInfo getServletRequestInfo(); @Override void setServletRequestInfo(@Nullable ServletRequestInfo servletRequestInfo);  }
@Test public void testStartQueryEntry() { assertThat(threadContext.startQueryEntry(null, "text", queryMessageSupplier, timerName)) .isEqualTo(NopTransactionService.QUERY_ENTRY); assertThat(threadContext.startQueryEntry("type", null, queryMessageSupplier, timerName)) .isEqualTo(NopTransactionService.QUERY_ENTRY); assertThat(threadContext.startQueryEntry("type", "text", null, timerName)) .isEqualTo(NopTransactionService.QUERY_ENTRY); assertThat(threadContext.startQueryEntry("type", "text", queryMessageSupplier, null)) .isEqualTo(NopTransactionService.QUERY_ENTRY); assertThat(threadContext.startQueryEntry("type", "text", queryMessageSupplier, timerName) .getClass().getName()).endsWith("$DummyTraceEntryOrQuery"); }
@Test public void testStartQueryEntryWithExecutionCount() { assertThat(threadContext.startQueryEntry(null, "text", 1, queryMessageSupplier, timerName)) .isEqualTo(NopTransactionService.QUERY_ENTRY); assertThat(threadContext.startQueryEntry("type", null, 1, queryMessageSupplier, timerName)) .isEqualTo(NopTransactionService.QUERY_ENTRY); assertThat(threadContext.startQueryEntry("type", "text", 1, null, timerName)) .isEqualTo(NopTransactionService.QUERY_ENTRY); assertThat(threadContext.startQueryEntry("type", "text", 1, queryMessageSupplier, null)) .isEqualTo(NopTransactionService.QUERY_ENTRY); assertThat(threadContext.startQueryEntry("type", "text", 1, queryMessageSupplier, timerName) .getClass().getName()).endsWith("$DummyTraceEntryOrQuery"); }