Skip to content

Commit 882c8ef

Browse files
committed
Merge branch 'master' into r2dbc-support
# Conflicts: # src/main/resources/org/mybatis/dynamic/sql/util/messages.properties
2 parents e0d9ef6 + 0e91dad commit 882c8ef

File tree

114 files changed

+4573
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+4573
-401
lines changed

.github/workflows/codeql.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ "master" ]
17+
pull_request:
18+
branches: [ "master" ]
19+
schedule:
20+
- cron: '26 13 * * 4'
21+
22+
jobs:
23+
analyze:
24+
name: Analyze
25+
# Runner size impacts CodeQL analysis time. To learn more, please see:
26+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
27+
# - https://gh.io/supported-runners-and-hardware-resources
28+
# - https://gh.io/using-larger-runners
29+
# Consider using larger runners for possible analysis time improvements.
30+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
31+
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
32+
permissions:
33+
# required for all workflows
34+
security-events: write
35+
36+
# only required for workflows in private repositories
37+
actions: read
38+
contents: read
39+
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
language: [ 'java-kotlin' ]
44+
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
45+
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
46+
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
47+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
48+
49+
steps:
50+
- name: Checkout repository
51+
uses: actions/checkout@v4
52+
53+
# Initializes the CodeQL tools for scanning.
54+
- name: Initialize CodeQL
55+
uses: github/codeql-action/init@v3
56+
with:
57+
languages: ${{ matrix.language }}
58+
# If you wish to specify custom queries, you can do so here or in a config file.
59+
# By default, queries listed here will override any specified in a config file.
60+
# Prefix the list here with "+" to use these queries and those in the config file.
61+
62+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
63+
# queries: security-extended,security-and-quality
64+
65+
66+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
67+
# If this step fails, then you should remove it and run the build manually (see below)
68+
- name: Autobuild
69+
uses: github/codeql-action/autobuild@v3
70+
71+
# ℹ️ Command-line programs to run using the OS shell.
72+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
73+
74+
# If the Autobuild fails above, remove it and uncomment the following three lines.
75+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
76+
77+
# - run: |
78+
# echo "Run, Build Application using script"
79+
# ./location_of_script_within_repo/buildscript.sh
80+
81+
- name: Perform CodeQL Analysis
82+
uses: github/codeql-action/analyze@v3
83+
with:
84+
category: "/language:${{matrix.language}}"

.github/workflows/sonar.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
java-version: 21
2121
distribution: zulu
2222
- name: Analyze with SonarCloud
23-
run: ./mvnw verify jacoco:report sonar:sonar -B -Dsonar.projectKey=mybatis_mybatis-dynamic-sql -Dsonar.organization=mybatis -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dlicense.skip=true --no-transfer-progress
23+
run: ./mvnw verify jacoco:report sonar:sonar -B -Dsonar.projectKey=mybatis_mybatis-dynamic-sql -Dsonar.organization=mybatis -Dsonar.host.url=https://sonarcloud.io -Dsonar.token=$SONAR_TOKEN -Dlicense.skip=true --no-transfer-progress
2424
env:
2525
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2626
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ buildNumber.properties
1616
.DS_Store
1717
.idea
1818
*.iml
19+
.github/keys/

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,31 @@ This log will detail notable changes to MyBatis Dynamic SQL. Full details are av
44

55
## Release 1.5.1 - Unreleased
66

7-
This is a minor release with a few small enhancements.
7+
This is a minor release with several enhancements.
88

99
GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/milestone/13](https://github.com/mybatis/mybatis-dynamic-sql/milestone/13)
1010

11+
### Case Expressions and Cast Function
12+
We've added support for CASE expressions to the library. Both simple and searched case expressions are supported.
13+
This is a fairly extensive enhancement as case expressions are quite complex, but we were able to reuse many of the
14+
building blocks from the WHERE and HAVING support already in the library. You should be able to build CASE expressions
15+
with relatively few limitations.
16+
17+
It is also common to use a CAST function with CASE expressions, so we have added CAST as a built-in function
18+
in the library.
19+
20+
The DSL for both Java and Kotlin has been updated to fully support CASE expressions in the same idiomatic forms
21+
as other parts of the library.
22+
23+
We've tested this extensively and the code is, of course, 100% covered by test code. But it is possible that we've not
24+
covered every scenario. Please let us know if you find issues.
25+
26+
Full documentation is available here:
27+
- [Java Case Expression DSL Documentation](caseExpressions.md)
28+
- [Kotlin Case Expression DSL Documentation](kotlinCaseExpressions.md)
29+
30+
The pull request for this change is ([#761](https://github.com/mybatis/mybatis-dynamic-sql/pull/761))
31+
1132
### Parameter Values in Joins
1233

1334
We've added the ability to specify typed values in equi-joins. This allows you to avoid the use of constants, and it is
@@ -39,6 +60,11 @@ types - which is a rare usage. Please let us know if this causes an undo hardshi
3960
your code accordingly. ([#662](https://github.com/mybatis/mybatis-dynamic-sql/pull/662))
4061
2. Added the ability to code a bound value in rendered SQL. This is similar to a constant, but the value is added to
4162
the parameter map and a bind parameter marker is rendered. ([#738](https://github.com/mybatis/mybatis-dynamic-sql/pull/738))
63+
3. Refactored the conditions to separate the concept of an empty condition from that of a renderable condition. This
64+
will enable a future change where conditions could decide to allow rendering even if they are considered empty (such
65+
as rendering empty lists). This change should be transparent to users unless they have implemented custom conditions.
66+
4. Added a configuration setting to allow empty list conditions to render. This could generate invalid SQL, but might be
67+
a good safety measure in some cases.
4268

4369
## Release 1.5.0 - April 21, 2023
4470

LICENSE

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Apache License
22
Version 2.0, January 2004
3-
http://www.apache.org/licenses/
3+
https://www.apache.org/licenses/
44

55
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
66

@@ -178,24 +178,25 @@
178178
APPENDIX: How to apply the Apache License to your work.
179179

180180
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "{}"
181+
boilerplate notice, with the fields enclosed by brackets "[]"
182182
replaced with your own identifying information. (Don't include
183183
the brackets!) The text should be enclosed in the appropriate
184184
comment syntax for the file format. We also recommend that a
185185
file or class name and description of purpose be included on the
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright [yyyy] [name of copyright owner]
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.
193193
You may obtain a copy of the License at
194194

195-
http://www.apache.org/licenses/LICENSE-2.0
195+
https://www.apache.org/licenses/LICENSE-2.0
196196

197197
Unless required by applicable law or agreed to in writing, software
198198
distributed under the License is distributed on an "AS IS" BASIS,
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201201
limitations under the License.
202+

pom.xml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@
2929
<name>MyBatis Dynamic SQL</name>
3030
<description>MyBatis framework for generating dynamic SQL</description>
3131
<inceptionYear>2016</inceptionYear>
32+
<url>https://www.mybatis.org/mybatis-dynamic-sql/</url>
3233

3334
<scm>
3435
<connection>scm:git:ssh://[email protected]/mybatis/mybatis-dynamic-sql.git</connection>
3536
<developerConnection>scm:git:ssh://[email protected]/mybatis/mybatis-dynamic-sql.git</developerConnection>
3637
<tag>HEAD</tag>
37-
<url>https://github.com/mybatis/mybatis-dynamic-sql</url>
38+
<url>https://github.com/mybatis/mybatis-dynamic-sql/</url>
3839
</scm>
3940
<issueManagement>
4041
<system>GitHub Issue Management</system>
@@ -55,23 +56,23 @@
5556
<properties>
5657
<java.version>17</java.version>
5758
<java.release.version>8</java.release.version>
58-
<junit.jupiter.version>5.10.1</junit.jupiter.version>
59-
<spring.batch.version>5.1.0</spring.batch.version>
59+
<junit.jupiter.version>5.10.2</junit.jupiter.version>
60+
<spring.batch.version>5.1.1</spring.batch.version>
6061

6162
<checkstyle.config>checkstyle-override.xml</checkstyle.config>
6263

6364
<clirr.comparisonVersion>1.5.0</clirr.comparisonVersion>
6465

6566
<module.name>org.mybatis.dynamic.sql</module.name>
6667

67-
<kotlin.version>1.9.22</kotlin.version>
68+
<kotlin.version>1.9.23</kotlin.version>
6869
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
6970

7071
<sonar.sources>pom.xml,src/main/java,src/main/kotlin</sonar.sources>
7172
<sonar.tests>src/test/java,src/test/kotlin</sonar.tests>
7273

7374
<kotlin.code.style>official</kotlin.code.style>
74-
<test.containers.version>1.19.4</test.containers.version>
75+
<test.containers.version>1.19.7</test.containers.version>
7576
<osgi.export>org.mybatis.dynamic.sql.*;version=${project.version};-noimport:=true</osgi.export>
7677

7778
<!-- Reproducible Builds -->
@@ -89,7 +90,7 @@
8990
<dependency>
9091
<groupId>org.springframework</groupId>
9192
<artifactId>spring-jdbc</artifactId>
92-
<version>6.1.3</version>
93+
<version>6.1.5</version>
9394
<scope>provided</scope>
9495
<optional>true</optional>
9596
</dependency>
@@ -122,7 +123,7 @@
122123
<dependency>
123124
<groupId>org.assertj</groupId>
124125
<artifactId>assertj-core</artifactId>
125-
<version>3.25.2</version>
126+
<version>3.25.3</version>
126127
<scope>test</scope>
127128
</dependency>
128129
<dependency>
@@ -158,7 +159,7 @@
158159
<dependency>
159160
<groupId>ch.qos.logback</groupId>
160161
<artifactId>logback-classic</artifactId>
161-
<version>1.4.14</version>
162+
<version>1.5.3</version>
162163
<scope>test</scope>
163164
</dependency>
164165
<!-- Hamcrest is only here to make Infinitest happy. Not really used in the project. -->
@@ -184,7 +185,7 @@
184185
<dependency>
185186
<groupId>org.postgresql</groupId>
186187
<artifactId>postgresql</artifactId>
187-
<version>42.7.1</version>
188+
<version>42.7.3</version>
188189
<scope>test</scope>
189190
</dependency>
190191
<dependency>
@@ -196,7 +197,7 @@
196197
<dependency>
197198
<groupId>org.mariadb.jdbc</groupId>
198199
<artifactId>mariadb-java-client</artifactId>
199-
<version>3.3.2</version>
200+
<version>3.3.3</version>
200201
<scope>test</scope>
201202
</dependency>
202203

renovate.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
33
"extends": [
4-
"config:base"
4+
"config:recommended"
55
]
66
}

src/main/java/org/mybatis/dynamic/sql/AbstractListValueCondition.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.stream.Collectors;
2424
import java.util.stream.Stream;
2525

26+
import org.mybatis.dynamic.sql.render.RenderingContext;
27+
2628
public abstract class AbstractListValueCondition<T> implements VisitableCondition<T> {
2729
protected final Collection<T> values;
2830

@@ -35,8 +37,17 @@ public final <R> Stream<R> mapValues(Function<T, R> mapper) {
3537
}
3638

3739
@Override
38-
public boolean shouldRender() {
39-
return !values.isEmpty();
40+
public boolean isEmpty() {
41+
return values.isEmpty();
42+
}
43+
44+
@Override
45+
public boolean shouldRender(RenderingContext renderingContext) {
46+
if (isEmpty()) {
47+
return renderingContext.isEmptyListConditionRenderingAllowed();
48+
} else {
49+
return true;
50+
}
4051
}
4152

4253
@Override
@@ -56,20 +67,20 @@ private Collection<T> applyFilter(Predicate<? super T> predicate) {
5667

5768
protected <S extends AbstractListValueCondition<T>> S filterSupport(Predicate<? super T> predicate,
5869
Function<Collection<T>, S> constructor, S self, Supplier<S> emptySupplier) {
59-
if (shouldRender()) {
70+
if (isEmpty()) {
71+
return self;
72+
} else {
6073
Collection<T> filtered = applyFilter(predicate);
6174
return filtered.isEmpty() ? emptySupplier.get() : constructor.apply(filtered);
62-
} else {
63-
return self;
6475
}
6576
}
6677

6778
protected <R, S extends AbstractListValueCondition<R>> S mapSupport(Function<? super T, ? extends R> mapper,
6879
Function<Collection<R>, S> constructor, Supplier<S> emptySupplier) {
69-
if (shouldRender()) {
70-
return constructor.apply(applyMapper(mapper));
71-
} else {
80+
if (isEmpty()) {
7281
return emptySupplier.get();
82+
} else {
83+
return constructor.apply(applyMapper(mapper));
7384
}
7485
}
7586

src/main/java/org/mybatis/dynamic/sql/AbstractNoValueCondition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public <R> R accept(ConditionVisitor<T, R> visitor) {
2727

2828
protected <S extends AbstractNoValueCondition<?>> S filterSupport(BooleanSupplier booleanSupplier,
2929
Supplier<S> emptySupplier, S self) {
30-
if (shouldRender()) {
31-
return booleanSupplier.getAsBoolean() ? self : emptySupplier.get();
32-
} else {
30+
if (isEmpty()) {
3331
return self;
32+
} else {
33+
return booleanSupplier.getAsBoolean() ? self : emptySupplier.get();
3434
}
3535
}
3636

src/main/java/org/mybatis/dynamic/sql/AbstractSingleValueCondition.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ public <R> R accept(ConditionVisitor<T, R> visitor) {
3737

3838
protected <S extends AbstractSingleValueCondition<T>> S filterSupport(Predicate<? super T> predicate,
3939
Supplier<S> emptySupplier, S self) {
40-
if (shouldRender()) {
41-
return predicate.test(value) ? self : emptySupplier.get();
42-
} else {
40+
if (isEmpty()) {
4341
return self;
42+
} else {
43+
return predicate.test(value) ? self : emptySupplier.get();
4444
}
4545
}
4646

4747
protected <R, S extends AbstractSingleValueCondition<R>> S mapSupport(Function<? super T, ? extends R> mapper,
4848
Function<R, S> constructor, Supplier<S> emptySupplier) {
49-
if (shouldRender()) {
50-
return constructor.apply(mapper.apply(value));
51-
} else {
49+
if (isEmpty()) {
5250
return emptySupplier.get();
51+
} else {
52+
return constructor.apply(mapper.apply(value));
5353
}
5454
}
5555

0 commit comments

Comments
 (0)