Skip to content

Commit

Permalink
chore: clean codes
Browse files Browse the repository at this point in the history
  • Loading branch information
hantsy committed Dec 5, 2024
1 parent 5cafabb commit 592773e
Show file tree
Hide file tree
Showing 27 changed files with 98 additions and 28 deletions.
2 changes: 1 addition & 1 deletion auditing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
2 changes: 1 addition & 1 deletion bookstore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
2 changes: 1 addition & 1 deletion boot-filepart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
2 changes: 1 addition & 1 deletion boot-oracle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
2 changes: 1 addition & 1 deletion boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
2 changes: 1 addition & 1 deletion connection-factories/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
2 changes: 1 addition & 1 deletion data-r2dbc-entitytemplate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
2 changes: 1 addition & 1 deletion data-r2dbc-repositories/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
2 changes: 1 addition & 1 deletion database-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down
2 changes: 1 addition & 1 deletion entitycallbacks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
2 changes: 1 addition & 1 deletion jooq/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
4 changes: 3 additions & 1 deletion komapper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ dependencies {
implementation("org.komapper:komapper-dialect-postgresql-r2dbc")
implementation("org.springframework.boot:spring-boot-starter-actuator")
ksp("org.komapper:komapper-processor")
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")

implementation("org.springframework:spring-r2dbc")
//implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("io.projectreactor.kotlin:reactor-kotlin-extensions")
Expand Down
12 changes: 7 additions & 5 deletions komapper/src/main/kotlin/com/example/demo/DataInitializer.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.example.demo

import com.example.demo.Post.Status.PUBLISHED
import com.example.demo.Status.PUBLISHED
import org.komapper.core.dsl.Meta
import org.komapper.core.dsl.QueryDsl
import org.komapper.core.dsl.query.first
import org.komapper.r2dbc.R2dbcDatabase
import org.slf4j.LoggerFactory
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.annotation.Profile
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component

@Component
@Profile("dev")
class DataInitializer(
private val r2dbcDatabase: R2dbcDatabase
) {
Expand All @@ -25,10 +27,10 @@ class DataInitializer(
r2dbcDatabase.withTransaction {

// create schema
r2dbcDatabase.runQuery {
QueryDsl.drop(p)
QueryDsl.create(p)
}
// r2dbcDatabase.runQuery {
// QueryDsl.drop(p)
// QueryDsl.create(p)
// }

// insert data
val newPost = r2dbcDatabase.runQuery {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,24 @@ class KomapperPostRepository(
}
}

override suspend fun saveAll(posts: List<Post>) = r2dbcDatabase.withTransaction{
r2dbcDatabase.runQuery{
QueryDsl.insert(p)
.multiple(posts)
.returning()
}
}

override suspend fun deleteById(id: Long): Long = r2dbcDatabase.withTransaction {
r2dbcDatabase.runQuery {
QueryDsl.delete(p).where { p.id eq id }
}
}

override suspend fun deleteAll(): Long = r2dbcDatabase.withTransaction {
r2dbcDatabase.runQuery {
QueryDsl.delete(p).all()
}
}

}
6 changes: 1 addition & 5 deletions komapper/src/main/kotlin/com/example/demo/Post.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,4 @@ data class Post(

@KomapperVersion
val version: Long? = null
) {
enum class Status {
DRAFT, PUBLISHED
}
}
)
4 changes: 4 additions & 0 deletions komapper/src/main/kotlin/com/example/demo/PostRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ interface PostRepository {

suspend fun save(post: Post): Post

suspend fun saveAll(posts: List<Post>): List<Post>

suspend fun deleteById(id: Long): Long

suspend fun deleteAll(): Long
}
5 changes: 5 additions & 0 deletions komapper/src/main/kotlin/com/example/demo/Status.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.demo

enum class Status {
DRAFT, PUBLISHED
}
10 changes: 10 additions & 0 deletions komapper/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
spring.application.name=demo
logging.level.root=INFO
logging.level.com.example.demo=DEBUG
logging.level.org.springframework.r2dbc=DEBUG
logging.level.web=DEBUG
logging.level.sql=DEBUG
logging.group.komapper=org.komapper.Sql,org.komapper.SqlWithArgs,org.komapper.Transaction
logging.level.komapper=DEBUG
# init db schema
spring.sql.init.mode=always
spring.codec.log-request-details=true
2 changes: 2 additions & 0 deletions komapper/src/main/resources/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO posts(title, body)
VALUES ('Sample Data Initialization', 'Sample Data Initialization');
15 changes: 15 additions & 0 deletions komapper/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE IF NOT EXISTS posts
(
id BIGSERIAL,
title VARCHAR(255) NOT NULL,
body VARCHAR(1000) NOT NULL,
status VARCHAR(10) NOT NULL DEFAULT 'DRAFT',
created_at TIMESTAMP, -- NOT NULL DEFAULT LOCALTIMESTAMP,
updated_at TIMESTAMP,
version BIGINT
);

ALTER TABLE posts
DROP CONSTRAINT IF EXISTS pk_posts;
ALTER TABLE posts
ADD CONSTRAINT pk_posts PRIMARY KEY (id);
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
package com.example.demo

import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.annotation.Import

@SpringBootTest
@Import(TestcontainersConfiguration::class)
class DemoApplicationTests {
companion object {
private val log = LoggerFactory.getLogger(DemoApplicationTests::class.java)
}

@Autowired
private lateinit var postRepository: PostRepository

@BeforeEach
fun setup(): Unit = runBlocking {
val deleted = postRepository.deleteAll()

log.debug("deleted posts: $deleted")

val data = listOf("An introduction to R2dbc", "Komapper and Spring R2dbc")
.map {
Post(title = it, body = "content of $it")
}
postRepository.saveAll(data).forEach { p -> log.debug("saved post: $p") }
}

@Test
fun contextLoads() = runTest {
postRepository.findAll().collect {
println(it)
log.debug("found post: $it")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.demo
import org.springframework.boot.fromApplication

fun main(args: Array<String>) {
System.getProperties().putIfAbsent("spring.profiles.active", "dev")
fromApplication<DemoApplication>()
.with(TestcontainersConfiguration::class.java)
.run(* args)
Expand Down
2 changes: 1 addition & 1 deletion kotlin-co/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pg-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pg-notifier-listener/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
2 changes: 1 addition & 1 deletion r2dbc-migrate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down
2 changes: 1 addition & 1 deletion testcontainers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
Expand Down

0 comments on commit 592773e

Please sign in to comment.