@@ -37,9 +37,8 @@ final class SimpleJpaQuery extends AbstractJpaQuery {
37
37
38
38
private static final Logger LOG = LoggerFactory .getLogger (SimpleJpaQuery .class );
39
39
40
- private final String queryString ;
41
- private final String countQuery ;
42
- private final String alias ;
40
+ private final StringQuery query ;
41
+ private final StringQuery countQuery ;
43
42
44
43
private final JpaQueryMethod method ;
45
44
@@ -50,11 +49,10 @@ final class SimpleJpaQuery extends AbstractJpaQuery {
50
49
51
50
super (method , em );
52
51
53
- this .queryString = queryString ;
54
- this .alias = QueryUtils .detectAlias (queryString );
55
- this .countQuery = method .getCountQuery () == null ? QueryUtils .createCountQueryFor (queryString ) : method
56
- .getCountQuery ();
57
52
this .method = method ;
53
+ this .query = new StringQuery (queryString );
54
+ this .countQuery = new StringQuery (method .getCountQuery () == null ? QueryUtils .createCountQueryFor (queryString )
55
+ : method .getCountQuery ());
58
56
59
57
Parameters parameters = method .getParameters ();
60
58
boolean hasPagingOrSortingParameter = parameters .hasPageableParameter () || parameters .hasSortParameter ();
@@ -66,7 +64,7 @@ final class SimpleJpaQuery extends AbstractJpaQuery {
66
64
// Try to create a Query object already to fail fast
67
65
if (!method .isNativeQuery ()) {
68
66
try {
69
- em .createQuery (queryString );
67
+ em .createQuery (query . getQuery () );
70
68
} catch (RuntimeException e ) {
71
69
// Needed as there's ambiguities in how an invalid query string shall be expressed by the persistence provider
72
70
// http://java.net/projects/jpa-spec/lists/jsr338-experts/archive/2012-07/message/17
@@ -82,6 +80,15 @@ final class SimpleJpaQuery extends AbstractJpaQuery {
82
80
this (method , em , method .getAnnotatedQuery ());
83
81
}
84
82
83
+ /*
84
+ * (non-Javadoc)
85
+ * @see org.springframework.data.jpa.repository.query.AbstractJpaQuery#createBinder(java.lang.Object[])
86
+ */
87
+ @ Override
88
+ protected ParameterBinder createBinder (Object [] values ) {
89
+ return new StringQueryParameterBinder (getQueryMethod ().getParameters (), values , query );
90
+ }
91
+
85
92
/*
86
93
* (non-Javadoc)
87
94
* @see org.springframework.data.jpa.repository.query.AbstractJpaQuery#createQuery(java.lang.Object[])
@@ -90,7 +97,7 @@ final class SimpleJpaQuery extends AbstractJpaQuery {
90
97
public Query doCreateQuery (Object [] values ) {
91
98
92
99
ParameterAccessor accessor = new ParametersParameterAccessor (method .getParameters (), values );
93
- String sortedQueryString = QueryUtils .applySorting (queryString , accessor .getSort (), alias );
100
+ String sortedQueryString = QueryUtils .applySorting (query . getQuery () , accessor .getSort (), query . getAlias () );
94
101
EntityManager em = getEntityManager ();
95
102
96
103
Query query = null ;
@@ -111,8 +118,7 @@ public Query doCreateQuery(Object[] values) {
111
118
*/
112
119
@ Override
113
120
protected TypedQuery <Long > doCreateCountQuery (Object [] values ) {
114
-
115
- return createBinder (values ).bind (getEntityManager ().createQuery (countQuery , Long .class ));
121
+ return createBinder (values ).bind (getEntityManager ().createQuery (countQuery .getQuery (), Long .class ));
116
122
}
117
123
118
124
/**
@@ -131,4 +137,4 @@ public static RepositoryQuery fromQueryAnnotation(JpaQueryMethod queryMethod, En
131
137
132
138
return query == null ? null : new SimpleJpaQuery (queryMethod , em , query );
133
139
}
134
- }
140
+ }
0 commit comments