This repository was archived by the owner on Jan 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +6
-8
lines changed
main/kotlin/com/mapk/krowmapper
test/kotlin/com/mapk/krowmapper Expand file tree Collapse file tree 3 files changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import org.springframework.jdbc.core.RowMapper
11
11
12
12
class KRowMapper <T : Any > private constructor(
13
13
private val function : KFunctionForCall <T >,
14
- parameterNameConverter : (String ) -> String = { it }
14
+ parameterNameConverter : (String ) -> String
15
15
) : RowMapper<T> {
16
16
constructor (function: KFunction <T >, propertyNameConverter: (String ) -> String = { it }) : this (
17
17
KFunctionForCall (function), propertyNameConverter
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ internal class ParameterForMap private constructor(
62
62
fun getObject (rs : ResultSet ): Any? = objectGetter(rs)
63
63
64
64
companion object {
65
- fun newInstance (param : KParameter , parameterNameConverter : (String ) -> String = { it } ): ParameterForMap {
65
+ fun newInstance (param : KParameter , parameterNameConverter : (String ) -> String ): ParameterForMap {
66
66
return ParameterForMap (
67
67
param,
68
68
parameterNameConverter(param.getAliasOrName()!! ),
@@ -91,18 +91,14 @@ private fun <T : Any> KClass<T>.getDeserializer(): KFunction<T>? {
91
91
deserializerFromCompanionObject(this )
92
92
93
93
return when {
94
- deserializers.isEmpty() -> null
95
- deserializers.size == 1 -> deserializers.single()
94
+ deserializers.size <= 1 -> deserializers.singleOrNull()
96
95
else -> throw IllegalArgumentException (" Find multiple deserializer from $jvmName " )
97
96
}
98
97
}
99
98
100
99
private fun <T > Collection<KFunction<T>>.getDeserializerFromFunctions (): Collection <KFunction <T >> {
101
100
return filter { it.annotations.any { annotation -> annotation is KColumnDeserializer } }
102
- .map { func ->
103
- func.isAccessible = true
104
- func
105
- }
101
+ .onEach { it.isAccessible = true }
106
102
}
107
103
108
104
private fun <T : Any > deserializerFromConstructors (clazz : KClass <T >): Collection <KFunction <T >> {
Original file line number Diff line number Diff line change @@ -6,13 +6,15 @@ import org.h2.jdbcx.JdbcDataSource
6
6
import org.junit.jupiter.api.AfterAll
7
7
import org.junit.jupiter.api.Assertions.assertEquals
8
8
import org.junit.jupiter.api.BeforeAll
9
+ import org.junit.jupiter.api.DisplayName
9
10
import org.junit.jupiter.api.Test
10
11
import org.junit.jupiter.api.TestInstance
11
12
import org.springframework.jdbc.core.JdbcTemplate
12
13
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource
13
14
import org.springframework.jdbc.core.simple.SimpleJdbcInsert
14
15
15
16
@TestInstance(TestInstance .Lifecycle .PER_CLASS )
17
+ @DisplayName(" DBを用いてマッピングを行うテスト" )
16
18
class UseDBMappingTest {
17
19
enum class FooStatus {
18
20
active, archive, deleted
You can’t perform that action at this time.
0 commit comments