Skip to content

Commit 67c069f

Browse files
authored
Merge pull request #143 from jeffgbutler/master
Misc Updates
2 parents 79f815f + ff4ec22 commit 67c069f

23 files changed

+380
-358
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<maven.compiler.target>${java.version}</maven.compiler.target>
3636
<junit.jupiter.version>5.5.2</junit.jupiter.version>
3737
<junit.platform.version>1.5.2</junit.platform.version>
38-
<spring.batch.version>4.1.2.RELEASE</spring.batch.version>
38+
<spring.batch.version>4.2.0.RELEASE</spring.batch.version>
3939
<clirr.comparisonVersion>1.1.0</clirr.comparisonVersion>
4040
<module.name>org.mybatis.dynamic.sql</module.name>
4141
<kotlin.version>1.3.50</kotlin.version>
@@ -174,7 +174,7 @@
174174
<dependency>
175175
<groupId>org.springframework</groupId>
176176
<artifactId>spring-jdbc</artifactId>
177-
<version>5.1.9.RELEASE</version>
177+
<version>5.2.0.RELEASE</version>
178178
<scope>provided</scope>
179179
</dependency>
180180

src/main/java/org/mybatis/dynamic/sql/render/RenderingStrategy.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.mybatis.dynamic.sql.render;
1717

18+
import java.util.concurrent.atomic.AtomicInteger;
19+
1820
import org.mybatis.dynamic.sql.BindableColumn;
1921

2022
public abstract class RenderingStrategy {
@@ -38,6 +40,10 @@ public abstract class RenderingStrategy {
3840

3941
public static final String DEFAULT_PARAMETER_PREFIX = "parameters"; //$NON-NLS-1$
4042

43+
public static String formatParameterMapKey(AtomicInteger sequence) {
44+
return "p" + sequence.getAndIncrement(); //$NON-NLS-1$
45+
}
46+
4147
public abstract String getFormattedJdbcPlaceholder(BindableColumn<?> column, String prefix, String parameterName);
4248

4349
public abstract String getFormattedJdbcPlaceholder(String prefix, String parameterName);

src/main/java/org/mybatis/dynamic/sql/select/render/FetchFirstPagingModelRenderer.java

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
2-
* Copyright 2016-2019 the original author or authors.
3-
* <p>
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
* <p>
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
* <p>
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616
package org.mybatis.dynamic.sql.select.render;
1717

@@ -23,14 +23,12 @@
2323
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
2424

2525
public class FetchFirstPagingModelRenderer {
26-
private static final String FETCH_FIRST_ROWS_PARAMETER = "_fetchFirstRows"; //$NON-NLS-1$
27-
private static final String OFFSET_PARAMETER = "_offset"; //$NON-NLS-1$
2826
private RenderingStrategy renderingStrategy;
2927
private PagingModel pagingModel;
3028
private AtomicInteger sequence;
3129

3230
public FetchFirstPagingModelRenderer(RenderingStrategy renderingStrategy,
33-
PagingModel pagingModel, AtomicInteger sequence) {
31+
PagingModel pagingModel, AtomicInteger sequence) {
3432
this.renderingStrategy = renderingStrategy;
3533
this.pagingModel = pagingModel;
3634
this.sequence = sequence;
@@ -53,25 +51,25 @@ private Optional<FragmentAndParameters> renderFetchFirstRowsOnly() {
5351
}
5452

5553
private Optional<FragmentAndParameters> renderFetchFirstRowsOnly(Long fetchFirstRows) {
56-
String mapKey = formatParameterMapKey(FETCH_FIRST_ROWS_PARAMETER);
54+
String mapKey = RenderingStrategy.formatParameterMapKey(sequence);
5755
return FragmentAndParameters
5856
.withFragment("fetch first " + renderPlaceholder(mapKey) //$NON-NLS-1$
59-
+ " rows only") //$NON-NLS-1$
57+
+ " rows only") //$NON-NLS-1$
6058
.withParameter(mapKey, fetchFirstRows)
6159
.buildOptional();
6260
}
6361

6462
private Optional<FragmentAndParameters> renderOffsetOnly(Long offset) {
65-
String mapKey = formatParameterMapKey(OFFSET_PARAMETER);
63+
String mapKey = RenderingStrategy.formatParameterMapKey(sequence);
6664
return FragmentAndParameters.withFragment("offset " + renderPlaceholder(mapKey) //$NON-NLS-1$
6765
+ " rows") //$NON-NLS-1$
6866
.withParameter(mapKey, offset)
6967
.buildOptional();
7068
}
7169

7270
private Optional<FragmentAndParameters> renderOffsetAndFetchFirstRows(Long offset, Long fetchFirstRows) {
73-
String mapKey1 = formatParameterMapKey(OFFSET_PARAMETER);
74-
String mapKey2 = formatParameterMapKey(FETCH_FIRST_ROWS_PARAMETER);
71+
String mapKey1 = RenderingStrategy.formatParameterMapKey(sequence);
72+
String mapKey2 = RenderingStrategy.formatParameterMapKey(sequence);
7573
return FragmentAndParameters.withFragment("offset " + renderPlaceholder(mapKey1) //$NON-NLS-1$
7674
+ " rows fetch first " + renderPlaceholder(mapKey2) //$NON-NLS-1$
7775
+ " rows only") //$NON-NLS-1$
@@ -80,10 +78,6 @@ private Optional<FragmentAndParameters> renderOffsetAndFetchFirstRows(Long offse
8078
.buildOptional();
8179
}
8280

83-
private String formatParameterMapKey(String parameterMapKey) {
84-
return parameterMapKey + sequence.getAndIncrement(); //$NON-NLS-1$
85-
}
86-
8781
private String renderPlaceholder(String parameterName) {
8882
return renderingStrategy.getFormattedJdbcPlaceholder(RenderingStrategy.DEFAULT_PARAMETER_PREFIX,
8983
parameterName);

src/main/java/org/mybatis/dynamic/sql/select/render/LimitAndOffsetPagingModelRenderer.java

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
2-
* Copyright 2016-2019 the original author or authors.
3-
* <p>
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
* <p>
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
* <p>
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616
package org.mybatis.dynamic.sql.select.render;
1717

@@ -23,15 +23,13 @@
2323
import org.mybatis.dynamic.sql.util.FragmentAndParameters;
2424

2525
public class LimitAndOffsetPagingModelRenderer {
26-
private static final String LIMIT_PARAMETER = "_limit"; //$NON-NLS-1$
27-
private static final String OFFSET_PARAMETER = "_offset"; //$NON-NLS-1$
2826
private RenderingStrategy renderingStrategy;
2927
private Long limit;
3028
private PagingModel pagingModel;
3129
private AtomicInteger sequence;
3230

3331
public LimitAndOffsetPagingModelRenderer(RenderingStrategy renderingStrategy,
34-
Long limit, PagingModel pagingModel, AtomicInteger sequence) {
32+
Long limit, PagingModel pagingModel, AtomicInteger sequence) {
3533
this.renderingStrategy = renderingStrategy;
3634
this.limit = limit;
3735
this.pagingModel = pagingModel;
@@ -44,26 +42,22 @@ public Optional<FragmentAndParameters> render() {
4442
}
4543

4644
private Optional<FragmentAndParameters> renderLimitOnly() {
47-
String mapKey = formatParameterMapKey(LIMIT_PARAMETER);
45+
String mapKey = RenderingStrategy.formatParameterMapKey(sequence);
4846
return FragmentAndParameters.withFragment("limit " + renderPlaceholder(mapKey)) //$NON-NLS-1$
4947
.withParameter(mapKey, limit)
5048
.buildOptional();
5149
}
5250

5351
private Optional<FragmentAndParameters> renderLimitAndOffset(Long offset) {
54-
String mapKey1 = formatParameterMapKey(LIMIT_PARAMETER);
55-
String mapKey2 = formatParameterMapKey(OFFSET_PARAMETER);
52+
String mapKey1 = RenderingStrategy.formatParameterMapKey(sequence);
53+
String mapKey2 = RenderingStrategy.formatParameterMapKey(sequence);
5654
return FragmentAndParameters.withFragment("limit " + renderPlaceholder(mapKey1) //$NON-NLS-1$
57-
+ " offset " + renderPlaceholder(mapKey2)) //$NON-NLS-1$
55+
+ " offset " + renderPlaceholder(mapKey2)) //$NON-NLS-1$
5856
.withParameter(mapKey1, limit)
5957
.withParameter(mapKey2, offset)
6058
.buildOptional();
6159
}
6260

63-
private String formatParameterMapKey(String parameterMapKey) {
64-
return parameterMapKey + sequence.getAndIncrement(); //$NON-NLS-1$
65-
}
66-
6761
private String renderPlaceholder(String parameterName) {
6862
return renderingStrategy.getFormattedJdbcPlaceholder(RenderingStrategy.DEFAULT_PARAMETER_PREFIX,
6963
parameterName);

src/main/java/org/mybatis/dynamic/sql/select/render/PagingModelRenderer.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
2-
* Copyright 2016-2019 the original author or authors.
3-
* <p>
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
* <p>
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
* <p>
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616
package org.mybatis.dynamic.sql.select.render;
1717

src/main/java/org/mybatis/dynamic/sql/select/render/SelectRenderer.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
2-
* Copyright 2016-2019 the original author or authors.
3-
* <p>
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
* <p>
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
* <p>
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
1515
*/
1616
package org.mybatis.dynamic.sql.select.render;
1717

@@ -83,7 +83,7 @@ private String calculateOrderByPhrase(SortSpecification column) {
8383

8484
private void renderPagingModel(FragmentCollector fragmentCollector) {
8585
selectModel.pagingModel().flatMap(this::renderPagingModel)
86-
.ifPresent(fragmentCollector::add);
86+
.ifPresent(fragmentCollector::add);
8787
}
8888

8989
private Optional<FragmentAndParameters> renderPagingModel(PagingModel pagingModel) {

src/main/java/org/mybatis/dynamic/sql/update/render/SetPhraseVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public FragmentAndParameters visit(StringConstantMapping mapping) {
6969

7070
@Override
7171
public <T> FragmentAndParameters visit(ValueMapping<T> mapping) {
72-
String mapKey = "p" + sequence.getAndIncrement(); //$NON-NLS-1$
72+
String mapKey = RenderingStrategy.formatParameterMapKey(sequence);
7373

7474
String jdbcPlaceholder = mapping.mapColumn(toJdbcPlaceholder(mapKey));
7575
String setPhrase = mapping.mapColumn(SqlColumn::name)

src/main/java/org/mybatis/dynamic/sql/util/mybatis3/MyBatis3Utils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public static int deleteFrom(ToIntFunction<DeleteStatementProvider> mapper,
8181
return mapper.applyAsInt(deleteFrom(table, completer));
8282
}
8383

84-
public static <R> InsertStatementProvider<R> insert(R record, SqlTable table, UnaryOperator<InsertDSL<R>> completer) {
84+
public static <R> InsertStatementProvider<R> insert(R record, SqlTable table,
85+
UnaryOperator<InsertDSL<R>> completer) {
8586
return completer.apply(SqlBuilder.insert(record).into(table))
8687
.build()
8788
.render(RenderingStrategies.MYBATIS3);

src/main/java/org/mybatis/dynamic/sql/where/render/WhereConditionVisitor.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public Optional<FragmentAndParameters> visit(AbstractNoValueCondition<T> conditi
7272

7373
@Override
7474
public Optional<FragmentAndParameters> visit(AbstractSingleValueCondition<T> condition) {
75-
String mapKey = formatParameterMapKey(sequence.getAndIncrement());
75+
String mapKey = RenderingStrategy.formatParameterMapKey(sequence);
7676
String fragment = condition.renderCondition(columnName(),
7777
getFormattedJdbcPlaceholder(mapKey));
7878

@@ -83,8 +83,8 @@ public Optional<FragmentAndParameters> visit(AbstractSingleValueCondition<T> con
8383

8484
@Override
8585
public Optional<FragmentAndParameters> visit(AbstractTwoValueCondition<T> condition) {
86-
String mapKey1 = formatParameterMapKey(sequence.getAndIncrement());
87-
String mapKey2 = formatParameterMapKey(sequence.getAndIncrement());
86+
String mapKey1 = RenderingStrategy.formatParameterMapKey(sequence);
87+
String mapKey2 = RenderingStrategy.formatParameterMapKey(sequence);
8888
String fragment = condition.renderCondition(columnName(),
8989
getFormattedJdbcPlaceholder(mapKey1),
9090
getFormattedJdbcPlaceholder(mapKey2));
@@ -118,17 +118,13 @@ public Optional<FragmentAndParameters> visit(AbstractColumnComparisonCondition<T
118118
}
119119

120120
private FragmentAndParameters toFragmentAndParameters(T value) {
121-
String mapKey = formatParameterMapKey(sequence.getAndIncrement());
122-
121+
String mapKey = RenderingStrategy.formatParameterMapKey(sequence);
122+
123123
return FragmentAndParameters.withFragment(getFormattedJdbcPlaceholder(mapKey))
124124
.withParameter(mapKey, value)
125125
.build();
126126
}
127127

128-
private String formatParameterMapKey(int number) {
129-
return "p" + number; //$NON-NLS-1$
130-
}
131-
132128
private String getFormattedJdbcPlaceholder(String mapKey) {
133129
return renderingStrategy.getFormattedJdbcPlaceholder(column, parameterPrefix, mapKey);
134130
}

0 commit comments

Comments
 (0)