Skip to content

Commit abf407e

Browse files
authored
Merge pull request #123 from jeffgbutler/master
Add a helper function to select all rows and specify order
2 parents 19f1dd0 + b962a19 commit abf407e

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

.travis.yml

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

33
jdk:
44
- openjdk11
5-
- oraclejdk8
5+
- openjdk8
66

77
after_success:
88
- chmod -R 777 ./travis/after_success.sh

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.List;
1919
import java.util.function.Function;
2020

21+
import org.mybatis.dynamic.sql.SortSpecification;
2122
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
2223
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
2324
import org.mybatis.dynamic.sql.util.Buildable;
@@ -86,4 +87,16 @@ public interface MyBatis3SelectByExampleHelper<T> extends
8687
static <T> MyBatis3SelectByExampleHelper<T> allRows() {
8788
return h -> h;
8889
}
90+
91+
/**
92+
* Returns a helper that can be used to select every row in a table with a specified sort order.
93+
*
94+
* @param <T> the type of row returned
95+
* @param columns sort columns
96+
*
97+
* @return the helper that will select every row in a table in the specified order
98+
*/
99+
static <T> MyBatis3SelectByExampleHelper<T> allRowsOrderdBy(SortSpecification...columns) {
100+
return h -> h.orderBy(columns);
101+
}
89102
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.mybatis.dynamic.sql.update.UpdateDSL;
2222

2323
/**
24-
* Represents a function that can be used to create an "UpdateByExample" method in the style
24+
* Represents a function that can be used to set values in an "UpdateByExample" method in the style
2525
* of MyBatis Generator. When using this function, you can create a method that will map record fields to
2626
* tables columns to be updated in a common mapper, and then allow a user to set a where clause as needed.
2727
*

src/test/java/examples/simple/SimpleTableAnnotatedNewStyleMapperTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ public void testSelectAll() {
8888
List<SimpleTableRecord> rows = mapper.selectByExample(MyBatis3SelectByExampleHelper.allRows());
8989

9090
assertThat(rows.size()).isEqualTo(6);
91+
assertThat(rows.get(0).getId()).isEqualTo(1);
92+
assertThat(rows.get(5).getId()).isEqualTo(6);
93+
}
94+
}
95+
96+
@Test
97+
public void testSelectAllOrdered() {
98+
try (SqlSession session = sqlSessionFactory.openSession()) {
99+
SimpleTableAnnotatedMapperNewStyle mapper = session.getMapper(SimpleTableAnnotatedMapperNewStyle.class);
100+
101+
List<SimpleTableRecord> rows = mapper
102+
.selectByExample(MyBatis3SelectByExampleHelper.allRowsOrderdBy(lastName.descending(), firstName.descending()));
103+
104+
assertThat(rows.size()).isEqualTo(6);
105+
assertThat(rows.get(0).getId()).isEqualTo(5);
106+
assertThat(rows.get(5).getId()).isEqualTo(1);
91107
}
92108
}
93109

travis/after_success.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
#
3-
# Copyright 2016-2018 the original author or authors.
3+
# Copyright 2016-2019 the original author or authors.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ echo "Current commit detected: ${commit_message}"
3232
# a. Use -q option to only display Maven errors and warnings.
3333
# b. Use --settings to force the usage of our "settings.xml" file.
3434

35-
if [ $TRAVIS_JDK_VERSION == "oraclejdk8" ] && [ $TRAVIS_REPO_SLUG == "mybatis/mybatis-dynamic-sql" ]; then
35+
if [ $TRAVIS_JDK_VERSION == "openjdk8" ] && [ $TRAVIS_REPO_SLUG == "mybatis/mybatis-dynamic-sql" ]; then
3636

3737
./mvnw clean test jacoco:report coveralls:report -q
3838
echo -e "Successfully ran coveralls under Travis job ${TRAVIS_JOB_NUMBER}"

0 commit comments

Comments
 (0)