Skip to content

Miscellaneous Small Fixes #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.mybatis.dynamic.sql.BindableColumn;

public abstract class RenderingStrategy {
@SuppressWarnings("squid:S2390")
public static final RenderingStrategy MYBATIS3 = new MyBatis3RenderingStrategy();
@SuppressWarnings("squid:S2390")
public static final RenderingStrategy SPRING_NAMED_PARAMETER = new SpringNamedParameterRenderingStrategy();
public static final String DEFAULT_PARAMETER_PREFIX = "parameters"; //$NON-NLS-1$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public SelectStatementProvider render() {
return new LimitAndOffsetDecorator(selectStatement);
}

public class LimitAndOffsetDecorator implements SelectStatementProvider {
public static class LimitAndOffsetDecorator implements SelectStatementProvider {
private Map<String, Object> parameters = new HashMap<>();
private String selectStatement;

Expand Down
17 changes: 0 additions & 17 deletions src/main/java/org/mybatis/dynamic/sql/where/condition/IsIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,6 @@ public IsIn<T> then(UnaryOperator<Stream<T>> valueStreamTransformer) {
return new IsIn<>(values, valueStreamTransformer);
}

/**
* This method allows you to modify the condition's values before they are placed into the parameter map.
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
* values out of the stream, then the condition will not render.
*
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
* the values are placed in the parameter map
* @return new condition with the specified transformer
*
* @deprecated See {@link IsIn#then(UnaryOperator)}
*/
@Deprecated
public IsIn<T> withValueStreamOperations(UnaryOperator<Stream<T>> valueStreamTransformer) {
return then(valueStreamTransformer);
}

public static <T> IsIn<T> of(Collection<T> values) {
return new IsIn<>(values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,6 @@ public IsInCaseInsensitive then(UnaryOperator<Stream<String>> valueStreamTransfo
return new IsInCaseInsensitive(values, valueStreamTransformer);
}

/**
* This method allows you to modify the condition's values before they are placed into the parameter map.
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
* values out of the stream, then the condition will not render.
*
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
* the values are placed in the parameter map
* @return new condition with the specified transformer
*
* @deprecated See {@link IsInCaseInsensitive#then(UnaryOperator)}
*/
@Deprecated
public IsInCaseInsensitive withValueStreamOperations(UnaryOperator<Stream<String>> valueStreamTransformer) {
return then(valueStreamTransformer);
}

public static IsInCaseInsensitive of(Collection<String> values) {
return new IsInCaseInsensitive(values);
}
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/org/mybatis/dynamic/sql/where/condition/IsNotIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,6 @@ public IsNotIn<T> then(UnaryOperator<Stream<T>> valueStreamTransformer) {
return new IsNotIn<>(values, valueStreamTransformer);
}

/**
* This method allows you to modify the condition's values before they are placed into the parameter map.
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
* values out of the stream, then the condition will not render.
*
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
* the values are placed in the parameter map
* @return new condition with the specified transformer
*
* @deprecated See {@link IsNotIn#then(UnaryOperator)}
*/
@Deprecated
public IsNotIn<T> withValueStreamOperations(UnaryOperator<Stream<T>> valueStreamTransformer) {
return then(valueStreamTransformer);
}

public static <T> IsNotIn<T> of(Collection<T> values) {
return new IsNotIn<>(values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,6 @@ public IsNotInCaseInsensitive then(UnaryOperator<Stream<String>> valueStreamTran
return new IsNotInCaseInsensitive(values, valueStreamTransformer);
}

/**
* This method allows you to modify the condition's values before they are placed into the parameter map.
* For example, you could filter nulls, or trim strings, etc. This process will run before final rendering of SQL.
* If you filter values out of the stream, then final condition will not reference those values. If you filter all
* values out of the stream, then the condition will not render.
*
* @param valueStreamTransformer a UnaryOperator that will transform the value stream before
* the values are placed in the parameter map
* @return new condition with the specified transformer
*
* @deprecated See {@link IsNotInCaseInsensitive#then(UnaryOperator)}
*/
@Deprecated
public IsNotInCaseInsensitive withValueStreamOperations(UnaryOperator<Stream<String>> valueStreamTransformer) {
return then(valueStreamTransformer);
}

public static IsNotInCaseInsensitive of(Collection<String> values) {
return new IsNotInCaseInsensitive(values);
}
Expand Down
2 changes: 1 addition & 1 deletion src/site/markdown/docs/complexQueries.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Complex Queries
Enhancements in version 1.1.2 make it easier to code complex queries. The Select DSL is implemented as a set of related objects. As the select statement is built, intermediate objects of various types are returned from the various methods that implement the DSL. The select statement can be completed by calling the `build()` method many of the intermediate objects. Prior to version 1.1.2, it was necessary to call `build()` on the **last** intermediate object. This restriction has been removed and it is now possible to call `build()` on **any** intermedtae object. This, along with several other enhancements, has simplified the coding of complex queries.
Enhancements in version 1.1.2 make it easier to code complex queries. The Select DSL is implemented as a set of related objects. As the select statement is built, intermediate objects of various types are returned from the various methods that implement the DSL. The select statement can be completed by calling the `build()` method many of the intermediate objects. Prior to version 1.1.2, it was necessary to call `build()` on the **last** intermediate object. This restriction has been removed and it is now possible to call `build()` on **any** intermediate object. This, along with several other enhancements, has simplified the coding of complex queries.

For example, suppose you want to code a complex search on a Person table. The search parameters are id, first name, and last name. The rules are:

Expand Down
2 changes: 1 addition & 1 deletion src/site/markdown/docs/conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ For example, you could code a search like this:

In this example, the three conditions will only be rendered if the values passed to them are not null. If all three values are null, then no where clause will be generated.

Each of the conditions accepts a lamba expression that can be used to determine if the condition should render or not. The lambas will all be of standard JDK types (either `java.util.function.BooleanSupplier`, `java.util.function.Predicate`, or `java.util.function.BiPredicate` depending on the type of condition). The following table lists the optional conditions and shows how to use them:
Each of the conditions accepts a lambda expression that can be used to determine if the condition should render or not. The lambdas will all be of standard JDK types (either `java.util.function.BooleanSupplier`, `java.util.function.Predicate`, or `java.util.function.BiPredicate` depending on the type of condition). The following table lists the optional conditions and shows how to use them:

| Condition | Example | Rendering Rules |
|-----------|---------|-----------------|
Expand Down
2 changes: 1 addition & 1 deletion src/site/markdown/docs/spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The SQL statement objects are created in exactly the same way as for MyBatis - o
```

## Executing Select Statements
The Spring Named Parameter JDBC template expects an SQL statement with parameter markers in the Spring format, and a set of matched parameters. MyBatis Dynamic SQL will generate both. The parameters returned from the generated SQL statement can be wrapped in a Spring `MapSqlParameterSource`. Spring also expects you to provide a row mapper for creating the returned objects. The followin code shows a complete example:
The Spring Named Parameter JDBC template expects an SQL statement with parameter markers in the Spring format, and a set of matched parameters. MyBatis Dynamic SQL will generate both. The parameters returned from the generated SQL statement can be wrapped in a Spring `MapSqlParameterSource`. Spring also expects you to provide a row mapper for creating the returned objects. The following code shows a complete example:

```java
NamedParameterJdbcTemplate template = getTemplate();
Expand Down
3 changes: 1 addition & 2 deletions src/site/markdown/docs/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ For example:
.set(animalName).equalToNull()
.build()
.render(RenderingStrategy.MYBATIS3);
```
```

## Annotated Mapper for Update Statements

Expand All @@ -52,7 +52,6 @@ import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
@UpdateProvider(type=SqlProviderAdapter.class, method="update")
int update(UpdateStatementProvider updateStatement);
...

```

## XML Mapper for Update Statements
Expand Down
2 changes: 1 addition & 1 deletion src/site/markdown/docs/whereClauses.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ In this mapper method there are three parameters. So in this case it will be ne
```
Notice that the string `whereClauseProvider` is used both as the parameter name in the mapper `@Param` annotation and the parameter name in the `render` method.

The render method also has an override that accepts a TableAliasCalculator and a parameter name.
The render method also has an override that accepts a TableAliasCalculator and a parameter name.
Original file line number Diff line number Diff line change
Expand Up @@ -454,30 +454,6 @@ public void testIsInWhenWithSomeValues() {
}
}

/**
* Delete this test when the deprecated method is deleted
*/
@Test
@Deprecated
public void testIsInWhenWithSomeValuesDeprecated() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
.from(animalData)
.where(id, isIn(3, NULL_INTEGER, 5).withValueStreamOperations(s -> s.filter(Objects::nonNull).map(i -> i + 3)))
.orderBy(id)
.build()
.render(RenderingStrategy.MYBATIS3);
List<AnimalData> animals = mapper.selectMany(selectStatement);
assertAll(
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) order by id"),
() -> assertThat(animals.size()).isEqualTo(2),
() -> assertThat(animals.get(0).getId()).isEqualTo(6),
() -> assertThat(animals.get(1).getId()).isEqualTo(8)
);
}
}

@Test
public void testIsInCaseInsensitiveWhenWithValue() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Expand Down Expand Up @@ -557,29 +533,6 @@ public void testIsInCaseInsensitiveWhenWithSomeValues() {
}
}

/**
* Delete this test when the deprecated method is deleted
*/
@Test
@Deprecated
public void testIsInCaseInsensitiveWhenWithSomeValuesDeprecated() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
.from(animalData)
.where(animalName, isInCaseInsensitive("mouse", null, "musk shrew").withValueStreamOperations(s -> s.filter(Objects::nonNull)))
.orderBy(id)
.build()
.render(RenderingStrategy.MYBATIS3);
List<AnimalData> animals = mapper.selectMany(selectStatement);
assertAll(
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) order by id"),
() -> assertThat(animals.size()).isEqualTo(2),
() -> assertThat(animals.get(0).getId()).isEqualTo(4)
);
}
}

@Test
public void testIsInCaseInsensitiveWhenWithNoValues() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Expand Down Expand Up @@ -640,30 +593,6 @@ public void testIsNotInWhenWithSomeValues() {
}
}

/**
* Delete this test when the deprecated method is deleted
*/
@Test
@Deprecated
public void testIsNotInWhenWithSomeValuesDeprecated() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
.from(animalData)
.where(id, isNotIn(3, NULL_INTEGER, 5).withValueStreamOperations(s -> s.filter(Objects::nonNull)))
.and(id, isLessThanOrEqualTo(10))
.orderBy(id)
.build()
.render(RenderingStrategy.MYBATIS3);
List<AnimalData> animals = mapper.selectMany(selectStatement);
assertAll(
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where id not in (#{parameters.p1,jdbcType=INTEGER},#{parameters.p2,jdbcType=INTEGER}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"),
() -> assertThat(animals.size()).isEqualTo(8),
() -> assertThat(animals.get(0).getId()).isEqualTo(1)
);
}
}

@Test
public void testIsNotInCaseInsensitiveWhenWithValue() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Expand Down Expand Up @@ -704,30 +633,6 @@ public void testIsNotInCaseInsensitiveWhenWithSomeValues() {
}
}

/**
* Delete this test when the deprecated method is deleted
*/
@Test
@Deprecated
public void testIsNotInCaseInsensitiveWhenWithSomeValuesDeprecated() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
AnimalDataMapper mapper = sqlSession.getMapper(AnimalDataMapper.class);
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
.from(animalData)
.where(animalName, isNotInCaseInsensitive("mouse", null, "musk shrew").withValueStreamOperations(s -> s.filter(Objects::nonNull)))
.and(id, isLessThanOrEqualTo(10))
.orderBy(id)
.build()
.render(RenderingStrategy.MYBATIS3);
List<AnimalData> animals = mapper.selectMany(selectStatement);
assertAll(
() -> assertThat(selectStatement.getSelectStatement()).isEqualTo("select id, animal_name, body_weight, brain_weight from AnimalData where upper(animal_name) not in (#{parameters.p1,jdbcType=VARCHAR},#{parameters.p2,jdbcType=VARCHAR}) and id <= #{parameters.p3,jdbcType=INTEGER} order by id"),
() -> assertThat(animals.size()).isEqualTo(8),
() -> assertThat(animals.get(0).getId()).isEqualTo(1)
);
}
}

@Test
public void testIsNotInCaseInsensitiveWhenWithNoValues() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Expand Down