@@ -63,7 +63,7 @@ object PersonDynamicSqlSupport {
63
63
val birthDate = column<Date >(name = " birth_date" , jdbcType = JDBCType .DATE )
64
64
val employed = column(
65
65
name = " employed" ,
66
- jdbcType = JDBCType .VARCHAR
66
+ jdbcType = JDBCType .VARCHAR ,
67
67
typeHandler = " foo.bar.StringToBooleanTypeHandler"
68
68
)
69
69
val occupation = column<String >(name = " occupation" , jdbcType = JDBCType .VARCHAR )
@@ -143,8 +143,9 @@ Then extensions could be added to make a shortcut method as follows:
143
143
``` kotlin
144
144
import org.mybatis.dynamic.sql.util.kotlin.SelectCompleter
145
145
import org.mybatis.dynamic.sql.util.kotlin.mybatis3.selectList
146
+ import org.mybatis.dynamic.sql.util.kotlin.elements.`as`
146
147
147
- private val columnList = listOf (id. `as `( " A_ID" ) , firstName, lastName, birthDate, employed, occupation, addressId)
148
+ private val columnList = listOf (id `as ` " A_ID" , firstName, lastName, birthDate, employed, occupation, addressId)
148
149
149
150
fun PersonMapper.select (completer : SelectCompleter ) =
150
151
selectList(this ::selectMany, columnList, Person , completer)
@@ -158,7 +159,7 @@ where clause and an order by clause as follows:
158
159
val rows = mapper.select {
159
160
where { id isLessThan 100 }
160
161
or {
161
- employed.isTrue())
162
+ employed.isTrue()
162
163
and { occupation isEqualTo " Developer" }
163
164
}
164
165
orderBy(id)
@@ -193,7 +194,7 @@ interface PersonMapper : CommonCountMapper
193
194
The mapper method can be used as follows:
194
195
195
196
``` kotlin
196
- val countStatement = count(.. . ) // not shown... see the overview page for examples
197
+ val countStatement = count() // not shown... see the overview page for examples
197
198
val mapper: PersonMapper = getMapper() // not shown
198
199
val rows: Long = mapper.count(countStatement)
199
200
```
@@ -267,7 +268,7 @@ interface PersonMapper : CommonDeleteMapper
267
268
The mapper method can be used as follows:
268
269
269
270
``` kotlin
270
- val deleteStatement = deleteFrom(.. . ) // not shown... see the overview page for examples
271
+ val deleteStatement = deleteFrom() // not shown... see the overview page for examples
271
272
val mapper: PersonMapper = getMapper() // not shown
272
273
val rows: Int = mapper.delete(deleteStatement)
273
274
```
@@ -332,7 +333,7 @@ interface PersonMapper : CommonInsertMapper<T>
332
333
The mapper method can be used as follows:
333
334
334
335
``` kotlin
335
- val insertStatement = insert(.. . ) // not shown, see overview page
336
+ val insertStatement = insert() // not shown, see overview page
336
337
val mapper: PersonMapper = getMapper() // not shown
337
338
val rows: Int = mapper.insert(insertStatement)
338
339
```
@@ -411,7 +412,7 @@ interface PersonMapper : CommonInsertMapper<T>
411
412
The mapper method can be used as follows:
412
413
413
414
``` kotlin
414
- val insertStatement = insertInto(.. . ) // not shown, see overview page
415
+ val insertStatement = insertInto() // not shown, see overview page
415
416
val mapper: PersonMapper = getMapper() // not shown
416
417
val rows: Int = mapper.generalInsert(insertStatement)
417
418
```
@@ -512,7 +513,7 @@ interface PersonMapper : CommonInsertMapper<T>
512
513
The mapper method can be used as follows:
513
514
514
515
``` kotlin
515
- val insertStatement = insertMultiple(.. . ) // not shown, see overview page
516
+ val insertStatement = insertMultiple() // not shown, see overview page
516
517
val mapper: PersonMapper = getMapper() // not shown
517
518
val rows: Int = mapper.insertMultiple(insertStatement)
518
519
```
@@ -600,7 +601,6 @@ batch such as update counts. The methods are coded as follows:
600
601
import org.apache.ibatis.annotations.Flush
601
602
import org.apache.ibatis.annotations.InsertProvider
602
603
import org.apache.ibatis.executor.BatchResult
603
- .. .
604
604
605
605
@Mapper
606
606
interface PersonMapper {
@@ -649,9 +649,9 @@ val sqlSessionFactory: SqlSessionFactory = getSessionFactory() // not shown
649
649
val sqlSession: SqlSession = sqlSessionFactory.openSession(ExecutorType .BATCH )
650
650
val mapper: PersonMapper = sqlSession.getMapper(PersonMapper ::class .java)
651
651
652
- val batchInsert = insertBatch(.. . ) // not shown, see overview page
652
+ val batchInsert = insertBatch() // not shown, see overview page
653
653
batchInsert.execute(mapper) // see note below about return value
654
- val batchResults: mapper.flush()
654
+ val batchResults = mapper.flush()
655
655
```
656
656
657
657
Note the use of the extension function ` BatchInsert.execute(mapper) ` . This function simply loops over all
@@ -700,7 +700,7 @@ val sqlSessionFactory: SqlSessionFactory = getSessionFactory() // not shown
700
700
val sqlSession: SqlSession = sqlSessionFactory.openSession(ExecutorType .BATCH )
701
701
val mapper: PersonMapper = sqlSession.getMapper(PersonMapper ::class .java)
702
702
mapper.insertBatch(record1, record2)
703
- val batchResults: mapper.flush()
703
+ val batchResults = mapper.flush()
704
704
```
705
705
706
706
### Generated Key Support
@@ -748,7 +748,7 @@ interface PersonMapper : CommonInsertMapper<T>
748
748
The mapper method can be used as follows:
749
749
750
750
``` kotlin
751
- val insertStatement = insertSelect(.. . ) // not shown, see overview page
751
+ val insertStatement = insertSelect() // not shown, see overview page
752
752
val mapper: PersonMapper = getMapper() // not shown
753
753
val rows: Int = mapper.insertSelect(insertStatement)
754
754
```
@@ -825,10 +825,10 @@ The methods can be used as follows:
825
825
``` kotlin
826
826
val mapper: PersonMapper = getMapper() // not shown
827
827
828
- val selectStatement = select(.. . ) // not shown... see the overview page for examples
828
+ val selectStatement = select() // not shown... see the overview page for examples
829
829
val rows: List <PersonRecord > = mapper.selectMany(selectStatement)
830
830
831
- val selectOneStatement = select(.. . ) // not shown... see the overview page for examples
831
+ val selectOneStatement = select() // not shown... see the overview page for examples
832
832
val row: PersonRecord ? = mapper.selectOne(selectStatement)
833
833
```
834
834
@@ -843,11 +843,12 @@ and selecting a single record:
843
843
844
844
``` kotlin
845
845
import org.mybatis.dynamic.sql.util.kotlin.SelectCompleter
846
+ import org.mybatis.dynamic.sql.util.kotlin.elements.`as`
846
847
import org.mybatis.dynamic.sql.util.kotlin.mybatis3.selectDistinct
847
848
import org.mybatis.dynamic.sql.util.kotlin.mybatis3.selectList
848
849
import org.mybatis.dynamic.sql.util.kotlin.mybatis3.selectOne
849
850
850
- private val columnList = listOf (id. `as `( " A_ID" ) , firstName, lastName, birthDate, employed, occupation, addressId)
851
+ private val columnList = listOf (id `as ` " A_ID" , firstName, lastName, birthDate, employed, occupation, addressId)
851
852
852
853
fun PersonMapper.selectOne (completer : SelectCompleter ) =
853
854
selectOne(this ::selectOne, columnList, Person , completer)
@@ -917,7 +918,7 @@ and other parts of a select statement. For example, you could code a mapper exte
917
918
``` kotlin
918
919
fun PersonWithAddressMapper.select (completer : SelectCompleter ): List <PersonWithAddress > =
919
920
select(
920
- id. `as `( " A_ID" ) , firstName, lastName, birthDate,
921
+ id `as ` " A_ID" , firstName, lastName, birthDate,
921
922
employed, occupation, address.id, address.streetAddress, address.city, address.state
922
923
) {
923
924
from(person, " p" )
@@ -967,7 +968,7 @@ interface PersonMapper : CommonUpdateMapper
967
968
The mapper method can be used as follows:
968
969
969
970
``` kotlin
970
- val updateStatement = update(.. . ) // not shown... see the overview page for examples
971
+ val updateStatement = update() // not shown... see the overview page for examples
971
972
val mapper: PersonMapper = getMapper() // not shown
972
973
val rows: Int = mapper.update(updateStatement)
973
974
```
@@ -1005,7 +1006,7 @@ If you wish to update all rows in a table, you can simply omit the where clause
1005
1006
``` kotlin
1006
1007
// update all rows...
1007
1008
val rows = mapper.update {
1008
- set(occupation). equalTo( " Programmer" )
1009
+ set(occupation) equalTo " Programmer"
1009
1010
}
1010
1011
```
1011
1012
@@ -1014,13 +1015,13 @@ It is also possible to write utility methods that will set values. For example:
1014
1015
``` kotlin
1015
1016
fun KotlinUpdateBuilder.updateSelectiveColumns (record : PersonRecord ) =
1016
1017
apply {
1017
- set(id). equalToWhenPresent( record::id)
1018
- set(firstName). equalToWhenPresent( record::firstName)
1019
- set(lastName). equalToWhenPresent( record::lastName)
1020
- set(birthDate). equalToWhenPresent( record::birthDate)
1021
- set(employed). equalToWhenPresent( record::employed)
1022
- set(occupation). equalToWhenPresent( record::occupation)
1023
- set(addressId). equalToWhenPresent( record::addressId)
1018
+ set(id) equalToWhenPresent record::id
1019
+ set(firstName) equalToWhenPresent record::firstName
1020
+ set(lastName) equalToWhenPresent record::lastName
1021
+ set(birthDate) equalToWhenPresent record::birthDate
1022
+ set(employed) equalToWhenPresent record::employed
1023
+ set(occupation) equalToWhenPresent record::occupation
1024
+ set(addressId) equalToWhenPresent record::addressId
1024
1025
}
1025
1026
```
1026
1027
@@ -1039,23 +1040,23 @@ If you wish to implement an "update by primary key" method, you can reuse the ex
1039
1040
``` kotlin
1040
1041
fun PersonMapper.updateByPrimaryKey (record : PersonRecord ) =
1041
1042
update {
1042
- set(firstName). equalToOrNull( record::firstName)
1043
- set(lastName). equalToOrNull( record::lastName)
1044
- set(birthDate). equalToOrNull( record::birthDate)
1045
- set(employed). equalToOrNull( record::employed)
1046
- set(occupation). equalToOrNull( record::occupation)
1047
- set(addressId). equalToOrNull( record::addressId)
1043
+ set(firstName) equalToOrNull record::firstName
1044
+ set(lastName) equalToOrNull record::lastName
1045
+ set(birthDate) equalToOrNull record::birthDate
1046
+ set(employed) equalToOrNull record::employed
1047
+ set(occupation) equalToOrNull record::occupation
1048
+ set(addressId) equalToOrNull record::addressId
1048
1049
where { id isEqualTo record.id!! }
1049
1050
}
1050
1051
1051
1052
fun PersonMapper.updateByPrimaryKeySelective (record : PersonRecord ) =
1052
1053
update {
1053
- set(firstName). equalToWhenPresent( record::firstName)
1054
- set(lastName). equalToWhenPresent( record::lastName)
1055
- set(birthDate). equalToWhenPresent( record::birthDate)
1056
- set(employed). equalToWhenPresent( record::employed)
1057
- set(occupation). equalToWhenPresent( record::occupation)
1058
- set(addressId). equalToWhenPresent( record::addressId)
1054
+ set(firstName) equalToWhenPresent record::firstName
1055
+ set(lastName) equalToWhenPresent record::lastName
1056
+ set(birthDate) equalToWhenPresent record::birthDate
1057
+ set(employed) equalToWhenPresent record::employed
1058
+ set(occupation) equalToWhenPresent record::occupation
1059
+ set(addressId) equalToWhenPresent record::addressId
1059
1060
where { id isEqualTo record.id!! }
1060
1061
}
1061
1062
```
0 commit comments