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

🔧 chore(build.gradle, gradle.properties, `.github/workflows/gradl… #43

Merged
merged 3 commits into from
Dec 20, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env:
GITHUB_REGISTRY: ghcr.io/${{ github.actor }}
DOCKER_REGISTRY: docker.io/alexbob
tags: |
type=semver,pattern={{version}},value=v0.0.3
type=semver,pattern={{version}},value=v0.0.4
type=semver,pattern={{major}}.{{minor}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=ref,event=tag
Expand Down
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 @@ -63,7 +63,7 @@ public class QueryFragment extends HashMap<String, Object> {
* }
* </pre>
*/
private final StringJoiner querySql = new StringJoiner(" ");
private final StringJoiner select = new StringJoiner(" ");

/**
* A StringJoiner to accumulate WHERE conditions.
Expand All @@ -74,7 +74,7 @@ public class QueryFragment extends HashMap<String, Object> {
* }
* </pre>
*/
private final StringJoiner whereSql = new StringJoiner(" AND ");
private final StringJoiner where = new StringJoiner(" AND ");

/**
* A StringJoiner to accumulate ORDER BY clauses.
Expand All @@ -85,7 +85,9 @@ public class QueryFragment extends HashMap<String, Object> {
* }
* </pre>
*/
private final StringJoiner orderSql = new StringJoiner(",");
private final StringJoiner orderBy = new StringJoiner(",");

private final StringJoiner groupBy = new StringJoiner(",");

/**
* The maximum number of rows to return (LIMIT clause).
Expand All @@ -101,7 +103,7 @@ public QueryFragment(int size, long offset, QueryFragment params) {
super(16);
this.size = size;
this.offset = offset;
this.mergeWhere(params.getWhereSql());
this.mergeWhere(params.getWhere());
this.putAll(params);
}

Expand Down Expand Up @@ -140,15 +142,15 @@ public QueryFragment addColumn(CharSequence... columns) {
}

public QueryFragment addQuery(CharSequence... queries) {
this.querySql.setEmptyValue("");
this.select.setEmptyValue("");
for (CharSequence query : queries) {
this.querySql.add(query);
this.select.add(query);
}
return this;
}

public QueryFragment addWhere(CharSequence where) {
whereSql.add(where);
this.where.add(where);
return this;
}

Expand All @@ -159,7 +161,7 @@ public QueryFragment addWhere(CharSequence where) {
* @return this
*/
public QueryFragment addOrder(CharSequence order) {
orderSql.add(order);
this.orderBy.add(order);
return this;
}

Expand All @@ -170,7 +172,7 @@ public QueryFragment addOrder(CharSequence order) {
* @return this
*/
public QueryFragment mergeWhere(StringJoiner where) {
whereSql.merge(where);
this.where.merge(where);
return this;
}

Expand All @@ -181,7 +183,7 @@ public QueryFragment mergeWhere(StringJoiner where) {
* @return this
*/
public QueryFragment mergeOrder(StringJoiner order) {
orderSql.merge(order);
this.orderBy.merge(order);
return this;
}

Expand All @@ -193,15 +195,15 @@ public QueryFragment mergeOrder(StringJoiner order) {
* @return A String forming the WHERE clause of the SQL query, or an empty string if no conditions are present.
*/
public String whereSql() {
if (this.whereSql.length() > 0) {
return " WHERE " + this.whereSql;
if (this.where.length() > 0) {
return " WHERE " + this.where;
}
return "";
}

public String orderSql() {
if (this.orderSql.length() > 0) {
return " ORDER BY " + this.orderSql;
if (this.orderBy.length() > 0) {
return " ORDER BY " + this.orderBy;
}
return "";
}
Expand All @@ -218,9 +220,9 @@ public String orderSql() {
* @throws QueryException if the querySql is null, indicating that the query structure is incomplete.
*/
public String querySql() {
if (this.querySql.length() > 0) {
if (this.select.length() > 0) {
return String.format("SELECT %s FROM %s %s %s LIMIT %d OFFSET %d",
this.columns, this.querySql, whereSql(), orderSql(), this.size, this.offset);
this.columns, this.select, whereSql(), orderSql(), this.size, this.offset);
}
throw QueryException.withError("This querySql is null, please use whereSql() method!",
new IllegalArgumentException("This querySql is null, please use whereSql() method"));
Expand All @@ -238,8 +240,8 @@ public String querySql() {
* @throws QueryException if the countSql is null, indicating that the query structure is incomplete.
*/
public String countSql() {
if (this.querySql.length() > 0) {
return "SELECT COUNT(*) FROM (" + String.format("SELECT %s FROM %s", this.columns, this.querySql)
if (this.select.length() > 0) {
return "SELECT COUNT(*) FROM (" + String.format("SELECT %s FROM %s", this.columns, this.select)
+ whereSql() + ") t";
}
throw QueryException.withError("This countSql is null, please use whereSql() method!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private static void processQueryKey(QueryFragment queryFragment, Map<String, Obj
if (objectMap.containsKey("query")) {
var jsonMap = (Map<String, Object>) objectMap.get("query");
var jsonQueryFragment = QueryJsonHelper.queryJson(jsonMap, prefix);
queryFragment.mergeWhere(jsonQueryFragment.getWhereSql());
queryFragment.mergeWhere(jsonQueryFragment.getWhere());
queryFragment.putAll(jsonQueryFragment);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static QueryFragment queryJson(Map<String, Object> params, String prefix)
QueryFragment queryFragment = QueryFragment.withNew();
for (Map.Entry<String, Object> entry : params.entrySet()) {
var condition = buildJsonCondition(entry, prefix);
queryFragment.mergeWhere(condition.getWhereSql());
queryFragment.mergeWhere(condition.getWhere());
queryFragment.putAll(condition);
}
return queryFragment;
Expand Down Expand Up @@ -231,7 +231,7 @@ private static QueryFragment buildJsonCondition(Map.Entry<String, Object> entry,
}
//处理最后键
QueryFragment lastCondition = buildLastCondition(keys, entry.getValue());
conditionBuilder.append(lastCondition.getWhereSql());
conditionBuilder.append(lastCondition.getWhere());
return QueryFragment.withMap(lastCondition).addWhere(conditionBuilder.toString());
}

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() {
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.springframework.boot' version '3.4.0' apply false
id 'org.springframework.boot' version '3.4.1' apply false
id 'io.spring.dependency-management' version '1.1.6'
id 'org.graalvm.buildtools.native' version '0.10.3'
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.0.3
version=0.0.4
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.daemon=true
Expand Down
Loading