Merged James' most recent changes.

This commit is contained in:
Anthony Sute 2019-11-12 13:57:02 -05:00
parent 09daf7aacc
commit 49ed6b48dc
1 changed files with 31 additions and 3 deletions

View File

@ -1865,9 +1865,11 @@ public class SearchBuilder implements ISearchBuilder {
codes.addAll(myTerminologySvc.expandValueSet(code)); codes.addAll(myTerminologySvc.expandValueSet(code));
} else if (modifier == TokenParamModifier.ABOVE) { } else if (modifier == TokenParamModifier.ABOVE) {
system = determineSystemIfMissing(theParamName, code, system); system = determineSystemIfMissing(theParamName, code, system);
validateHaveSystemAndCodeForToken(theParamName, code, system);
codes.addAll(myTerminologySvc.findCodesAbove(system, code)); codes.addAll(myTerminologySvc.findCodesAbove(system, code));
} else if (modifier == TokenParamModifier.BELOW) { } else if (modifier == TokenParamModifier.BELOW) {
system = determineSystemIfMissing(theParamName, code, system); system = determineSystemIfMissing(theParamName, code, system);
validateHaveSystemAndCodeForToken(theParamName, code, system);
codes.addAll(myTerminologySvc.findCodesBelow(system, code)); codes.addAll(myTerminologySvc.findCodesBelow(system, code));
} else { } else {
codes.add(new VersionIndependentConcept(system, code)); codes.add(new VersionIndependentConcept(system, code));
@ -1910,6 +1912,19 @@ public class SearchBuilder implements ISearchBuilder {
return retVal; return retVal;
} }
private void validateHaveSystemAndCodeForToken(String theParamName, String theCode, String theSystem) {
String systemDesc = defaultIfBlank(theSystem, "(missing)");
String codeDesc = defaultIfBlank(theCode, "(missing)");
if (isBlank(theCode)) {
String msg = myContext.getLocalizer().getMessage(SearchBuilder.class, "invalidCodeMissingSystem", theParamName, systemDesc, codeDesc);
throw new InvalidRequestException(msg);
}
if (isBlank(theSystem)) {
String msg = myContext.getLocalizer().getMessage(SearchBuilder.class, "invalidCodeMissingCode", theParamName, systemDesc, codeDesc);
throw new InvalidRequestException(msg);
}
}
private Predicate addPredicateToken(String theResourceName, String theParamName, CriteriaBuilder theBuilder, From<?, ResourceIndexedSearchParamToken> theFrom, List<VersionIndependentConcept> theTokens, TokenParamModifier theModifier, TokenModeEnum theTokenMode) { private Predicate addPredicateToken(String theResourceName, String theParamName, CriteriaBuilder theBuilder, From<?, ResourceIndexedSearchParamToken> theFrom, List<VersionIndependentConcept> theTokens, TokenParamModifier theModifier, TokenModeEnum theTokenMode) {
if (myDontUseHashesForSearch) { if (myDontUseHashesForSearch) {
final Path<String> systemExpression = theFrom.get("mySystem"); final Path<String> systemExpression = theFrom.get("mySystem");
@ -2064,6 +2079,7 @@ public class SearchBuilder implements ISearchBuilder {
outerQuery.multiselect(myBuilder.countDistinct(myResourceTableRoot)); outerQuery.multiselect(myBuilder.countDistinct(myResourceTableRoot));
} else { } else {
outerQuery.multiselect(myResourceTableRoot.get("myId").as(Long.class)); outerQuery.multiselect(myResourceTableRoot.get("myId").as(Long.class));
outerQuery.distinct(true);
} }
} }
@ -3133,6 +3149,8 @@ public class SearchBuilder implements ISearchBuilder {
private final SearchRuntimeDetails mySearchRuntimeDetails; private final SearchRuntimeDetails mySearchRuntimeDetails;
private final RequestDetails myRequest; private final RequestDetails myRequest;
private final boolean myHaveRawSqlHooks;
private final boolean myHavePerftraceFoundIdHook;
private boolean myFirst = true; private boolean myFirst = true;
private IncludesIterator myIncludesIterator; private IncludesIterator myIncludesIterator;
private Long myNext; private Long myNext;
@ -3151,13 +3169,16 @@ public class SearchBuilder implements ISearchBuilder {
if (myParams.getEverythingMode() != null) { if (myParams.getEverythingMode() != null) {
myStillNeedToFetchIncludes = true; myStillNeedToFetchIncludes = true;
} }
myHavePerftraceFoundIdHook =JpaInterceptorBroadcaster.hasHooks(Pointcut.JPA_PERFTRACE_SEARCH_FOUND_ID, myInterceptorBroadcaster, myRequest);
myHaveRawSqlHooks = JpaInterceptorBroadcaster.hasHooks(Pointcut.JPA_PERFTRACE_RAW_SQL, myInterceptorBroadcaster, myRequest);
} }
private void fetchNext() { private void fetchNext() {
boolean haveRawSqlHooks = JpaInterceptorBroadcaster.hasHooks(Pointcut.JPA_PERFTRACE_RAW_SQL, myInterceptorBroadcaster, myRequest);
try { try {
if (haveRawSqlHooks) { if (myHaveRawSqlHooks) {
CurrentThreadCaptureQueriesListener.startCapturing(); CurrentThreadCaptureQueriesListener.startCapturing();
} }
@ -3198,6 +3219,13 @@ public class SearchBuilder implements ISearchBuilder {
if (myNext == null) { if (myNext == null) {
while (myResultsIterator.hasNext()) { while (myResultsIterator.hasNext()) {
Long next = myResultsIterator.next(); Long next = myResultsIterator.next();
if (myHavePerftraceFoundIdHook) {
HookParams params = new HookParams()
.add(Integer.class, System.identityHashCode(this))
.add(Object.class, next);
JpaInterceptorBroadcaster.doCallHooks(myInterceptorBroadcaster, myRequest, Pointcut.JPA_PERFTRACE_SEARCH_FOUND_ID, params);
}
if (next != null) { if (next != null) {
if (myPidSet.add(next)) { if (myPidSet.add(next)) {
myNext = next; myNext = next;
@ -3236,7 +3264,7 @@ public class SearchBuilder implements ISearchBuilder {
mySearchRuntimeDetails.setFoundMatchesCount(myPidSet.size()); mySearchRuntimeDetails.setFoundMatchesCount(myPidSet.size());
} finally { } finally {
if (haveRawSqlHooks) { if (myHaveRawSqlHooks) {
SqlQueryList capturedQueries = CurrentThreadCaptureQueriesListener.getCurrentQueueAndStopCapturing(); SqlQueryList capturedQueries = CurrentThreadCaptureQueriesListener.getCurrentQueueAndStopCapturing();
HookParams params = new HookParams() HookParams params = new HookParams()
.add(RequestDetails.class, myRequest) .add(RequestDetails.class, myRequest)