Skip to content

DATAJPA-948 - Provide extensibility of query creation #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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<ParameterMetadata<?>> expressions;
Expand Down