Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #26 from k163377/feature
Browse files Browse the repository at this point in the history
Update libs and formatting.
  • Loading branch information
k163377 authored Aug 29, 2020
2 parents 61b7b17 + b4d67fc commit b4929f8
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 22 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/mapk/krowmapper/KRowMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<T : Any> private constructor(private val function: KFunctionForCall<T>) : RowMapper<T> {
constructor(function: KFunction<T>, parameterNameConverter: ((String) -> String)? = null) : this(
Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/com/mapk/krowmapper/ParameterForMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@ private fun <T : Any> ValueParameter<T>.getDeserializer(): AbstractKColumnDeseri
}

private fun <T : Any> KClass<T>.getDeserializer(): KFunction<T>? {
val deserializers = deserializerFromConstructors(this) +
deserializerFromStaticMethods(this) +
deserializerFromCompanionObject(this)
val deserializers: List<KFunction<T>> = ArrayList<KFunction<T>>().also {
it.addAll(deserializerFromConstructors(this))
it.addAll(deserializerFromStaticMethods(this))
it.addAll(deserializerFromCompanionObject(this))
}

return when {
deserializers.size <= 1 -> deserializers.singleOrNull()
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/mapk/krowmapper/DefaultValueTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/com/mapk/krowmapper/DeserializerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/com/mapk/krowmapper/KParameterFlattenTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/mapk/krowmapper/SimpleMappingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 9 additions & 6 deletions src/test/kotlin/com/mapk/krowmapper/UseDBMappingTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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を用いてマッピングを行うテスト")
Expand Down Expand Up @@ -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,
Expand All @@ -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)

Expand All @@ -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),
Expand Down

0 comments on commit b4929f8

Please sign in to comment.