From f69d91d904078332a29185a2c77a3a2bf64aa1cf Mon Sep 17 00:00:00 2001 From: Liu Rui Date: Wed, 31 Jul 2024 23:10:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20uni=20=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=E5=AE=9E=E7=8E=B0=EF=BC=8C=E7=9B=AE=E5=89=8D?= =?UTF-8?q?=E5=8F=AA=E5=81=9A=E4=BA=86=20create?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http/test.http | 2 +- my-ability-uni/build.gradle | 15 ++++ .../muyun/ability/uni/ICURDUniAbility.java | 4 ++ .../muyun/ability/uni/ICreateAbilityUni.java | 19 +++++ my-ability/build.gradle | 12 ++++ .../ximatai/muyun/ability}/ICURDAbility.java | 2 +- .../muyun/ability}/ICreateAbility.java | 4 +- .../muyun/ability}/IDeleteAbility.java | 4 +- .../muyun/ability}/ISelectAbility.java | 4 +- .../muyun/ability}/IUpdateAbility.java | 4 +- .../src/main/resources/application.properties | 4 ++ .../{core => }/ability/IDatabaseAbility.java | 2 +- .../muyun/ability/IDatabaseUniAbility.java | 9 +++ .../{core => }/ability/IMetadataAbility.java | 2 +- my-database-uni/build.gradle | 6 +- .../muyun/database/uni/UniDataAccess.java | 70 +++++++++++++++++++ my-database/build.gradle | 2 + .../muyun/database/IDatabaseAccess.java | 2 +- .../muyun/database/IDatabaseAccessBase.java | 21 ++++++ .../muyun/database/IDatabaseAccessUni.java | 24 +++++++ my-platform/build.gradle | 3 +- .../platform/controller/ModuleController.java | 18 ++--- settings.gradle | 3 +- 23 files changed, 207 insertions(+), 29 deletions(-) create mode 100644 my-ability-uni/build.gradle create mode 100644 my-ability-uni/src/main/java/net/ximatai/muyun/ability/uni/ICURDUniAbility.java create mode 100644 my-ability-uni/src/main/java/net/ximatai/muyun/ability/uni/ICreateAbilityUni.java create mode 100644 my-ability/build.gradle rename {my-core/src/main/java/net/ximatai/muyun/core/ability/curd => my-ability/src/main/java/net/ximatai/muyun/ability}/ICURDAbility.java (70%) rename {my-core/src/main/java/net/ximatai/muyun/core/ability/curd => my-ability/src/main/java/net/ximatai/muyun/ability}/ICreateAbility.java (65%) rename {my-core/src/main/java/net/ximatai/muyun/core/ability/curd => my-ability/src/main/java/net/ximatai/muyun/ability}/IDeleteAbility.java (80%) rename {my-core/src/main/java/net/ximatai/muyun/core/ability/curd => my-ability/src/main/java/net/ximatai/muyun/ability}/ISelectAbility.java (70%) rename {my-core/src/main/java/net/ximatai/muyun/core/ability/curd => my-ability/src/main/java/net/ximatai/muyun/ability}/IUpdateAbility.java (80%) rename my-core/src/main/java/net/ximatai/muyun/{core => }/ability/IDatabaseAbility.java (76%) create mode 100644 my-core/src/main/java/net/ximatai/muyun/ability/IDatabaseUniAbility.java rename my-core/src/main/java/net/ximatai/muyun/{core => }/ability/IMetadataAbility.java (96%) create mode 100644 my-database-uni/src/main/java/net/ximatai/muyun/database/uni/UniDataAccess.java create mode 100644 my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccessBase.java create mode 100644 my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccessUni.java diff --git a/http/test.http b/http/test.http index 392bda0d..12078325 100644 --- a/http/test.http +++ b/http/test.http @@ -1,4 +1,4 @@ -POST http://localhost:8080/module/create +POST http://localhost:8080/api/module/create Content-Type: application/json { diff --git a/my-ability-uni/build.gradle b/my-ability-uni/build.gradle new file mode 100644 index 00000000..c618c472 --- /dev/null +++ b/my-ability-uni/build.gradle @@ -0,0 +1,15 @@ +plugins { + id 'java' + id 'java-library' + id 'checkstyle' + id 'configure-jandex' +} + + +dependencies { + api enforcedPlatform(libs.quarkus.platform.bom) + + api project(':my-ability') + api project(':my-database-uni') + +} diff --git a/my-ability-uni/src/main/java/net/ximatai/muyun/ability/uni/ICURDUniAbility.java b/my-ability-uni/src/main/java/net/ximatai/muyun/ability/uni/ICURDUniAbility.java new file mode 100644 index 00000000..f2192151 --- /dev/null +++ b/my-ability-uni/src/main/java/net/ximatai/muyun/ability/uni/ICURDUniAbility.java @@ -0,0 +1,4 @@ +package net.ximatai.muyun.ability.uni; + +public interface ICURDUniAbility extends ICreateAbilityUni { +} diff --git a/my-ability-uni/src/main/java/net/ximatai/muyun/ability/uni/ICreateAbilityUni.java b/my-ability-uni/src/main/java/net/ximatai/muyun/ability/uni/ICreateAbilityUni.java new file mode 100644 index 00000000..e5442b04 --- /dev/null +++ b/my-ability-uni/src/main/java/net/ximatai/muyun/ability/uni/ICreateAbilityUni.java @@ -0,0 +1,19 @@ +package net.ximatai.muyun.ability.uni; + +import io.smallrye.mutiny.Uni; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import net.ximatai.muyun.ability.IDatabaseUniAbility; +import net.ximatai.muyun.ability.IMetadataAbility; + +import java.util.Map; + +public interface ICreateAbilityUni extends IDatabaseUniAbility, IMetadataAbility { + + @POST + @Path("/create") + default Uni create(Map body) { + return getDatabase().insert(getInsertSql(body), body); + } + +} diff --git a/my-ability/build.gradle b/my-ability/build.gradle new file mode 100644 index 00000000..ecf67063 --- /dev/null +++ b/my-ability/build.gradle @@ -0,0 +1,12 @@ +plugins { + id 'java' + id 'java-library' + id 'checkstyle' + id 'configure-jandex' +} + + +dependencies { + api enforcedPlatform(libs.quarkus.platform.bom) + api project(':my-core') +} diff --git a/my-core/src/main/java/net/ximatai/muyun/core/ability/curd/ICURDAbility.java b/my-ability/src/main/java/net/ximatai/muyun/ability/ICURDAbility.java similarity index 70% rename from my-core/src/main/java/net/ximatai/muyun/core/ability/curd/ICURDAbility.java rename to my-ability/src/main/java/net/ximatai/muyun/ability/ICURDAbility.java index 8ea9f7c6..433d06c7 100644 --- a/my-core/src/main/java/net/ximatai/muyun/core/ability/curd/ICURDAbility.java +++ b/my-ability/src/main/java/net/ximatai/muyun/ability/ICURDAbility.java @@ -1,4 +1,4 @@ -package net.ximatai.muyun.core.ability.curd; +package net.ximatai.muyun.ability; public interface ICURDAbility extends ICreateAbility, IUpdateAbility, IDeleteAbility, ISelectAbility { } diff --git a/my-core/src/main/java/net/ximatai/muyun/core/ability/curd/ICreateAbility.java b/my-ability/src/main/java/net/ximatai/muyun/ability/ICreateAbility.java similarity index 65% rename from my-core/src/main/java/net/ximatai/muyun/core/ability/curd/ICreateAbility.java rename to my-ability/src/main/java/net/ximatai/muyun/ability/ICreateAbility.java index ef32cf8a..94e4893d 100644 --- a/my-core/src/main/java/net/ximatai/muyun/core/ability/curd/ICreateAbility.java +++ b/my-ability/src/main/java/net/ximatai/muyun/ability/ICreateAbility.java @@ -1,9 +1,7 @@ -package net.ximatai.muyun.core.ability.curd; +package net.ximatai.muyun.ability; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; -import net.ximatai.muyun.core.ability.IDatabaseAbility; -import net.ximatai.muyun.core.ability.IMetadataAbility; import java.util.Map; diff --git a/my-core/src/main/java/net/ximatai/muyun/core/ability/curd/IDeleteAbility.java b/my-ability/src/main/java/net/ximatai/muyun/ability/IDeleteAbility.java similarity index 80% rename from my-core/src/main/java/net/ximatai/muyun/core/ability/curd/IDeleteAbility.java rename to my-ability/src/main/java/net/ximatai/muyun/ability/IDeleteAbility.java index 1cc50fad..d93a63d0 100644 --- a/my-core/src/main/java/net/ximatai/muyun/core/ability/curd/IDeleteAbility.java +++ b/my-ability/src/main/java/net/ximatai/muyun/ability/IDeleteAbility.java @@ -1,11 +1,9 @@ -package net.ximatai.muyun.core.ability.curd; +package net.ximatai.muyun.ability; import jakarta.transaction.Transactional; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; -import net.ximatai.muyun.core.ability.IDatabaseAbility; -import net.ximatai.muyun.core.ability.IMetadataAbility; import net.ximatai.muyun.database.exception.MyDatabaseException; import java.util.Map; diff --git a/my-core/src/main/java/net/ximatai/muyun/core/ability/curd/ISelectAbility.java b/my-ability/src/main/java/net/ximatai/muyun/ability/ISelectAbility.java similarity index 70% rename from my-core/src/main/java/net/ximatai/muyun/core/ability/curd/ISelectAbility.java rename to my-ability/src/main/java/net/ximatai/muyun/ability/ISelectAbility.java index 0c9bcb4c..b797c93e 100644 --- a/my-core/src/main/java/net/ximatai/muyun/core/ability/curd/ISelectAbility.java +++ b/my-ability/src/main/java/net/ximatai/muyun/ability/ISelectAbility.java @@ -1,10 +1,8 @@ -package net.ximatai.muyun.core.ability.curd; +package net.ximatai.muyun.ability; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; -import net.ximatai.muyun.core.ability.IDatabaseAbility; -import net.ximatai.muyun.core.ability.IMetadataAbility; import java.util.Map; diff --git a/my-core/src/main/java/net/ximatai/muyun/core/ability/curd/IUpdateAbility.java b/my-ability/src/main/java/net/ximatai/muyun/ability/IUpdateAbility.java similarity index 80% rename from my-core/src/main/java/net/ximatai/muyun/core/ability/curd/IUpdateAbility.java rename to my-ability/src/main/java/net/ximatai/muyun/ability/IUpdateAbility.java index 8db33958..f531d8d6 100644 --- a/my-core/src/main/java/net/ximatai/muyun/core/ability/curd/IUpdateAbility.java +++ b/my-ability/src/main/java/net/ximatai/muyun/ability/IUpdateAbility.java @@ -1,11 +1,9 @@ -package net.ximatai.muyun.core.ability.curd; +package net.ximatai.muyun.ability; import jakarta.transaction.Transactional; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; -import net.ximatai.muyun.core.ability.IDatabaseAbility; -import net.ximatai.muyun.core.ability.IMetadataAbility; import net.ximatai.muyun.database.exception.MyDatabaseException; import java.util.Map; diff --git a/my-boot/src/main/resources/application.properties b/my-boot/src/main/resources/application.properties index 9770f88a..7254bfa3 100644 --- a/my-boot/src/main/resources/application.properties +++ b/my-boot/src/main/resources/application.properties @@ -8,5 +8,9 @@ quarkus.datasource.username=postgres quarkus.datasource.password=muyun2024 quarkus.datasource.jdbc.url= jdbc:postgresql://localhost:54324/muyun +quarkus.datasource.reactive.url = vertx-reactive:postgresql://localhost:54324/muyun + +quarkus.datasource.jdbc=false + quarkus.hibernate-orm.database.generation=drop-and-create quarkus.hibernate-orm.log.sql=true diff --git a/my-core/src/main/java/net/ximatai/muyun/core/ability/IDatabaseAbility.java b/my-core/src/main/java/net/ximatai/muyun/ability/IDatabaseAbility.java similarity index 76% rename from my-core/src/main/java/net/ximatai/muyun/core/ability/IDatabaseAbility.java rename to my-core/src/main/java/net/ximatai/muyun/ability/IDatabaseAbility.java index 45f1b6a4..e1df4549 100644 --- a/my-core/src/main/java/net/ximatai/muyun/core/ability/IDatabaseAbility.java +++ b/my-core/src/main/java/net/ximatai/muyun/ability/IDatabaseAbility.java @@ -1,4 +1,4 @@ -package net.ximatai.muyun.core.ability; +package net.ximatai.muyun.ability; import net.ximatai.muyun.database.IDatabaseAccess; diff --git a/my-core/src/main/java/net/ximatai/muyun/ability/IDatabaseUniAbility.java b/my-core/src/main/java/net/ximatai/muyun/ability/IDatabaseUniAbility.java new file mode 100644 index 00000000..4da4324f --- /dev/null +++ b/my-core/src/main/java/net/ximatai/muyun/ability/IDatabaseUniAbility.java @@ -0,0 +1,9 @@ +package net.ximatai.muyun.ability; + +import net.ximatai.muyun.database.IDatabaseAccessUni; + +public interface IDatabaseUniAbility { + + IDatabaseAccessUni getDatabase(); + +} diff --git a/my-core/src/main/java/net/ximatai/muyun/core/ability/IMetadataAbility.java b/my-core/src/main/java/net/ximatai/muyun/ability/IMetadataAbility.java similarity index 96% rename from my-core/src/main/java/net/ximatai/muyun/core/ability/IMetadataAbility.java rename to my-core/src/main/java/net/ximatai/muyun/ability/IMetadataAbility.java index 29c3ae4a..b5f709f5 100644 --- a/my-core/src/main/java/net/ximatai/muyun/core/ability/IMetadataAbility.java +++ b/my-core/src/main/java/net/ximatai/muyun/ability/IMetadataAbility.java @@ -1,4 +1,4 @@ -package net.ximatai.muyun.core.ability; +package net.ximatai.muyun.ability; import java.util.Map; import java.util.StringJoiner; diff --git a/my-database-uni/build.gradle b/my-database-uni/build.gradle index 639aef19..fbc80ac9 100644 --- a/my-database-uni/build.gradle +++ b/my-database-uni/build.gradle @@ -1,11 +1,15 @@ plugins { id 'java' + id 'java-library' id 'checkstyle' id 'configure-jandex' } dependencies { + api enforcedPlatform(libs.quarkus.platform.bom) implementation project(':my-database') -// implementation project(':my-core-uni') + + api "io.quarkus:quarkus-hibernate-reactive-panache" + api "io.quarkus:quarkus-reactive-pg-client" } diff --git a/my-database-uni/src/main/java/net/ximatai/muyun/database/uni/UniDataAccess.java b/my-database-uni/src/main/java/net/ximatai/muyun/database/uni/UniDataAccess.java new file mode 100644 index 00000000..ea56659d --- /dev/null +++ b/my-database-uni/src/main/java/net/ximatai/muyun/database/uni/UniDataAccess.java @@ -0,0 +1,70 @@ +package net.ximatai.muyun.database.uni; + +import io.smallrye.mutiny.Uni; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.persistence.NoResultException; +import jakarta.persistence.Tuple; +import net.ximatai.muyun.database.IDatabaseAccessUni; +import net.ximatai.muyun.database.tool.TupleTool; +import org.hibernate.reactive.mutiny.Mutiny; + +import java.util.List; +import java.util.Map; + +@ApplicationScoped +public class UniDataAccess implements IDatabaseAccessUni { + + @Inject + Mutiny.SessionFactory sessionFactory; + + @Override + public Uni insert(String sql, Map params) { + return this.row(sql, params).map(row -> row.get("id").toString()); + } + + @Override + public Uni> row(String sql, Map params) { + return sessionFactory.withSession(session -> { + + Mutiny.SelectionQuery query = session.createNativeQuery(sql, Tuple.class); + + if (params != null) { + params.forEach(query::setParameter); + } + + return query + .getSingleResult() + .map(TupleTool::toMap) + .onFailure(NoResultException.class) + .recoverWithItem(() -> null); + }); + } + + @Override + public Uni> row(String sql) { + return null; + } + + @Override + public Uni>> query(String sql, Map params) { + return null; + } + + @Override + public Uni>> query(String sql) { + return null; + } + + @Override + public Uni update(String sql, Map params) { + return null; + } + + @Override + public Uni delete(String sql, Map params) { + return null; + } + + +} diff --git a/my-database/build.gradle b/my-database/build.gradle index 8c5edafe..7a0cae34 100644 --- a/my-database/build.gradle +++ b/my-database/build.gradle @@ -12,5 +12,7 @@ dependencies { api 'io.quarkus:quarkus-arc' api "io.quarkus:quarkus-hibernate-orm" + + compileOnlyApi "io.quarkus:quarkus-hibernate-reactive-panache" } diff --git a/my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccess.java b/my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccess.java index 9299df5f..5873337b 100644 --- a/my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccess.java +++ b/my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccess.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.Map; -public interface IDatabaseAccess { +public interface IDatabaseAccess extends IDatabaseAccessBase { String insert(String sql, Map params); diff --git a/my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccessBase.java b/my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccessBase.java new file mode 100644 index 00000000..9a638045 --- /dev/null +++ b/my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccessBase.java @@ -0,0 +1,21 @@ +package net.ximatai.muyun.database; + +import java.util.Map; + +public interface IDatabaseAccessBase { + + Object insert(String sql, Map params); + + Object row(String sql, Map params); + + Object row(String sql); + + Object query(String sql, Map params); + + Object query(String sql); + + Object update(String sql, Map params); + + Object delete(String sql, Map params); + +} diff --git a/my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccessUni.java b/my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccessUni.java new file mode 100644 index 00000000..61155c5e --- /dev/null +++ b/my-database/src/main/java/net/ximatai/muyun/database/IDatabaseAccessUni.java @@ -0,0 +1,24 @@ +package net.ximatai.muyun.database; + +import io.smallrye.mutiny.Uni; + +import java.util.List; +import java.util.Map; + +public interface IDatabaseAccessUni { + + Uni insert(String sql, Map params); + + Uni> row(String sql, Map params); + + Uni> row(String sql); + + Uni>> query(String sql, Map params); + + Uni>> query(String sql); + + Uni update(String sql, Map params); + + Uni delete(String sql, Map params); + +} diff --git a/my-platform/build.gradle b/my-platform/build.gradle index 4fbfdb1a..124da8d5 100644 --- a/my-platform/build.gradle +++ b/my-platform/build.gradle @@ -7,6 +7,7 @@ plugins { dependencies { implementation project(':my-core') - implementation project(':my-database-standard') + implementation project(':my-ability-uni') + implementation project(':my-database-uni') // implementation project(':my-core-uni') } diff --git a/my-platform/src/main/java/net/ximatai/muyun/platform/controller/ModuleController.java b/my-platform/src/main/java/net/ximatai/muyun/platform/controller/ModuleController.java index 3f7fabe2..0a01790e 100644 --- a/my-platform/src/main/java/net/ximatai/muyun/platform/controller/ModuleController.java +++ b/my-platform/src/main/java/net/ximatai/muyun/platform/controller/ModuleController.java @@ -2,23 +2,23 @@ import jakarta.inject.Inject; import jakarta.ws.rs.Path; -import net.ximatai.muyun.core.ability.curd.ICURDAbility; -import net.ximatai.muyun.database.IDatabaseAccess; -import net.ximatai.muyun.database.standard.DataAccess; +import net.ximatai.muyun.ability.uni.ICURDUniAbility; +import net.ximatai.muyun.database.IDatabaseAccessUni; @Path("/module") -public class ModuleController implements ICURDAbility { +public class ModuleController implements ICURDUniAbility { @Inject - DataAccess dataAccess; + IDatabaseAccessUni databaseAccess; - @Override - public IDatabaseAccess getDatabase() { - return dataAccess; - } @Override public String getMainTable() { return "app_module"; } + + @Override + public IDatabaseAccessUni getDatabase() { + return databaseAccess; + } } diff --git a/settings.gradle b/settings.gradle index 1b146944..bff07640 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,7 +8,8 @@ assert JavaVersion.current() >= JavaVersion.VERSION_21: "You must use at least Java 21 to build the project, you're currently using ${System.getProperty("java.version")}" include 'my-core' -//include 'my-core-uni' +include 'my-ability' +include 'my-ability-uni' include 'my-platform' include 'my-database' include 'my-database-standard'