Skip to content

Commit 6c94034

Browse files
authored
Merge pull request #28 from joutvhu/develop
Fix deriveCountQuery method for spring boot > 3.1.9
2 parents dab4b89 + 9adc38e commit 6c94034

File tree

4 files changed

+38
-35
lines changed

4 files changed

+38
-35
lines changed

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,32 @@ The Spring Dynamic JPA will make it easy to implement dynamic queries with JpaRe
77
### Install dependency
88

99
```groovy
10-
implementation 'com.github.joutvhu:spring-dynamic-jpa:3.0.8'
10+
implementation 'com.github.joutvhu:spring-dynamic-jpa:3.1.8'
1111
```
1212

1313
```xml
1414
<dependency>
1515
<groupId>com.github.joutvhu</groupId>
1616
<artifactId>spring-dynamic-jpa</artifactId>
17-
<version>3.0.8</version>
17+
<version>3.1.8</version>
1818
</dependency>
1919
```
2020

2121
- Please choose the _Spring Dynamic JPA_ version appropriate with your spring version.
2222

2323
| Spring Boot version | Spring Dynamic JPA version |
24-
|:----------:|:-------------:|
25-
| 2.0.x.RELEASE | 2.0.8 |
26-
| 2.1.x.RELEASE | 2.1.8 |
27-
| 2.2.x.RELEASE | 2.2.8 |
28-
| 2.3.x.RELEASE | 2.3.8 |
29-
| 2.4.x | 2.3.8 |
30-
| 2.5.x | 2.3.8 |
31-
| 2.6.x | 2.3.8 |
32-
| 2.7.x | 2.7.8 |
33-
| 3.0.x | 3.0.8 |
24+
|:-------------------:|:--------------------------:|
25+
| 2.0.x.RELEASE | 2.0.8 |
26+
| 2.1.x.RELEASE | 2.1.8 |
27+
| 2.2.x.RELEASE | 2.2.8 |
28+
| 2.3.x.RELEASE | 2.3.8 |
29+
| 2.4.x | 2.3.8 |
30+
| 2.5.x | 2.3.8 |
31+
| 2.6.x | 2.3.8 |
32+
| 2.7.x | 2.7.8 |
33+
| 3.0.x | 3.0.8 |
34+
| 3.1.x | 3.1.8 |
35+
| 3.2.x | 3.1.8 |
3436

3537
Also, you have to choose a [Dynamic Query Template Provider](https://github.com/joutvhu/spring-dynamic-commons#dynamic-query-template-provider) to use,
3638
the Dynamic Query Template Provider will decide the style you write dynamic query template.
@@ -39,14 +41,14 @@ In this document, I will use [Spring Dynamic Freemarker](https://github.com/jout
3941
If you migrated from a lower version, you should use it.
4042

4143
```groovy
42-
implementation 'com.github.joutvhu:spring-dynamic-freemarker:1.0.0'
44+
implementation 'com.github.joutvhu:spring-dynamic-freemarker:1.0.1'
4345
```
4446

4547
```xml
4648
<dependency>
4749
<groupId>com.github.joutvhu</groupId>
4850
<artifactId>spring-dynamic-freemarker</artifactId>
49-
<version>1.0.0</version>
51+
<version>1.0.1</version>
5052
</dependency>
5153
```
5254

build.gradle

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ plugins {
55
id 'signing'
66
id 'java-library'
77
id 'maven-publish'
8-
id 'org.springframework.boot' version '3.0.0'
9-
id 'io.spring.dependency-management' version '1.1.0'
8+
id 'org.springframework.boot' version '3.1.0'
9+
id 'io.spring.dependency-management' version '1.1.5'
1010
}
1111

1212
group = 'com.github.joutvhu'
13-
version = '3.0.8'
13+
version = '3.1.8'
1414

1515
def snapshotVersion = version.endsWith('-SNAPSHOT') || version.endsWith('.SNAPSHOT')
1616

@@ -27,20 +27,11 @@ repositories {
2727

2828
ext {
2929
versions = [
30-
'spring-boot.version' : '3.0.0',
31-
'spring-framework.version' : '6.0.2',
32-
'spring-dynamic-commons.version': '2.0.0',
33-
'hibernate.version' : '6.1.5.Final'
30+
'spring-boot.version' : '3.1.0',
31+
'spring-dynamic-commons.version': '2.0.0'
3432
]
3533
managedVersions = [
36-
'org.springframework:spring-aspects' : 'spring-framework.version',
37-
'org.springframework:spring-context' : 'spring-framework.version',
38-
'org.springframework:spring-jcl' : 'spring-framework.version',
39-
'org.springframework:spring-context-support' : 'spring-framework.version',
40-
'org.springframework.data:spring-data-commons': 'spring-boot.version',
41-
'org.springframework.data:spring-data-jpa' : 'spring-boot.version',
42-
'com.github.joutvhu:spring-dynamic-commons' : 'spring-dynamic-commons.version',
43-
'org.hibernate.orm:hibernate-core' : 'hibernate.version'
34+
'com.github.joutvhu:spring-dynamic-commons' : 'spring-dynamic-commons.version'
4435
]
4536
otherVersions = [
4637
'org.springframework.boot:spring-boot-dependencies': 'spring-boot.version'
@@ -70,8 +61,8 @@ dependencies {
7061

7162
implementation 'org.hibernate.orm:hibernate-core'
7263

73-
compileOnly 'org.projectlombok:lombok:1.18.26'
74-
annotationProcessor 'org.projectlombok:lombok:1.18.26'
64+
compileOnly 'org.projectlombok:lombok:1.18.32'
65+
annotationProcessor 'org.projectlombok:lombok:1.18.32'
7566

7667
testImplementation(platform('org.junit:junit-bom:5.8.2'))
7768
testImplementation 'org.junit.jupiter:junit-jupiter-api'
@@ -85,10 +76,10 @@ dependencies {
8576
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
8677
}
8778
testImplementation 'com.h2database:h2'
88-
testImplementation 'com.github.joutvhu:spring-dynamic-freemarker:1.0.0'
79+
testImplementation 'com.github.joutvhu:spring-dynamic-freemarker:1.0.1'
8980

90-
testCompileOnly 'org.projectlombok:lombok:1.18.26'
91-
testAnnotationProcessor 'org.projectlombok:lombok:1.18.26'
81+
testCompileOnly 'org.projectlombok:lombok:1.18.32'
82+
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'
9283
}
9384

9485
jar {

src/main/java/com/joutvhu/dynamic/jpa/query/DynamicJpaRepositoryQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ protected Query doCreateCountQuery(JpaParametersParameterAccessor accessor) {
125125
String countProjectionString = buildQuery(method.getCountProjectionTemplate(), accessor);
126126

127127
countQuery = new DynamicBasedStringQuery(
128-
query.deriveCountQuery(countQueryString, countProjectionString),
128+
query.deriveCountQueryString(countQueryString, countProjectionString),
129129
method.getEntityInformation(), PARSER, method.isNativeQuery());
130130

131131
if (!method.isNativeQuery() && method.isPageQuery())

src/main/java/org/springframework/data/jpa/repository/query/DynamicBasedStringQuery.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.springframework.data.jpa.repository.query;
22

33
import org.springframework.expression.spel.standard.SpelExpressionParser;
4+
import org.springframework.lang.Nullable;
5+
import org.springframework.util.StringUtils;
46

57
/**
68
* Extension of {@link StringQuery} that evaluates the given query string as a SpEL template-expression.
@@ -9,6 +11,8 @@
911
* @since 2.x.1
1012
*/
1113
public class DynamicBasedStringQuery extends ExpressionBasedStringQuery {
14+
private final QueryEnhancer queryEnhancer;
15+
1216
/**
1317
* Creates a new {@link DynamicBasedStringQuery} for the given query and {@link org.springframework.data.repository.core.EntityMetadata}.
1418
*
@@ -19,6 +23,7 @@ public class DynamicBasedStringQuery extends ExpressionBasedStringQuery {
1923
*/
2024
public DynamicBasedStringQuery(String query, JpaEntityMetadata<?> metadata, SpelExpressionParser parser, boolean nativeQuery) {
2125
super(query, metadata, parser, nativeQuery);
26+
this.queryEnhancer = QueryEnhancerFactory.forQuery(this);
2227
}
2328

2429
public DynamicBasedStringQuery(DeclaredQuery query, JpaEntityMetadata<?> metadata, SpelExpressionParser parser) {
@@ -28,4 +33,9 @@ public DynamicBasedStringQuery(DeclaredQuery query, JpaEntityMetadata<?> metadat
2833
public DynamicBasedStringQuery(DeclaredQuery query, JpaEntityMetadata<?> metadata, SpelExpressionParser parser, boolean nativeQuery) {
2934
this(query.getQueryString(), metadata, parser, nativeQuery);
3035
}
36+
37+
public String deriveCountQueryString(@Nullable String countQuery, @Nullable String countQueryProjection) {
38+
return StringUtils.hasText(countQuery) ? countQuery : this.queryEnhancer
39+
.createCountQueryFor(countQueryProjection);
40+
}
3141
}

0 commit comments

Comments
 (0)