From ab6c26c248c51f316f66aa7ab907466fbb4323df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Lecomte?= Date: Tue, 9 Aug 2016 22:48:16 +0200 Subject: [PATCH] DATAJPA-948 - Provide extensibility of query creation. changed some visibilities to public --- .../query/JpaQueryLookupStrategy.java | 10 +++---- .../repository/query/PartTreeJpaQuery.java | 30 +++++++++++++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryLookupStrategy.java b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryLookupStrategy.java index cbafb058d9..b92ba914f0 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryLookupStrategy.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryLookupStrategy.java @@ -49,7 +49,7 @@ private JpaQueryLookupStrategy() {} * @author Oliver Gierke * @author Thomas Darimont */ - private abstract static class AbstractQueryLookupStrategy implements QueryLookupStrategy { + public abstract static class AbstractQueryLookupStrategy implements QueryLookupStrategy { private final EntityManager em; private final QueryExtractor provider; @@ -72,7 +72,7 @@ public AbstractQueryLookupStrategy(EntityManager em, QueryExtractor extractor) { * @see org.springframework.data.repository.query.QueryLookupStrategy#resolveQuery(java.lang.reflect.Method, org.springframework.data.repository.core.RepositoryMetadata, org.springframework.data.projection.ProjectionFactory, org.springframework.data.repository.core.NamedQueries) */ @Override - public final RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, + public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, NamedQueries namedQueries) { return resolveQuery(new JpaQueryMethod(method, metadata, factory, provider), em, namedQueries); } @@ -86,7 +86,7 @@ public final RepositoryQuery resolveQuery(Method method, RepositoryMetadata meta * @author Oliver Gierke * @author Thomas Darimont */ - private static class CreateQueryLookupStrategy extends AbstractQueryLookupStrategy { + public static class CreateQueryLookupStrategy extends AbstractQueryLookupStrategy { private final PersistenceProvider persistenceProvider; @@ -116,7 +116,7 @@ protected RepositoryQuery resolveQuery(JpaQueryMethod method, EntityManager em, * @author Oliver Gierke * @author Thomas Darimont */ - private static class DeclaredQueryLookupStrategy extends AbstractQueryLookupStrategy { + public static class DeclaredQueryLookupStrategy extends AbstractQueryLookupStrategy { private final EvaluationContextProvider evaluationContextProvider; @@ -178,7 +178,7 @@ protected RepositoryQuery resolveQuery(JpaQueryMethod method, EntityManager em, * @author Oliver Gierke * @author Thomas Darimont */ - private static class CreateIfNotFoundQueryLookupStrategy extends AbstractQueryLookupStrategy { + public static class CreateIfNotFoundQueryLookupStrategy extends AbstractQueryLookupStrategy { private final DeclaredQueryLookupStrategy lookupStrategy; private final CreateQueryLookupStrategy createStrategy; diff --git a/src/main/java/org/springframework/data/jpa/repository/query/PartTreeJpaQuery.java b/src/main/java/org/springframework/data/jpa/repository/query/PartTreeJpaQuery.java index 501269d144..59ab7017a6 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/PartTreeJpaQuery.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/PartTreeJpaQuery.java @@ -65,8 +65,8 @@ public PartTreeJpaQuery(JpaQueryMethod method, EntityManager em, PersistenceProv boolean recreationRequired = parameters.hasDynamicProjection() || parameters.potentiallySortsDynamically(); - this.countQuery = new CountQueryPreparer(persistenceProvider, recreationRequired); - this.query = tree.isCountProjection() ? countQuery : new QueryPreparer(persistenceProvider, recreationRequired); + this.countQuery = createCountQueryPreparer(persistenceProvider, recreationRequired); + this.query = tree.isCountProjection() ? countQuery : createQueryPreparer(persistenceProvider, recreationRequired); } /* @@ -97,13 +97,37 @@ protected JpaQueryExecution getExecution() { return this.tree.isDelete() ? new DeleteExecution(em) : super.getExecution(); } + /** + * @return the {@link CountQueryPreparer} to use + */ + protected CountQueryPreparer createCountQueryPreparer(PersistenceProvider persistenceProvider, + boolean recreationRequired) { + return new CountQueryPreparer(persistenceProvider, recreationRequired); + } + + /** + * @return the {@link QueryPreparer} to use + */ + protected QueryPreparer createQueryPreparer(PersistenceProvider persistenceProvider, + boolean recreationRequired) { + return new QueryPreparer(persistenceProvider, recreationRequired); + } + + protected PartTree getTree() { + return tree; + } + + protected JpaParameters getParameters() { + return parameters; + } + /** * Query preparer to create {@link CriteriaQuery} instances and potentially cache them. * * @author Oliver Gierke * @author Thomas Darimont */ - private class QueryPreparer { + protected class QueryPreparer { private final CriteriaQuery cachedCriteriaQuery; private final List> expressions;