Skip to content

Commit

Permalink
Merge pull request #28 from joutvhu/develop
Browse files Browse the repository at this point in the history
Fix deriveCountQuery method for spring boot > 3.1.9
  • Loading branch information
joutvhu authored May 14, 2024
2 parents dab4b89 + 9adc38e commit 6c94034
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,32 @@ The Spring Dynamic JPA will make it easy to implement dynamic queries with JpaRe
### Install dependency

```groovy
implementation 'com.github.joutvhu:spring-dynamic-jpa:3.0.8'
implementation 'com.github.joutvhu:spring-dynamic-jpa:3.1.8'
```

```xml
<dependency>
<groupId>com.github.joutvhu</groupId>
<artifactId>spring-dynamic-jpa</artifactId>
<version>3.0.8</version>
<version>3.1.8</version>
</dependency>
```

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

| Spring Boot version | Spring Dynamic JPA version |
|:----------:|:-------------:|
| 2.0.x.RELEASE | 2.0.8 |
| 2.1.x.RELEASE | 2.1.8 |
| 2.2.x.RELEASE | 2.2.8 |
| 2.3.x.RELEASE | 2.3.8 |
| 2.4.x | 2.3.8 |
| 2.5.x | 2.3.8 |
| 2.6.x | 2.3.8 |
| 2.7.x | 2.7.8 |
| 3.0.x | 3.0.8 |
|:-------------------:|:--------------------------:|
| 2.0.x.RELEASE | 2.0.8 |
| 2.1.x.RELEASE | 2.1.8 |
| 2.2.x.RELEASE | 2.2.8 |
| 2.3.x.RELEASE | 2.3.8 |
| 2.4.x | 2.3.8 |
| 2.5.x | 2.3.8 |
| 2.6.x | 2.3.8 |
| 2.7.x | 2.7.8 |
| 3.0.x | 3.0.8 |
| 3.1.x | 3.1.8 |
| 3.2.x | 3.1.8 |

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

```groovy
implementation 'com.github.joutvhu:spring-dynamic-freemarker:1.0.0'
implementation 'com.github.joutvhu:spring-dynamic-freemarker:1.0.1'
```

```xml
<dependency>
<groupId>com.github.joutvhu</groupId>
<artifactId>spring-dynamic-freemarker</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</dependency>
```

Expand Down
31 changes: 11 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {
id 'signing'
id 'java-library'
id 'maven-publish'
id 'org.springframework.boot' version '3.0.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.springframework.boot' version '3.1.0'
id 'io.spring.dependency-management' version '1.1.5'
}

group = 'com.github.joutvhu'
version = '3.0.8'
version = '3.1.8'

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

Expand All @@ -27,20 +27,11 @@ repositories {

ext {
versions = [
'spring-boot.version' : '3.0.0',
'spring-framework.version' : '6.0.2',
'spring-dynamic-commons.version': '2.0.0',
'hibernate.version' : '6.1.5.Final'
'spring-boot.version' : '3.1.0',
'spring-dynamic-commons.version': '2.0.0'
]
managedVersions = [
'org.springframework:spring-aspects' : 'spring-framework.version',
'org.springframework:spring-context' : 'spring-framework.version',
'org.springframework:spring-jcl' : 'spring-framework.version',
'org.springframework:spring-context-support' : 'spring-framework.version',
'org.springframework.data:spring-data-commons': 'spring-boot.version',
'org.springframework.data:spring-data-jpa' : 'spring-boot.version',
'com.github.joutvhu:spring-dynamic-commons' : 'spring-dynamic-commons.version',
'org.hibernate.orm:hibernate-core' : 'hibernate.version'
'com.github.joutvhu:spring-dynamic-commons' : 'spring-dynamic-commons.version'
]
otherVersions = [
'org.springframework.boot:spring-boot-dependencies': 'spring-boot.version'
Expand Down Expand Up @@ -70,8 +61,8 @@ dependencies {

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

compileOnly 'org.projectlombok:lombok:1.18.26'
annotationProcessor 'org.projectlombok:lombok:1.18.26'
compileOnly 'org.projectlombok:lombok:1.18.32'
annotationProcessor 'org.projectlombok:lombok:1.18.32'

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

testCompileOnly 'org.projectlombok:lombok:1.18.26'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.26'
testCompileOnly 'org.projectlombok:lombok:1.18.32'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected Query doCreateCountQuery(JpaParametersParameterAccessor accessor) {
String countProjectionString = buildQuery(method.getCountProjectionTemplate(), accessor);

countQuery = new DynamicBasedStringQuery(
query.deriveCountQuery(countQueryString, countProjectionString),
query.deriveCountQueryString(countQueryString, countProjectionString),
method.getEntityInformation(), PARSER, method.isNativeQuery());

if (!method.isNativeQuery() && method.isPageQuery())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.springframework.data.jpa.repository.query;

import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;

/**
* Extension of {@link StringQuery} that evaluates the given query string as a SpEL template-expression.
Expand All @@ -9,6 +11,8 @@
* @since 2.x.1
*/
public class DynamicBasedStringQuery extends ExpressionBasedStringQuery {
private final QueryEnhancer queryEnhancer;

/**
* Creates a new {@link DynamicBasedStringQuery} for the given query and {@link org.springframework.data.repository.core.EntityMetadata}.
*
Expand All @@ -19,6 +23,7 @@ public class DynamicBasedStringQuery extends ExpressionBasedStringQuery {
*/
public DynamicBasedStringQuery(String query, JpaEntityMetadata<?> metadata, SpelExpressionParser parser, boolean nativeQuery) {
super(query, metadata, parser, nativeQuery);
this.queryEnhancer = QueryEnhancerFactory.forQuery(this);
}

public DynamicBasedStringQuery(DeclaredQuery query, JpaEntityMetadata<?> metadata, SpelExpressionParser parser) {
Expand All @@ -28,4 +33,9 @@ public DynamicBasedStringQuery(DeclaredQuery query, JpaEntityMetadata<?> metadat
public DynamicBasedStringQuery(DeclaredQuery query, JpaEntityMetadata<?> metadata, SpelExpressionParser parser, boolean nativeQuery) {
this(query.getQueryString(), metadata, parser, nativeQuery);
}

public String deriveCountQueryString(@Nullable String countQuery, @Nullable String countQueryProjection) {
return StringUtils.hasText(countQuery) ? countQuery : this.queryEnhancer
.createCountQueryFor(countQueryProjection);
}
}

0 comments on commit 6c94034

Please sign in to comment.