Skip to content

Commit 5269f47

Browse files
authored
Merge pull request #109 from jeffgbutler/master
Add the ability to alter any condition value before it is placed in the parameter map
2 parents b18f7db + 1171118 commit 5269f47

35 files changed

+1338
-53
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=miles
88

99
### Added
1010

11-
- 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
12-
- 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
13-
- 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
11+
- 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)
12+
- 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)
13+
- 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)
14+
- 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)
15+
- 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)
16+
- 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)
1417

1518

1619
## Release 1.1.1 - April 7, 2019

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424

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

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

33-
protected AbstractListValueCondition(Collection<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/where/condition/IsBetween.java

Lines changed: 7 additions & 1 deletion
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,6 +17,7 @@
1717

1818
import java.util.function.BiPredicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractTwoValueCondition;
2223

@@ -53,4 +54,9 @@ public static <T> Builder<T> isBetween(Supplier<T> valueSupplier1) {
5354
public IsBetween<T> when(BiPredicate<T, T> predicate) {
5455
return new IsBetween<>(valueSupplier1, valueSupplier2, predicate);
5556
}
57+
58+
public IsBetween<T> then(UnaryOperator<T> transformer1, UnaryOperator<T> transformer2) {
59+
return shouldRender() ? new IsBetween<>(() -> transformer1.apply(value1()),
60+
() -> transformer2.apply(value2())) : this;
61+
}
5662
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsBetweenWhenPresent.java

Lines changed: 8 additions & 1 deletion
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,6 +16,7 @@
1616
package org.mybatis.dynamic.sql.where.condition;
1717

1818
import java.util.function.Supplier;
19+
import java.util.function.UnaryOperator;
1920

2021
import org.mybatis.dynamic.sql.util.Predicates;
2122

@@ -39,4 +40,10 @@ protected IsBetweenWhenPresent<T> build() {
3940
public static <T> Builder<T> isBetweenWhenPresent(Supplier<T> valueSupplier) {
4041
return new Builder<>(valueSupplier);
4142
}
43+
44+
@Override
45+
public IsBetweenWhenPresent<T> then(UnaryOperator<T> transformer1, UnaryOperator<T> transformer2) {
46+
return shouldRender() ? new IsBetweenWhenPresent<>(() -> transformer1.apply(value1()),
47+
() -> transformer2.apply(value2())) : this;
48+
}
4249
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsEqualTo.java

Lines changed: 6 additions & 1 deletion
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,6 +17,7 @@
1717

1818
import java.util.function.Predicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2223

@@ -42,4 +43,8 @@ public static <T> IsEqualTo<T> of(Supplier<T> valueSupplier) {
4243
public IsEqualTo<T> when(Predicate<T> predicate) {
4344
return new IsEqualTo<>(valueSupplier, predicate);
4445
}
46+
47+
public IsEqualTo<T> then(UnaryOperator<T> transformer) {
48+
return shouldRender() ? new IsEqualTo<>(() -> transformer.apply(value())) : this;
49+
}
4550
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsEqualToWhenPresent.java

Lines changed: 7 additions & 1 deletion
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,6 +17,7 @@
1717

1818
import java.util.Objects;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
public class IsEqualToWhenPresent<T> extends IsEqualTo<T> {
2223

@@ -27,4 +28,9 @@ protected IsEqualToWhenPresent(Supplier<T> valueSupplier) {
2728
public static <T> IsEqualToWhenPresent<T> of(Supplier<T> valueSupplier) {
2829
return new IsEqualToWhenPresent<>(valueSupplier);
2930
}
31+
32+
@Override
33+
public IsEqualToWhenPresent<T> then(UnaryOperator<T> transformer) {
34+
return shouldRender() ? new IsEqualToWhenPresent<>(() -> transformer.apply(value())) : this;
35+
}
3036
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThan.java

Lines changed: 6 additions & 1 deletion
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,6 +17,7 @@
1717

1818
import java.util.function.Predicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2223

@@ -42,4 +43,8 @@ public static <T> IsGreaterThan<T> of(Supplier<T> valueSupplier) {
4243
public IsGreaterThan<T> when(Predicate<T> predicate) {
4344
return new IsGreaterThan<>(valueSupplier, predicate);
4445
}
46+
47+
public IsGreaterThan<T> then(UnaryOperator<T> transformer) {
48+
return shouldRender() ? new IsGreaterThan<>(() -> transformer.apply(value())) : this;
49+
}
4550
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThanOrEqualTo.java

Lines changed: 6 additions & 1 deletion
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,6 +17,7 @@
1717

1818
import java.util.function.Predicate;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
import org.mybatis.dynamic.sql.AbstractSingleValueCondition;
2223

@@ -42,4 +43,8 @@ public static <T> IsGreaterThanOrEqualTo<T> of(Supplier<T> valueSupplier) {
4243
public IsGreaterThanOrEqualTo<T> when(Predicate<T> predicate) {
4344
return new IsGreaterThanOrEqualTo<>(valueSupplier, predicate);
4445
}
46+
47+
public IsGreaterThanOrEqualTo<T> then(UnaryOperator<T> transformer) {
48+
return shouldRender() ? new IsGreaterThanOrEqualTo<>(() -> transformer.apply(value())) : this;
49+
}
4550
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThanOrEqualToWhenPresent.java

Lines changed: 7 additions & 1 deletion
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,6 +17,7 @@
1717

1818
import java.util.Objects;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
public class IsGreaterThanOrEqualToWhenPresent<T> extends IsGreaterThanOrEqualTo<T> {
2223

@@ -27,4 +28,9 @@ protected IsGreaterThanOrEqualToWhenPresent(Supplier<T> valueSupplier) {
2728
public static <T> IsGreaterThanOrEqualToWhenPresent<T> of(Supplier<T> valueSupplier) {
2829
return new IsGreaterThanOrEqualToWhenPresent<>(valueSupplier);
2930
}
31+
32+
@Override
33+
public IsGreaterThanOrEqualToWhenPresent<T> then(UnaryOperator<T> transformer) {
34+
return shouldRender() ? new IsGreaterThanOrEqualToWhenPresent<>(() -> transformer.apply(value())) : this;
35+
}
3036
}

src/main/java/org/mybatis/dynamic/sql/where/condition/IsGreaterThanWhenPresent.java

Lines changed: 7 additions & 1 deletion
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,6 +17,7 @@
1717

1818
import java.util.Objects;
1919
import java.util.function.Supplier;
20+
import java.util.function.UnaryOperator;
2021

2122
public class IsGreaterThanWhenPresent<T> extends IsGreaterThan<T> {
2223

@@ -27,4 +28,9 @@ protected IsGreaterThanWhenPresent(Supplier<T> valueSupplier) {
2728
public static <T> IsGreaterThanWhenPresent<T> of(Supplier<T> valueSupplier) {
2829
return new IsGreaterThanWhenPresent<>(valueSupplier);
2930
}
31+
32+
@Override
33+
public IsGreaterThanWhenPresent<T> then(UnaryOperator<T> transformer) {
34+
return shouldRender() ? new IsGreaterThanWhenPresent<>(() -> transformer.apply(value())) : this;
35+
}
3036
}

0 commit comments

Comments
 (0)