Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : adds R2DBC Test #1627

Merged
merged 8 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions r2dbc/boot-jooq-r2dbc-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@
<style>AOSP</style>
</googleJavaFormat>
</java>
<sql>
<includes>
<include>src/main/resources/**/*.sql</include>
</includes>
<dbeaver />
</sql>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.example.jooq.r2dbc.config;

import static com.example.jooq.r2dbc.repository.custom.impl.CustomPostRepositoryImpl.retrievePostsWithCommentsAndTags;
import static com.example.jooq.r2dbc.testcontainersflyway.db.Tables.POSTS_TAGS;
import static com.example.jooq.r2dbc.testcontainersflyway.db.tables.PostComments.POST_COMMENTS;
import static com.example.jooq.r2dbc.testcontainersflyway.db.tables.Posts.POSTS;
import static com.example.jooq.r2dbc.testcontainersflyway.db.tables.Tags.TAGS;
import static org.jooq.impl.DSL.multiset;
import static org.jooq.impl.DSL.select;

import com.example.jooq.r2dbc.config.logging.Loggable;
import com.example.jooq.r2dbc.model.response.PostCommentResponse;
import com.example.jooq.r2dbc.model.response.PostResponse;
import com.example.jooq.r2dbc.testcontainersflyway.db.tables.records.PostCommentsRecord;
import com.example.jooq.r2dbc.testcontainersflyway.db.tables.records.PostsRecord;
import com.example.jooq.r2dbc.testcontainersflyway.db.tables.records.PostsTagsRecord;
Expand All @@ -18,7 +15,6 @@
import lombok.extern.slf4j.Slf4j;
import org.jooq.DSLContext;
import org.jooq.DeleteUsingStep;
import org.jooq.Record1;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
Expand All @@ -33,7 +29,7 @@ public class Initializer implements CommandLineRunner {
@Override
@Loggable
public void run(String... args) {
log.info("Running Initializer.....");
log.info("Running Initializer to use JOOQ only.....");
DeleteUsingStep<PostsTagsRecord> postsTagsRecordDeleteUsingStep =
dslContext.deleteFrom(POSTS_TAGS);
DeleteUsingStep<TagsRecord> tagsRecordDeleteUsingStep = dslContext.deleteFrom(TAGS);
Expand Down Expand Up @@ -89,40 +85,9 @@ public void run(String... args) {
"test comments 2")
.returningResult(POST_COMMENTS.ID))
.collectList())
.thenMany(
dslContext
.select(
POSTS.ID,
POSTS.TITLE,
POSTS.CONTENT,
multiset(
select(
POST_COMMENTS.ID,
POST_COMMENTS.CONTENT,
POST_COMMENTS.CREATED_AT)
.from(POST_COMMENTS)
.where(
POST_COMMENTS.POST_ID.eq(
POSTS.ID)))
.as("comments")
.convertFrom(
record3s ->
record3s.into(
PostCommentResponse.class)),
multiset(
select(TAGS.NAME)
.from(TAGS)
.join(POSTS_TAGS)
.on(TAGS.ID.eq(POSTS_TAGS.TAG_ID))
.where(
POSTS_TAGS.POST_ID.eq(
POSTS.ID)))
.as("tags")
.convertFrom(record -> record.map(Record1::value1)))
.from(POSTS)
.orderBy(POSTS.CREATED_AT))
.thenMany(retrievePostsWithCommentsAndTags(dslContext, null))
.subscribe(
data -> log.debug("Retrieved data: {}", data.into(PostResponse.class)),
data -> log.debug("Retrieved data: {}", data),
error -> log.debug("error: ", error),
() -> log.debug("done"));
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,13 @@

import java.time.LocalDateTime;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;

@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(value = "post_comments")
public class Comment {

Expand All @@ -35,4 +25,42 @@ public class Comment {

@Column("post_id")
private UUID postId;

public Comment() {}

public UUID getId() {
return id;
}

public Comment setId(UUID id) {
this.id = id;
return this;
}

public String getContent() {
return content;
}

public Comment setContent(String content) {
this.content = content;
return this;
}

public LocalDateTime getCreatedAt() {
return createdAt;
}

public Comment setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
return this;
}

public UUID getPostId() {
return postId;
}

public Comment setPostId(UUID postId) {
this.postId = postId;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

import java.time.LocalDateTime;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
Expand All @@ -16,12 +11,7 @@
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;

@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(value = "posts")
public class Post {

Expand All @@ -36,7 +26,6 @@ public class Post {
private String content;

@Column("status")
@Builder.Default
private Status status = Status.DRAFT;

@Column("created_at")
Expand All @@ -54,4 +43,78 @@ public class Post {
@Column("version")
@Version
private Short version;

public Post() {}

public UUID getId() {
return id;
}

public Post setId(UUID id) {
this.id = id;
return this;
}

public String getTitle() {
return title;
}

public Post setTitle(String title) {
this.title = title;
return this;
}

public String getContent() {
return content;
}

public Post setContent(String content) {
this.content = content;
return this;
}

public Status getStatus() {
return status;
}

public Post setStatus(Status status) {
this.status = status;
return this;
}

public LocalDateTime getCreatedAt() {
return createdAt;
}

public Post setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
return this;
}

public String getCreatedBy() {
return createdBy;
}

public Post setCreatedBy(String createdBy) {
this.createdBy = createdBy;
return this;
}

public LocalDateTime getUpdatedAt() {
return updatedAt;
}

public Post setUpdatedAt(LocalDateTime updatedAt) {
this.updatedAt = updatedAt;
return this;
}

public Short getVersion() {
return version;
}

public Post setVersion(Short version) {
this.version = version;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ public record PostResponse(
UUID id,
String title,
String content,
String createdBy,
String status,
List<PostCommentResponse> comments,
List<String> tags) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.jooq.r2dbc.repository;

import com.example.jooq.r2dbc.entities.PostTagRelation;
import java.util.UUID;
import org.springframework.data.r2dbc.repository.R2dbcRepository;

public interface PostTagRepository extends R2dbcRepository<PostTagRelation, UUID> {}
Loading
Loading