@@ -63,7 +63,7 @@ object PersonDynamicSqlSupport {
6363 val birthDate = column<Date >(name = " birth_date" , jdbcType = JDBCType .DATE )
6464 val employed = column(
6565 name = " employed" ,
66- jdbcType = JDBCType .VARCHAR
66+ jdbcType = JDBCType .VARCHAR ,
6767 typeHandler = " foo.bar.StringToBooleanTypeHandler"
6868 )
6969 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:
143143``` kotlin
144144import org.mybatis.dynamic.sql.util.kotlin.SelectCompleter
145145import org.mybatis.dynamic.sql.util.kotlin.mybatis3.selectList
146+ import org.mybatis.dynamic.sql.util.kotlin.elements.`as`
146147
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)
148149
149150fun PersonMapper.select (completer : SelectCompleter ) =
150151 selectList(this ::selectMany, columnList, Person , completer)
@@ -158,7 +159,7 @@ where clause and an order by clause as follows:
158159val rows = mapper.select {
159160 where { id isLessThan 100 }
160161 or {
161- employed.isTrue())
162+ employed.isTrue()
162163 and { occupation isEqualTo " Developer" }
163164 }
164165 orderBy(id)
@@ -193,7 +194,7 @@ interface PersonMapper : CommonCountMapper
193194The mapper method can be used as follows:
194195
195196``` 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
197198val mapper: PersonMapper = getMapper() // not shown
198199val rows: Long = mapper.count(countStatement)
199200```
@@ -267,7 +268,7 @@ interface PersonMapper : CommonDeleteMapper
267268The mapper method can be used as follows:
268269
269270``` 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
271272val mapper: PersonMapper = getMapper() // not shown
272273val rows: Int = mapper.delete(deleteStatement)
273274```
@@ -332,7 +333,7 @@ interface PersonMapper : CommonInsertMapper<T>
332333The mapper method can be used as follows:
333334
334335``` kotlin
335- val insertStatement = insert(.. . ) // not shown, see overview page
336+ val insertStatement = insert() // not shown, see overview page
336337val mapper: PersonMapper = getMapper() // not shown
337338val rows: Int = mapper.insert(insertStatement)
338339```
@@ -411,7 +412,7 @@ interface PersonMapper : CommonInsertMapper<T>
411412The mapper method can be used as follows:
412413
413414``` kotlin
414- val insertStatement = insertInto(.. . ) // not shown, see overview page
415+ val insertStatement = insertInto() // not shown, see overview page
415416val mapper: PersonMapper = getMapper() // not shown
416417val rows: Int = mapper.generalInsert(insertStatement)
417418```
@@ -512,7 +513,7 @@ interface PersonMapper : CommonInsertMapper<T>
512513The mapper method can be used as follows:
513514
514515``` kotlin
515- val insertStatement = insertMultiple(.. . ) // not shown, see overview page
516+ val insertStatement = insertMultiple() // not shown, see overview page
516517val mapper: PersonMapper = getMapper() // not shown
517518val rows: Int = mapper.insertMultiple(insertStatement)
518519```
@@ -600,7 +601,6 @@ batch such as update counts. The methods are coded as follows:
600601import org.apache.ibatis.annotations.Flush
601602import org.apache.ibatis.annotations.InsertProvider
602603import org.apache.ibatis.executor.BatchResult
603- .. .
604604
605605@Mapper
606606interface PersonMapper {
@@ -649,9 +649,9 @@ val sqlSessionFactory: SqlSessionFactory = getSessionFactory() // not shown
649649val sqlSession: SqlSession = sqlSessionFactory.openSession(ExecutorType .BATCH )
650650val mapper: PersonMapper = sqlSession.getMapper(PersonMapper ::class .java)
651651
652- val batchInsert = insertBatch(.. . ) // not shown, see overview page
652+ val batchInsert = insertBatch() // not shown, see overview page
653653batchInsert.execute(mapper) // see note below about return value
654- val batchResults: mapper.flush()
654+ val batchResults = mapper.flush()
655655```
656656
657657Note 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
700700val sqlSession: SqlSession = sqlSessionFactory.openSession(ExecutorType .BATCH )
701701val mapper: PersonMapper = sqlSession.getMapper(PersonMapper ::class .java)
702702mapper.insertBatch(record1, record2)
703- val batchResults: mapper.flush()
703+ val batchResults = mapper.flush()
704704```
705705
706706### Generated Key Support
@@ -748,7 +748,7 @@ interface PersonMapper : CommonInsertMapper<T>
748748The mapper method can be used as follows:
749749
750750``` kotlin
751- val insertStatement = insertSelect(.. . ) // not shown, see overview page
751+ val insertStatement = insertSelect() // not shown, see overview page
752752val mapper: PersonMapper = getMapper() // not shown
753753val rows: Int = mapper.insertSelect(insertStatement)
754754```
@@ -825,10 +825,10 @@ The methods can be used as follows:
825825``` kotlin
826826val mapper: PersonMapper = getMapper() // not shown
827827
828- val selectStatement = select(.. . ) // not shown... see the overview page for examples
828+ val selectStatement = select() // not shown... see the overview page for examples
829829val rows: List <PersonRecord > = mapper.selectMany(selectStatement)
830830
831- val selectOneStatement = select(.. . ) // not shown... see the overview page for examples
831+ val selectOneStatement = select() // not shown... see the overview page for examples
832832val row: PersonRecord ? = mapper.selectOne(selectStatement)
833833```
834834
@@ -843,11 +843,12 @@ and selecting a single record:
843843
844844``` kotlin
845845import org.mybatis.dynamic.sql.util.kotlin.SelectCompleter
846+ import org.mybatis.dynamic.sql.util.kotlin.elements.`as`
846847import org.mybatis.dynamic.sql.util.kotlin.mybatis3.selectDistinct
847848import org.mybatis.dynamic.sql.util.kotlin.mybatis3.selectList
848849import org.mybatis.dynamic.sql.util.kotlin.mybatis3.selectOne
849850
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)
851852
852853fun PersonMapper.selectOne (completer : SelectCompleter ) =
853854 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
917918``` kotlin
918919fun PersonWithAddressMapper.select (completer : SelectCompleter ): List <PersonWithAddress > =
919920 select(
920- id. `as `( " A_ID" ) , firstName, lastName, birthDate,
921+ id `as ` " A_ID" , firstName, lastName, birthDate,
921922 employed, occupation, address.id, address.streetAddress, address.city, address.state
922923 ) {
923924 from(person, " p" )
@@ -967,7 +968,7 @@ interface PersonMapper : CommonUpdateMapper
967968The mapper method can be used as follows:
968969
969970``` 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
971972val mapper: PersonMapper = getMapper() // not shown
972973val rows: Int = mapper.update(updateStatement)
973974```
@@ -1005,7 +1006,7 @@ If you wish to update all rows in a table, you can simply omit the where clause
10051006``` kotlin
10061007// update all rows...
10071008val rows = mapper.update {
1008- set(occupation). equalTo( " Programmer" )
1009+ set(occupation) equalTo " Programmer"
10091010}
10101011```
10111012
@@ -1014,13 +1015,13 @@ It is also possible to write utility methods that will set values. For example:
10141015``` kotlin
10151016fun KotlinUpdateBuilder.updateSelectiveColumns (record : PersonRecord ) =
10161017 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
10241025 }
10251026```
10261027
@@ -1039,23 +1040,23 @@ If you wish to implement an "update by primary key" method, you can reuse the ex
10391040``` kotlin
10401041fun PersonMapper.updateByPrimaryKey (record : PersonRecord ) =
10411042 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
10481049 where { id isEqualTo record.id!! }
10491050 }
10501051
10511052fun PersonMapper.updateByPrimaryKeySelective (record : PersonRecord ) =
10521053 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
10591060 where { id isEqualTo record.id!! }
10601061 }
10611062```
0 commit comments