Skip to content

Commit d06e765

Browse files
author
Martin Fekete
committed
JsonbConfigurationSupport -> JsonbConfiguration
1 parent 2f45d43 commit d06e765

File tree

4 files changed

+25
-67
lines changed

4 files changed

+25
-67
lines changed
Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,29 @@
11
package io.github.perplexhub.rsql.jsonb;
22

3+
import lombok.Builder;
4+
35
/**
4-
* jsonb expression configuration
6+
* convenient way to define configuration, based on default values
7+
*
8+
* @param pathExists Postgresql {@code jsonb_path_exists} function to use
9+
* @param pathExistsTz Postgresql {@code jsonb_path_exists_tz} function to use
10+
* @param useDateTime enable temporal values support
511
*/
6-
public interface JsonbConfiguration {
7-
8-
JsonbConfiguration DEFAULT = new JsonbConfiguration() {
12+
@Builder
13+
public record JsonbConfiguration(String pathExists, String pathExistsTz, boolean useDateTime) {
914

10-
@Override
11-
public String pathExists() {
12-
return "jsonb_path_exists";
13-
}
14-
15-
@Override
16-
public String pathExistsTz() {
17-
return "jsonb_path_exists_tz";
18-
}
15+
public static final JsonbConfiguration DEFAULT = JsonbConfiguration.builder().build();
1916

20-
@Override
21-
public boolean useDateTime() {
22-
return false;
17+
public static class JsonbConfigurationBuilder {
18+
JsonbConfigurationBuilder() {
19+
pathExists = "jsonb_path_exists";
20+
pathExistsTz = "jsonb_path_exists_tz";
21+
useDateTime = false;
2322
}
23+
}
2424

25-
@Override
26-
public String toString() {
27-
return String.format("pathExists:%s,pathExistsTz:%s,useDateTime:%b", pathExists(), pathExistsTz(), useDateTime());
28-
}
29-
};
30-
31-
/**
32-
*
33-
* @return Postgresql {@code jsonb_path_exists} function to use
34-
*/
35-
String pathExists();
36-
37-
/**
38-
*
39-
* @return Postgresql {@code jsonb_path_exists_tz} function to use
40-
*/
41-
String pathExistsTz();
42-
43-
/**
44-
*
45-
* @return enable temporal values support
46-
*/
47-
boolean useDateTime();
25+
@Override
26+
public String toString() {
27+
return String.format("pathExists:%s,pathExistsTz:%s,useDateTime:%b", pathExists, pathExistsTz, useDateTime);
28+
}
4829
}

rsql-jpa/src/main/java/io/github/perplexhub/rsql/jsonb/JsonbConfigurationSupport.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

rsql-jpa/src/test/java/io/github/perplexhub/rsql/RSQLJPASupportPostgresJsonTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.github.perplexhub.rsql;
22

3-
import io.github.perplexhub.rsql.jsonb.JsonbConfigurationSupport;
3+
import io.github.perplexhub.rsql.jsonb.JsonbConfiguration;
44
import io.github.perplexhub.rsql.model.EntityWithJsonb;
55
import io.github.perplexhub.rsql.model.JsonbEntity;
66
import io.github.perplexhub.rsql.model.PostgresJsonEntity;
@@ -87,7 +87,7 @@ void testJsonSearchOfTemporal(List<PostgresJsonEntity> entities, String rsql, Li
8787
repository.saveAllAndFlush(entities);
8888

8989
//when
90-
List<PostgresJsonEntity> result = repository.findAll(toSpecification(QuerySupport.builder().rsqlQuery(rsql).jsonbConfiguration(JsonbConfigurationSupport.builder().useDateTime(true).build()).build()));
90+
List<PostgresJsonEntity> result = repository.findAll(toSpecification(QuerySupport.builder().rsqlQuery(rsql).jsonbConfiguration(JsonbConfiguration.builder().useDateTime(true).build()).build()));
9191

9292
//then
9393
assertThat(result)
@@ -728,7 +728,7 @@ void testJsonSearchCustomFunction(List<PostgresJsonEntity> entities, String rsql
728728
repository.saveAllAndFlush(entities);
729729

730730
//when
731-
List<PostgresJsonEntity> result = repository.findAll(toSpecification(QuerySupport.builder().rsqlQuery(rsql).jsonbConfiguration(JsonbConfigurationSupport.builder().pathExists("my_jsonb_path_exists").build()).build()));
731+
List<PostgresJsonEntity> result = repository.findAll(toSpecification(QuerySupport.builder().rsqlQuery(rsql).jsonbConfiguration(JsonbConfiguration.builder().pathExists("my_jsonb_path_exists").build()).build()));
732732

733733
//then
734734
assertThat(result)

rsql-jpa/src/test/java/io/github/perplexhub/rsql/jsonb/JsonbExpressionBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void testJsonbPathExpression(ComparisonOperator operator, String keyPath, List<S
2929
@ParameterizedTest
3030
@MethodSource("temporal")
3131
void testJsonbPathExpressionWithTemporal(ComparisonOperator operator, String keyPath, List<String> arguments, String expectedJsonbFunction, String expectedJsonbPath) {
32-
JsonbExpressionBuilder builder = new JsonbExpressionBuilder(operator, keyPath, arguments, JsonbConfigurationSupport.builder().useDateTime(true).build());
32+
JsonbExpressionBuilder builder = new JsonbExpressionBuilder(operator, keyPath, arguments, JsonbConfiguration.builder().useDateTime(true).build());
3333
var expression = builder.getJsonPathExpression();
3434
assertEquals(expectedJsonbFunction, expression.jsonbFunction());
3535
assertEquals(expectedJsonbPath, expression.jsonbPath());
@@ -38,7 +38,7 @@ void testJsonbPathExpressionWithTemporal(ComparisonOperator operator, String key
3838
@ParameterizedTest
3939
@MethodSource("customized")
4040
void testJsonbPathExpressionCustomized(ComparisonOperator operator, String keyPath, List<String> arguments, String expectedJsonbFunction, String expectedJsonbPath) {
41-
JsonbExpressionBuilder builder = new JsonbExpressionBuilder(operator, keyPath, arguments, JsonbConfigurationSupport.builder().pathExists("my_jsonb_path_exists").pathExistsTz("my_jsonb_path_exists_tz").useDateTime(true).build());
41+
JsonbExpressionBuilder builder = new JsonbExpressionBuilder(operator, keyPath, arguments, JsonbConfiguration.builder().pathExists("my_jsonb_path_exists").pathExistsTz("my_jsonb_path_exists_tz").useDateTime(true).build());
4242
var expression = builder.getJsonPathExpression();
4343
assertEquals(expectedJsonbFunction, expression.jsonbFunction());
4444
assertEquals(expectedJsonbPath, expression.jsonbPath());

0 commit comments

Comments
 (0)