Skip to content

Commit e76e745

Browse files
authored
Merge pull request #369 from jeffgbutler/master
Use Spring to Configure Spring Tests
2 parents 80ecc4e + 4e93050 commit e76e745

18 files changed

+387
-312
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ The library test cases provide several complete examples of using the library in
5959

6060
| Language | Runtime | Comments | Code Directory |
6161
|---|---|---|---|
62-
| Java | MyBatis3 | Example using Java utility classes for MyBatis in the style of MyBatis Generator | [src/test/java/examples/simple](src/test/java/examples/simple) |
63-
| Java | MyBatis3 | Example using Java utility classes for the MyBatis integration with Spring Batch | [src/test/java/examples/springbatch](src/test/java/examples/springbatch) |
64-
| Java | Spring JDBC | Example using Java utility classes for Spring JDBC Template | [src/test/java/examples/spring](src/test/java/examples/spring) |
65-
| Kotlin | MyBatis3 | Example using Kotlin utility classes for MyBatis in the style of MyBatis Generator | [src/test/kotlin/examples/kotlin/mybatis3/canonical](src/test/kotlin/examples/kotlin/mybatis3/canonical) |
66-
| Kotlin | Spring JDBC | Example using Kotlin utility classes for Spring JDBC Template | [src/test/kotlin/examples/kotlin/spring/canonical](src/test/kotlin/examples/kotlin/spring/canonical) |
62+
| Java | MyBatis3 | Example using Java utility classes for MyBatis in the style of MyBatis Generator | [../examples/simple](src/test/java/examples/simple) |
63+
| Java | MyBatis3 + MyBatis-Spring | Example using MyBatis-Spring integration | [../examples/column/comparison](src/test/java/examples/column/comparison) |
64+
| Java | MyBatis3 + MyBatis-Spring (Spring Batch)| Example using Java utility classes for the MyBatis integration with Spring Batch | [../examples/springbatch](src/test/java/examples/springbatch) |
65+
| Java | Spring JDBC | Example using Java utility classes for Spring JDBC Template | [../examples/spring](src/test/java/examples/spring) |
66+
| Kotlin | MyBatis3 | Example using Kotlin utility classes for MyBatis in the style of MyBatis Generator | [../examples/kotlin/mybatis3/canonical](src/test/kotlin/examples/kotlin/mybatis3/canonical) |
67+
| Kotlin | MyBatis3 + MyBatis-Spring | Example using MyBatis-Spring integration in Kotlin | [../examples/kotlin/mybatis3/column/comparison](src/test/kotlin/examples/kotlin/mybatis3/column/comparison) |
68+
| Kotlin | Spring JDBC | Example using Kotlin utility classes for Spring JDBC Template | [../examples/kotlin/spring/canonical](src/test/kotlin/examples/kotlin/spring/canonical) |
6769

6870

6971
## Requirements
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2016-2021 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.
15+
*/
16+
package examples.column.comparison;
17+
18+
import javax.sql.DataSource;
19+
20+
import org.apache.ibatis.session.SqlSessionFactory;
21+
import org.mybatis.spring.SqlSessionFactoryBean;
22+
import org.mybatis.spring.annotation.MapperScan;
23+
import org.springframework.context.annotation.Bean;
24+
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
26+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
27+
28+
@Configuration
29+
@MapperScan("examples.column.comparison")
30+
public class ColumnComparisonConfiguration {
31+
@Bean
32+
public DataSource datasource() {
33+
return new EmbeddedDatabaseBuilder()
34+
.setType(EmbeddedDatabaseType.HSQL)
35+
.generateUniqueName(true)
36+
.addScript("classpath:/examples/column/comparison/CreateDB.sql")
37+
.build();
38+
}
39+
40+
@Bean
41+
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
42+
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
43+
factoryBean.setDataSource(dataSource);
44+
return factoryBean.getObject();
45+
}
46+
}

src/test/java/examples/column/comparison/ColumnComparisonDynamicSqlSupport.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 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.sql.JDBCType;
1919

20+
import org.mybatis.dynamic.sql.BasicColumn;
2021
import org.mybatis.dynamic.sql.SqlColumn;
2122
import org.mybatis.dynamic.sql.SqlTable;
2223

@@ -25,6 +26,8 @@ public final class ColumnComparisonDynamicSqlSupport {
2526
public static final SqlColumn<Integer> number1 = columnComparison.number1;
2627
public static final SqlColumn<Integer> number2 = columnComparison.number2;
2728

29+
public static final BasicColumn[] columnList = { number1, number2 };
30+
2831
public static final class ColumnComparison extends SqlTable {
2932
public final SqlColumn<Integer> number1 = column("number1", JDBCType.INTEGER);
3033
public final SqlColumn<Integer> number2 = column("number2", JDBCType.INTEGER);

src/test/java/examples/column/comparison/ColumnComparisonMapper.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2021 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.
@@ -20,8 +20,10 @@
2020
import org.apache.ibatis.annotations.Result;
2121
import org.apache.ibatis.annotations.Results;
2222
import org.apache.ibatis.annotations.SelectProvider;
23+
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
2324
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
2425
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
26+
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;
2527

2628
public interface ColumnComparisonMapper {
2729

@@ -31,4 +33,9 @@ public interface ColumnComparisonMapper {
3133
@Result(column="number2", property="number2", id=true)
3234
})
3335
List<ColumnComparisonRecord> selectMany(SelectStatementProvider selectStatement);
36+
37+
default List<ColumnComparisonRecord> select(SelectDSLCompleter completer) {
38+
return MyBatis3Utils.selectList(this::selectMany, ColumnComparisonDynamicSqlSupport.columnList,
39+
ColumnComparisonDynamicSqlSupport.columnComparison, completer);
40+
}
3441
}

0 commit comments

Comments
 (0)