Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions guide-projects/plus-sql-java-kotlin-guide/build.gradle
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
id "spring.jdbc.plus.java-conventions"
id "spring.jdbc.plus.spring-bom-conventions"
id "org.jetbrains.kotlin.jvm"
}

compileKotlin {
kotlinOptions {
javaParameters = true
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "17"
}
}

compileTestKotlin {
kotlinOptions {
kotlin {
compilerOptions {
javaParameters = true
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "17"
freeCompilerArgs.addAll("-Xjsr305=strict")
jvmTarget = JvmTarget.JVM_17
}
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation project(":spring-boot-starter-data-jdbc-plus-sql")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("com.h2database:h2")
implementation("org.projectlombok:lombok")
Expand All @@ -37,6 +30,13 @@ dependencies {

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.projectlombok:lombok")

// FixtureMonkey
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter:${fixtureMonkeyVersion}")
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-jackson:${fixtureMonkeyVersion}")
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-jakarta-validation:${fixtureMonkeyVersion}")

testAnnotationProcessor("org.projectlombok:lombok")

testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixtureMonkeyVersion=1.1.6
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

package com.navercorp.spring.data.jdbc.plus.sql.guide.board;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toCollection;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -34,169 +35,205 @@
import org.springframework.data.relational.core.mapping.Table;

import lombok.Builder;
import lombok.Getter;
import lombok.Value;
import lombok.With;

import com.navercorp.spring.jdbc.plus.commons.annotations.SqlTableAlias;

/**
* @author Myeonghyeon Lee
*/
@Builder(toBuilder = true)
@Table("n_board")
@Getter
@Builder
public class Board {
public record Board(
@Id
private Long id;
Long id,

private String name;
String name,

@MappedCollection(idColumn = "board_id")
@Builder.Default
private Set<Label> labels = new HashSet<>();
@Nullable Set<Label> labels,

@MappedCollection(idColumn = "board_id", keyColumn = "board_index")
@Builder.Default
private List<Post> posts = new ArrayList<>();
@Nullable List<Post> posts,

@SqlTableAlias("b_audit")
@Column("board_id")
private @Nullable Audit audit;
@Nullable Audit audit,

@Embedded.Nullable(prefix = "board_")
private @Nullable Memo memo;
@Nullable Memo memo,

@MappedCollection(idColumn = "board_id", keyColumn = "config_key")
@Builder.Default
private @Nullable Map<String, Config> configMap = new HashMap<>();
@Nullable Map<String, Config> configMap
) {
public Board {
labels = labels == null ? Set.of() : labels;
posts = posts == null ? List.of() : posts;
configMap = configMap == null ? Map.of() : configMap;
}

public Board sort() {
return toBuilder()
.labels(labels.stream()
.sorted(comparing(label -> label.id().title()))
.collect(toCollection(LinkedHashSet::new)))
.posts(posts.stream()
.map(Post::sort)
.sorted(comparing(Post::id))
.toList())
.audit(audit != null ? audit.sort() : null)
.build();
}

@Builder(toBuilder = true)
@Table("n_label")
@Getter
@Builder
public static class Label implements Persistable<LabelId> {
public record Label(
@Id
@Nullable
@Embedded.Empty
private LabelId id;
LabelId id,

private String name;
String name
) implements Persistable<LabelId> {
@Override
public @Nullable LabelId getId() {
return id;
}

@Override
public boolean isNew() {
return false;
}
}

@Value
@Builder
public static class LabelId {
@Builder(toBuilder = true)
public record LabelId(
@Column("title")
String title;
String title,

@Column("project_name")
String projectName;
String projectName
) {
}

@Builder(toBuilder = true)
@Table("n_post")
@Getter
@Builder
public static class Post {
public record Post(
@Id
private Long id;
Long id,

private Long postNo;
Long postNo,

private String title;
String title,

private String content;
String content,

@MappedCollection(idColumn = "post_id")
@Builder.Default
private Set<Tag> tags = new HashSet<>();
@Nullable Set<Tag> tags,

@MappedCollection(idColumn = "post_id", keyColumn = "post_index")
@Builder.Default
private List<Comment> comments = new ArrayList<>();
@Nullable List<Comment> comments,

@Column("post_id")
private @Nullable Audit audit;
@Nullable Audit audit,

@Embedded.Nullable
private @Nullable Memo memo;
@Nullable Memo memo,

@MappedCollection(idColumn = "post_id", keyColumn = "config_key")
@Builder.Default
private @Nullable Map<String, Config> configMap = new HashMap<>();
@Nullable Map<String, Config> configMap
) {
public Post {
tags = tags == null ? Set.of() : tags;
comments = comments == null ? List.of() : comments;
configMap = configMap == null ? Map.of() : configMap;
}

public Post sort() {
return toBuilder()
.tags(tags.stream()
.sorted(comparing(Tag::id))
.collect(toCollection(LinkedHashSet::new)))
.comments(comments.stream()
.map(Comment::sort)
.sorted(comparing(Comment::id))
.toList())
.audit(audit != null ? audit.sort() : null)
.build();
}
}

@Builder(toBuilder = true)
@Table("n_tag")
@Value
@Builder
public static class Tag {
public record Tag(
@Id
@With
Long id;
Long id,

String content;
String content
) {
}

@Builder(toBuilder = true)
@Table("n_comment")
@Getter
@Builder
public static class Comment {
public record Comment(
@Id
private Long id;
Long id,

private String content;
String content,

@Column("comment_id")
private @Nullable Audit audit;
@Nullable Audit audit
) {
public Comment sort() {
return toBuilder()
.audit(audit != null ? audit.sort() : null)
.build();
}
}

@Builder(toBuilder = true)
@Table("n_audit")
@Getter
@Builder
public static class Audit {
public record Audit(
@Id
private Long id;
Long id,

private String name;
String name,

@Embedded.Nullable
private @Nullable Memo memo;
@Nullable Memo memo,

@Column("audit_id")
private @Nullable AuditSecret secret;
@Nullable AuditSecret secret
) {
public Audit sort() {
return this;
}
}

@Value
@Builder
public static class Memo {
String memo;
@Builder(toBuilder = true)
public record Memo(
String memo
) {
}

@Builder(toBuilder = true)
@Table("n_audit_secret")
@Value
@Builder
public static class AuditSecret {
public record AuditSecret(
@Id
@With
Long id;
Long id,

String secret;
String secret
) {
}

@Builder(toBuilder = true)
@Table("n_config")
@Value
@Builder
public static class Config {
public record Config(
@Id
@With
Long id;
Long id,

String configKey;
String configKey,

String configValue;
String configValue
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
package com.navercorp.spring.data.jdbc.plus.sql.guide.board;

import org.jspecify.annotations.NullMarked;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.ListCrudRepository;

/**
* @author Myeonghyeon Lee
*/
@NullMarked
public interface BoardRepository extends CrudRepository<Board, Long>, BoardRepositoryCustom {
public interface BoardRepository extends ListCrudRepository<Board, Long>, BoardRepositoryCustom {
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,23 @@
import org.springframework.data.relational.core.mapping.Table;

import lombok.Builder;
import lombok.Value;

import com.navercorp.spring.jdbc.plus.commons.annotations.SqlTableAlias;

/**
* @author Myeonghyeon Lee
*/
@Value
@Builder
@Table("post")
public class PostDto {
public record PostDto(
@Id
Long id;
Long id,

@Column
Board.Post post;
Board.Post post,

@SqlTableAlias("p_labels")
@MappedCollection(idColumn = "board_id")
Set<Board.Label> labels;
Set<Board.Label> labels
) {
}
Loading
Loading