diff --git a/build.gradle.kts b/build.gradle.kts index 29a8f65..c9034ce 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,15 +1,15 @@ plugins { id("maven") id("java") - id("org.jetbrains.kotlin.jvm") version "1.3.72" + id("org.jetbrains.kotlin.jvm") version "1.4.0" // その他補助系 - id("org.jlleitschuh.gradle.ktlint") version "9.2.1" + id("org.jlleitschuh.gradle.ktlint") version "9.3.0" id("jacoco") id("com.github.ben-manes.versions") version "0.28.0" } group = "com.mapk" -version = "0.15" +version = "0.16" java { sourceCompatibility = JavaVersion.VERSION_1_8 @@ -33,7 +33,7 @@ repositories { dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation(kotlin("reflect")) - api("com.github.ProjectMapK:Shared:0.16") + api("com.github.ProjectMapK:Shared:0.17") // 使うのはRowMapperのみなため他はexclude、またバージョンそのものは使う相手に合わせるためcompileOnly compileOnly(group = "org.springframework", name = "spring-jdbc", version = "5.2.7.RELEASE") { exclude(module = "spring-beans") diff --git a/src/main/kotlin/com/mapk/krowmapper/KRowMapper.kt b/src/main/kotlin/com/mapk/krowmapper/KRowMapper.kt index 7b8fa48..8f4832e 100644 --- a/src/main/kotlin/com/mapk/krowmapper/KRowMapper.kt +++ b/src/main/kotlin/com/mapk/krowmapper/KRowMapper.kt @@ -2,10 +2,10 @@ package com.mapk.krowmapper import com.mapk.core.KFunctionForCall import com.mapk.core.toKConstructor +import org.springframework.jdbc.core.RowMapper import java.sql.ResultSet import kotlin.reflect.KClass import kotlin.reflect.KFunction -import org.springframework.jdbc.core.RowMapper class KRowMapper private constructor(private val function: KFunctionForCall) : RowMapper { constructor(function: KFunction, parameterNameConverter: ((String) -> String)? = null) : this( diff --git a/src/main/kotlin/com/mapk/krowmapper/ParameterForMap.kt b/src/main/kotlin/com/mapk/krowmapper/ParameterForMap.kt index c217d40..7eba1b7 100644 --- a/src/main/kotlin/com/mapk/krowmapper/ParameterForMap.kt +++ b/src/main/kotlin/com/mapk/krowmapper/ParameterForMap.kt @@ -80,9 +80,11 @@ private fun ValueParameter.getDeserializer(): AbstractKColumnDeseri } private fun KClass.getDeserializer(): KFunction? { - val deserializers = deserializerFromConstructors(this) + - deserializerFromStaticMethods(this) + - deserializerFromCompanionObject(this) + val deserializers: List> = ArrayList>().also { + it.addAll(deserializerFromConstructors(this)) + it.addAll(deserializerFromStaticMethods(this)) + it.addAll(deserializerFromCompanionObject(this)) + } return when { deserializers.size <= 1 -> deserializers.singleOrNull() diff --git a/src/test/kotlin/com/mapk/krowmapper/DefaultValueTest.kt b/src/test/kotlin/com/mapk/krowmapper/DefaultValueTest.kt index ae1f030..f96f108 100644 --- a/src/test/kotlin/com/mapk/krowmapper/DefaultValueTest.kt +++ b/src/test/kotlin/com/mapk/krowmapper/DefaultValueTest.kt @@ -5,10 +5,10 @@ import com.mapk.annotations.KUseDefaultArgument import io.mockk.every import io.mockk.mockk import io.mockk.verify -import java.sql.ResultSet import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test +import java.sql.ResultSet class DefaultValueTest { data class Dst(val fooId: Int, @param:KUseDefaultArgument val barValue: String = "default") diff --git a/src/test/kotlin/com/mapk/krowmapper/DeserializeByMethodTest.kt b/src/test/kotlin/com/mapk/krowmapper/DeserializeByMethodTest.kt index cd8cb10..610b8c9 100644 --- a/src/test/kotlin/com/mapk/krowmapper/DeserializeByMethodTest.kt +++ b/src/test/kotlin/com/mapk/krowmapper/DeserializeByMethodTest.kt @@ -3,11 +3,11 @@ package com.mapk.krowmapper import com.mapk.annotations.KColumnDeserializer import io.mockk.every import io.mockk.mockk -import java.sql.ResultSet import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows +import java.sql.ResultSet class DeserializeByMethodTest { data class ByConstructor @KColumnDeserializer constructor(val fooString: String) diff --git a/src/test/kotlin/com/mapk/krowmapper/DeserializerTest.kt b/src/test/kotlin/com/mapk/krowmapper/DeserializerTest.kt index a148aac..b6da02c 100644 --- a/src/test/kotlin/com/mapk/krowmapper/DeserializerTest.kt +++ b/src/test/kotlin/com/mapk/krowmapper/DeserializerTest.kt @@ -4,13 +4,13 @@ import com.mapk.deserialization.AbstractKColumnDeserializer import com.mapk.deserialization.KColumnDeserializeBy import io.mockk.every import io.mockk.mockk -import java.sql.ResultSet -import java.time.LocalDateTime -import java.time.format.DateTimeFormatter import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test +import java.sql.ResultSet +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter @DisplayName("アノテーションによるデシリアライザー指定のテスト") class DeserializerTest { diff --git a/src/test/kotlin/com/mapk/krowmapper/KParameterFlattenTest.kt b/src/test/kotlin/com/mapk/krowmapper/KParameterFlattenTest.kt index 782d166..fa5b8f9 100644 --- a/src/test/kotlin/com/mapk/krowmapper/KParameterFlattenTest.kt +++ b/src/test/kotlin/com/mapk/krowmapper/KParameterFlattenTest.kt @@ -6,11 +6,11 @@ import com.mapk.core.NameJoiner import io.mockk.every import io.mockk.mockk import io.mockk.verify -import java.sql.ResultSet -import java.time.LocalDateTime import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test +import java.sql.ResultSet +import java.time.LocalDateTime @DisplayName("KParameterFlattenテスト") class KParameterFlattenTest { diff --git a/src/test/kotlin/com/mapk/krowmapper/SimpleMappingTest.kt b/src/test/kotlin/com/mapk/krowmapper/SimpleMappingTest.kt index 19cf04a..f2b07bb 100644 --- a/src/test/kotlin/com/mapk/krowmapper/SimpleMappingTest.kt +++ b/src/test/kotlin/com/mapk/krowmapper/SimpleMappingTest.kt @@ -4,10 +4,10 @@ import com.google.common.base.CaseFormat import io.mockk.every import io.mockk.mockk import io.mockk.verify -import java.sql.ResultSet import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test +import java.sql.ResultSet @DisplayName("単純なマッピングテスト") class SimpleMappingTest { diff --git a/src/test/kotlin/com/mapk/krowmapper/UseDBMappingTest.kt b/src/test/kotlin/com/mapk/krowmapper/UseDBMappingTest.kt index 397cfac..374e013 100644 --- a/src/test/kotlin/com/mapk/krowmapper/UseDBMappingTest.kt +++ b/src/test/kotlin/com/mapk/krowmapper/UseDBMappingTest.kt @@ -1,7 +1,6 @@ package com.mapk.krowmapper import com.google.common.base.CaseFormat -import javax.sql.DataSource import org.h2.jdbcx.JdbcDataSource import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.Assertions.assertEquals @@ -12,6 +11,7 @@ import org.junit.jupiter.api.TestInstance import org.springframework.jdbc.core.JdbcTemplate import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource import org.springframework.jdbc.core.simple.SimpleJdbcInsert +import javax.sql.DataSource @TestInstance(TestInstance.Lifecycle.PER_CLASS) @DisplayName("DBを用いてマッピングを行うテスト") @@ -61,7 +61,8 @@ class UseDBMappingTest { jdbcTemplate = JdbcTemplate(dataSource) - jdbcTemplate.execute(""" + jdbcTemplate.execute( + """ CREATE TABLE IF NOT EXISTS `foo_table` ( `foo_id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `foo_name` VARCHAR(255) NOT NULL, @@ -70,7 +71,8 @@ class UseDBMappingTest { `description` VARCHAR(1023) NULL DEFAULT NULL, PRIMARY KEY (`foo_id`) ); - """.trimIndent()) + """.trimIndent() + ) val data = FooInsert(10, "Foo", FooStatus.archive, false, null) @@ -79,9 +81,10 @@ class UseDBMappingTest { @Test fun test() { - val result = jdbcTemplate.query("SELECT * FROM foo_table", KRowMapper((Foo)::fooFactory) { - CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, it) - }).single() + val result = jdbcTemplate.query( + "SELECT * FROM foo_table", + KRowMapper((Foo)::fooFactory) { CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, it) } + ).single() assertEquals( Foo(10, "Foo", FooStatus.archive, false, null),