return new JPAQueryComposer<>(this, (JPQLQuery<U>)cachedQuery.get(), lambdas);
}
public <U> JPAQueryComposer<U> applyTransformWithLambda(JPQLOneLambdaQueryTransform transform, Object lambda)
{
LambdaInfo lambdaInfo = lambdaAnalyzer.extractSurfaceInfo(lambda, lambdas.size(), hints.dieOnError);
if (lambdaInfo == null) { translationFail(); return null; }
Optional<JPQLQuery<?>> cachedQuery = hints.useCaching ?
cachedQueries.findInCache(query, transform.getTransformationTypeCachingTag(), new String[] {lambdaInfo.getLambdaSourceString()}) : null;
if (cachedQuery == null)
{
cachedQuery = Optional.empty();
JPQLQuery<U> newQuery = null;
try {
LambdaAnalysis lambdaAnalysis = lambdaInfo.fullyAnalyze(metamodel, hints.lambdaClassLoader, hints.isObjectEqualsSafe, hints.dieOnError);
if (lambdaAnalysis == null) { translationFail(); return null; }
getConfig().checkLambdaSideEffects(lambdaAnalysis);
newQuery = transform.apply(query, lambdaAnalysis, null);
}
catch (QueryTransformException e)
{
translationFail(e);
}
finally
{
// Always cache the resulting query, even if it is an error
cachedQuery = Optional.ofNullable(newQuery);
if (hints.useCaching)
cachedQuery = cachedQueries.cacheQuery(query, transform.getTransformationTypeCachingTag(), new String[] {lambdaInfo.getLambdaSourceString()}, cachedQuery);
}
}
if (!cachedQuery.isPresent()) { translationFail(); return null; }
return new JPAQueryComposer<>(this, (JPQLQuery<U>)cachedQuery.get(), lambdas, lambdaInfo);
}