Skip to content

Commit 9e7a99b

Browse files
committed
Merge branch 'master' into multi-insert
2 parents 2dc94f1 + c554e74 commit 9e7a99b

File tree

114 files changed

+8819
-417
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

+8819
-417
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: java
22

33
jdk:
4-
- oraclejdk11
4+
- openjdk11
55
- oraclejdk8
66

77
after_success:

CHANGELOG.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,30 @@
22

33
This log will detail notable changes to MyBatis Dynamic SQL. Full details are available on the GitHub milestone pages.
44

5-
## Release 1.1.1
5+
## Release 1.1.3 - Unreleased
6+
7+
GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.1.2+](https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.1.3+)
8+
9+
### Added
10+
11+
- Added support for `count(distinct ...)` [#112](https://github.com/mybatis/mybatis-dynamic-sql/issues/112)
12+
13+
14+
## Release 1.1.2 - July 5, 2019
15+
16+
GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.1.2+](https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.1.2+)
17+
18+
### Added
19+
20+
- Changed the public SQLBuilder API to accept Collection instead of List for in conditions and batch record inserts. This should have no impact on existing code, but allow for some future flexibility [#88](https://github.com/mybatis/mybatis-dynamic-sql/pull/88)
21+
- Added the ability have have table catalog and/or schema calculated at query runtime. This is useful for situations where there are different database schemas for different environments, or in some sharding situations [#92](https://github.com/mybatis/mybatis-dynamic-sql/pull/92)
22+
- Add support for paging queries with "offset" and "fetch first" - this seems to be standard on most databases [#96](https://github.com/mybatis/mybatis-dynamic-sql/pull/96)
23+
- Added the ability to call a builder method on any intermediate object in a select statement and receive a fully rendered statement. This makes it easier to build very dynamic queries [#106](https://github.com/mybatis/mybatis-dynamic-sql/pull/106)
24+
- Add the ability to modify values on any condition before they are placed in the parameter map [#105](https://github.com/mybatis/mybatis-dynamic-sql/issues/105)
25+
- Add the ability to call `where()` with no parameters. This aids in constructing very dynamic queries [#107](https://github.com/mybatis/mybatis-dynamic-sql/issues/107)
26+
27+
28+
## Release 1.1.1 - April 7, 2019
629

730
GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.1.1+](https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.1.1+)
831

@@ -19,7 +42,7 @@ GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=miles
1942
- Fixed self joins
2043

2144

22-
## Release 1.1.0
45+
## Release 1.1.0 - April 24, 2018
2346

2447
GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.1.0+](https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.1.0+)
2548

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![Build Status](https://travis-ci.org/mybatis/mybatis-dynamic-sql.svg?branch=master)](https://travis-ci.org/mybatis/mybatis-dynamic-sql)
44
[![Coverage Status](https://coveralls.io/repos/github/mybatis/mybatis-dynamic-sql/badge.svg?branch=master)](https://coveralls.io/github/mybatis/mybatis-dynamic-sql?branch=master)
55
[![Maven central](https://maven-badges.herokuapp.com/maven-central/org.mybatis.dynamic-sql/mybatis-dynamic-sql/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.mybatis.dynamic-sql/mybatis-dynamic-sql)
6+
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.mybatis.dynamic-sql/mybatis-dynamic-sql.svg)](https://oss.sonatype.org/content/repositories/snapshots/org/mybatis/dynamic-sql/mybatis-dynamic-sql)
67
[![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
78

89
## What Is This?
@@ -253,9 +254,8 @@ an example from `examples.simple.SimpleTableAnnotatedMapperTest`:
253254
```java
254255
@Test
255256
public void testSelectByExample() {
256-
SqlSession session = sqlSessionFactory.openSession();
257-
try {
258-
SimpleTableXmlMapper mapper = session.getMapper(SimpleTableXmlMapper.class);
257+
try (SqlSession session = sqlSessionFactory.openSession()) {
258+
SimpleTableAnnotatedMapper mapper = session.getMapper(SimpleTableAnnotatedMapper.class);
259259

260260
SelectStatementProvider selectStatement = select(id.as("A_ID"), firstName, lastName, birthDate, employed, occupation)
261261
.from(simpleTable)
@@ -267,8 +267,6 @@ an example from `examples.simple.SimpleTableAnnotatedMapperTest`:
267267
List<SimpleTableRecord> rows = mapper.selectMany(selectStatement);
268268

269269
assertThat(rows.size()).isEqualTo(3);
270-
} finally {
271-
session.close();
272270
}
273271
}
274272
```

pom.xml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
</parent>
3232
<groupId>org.mybatis.dynamic-sql</groupId>
3333
<artifactId>mybatis-dynamic-sql</artifactId>
34-
<version>1.1.2-SNAPSHOT</version>
34+
<version>1.1.3-SNAPSHOT</version>
3535
<name>MyBatis Dynamic SQL</name>
3636
<description>MyBatis framework for generating dynamic SQL</description>
3737
<inceptionYear>2016</inceptionYear>
@@ -40,8 +40,8 @@
4040
<java.version>1.8</java.version>
4141
<maven.compiler.source>${java.version}</maven.compiler.source>
4242
<maven.compiler.target>${java.version}</maven.compiler.target>
43-
<junit.jupiter.version>5.4.1</junit.jupiter.version>
44-
<junit.platform.version>1.4.1</junit.platform.version>
43+
<junit.jupiter.version>5.5.0</junit.jupiter.version>
44+
<junit.platform.version>1.5.0</junit.platform.version>
4545
<spring.batch.version>4.1.2.RELEASE</spring.batch.version>
4646
<clirr.comparisonVersion>1.1.0</clirr.comparisonVersion>
4747
<module.name>org.mybatis.dynamic.sql</module.name>
@@ -138,13 +138,13 @@
138138
<dependency>
139139
<groupId>org.hsqldb</groupId>
140140
<artifactId>hsqldb</artifactId>
141-
<version>2.4.1</version>
141+
<version>2.5.0</version>
142142
<scope>test</scope>
143143
</dependency>
144144
<dependency>
145145
<groupId>org.springframework</groupId>
146146
<artifactId>spring-jdbc</artifactId>
147-
<version>5.1.6.RELEASE</version>
147+
<version>5.1.8.RELEASE</version>
148148
<scope>test</scope>
149149
</dependency>
150150
<dependency>
@@ -171,6 +171,13 @@
171171
<version>1.2.3</version>
172172
<scope>test</scope>
173173
</dependency>
174+
<!-- Hamcrest is only here to make Infinitest happy. Not really used in the project. -->
175+
<dependency>
176+
<groupId>org.hamcrest</groupId>
177+
<artifactId>hamcrest</artifactId>
178+
<version>2.1</version>
179+
<scope>test</scope>
180+
</dependency>
174181
</dependencies>
175182

176183
<scm>

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,27 +16,27 @@
1616
package org.mybatis.dynamic.sql;
1717

1818
import java.util.ArrayList;
19-
import java.util.List;
19+
import java.util.Collection;
2020
import java.util.Objects;
2121
import java.util.function.Function;
2222
import java.util.function.UnaryOperator;
2323
import java.util.stream.Stream;
2424

2525
public abstract class AbstractListValueCondition<T> implements VisitableCondition<T> {
26-
protected List<T> values;
27-
protected UnaryOperator<Stream<T>> valueStreamOperations;
26+
protected Collection<T> values;
27+
protected UnaryOperator<Stream<T>> valueStreamTransformer;
2828

29-
protected AbstractListValueCondition(List<T> values) {
29+
protected AbstractListValueCondition(Collection<T> values) {
3030
this(values, UnaryOperator.identity());
3131
}
3232

33-
protected AbstractListValueCondition(List<T> values, UnaryOperator<Stream<T>> valueStreamOperations) {
33+
protected AbstractListValueCondition(Collection<T> values, UnaryOperator<Stream<T>> valueStreamTransformer) {
3434
this.values = new ArrayList<>(Objects.requireNonNull(values));
35-
this.valueStreamOperations = Objects.requireNonNull(valueStreamOperations);
35+
this.valueStreamTransformer = Objects.requireNonNull(valueStreamTransformer);
3636
}
3737

3838
public final <R> Stream<R> mapValues(Function<T, R> mapper) {
39-
return valueStreamOperations.apply(values.stream()).map(mapper);
39+
return valueStreamTransformer.apply(values.stream()).map(mapper);
4040
}
4141

4242
@Override

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616
package org.mybatis.dynamic.sql;
1717

1818
import java.util.Arrays;
19-
import java.util.List;
19+
import java.util.Collection;
2020
import java.util.function.Supplier;
2121

2222
import org.mybatis.dynamic.sql.delete.DeleteDSL;
@@ -31,6 +31,7 @@
3131
import org.mybatis.dynamic.sql.select.aggregate.Avg;
3232
import org.mybatis.dynamic.sql.select.aggregate.Count;
3333
import org.mybatis.dynamic.sql.select.aggregate.CountAll;
34+
import org.mybatis.dynamic.sql.select.aggregate.CountDistinct;
3435
import org.mybatis.dynamic.sql.select.aggregate.Max;
3536
import org.mybatis.dynamic.sql.select.aggregate.Min;
3637
import org.mybatis.dynamic.sql.select.aggregate.Sum;
@@ -113,7 +114,7 @@ static <T> BatchInsertDSL.IntoGatherer<T> insert(T...records) {
113114
return BatchInsertDSL.insert(records);
114115
}
115116

116-
static <T> BatchInsertDSL.IntoGatherer<T> insert(List<T> records) {
117+
static <T> BatchInsertDSL.IntoGatherer<T> insert(Collection<T> records) {
117118
return BatchInsertDSL.insert(records);
118119
}
119120

@@ -133,6 +134,10 @@ static UpdateDSL<UpdateModel> update(SqlTable table) {
133134
return UpdateDSL.update(table);
134135
}
135136

137+
static WhereDSL where() {
138+
return WhereDSL.where();
139+
}
140+
136141
static <T> WhereDSL where(BindableColumn<T> column, VisitableCondition<T> condition) {
137142
return WhereDSL.where(column, condition);
138143
}
@@ -196,6 +201,10 @@ static Count count(BasicColumn column) {
196201
return Count.of(column);
197202
}
198203

204+
static CountDistinct countDistinct(BasicColumn column) {
205+
return CountDistinct.of(column);
206+
}
207+
199208
static Max max(BasicColumn column) {
200209
return Max.of(column);
201210
}
@@ -417,7 +426,7 @@ static <T> IsIn<T> isIn(T...values) {
417426
return isIn(Arrays.asList(values));
418427
}
419428

420-
static <T> IsIn<T> isIn(List<T> values) {
429+
static <T> IsIn<T> isIn(Collection<T> values) {
421430
return IsIn.of(values);
422431
}
423432

@@ -430,7 +439,7 @@ static <T> IsInWhenPresent<T> isInWhenPresent(T...values) {
430439
return isInWhenPresent(Arrays.asList(values));
431440
}
432441

433-
static <T> IsInWhenPresent<T> isInWhenPresent(List<T> values) {
442+
static <T> IsInWhenPresent<T> isInWhenPresent(Collection<T> values) {
434443
return IsInWhenPresent.of(values);
435444
}
436445

@@ -439,7 +448,7 @@ static <T> IsNotIn<T> isNotIn(T...values) {
439448
return isNotIn(Arrays.asList(values));
440449
}
441450

442-
static <T> IsNotIn<T> isNotIn(List<T> values) {
451+
static <T> IsNotIn<T> isNotIn(Collection<T> values) {
443452
return IsNotIn.of(values);
444453
}
445454

@@ -452,7 +461,7 @@ static <T> IsNotInWhenPresent<T> isNotInWhenPresent(T...values) {
452461
return isNotInWhenPresent(Arrays.asList(values));
453462
}
454463

455-
static <T> IsNotInWhenPresent<T> isNotInWhenPresent(List<T> values) {
464+
static <T> IsNotInWhenPresent<T> isNotInWhenPresent(Collection<T> values) {
456465
return IsNotInWhenPresent.of(values);
457466
}
458467

@@ -558,31 +567,31 @@ static IsInCaseInsensitive isInCaseInsensitive(String...values) {
558567
return isInCaseInsensitive(Arrays.asList(values));
559568
}
560569

561-
static IsInCaseInsensitive isInCaseInsensitive(List<String> values) {
570+
static IsInCaseInsensitive isInCaseInsensitive(Collection<String> values) {
562571
return IsInCaseInsensitive.of(values);
563572
}
564573

565574
static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(String...values) {
566575
return isInCaseInsensitiveWhenPresent(Arrays.asList(values));
567576
}
568577

569-
static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(List<String> values) {
578+
static IsInCaseInsensitiveWhenPresent isInCaseInsensitiveWhenPresent(Collection<String> values) {
570579
return IsInCaseInsensitiveWhenPresent.of(values);
571580
}
572581

573582
static IsNotInCaseInsensitive isNotInCaseInsensitive(String...values) {
574583
return isNotInCaseInsensitive(Arrays.asList(values));
575584
}
576585

577-
static IsNotInCaseInsensitive isNotInCaseInsensitive(List<String> values) {
586+
static IsNotInCaseInsensitive isNotInCaseInsensitive(Collection<String> values) {
578587
return IsNotInCaseInsensitive.of(values);
579588
}
580589

581590
static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(String...values) {
582591
return isNotInCaseInsensitiveWhenPresent(Arrays.asList(values));
583592
}
584593

585-
static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(List<String> values) {
594+
static IsNotInCaseInsensitiveWhenPresent isNotInCaseInsensitiveWhenPresent(Collection<String> values) {
586595
return IsNotInCaseInsensitiveWhenPresent.of(values);
587596
}
588597

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

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 the original author or authors.
2+
* Copyright 2016-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,17 +17,68 @@
1717

1818
import java.sql.JDBCType;
1919
import java.util.Objects;
20+
import java.util.Optional;
21+
import java.util.function.Supplier;
2022

2123
public class SqlTable {
24+
25+
private Supplier<String> nameSupplier;
26+
27+
protected SqlTable(String tableName) {
28+
Objects.requireNonNull(tableName);
29+
30+
this.nameSupplier = () -> tableName;
31+
}
32+
33+
protected SqlTable(Supplier<String> tableNameSupplier) {
34+
Objects.requireNonNull(tableNameSupplier);
35+
36+
this.nameSupplier = tableNameSupplier;
37+
}
38+
39+
protected SqlTable(Supplier<Optional<String>> schemaSupplier, String tableName) {
40+
this(Optional::empty, schemaSupplier, tableName);
41+
}
42+
43+
protected SqlTable(Supplier<Optional<String>> catalogSupplier, Supplier<Optional<String>> schemaSupplier,
44+
String tableName) {
45+
Objects.requireNonNull(catalogSupplier);
46+
Objects.requireNonNull(schemaSupplier);
47+
Objects.requireNonNull(tableName);
48+
49+
this.nameSupplier = () -> compose(catalogSupplier, schemaSupplier, tableName);
50+
}
51+
52+
private String compose(Supplier<Optional<String>> catalogSupplier, Supplier<Optional<String>> schemaSupplier,
53+
String tableName) {
54+
return catalogSupplier.get().map(c -> compose(c, schemaSupplier, tableName))
55+
.orElseGet(() -> compose(schemaSupplier, tableName));
56+
}
57+
58+
private String compose(String catalog, Supplier<Optional<String>> schemaSupplier, String tableName) {
59+
return schemaSupplier.get().map(s -> composeCatalogSchemaAndAndTable(catalog, s, tableName))
60+
.orElseGet(() -> composeCatalogAndTable(catalog, tableName));
61+
}
2262

23-
private String name;
63+
private String compose(Supplier<Optional<String>> schemaSupplier, String tableName) {
64+
return schemaSupplier.get().map(s -> composeSchemaAndTable(s, tableName))
65+
.orElse(tableName);
66+
}
67+
68+
private String composeCatalogAndTable(String catalog, String tableName) {
69+
return catalog + ".." + tableName; //$NON-NLS-1$
70+
}
2471

25-
protected SqlTable(String name) {
26-
this.name = Objects.requireNonNull(name);
72+
private String composeSchemaAndTable(String schema, String tableName) {
73+
return schema + "." + tableName; //$NON-NLS-1$
2774
}
2875

29-
public String name() {
30-
return name;
76+
private String composeCatalogSchemaAndAndTable(String catalog, String schema, String tableName) {
77+
return catalog + "." + schema + "." + tableName; //$NON-NLS-1$ //$NON-NLS-2$
78+
}
79+
80+
public String tableNameAtRuntime() {
81+
return nameSupplier.get();
3182
}
3283

3384
public <T> SqlColumn<T> allColumns() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy