-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from cj848/feature/support-boot-2.7.0
Support Spring Boot 2.7.0
- Loading branch information
Showing
29 changed files
with
534 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
80 changes: 80 additions & 0 deletions
80
...ples/spring-boot-2.7/src/main/kotlin/com/linecorp/kotlinjdsl/spring/data/example/Books.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}""" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/spring-boot-2.7/src/main/kotlin/com/linecorp/kotlinjdsl/spring/data/example/Main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
17 changes: 17 additions & 0 deletions
17
...pring-boot-2.7/src/main/kotlin/com/linecorp/kotlinjdsl/spring/data/example/entity/Book.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
examples/spring-boot-2.7/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.