Skip to content

Commit

Permalink
Merge pull request #59 from cj848/feature/support-boot-2.7.0
Browse files Browse the repository at this point in the history
Support Spring Boot 2.7.0
  • Loading branch information
Hyunsik Kang authored May 27, 2022
2 parents d395503 + 26bed47 commit 1a8b619
Show file tree
Hide file tree
Showing 29 changed files with 534 additions and 34 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {

allprojects {
group = "com.linecorp.kotlin-jdsl"
version = "2.0.2.RELEASE"
version = "2.0.3.RELEASE"

repositories {
mavenCentral()
Expand Down
22 changes: 11 additions & 11 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import org.gradle.api.artifacts.dsl.DependencyHandler

object Dependencies {
const val kotlinVersion = "1.6.21"
const val springCoreVersion = "5.3.19"
const val springBootVersion = "2.6.7"
const val springDataJpaVersion = "2.6.4"
const val springCoreVersion = "5.3.20"
const val springBootVersion = "2.7.0"
const val springDataJpaVersion = "2.7.0"
const val coroutineVersion = "1.6.1"

// kotlin
Expand All @@ -17,12 +17,12 @@ object Dependencies {
const val javaPersistenceApi = "javax.persistence:javax.persistence-api:2.2"
const val slf4j = "org.slf4j:slf4j-api:1.7.36"
const val logback = "ch.qos.logback:logback-classic:1.2.11"
const val hibernate = "org.hibernate:hibernate-core:5.6.8.Final"
const val hibernateReactive = "org.hibernate.reactive:hibernate-reactive-core:1.1.4.Final"
const val hibernate = "org.hibernate:hibernate-core:5.6.9.Final"
const val hibernateReactive = "org.hibernate.reactive:hibernate-reactive-core:1.1.6.Final"
const val eclipselink = "org.eclipse.persistence:org.eclipse.persistence.jpa:2.7.10"
const val jacksonKotlinModule = "com.fasterxml.jackson.module:jackson-module-kotlin"
const val agroalPool = "io.agroal:agroal-pool:1.14"
const val vertxJdbcClient = "io.vertx:vertx-jdbc-client:4.2.7"
const val agroalPool = "io.agroal:agroal-pool:2.0"
const val vertxJdbcClient = "io.vertx:vertx-jdbc-client:4.3.1"
const val coroutineJdk8 = "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:$coroutineVersion"
const val coroutineReactor = "org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$coroutineVersion"

Expand All @@ -42,16 +42,16 @@ object Dependencies {
const val springCore = "org.springframework:spring-core:${springCoreVersion}"
const val springBeans = "org.springframework:spring-beans:${springCoreVersion}"
const val springJpa = "org.springframework.data:spring-data-jpa:${springDataJpaVersion}"
const val springBatchInfrastructure = "org.springframework.batch:spring-batch-infrastructure:4.3.5"
const val springBatchInfrastructure = "org.springframework.batch:spring-batch-infrastructure:4.3.6"

// Test
const val junit = "org.junit.jupiter:junit-jupiter:5.8.2"
const val assertJ = "org.assertj:assertj-core:3.22.0"
const val mockk = "io.mockk:mockk:1.12.3"
const val mockk = "io.mockk:mockk:1.12.4"

const val h2 = "com.h2database:h2:1.4.200"
const val h2 = "com.h2database:h2:2.1.212"

const val mutinyVersion = "1.4.0"
const val mutinyVersion = "1.5.0"
const val mutinyCore = "io.smallrye.reactive:mutiny:$mutinyVersion"
const val mutinyKotlin = "io.smallrye.reactive:mutiny-kotlin:$mutinyVersion"
val mutiny = listOf(mutinyCore, mutinyKotlin)
Expand Down
4 changes: 3 additions & 1 deletion eclipselink/src/test/resources/META-INF/persistence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
<properties>
<property name="eclipselink.logging.level" value="INFO" />
<property name="eclipselink.logging.level.sql" value="FINE" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;MODE=MYSQL"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;MODE=MYSQL;DATABASE_TO_LOWER=TRUE"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.MySQLPlatform"/>
<property name="eclipselink.target-database-properties" value="shouldBindLiterals=false"/>
</properties>
</persistence-unit>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<class>com.linecorp.kotlinjdsl.eclipselink.example.entity.Book</class>

<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;MODE=MYSQL"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;MODE=MYSQL;DATABASE_TO_LOWER=TRUE"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<class>com.linecorp.kotlinjdsl.hibernate.example.entity.Book</class>

<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;MODE=MYSQL"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;MODE=MYSQL;DATABASE_TO_LOWER=TRUE"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test;MODE=MYSQL
url: jdbc:h2:mem:test;MODE=MYSQL;DATABASE_TO_LOWER=TRUE
username: sa
password: password

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test;MODE=MYSQL
url: jdbc:h2:mem:test;MODE=MYSQL;DATABASE_TO_LOWER=TRUE
username: sa
password: password

Expand Down
4 changes: 2 additions & 2 deletions examples/spring-boot-2.5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("org.springframework.boot") version "2.5.8"
id("org.springframework.boot") version "2.5.14"
kotlin("plugin.spring")
kotlin("plugin.jpa")
}
Expand All @@ -24,7 +24,7 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation(Dependencies.jacksonKotlinModule)
implementation(Dependencies.h2)
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.5.8"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.5.14"))

testImplementation("org.springframework.boot:spring-boot-starter-test")
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test;MODE=MYSQL
url: jdbc:h2:mem:test;MODE=MYSQL;DATABASE_TO_LOWER=TRUE
username: sa
password: password

Expand Down
10 changes: 5 additions & 5 deletions examples/spring-boot-2.6/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("org.springframework.boot") version Dependencies.springBootVersion
id("org.springframework.boot") version "2.6.8"
kotlin("plugin.spring")
kotlin("plugin.jpa")
}
Expand All @@ -16,11 +16,11 @@ dependencies {
// implementation("com.linecorp.kotlin-jdsl:spring-data-kotlin-jdsl-starter:x.y.z")
implementation(Modules.springDataStarter)

implementation(Dependencies.springBootWeb)
implementation(Dependencies.springBootJpa)
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation(Dependencies.jacksonKotlinModule)
implementation(Dependencies.h2)
implementation(platform(Dependencies.springBootBom))
implementation(platform("org.springframework.boot:spring-boot-dependencies:2.6.8"))

testImplementation(Dependencies.springBootTest)
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test;MODE=MYSQL
url: jdbc:h2:mem:test;MODE=MYSQL;DATABASE_TO_LOWER=TRUE
username: sa
password: password

Expand Down
26 changes: 26 additions & 0 deletions examples/spring-boot-2.7/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
plugins {
id("org.springframework.boot") version Dependencies.springBootVersion
kotlin("plugin.spring")
kotlin("plugin.jpa")
}

apply(plugin = "org.springframework.boot")
apply(plugin = "kotlin-spring")
apply(plugin = "kotlin-jpa")

coverage {
exclude(project)
}

dependencies {
// implementation("com.linecorp.kotlin-jdsl:spring-data-kotlin-jdsl-starter:x.y.z")
implementation(Modules.springDataStarter)

implementation(Dependencies.springBootWeb)
implementation(Dependencies.springBootJpa)
implementation(Dependencies.jacksonKotlinModule)
implementation(Dependencies.h2)
implementation(platform(Dependencies.springBootBom))

testImplementation(Dependencies.springBootTest)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.linecorp.kotlinjdsl.spring.data.example

import com.linecorp.kotlinjdsl.querydsl.expression.col
import com.linecorp.kotlinjdsl.spring.data.SpringDataQueryFactory
import com.linecorp.kotlinjdsl.spring.data.example.entity.Book
import com.linecorp.kotlinjdsl.spring.data.listQuery
import com.linecorp.kotlinjdsl.spring.data.singleQuery
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.bind.annotation.*
import javax.persistence.EntityManager

@RestController
@RequestMapping("/api/v1/books")
class BookController(
private val bookService: BookService,
) {
@PostMapping
fun createBook(@RequestBody spec: BookService.CreateBookSpec): ResponseEntity<Long> {
val book = bookService.create(spec)

return ResponseEntity.ok(book.id)
}

@GetMapping("/{bookId}")
fun findById(@PathVariable bookId: Long): ResponseEntity<Book> {
val book = bookService.findById(bookId)

return ResponseEntity.ok(book)
}

@GetMapping
fun findAll(@RequestParam("name") name: String): ResponseEntity<List<Book>> {
val books = bookService.findAll(BookService.FindBookSpec(name = name))

return ResponseEntity.ok(books)
}
}

@Service
@Transactional
class BookService(
private val entityManager: EntityManager,
private val queryFactory: SpringDataQueryFactory,
) {
fun create(spec: CreateBookSpec): Book {
return Book(name = spec.name).also {
entityManager.persist(it)
}
}

fun findById(id: Long): Book {
return queryFactory.singleQuery {
select(entity(Book::class))
from(entity(Book::class))
where(col(Book::id).equal(id))
}
}

fun findAll(spec: FindBookSpec): List<Book> {
return queryFactory.listQuery {
select(entity(Book::class))
from(entity(Book::class))
where(col(Book::name).like("%${spec.name}%"))
}
}

data class CreateBookSpec(
val name: String
) {
fun toJson() = """{"name":"$name"}"""
}

data class FindBookSpec(
val name: String
) {
fun toJson() = """{"name":"$name"}"""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.linecorp.kotlinjdsl.spring.data.example

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class ExampleApplication

fun main(args: Array<String>) {
runApplication<ExampleApplication>(*args)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.linecorp.kotlinjdsl.spring.data.example.entity

import javax.persistence.*

@Entity
@Table(name = "book")
data class Book(
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0,

@Column
val name: String,
) {
fun toJson() = """{"id":$id,"name":"$name"}"""
}
20 changes: 20 additions & 0 deletions examples/spring-boot-2.7/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
spring:
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test;MODE=MYSQL;DATABASE_TO_LOWER=TRUE
username: sa
password: password

jpa:
database-platform: org.hibernate.dialect.MySQL8Dialect
hibernate:
ddl-auto: update
use-new-id-generator-mappings: true
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
properties:
hibernate:
check_nullability: true
use_sql_comments: true
format_sql: true
show_sql: true
Loading

0 comments on commit 1a8b619

Please sign in to comment.