Skip to content

Commit

Permalink
✨ feat(boot/platform/build.gradle, `boot/platform/src/main/java/com…
Browse files Browse the repository at this point in the history
…/plate/boot/*`): Add JOOQ support and integrate with R2DBC for database operations.
  • Loading branch information
vnobo committed Dec 20, 2024
1 parent 1c7e11b commit aeb9399
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions boot/platform/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.springframework.boot:spring-boot-starter-data-redis-reactive")

//implementation("org.springframework.boot:spring-boot-starter-jooq")
implementation("org.jooq:jooq")
implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
implementation("org.postgresql:r2dbc-postgresql")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.plate.boot.security.SecurityDetails;
import com.plate.boot.security.core.user.UsersService;
import lombok.extern.log4j.Log4j2;
import org.jooq.DSLContext;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
Expand Down Expand Up @@ -34,6 +35,7 @@
@Component
public final class ContextUtils implements InitializingBean {


/**
* Constant defining the role identifier for administrators within the system.
* This role grants access to administrative functionalities and permissions.
Expand Down Expand Up @@ -105,15 +107,18 @@ public final class ContextUtils implements InitializingBean {
*/
public static UsersService USERS_SERVICE;

public static DSLContext JOOQDSL;

/**
* Initializes the ContextUtils class with necessary dependencies.
*
* @param objectMapper The ObjectMapper instance used for JSON serialization and deserialization.
* @param usersService The UsersService instance to provide access to user-related operations.
*/
ContextUtils(ObjectMapper objectMapper, UsersService usersService) {
ContextUtils(ObjectMapper objectMapper, UsersService usersService, DSLContext create) {
ContextUtils.OBJECT_MAPPER = objectMapper;
ContextUtils.USERS_SERVICE = usersService;
ContextUtils.JOOQDSL = create;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import lombok.RequiredArgsConstructor;
import org.jooq.DSLContext;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.ReactiveAuditorAware;
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
import org.springframework.data.r2dbc.config.EnableR2dbcAuditing;
import org.springframework.lang.NonNull;
import org.springframework.r2dbc.connection.TransactionAwareConnectionFactoryProxy;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.List;
Expand Down Expand Up @@ -71,4 +75,11 @@ public ReactiveAuditorAware<UserAuditor> userAuditorProvider() {
return new UserAuditorAware();
}

@Bean
public DSLContext dslContext(ConnectionFactory connectionFactory) {
return DSL.using(
new TransactionAwareConnectionFactoryProxy(connectionFactory),
SQLDialect.POSTGRES
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package com.plate.boot.commons.utils.query;

import org.junit.jupiter.api.Test;

class QueryHelperTest {

@Test
void jooqTest() {
}
}

0 comments on commit aeb9399

Please sign in to comment.