From 6b607514b6ac94c99242c98903841124679014ea Mon Sep 17 00:00:00 2001 From: "j.x" Date: Fri, 26 Jul 2024 13:24:46 +0800 Subject: [PATCH] feat: improvement Tree Traversal and add Before-Post-Compensate Operator model --- .../tree/BreadthTraversalMode.java | 6 +- .../datastructure/tree/DeepTraversalMode.java | 6 +- .../uno/core/datastructure/tree/Element.java | 12 +- .../datastructure/tree/NoneTraversalMode.java | 10 +- .../core/datastructure/tree/Traversal.java | 12 +- .../datastructure/tree/TraversalElement.java | 4 +- ...raversalMode.java => TraversalMethod.java} | 20 +- .../cc/allio/uno/data/orm/dsl/Operator.java | 79 +++++++- .../allio/uno/data/orm/dsl/OperatorKey.java | 2 + .../data/orm/dsl/UnrecognizedOperator.java | 11 ++ .../data/orm/dsl/ddl/AlterTableOperator.java | 4 +- .../data/orm/dsl/ddl/CreateTableOperator.java | 4 +- .../data/orm/dsl/ddl/DropTableOperator.java | 4 +- .../data/orm/dsl/ddl/ExistTableOperator.java | 4 +- .../data/orm/dsl/ddl/ShowColumnsOperator.java | 4 +- .../data/orm/dsl/ddl/ShowTablesOperator.java | 4 +- .../uno/data/orm/dsl/dml/DeleteOperator.java | 4 +- .../uno/data/orm/dsl/dml/InsertOperator.java | 4 +- .../uno/data/orm/dsl/dml/QueryOperator.java | 6 +- .../uno/data/orm/dsl/dml/UpdateOperator.java | 4 +- .../MetaAcceptorAlterTableOperator.java | 16 ++ .../MetaAcceptorCreateTableOperator.java | 16 ++ .../MetaAcceptorDropTableOperator.java | 16 ++ .../MetaAcceptorExistTableOperator.java | 15 ++ .../MetaAcceptorInsertOperator.java | 15 ++ .../MetaAcceptorQueryOperator.java | 15 ++ .../MetaAcceptorSetOperatorGroup.java | 9 +- .../MetaAcceptorShowColumnsOperator.java | 15 ++ .../MetaAcceptorShowTablesOperator.java | 15 ++ .../MetaAcceptorUpdateOperator.java | 15 ++ .../{OperatorGroup.java => Operators.java} | 36 +++- .../uno/data/orm/dsl/type/TypeRegistry.java | 6 +- .../orm/executor/AbstractCommandExecutor.java | 180 +++++++++++++++--- .../data/orm/executor/CommandExecutor.java | 8 +- .../uno/data/orm/executor/CommandType.java | 7 +- .../internal/InnerCommandExecutorManager.java | 13 ++ .../internal/UnknownInnerCommandExecutor.java | 19 ++ .../orm/executor/options/ExecutorKey.java | 1 + .../orm/executor/options/ExecutorOptions.java | 16 ++ .../allio/uno/data/query/BaseQueryFilter.java | 6 +- .../dsl/operatorgroup/OperatorGroupTest.java | 4 +- .../orm/executor/db/DbCommandExecutor.java | 12 +- .../elasticsearch/EsCommandExecutor.java | 8 +- .../dml/InfluxdbSQLWhereOperatorImpl.java | 4 +- .../influxdb/InfluxdbCommandExecutor.java | 8 +- .../mongodb/MongodbCommandExecutor.java | 8 +- .../ddl/MongoAlterCollectionOperatorTest.java | 4 +- .../MongodbCreateCollectionOperatorTest.java | 4 +- .../MongodbDropCollectionOperatorTest.java | 4 +- .../MongodbExistCollectionOperatorTest.java | 4 +- .../MongodbShowCollectionsOperatorTest.java | 4 +- .../dml/MongodbDeleteOperatorTest.java | 10 +- .../dml/MongodbInsertOperatorTest.java | 8 +- .../orm/dsl/sql/SQLUnrecognizedOperator.java | 48 +++++ .../data/orm/dsl/sql/ddl/DDLSQLSupport.java | 43 ++++- .../dsl/sql/ddl/SQLAlterTableOperator.java | 30 ++- .../dsl/sql/ddl/SQLCreateTableOperator.java | 33 ++++ .../dsl/sql/ddl/SQLExistTableOperator.java | 4 +- .../dsl/sql/ddl/SQLShowColumnsOperator.java | 4 +- .../dsl/sql/ddl/SQLShowTablesOperator.java | 4 +- .../orm/dsl/type/DruidDataTypeAdapter.java | 14 +- .../orm/dsl/ddl/sql/DDLSQLSupportTest.java | 34 ++++ .../ddl/sql/SQLAlterTableOperatorTest.java | 10 +- .../dsl/ddl/sql/SQLCreateOperatorTest.java | 10 +- .../ddl/sql/SQLShowColumnsOperatorTest.java | 4 +- .../ddl/sql/SQLShowTablesOperatorTest.java | 12 +- .../dsl/dml/sql/SQLDeleteOperatorTest.java | 11 +- .../dsl/dml/sql/SQLInsertOperatorTest.java | 23 ++- .../orm/dsl/dml/sql/SQLQueryOperatorTest.java | 55 +++--- .../dsl/dml/sql/SQLUpdateOperatorTest.java | 25 ++- .../test/executor/FakeCommandExecutor.java | 4 +- 71 files changed, 862 insertions(+), 231 deletions(-) rename uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/{TraversalMode.java => TraversalMethod.java} (60%) create mode 100644 uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/UnrecognizedOperator.java rename uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/{OperatorGroup.java => Operators.java} (93%) create mode 100644 uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/internal/UnknownInnerCommandExecutor.java create mode 100644 uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/SQLUnrecognizedOperator.java create mode 100644 uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/DDLSQLSupportTest.java diff --git a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/BreadthTraversalMode.java b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/BreadthTraversalMode.java index 0f28ae2b..24bd0d0b 100644 --- a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/BreadthTraversalMode.java +++ b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/BreadthTraversalMode.java @@ -12,7 +12,7 @@ * @date 2023/4/27 09:17 * @since 1.1.4 */ -public class BreadthTraversalMode implements TraversalMode { +public class BreadthTraversalMode implements TraversalMethod { @Override public > void doTraversal(T e, Visitor visitor) { @@ -28,7 +28,7 @@ public > void doTraversal(T e, Visitor visitor) } @Override - public Traversal getMode() { - return Traversal.BREADTH; + public String getMode() { + return Traversal.BREADTH.getValue(); } } diff --git a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/DeepTraversalMode.java b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/DeepTraversalMode.java index ddf950b8..ebb2a791 100644 --- a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/DeepTraversalMode.java +++ b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/DeepTraversalMode.java @@ -13,7 +13,7 @@ * @date 2023/4/27 09:16 * @since 1.1.4 */ -public class DeepTraversalMode implements TraversalMode { +public class DeepTraversalMode implements TraversalMethod { @Override public > void doTraversal(T e, Visitor visitor) { @@ -36,7 +36,7 @@ private > void deepAccept(List childrens, Deque } @Override - public Traversal getMode() { - return Traversal.DEEP; + public String getMode() { + return Traversal.DEEP.getValue(); } } diff --git a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/Element.java b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/Element.java index a491a00a..1e161eea 100644 --- a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/Element.java +++ b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/Element.java @@ -152,7 +152,17 @@ default void accept(Visitor visitor) { * @param visitor visitor * @param traversal 遍历原则 */ - void accept(Visitor visitor, Traversal traversal); + default void accept(Visitor visitor, Traversal traversal) { + accept(visitor, TraversalMethod.get(traversal)); + } + + /** + * 树的访问 + * + * @param visitor visitor + * @param method traversal method + */ + void accept(Visitor visitor, TraversalMethod method); /** * 获取Sentinel结点 diff --git a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/NoneTraversalMode.java b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/NoneTraversalMode.java index 51a7e58a..158d54e3 100644 --- a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/NoneTraversalMode.java +++ b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/NoneTraversalMode.java @@ -7,18 +7,16 @@ * @date 2023/4/27 09:13 * @since 1.1.4 */ -public class NoneTraversalMode implements TraversalMode { - - NoneTraversalMode() {} +public class NoneTraversalMode implements TraversalMethod { @Override public > void doTraversal(T e, Visitor visitor) { e.doAccept(visitor); - e.getChildren().forEach(c -> c.accept(visitor, getMode())); + e.getChildren().forEach(c -> c.accept(visitor, Traversal.NONE)); } @Override - public Traversal getMode() { - return Traversal.NONE; + public String getMode() { + return Traversal.NONE.getValue(); } } diff --git a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/Traversal.java b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/Traversal.java index a6cec248..ba1bc7ca 100644 --- a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/Traversal.java +++ b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/Traversal.java @@ -1,5 +1,8 @@ package cc.allio.uno.core.datastructure.tree; +import lombok.AllArgsConstructor; +import lombok.Getter; + /** * 规则树遍历方式 *
    @@ -8,6 +11,13 @@ *
  • {@link #BREADTH}:广度优先
  • *
*/ +@AllArgsConstructor +@Getter public enum Traversal { - NONE, DEEP, BREADTH; + + NONE("NONE"), + DEEP("NONE"), + BREADTH("NONE"); + + private final String value; } diff --git a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TraversalElement.java b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TraversalElement.java index 3bfd5423..850afcdb 100644 --- a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TraversalElement.java +++ b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TraversalElement.java @@ -10,8 +10,8 @@ public abstract class TraversalElement> implements Element { @Override - public void accept(Visitor visitor, Traversal traversal) { - TraversalMode.get(traversal).doTraversal((T) this, visitor); + public void accept(Visitor visitor, TraversalMethod method) { + method.doTraversal((T) this, visitor); } /** diff --git a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TraversalMode.java b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TraversalMethod.java similarity index 60% rename from uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TraversalMode.java rename to uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TraversalMethod.java index 5ab0e3c0..e050e7da 100644 --- a/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TraversalMode.java +++ b/uno-core/src/main/java/cc/allio/uno/core/datastructure/tree/TraversalMethod.java @@ -9,10 +9,10 @@ * @date 2023/4/27 09:12 * @since 1.1.4 */ -public interface TraversalMode { - TraversalMode NONE = new NoneTraversalMode(); - TraversalMode DEEP = new DeepTraversalMode(); - TraversalMode BREADTH = new BreadthTraversalMode(); +public interface TraversalMethod { + TraversalMethod NONE = new NoneTraversalMode(); + TraversalMethod DEEP = new DeepTraversalMode(); + TraversalMethod BREADTH = new BreadthTraversalMode(); /** * 根据遍历的方式获取对应的遍历实例 @@ -20,12 +20,12 @@ public interface TraversalMode { * @param traversal traversal * @return TraversalMode实例 */ - static TraversalMode get(Traversal traversal) { - if (NONE.getMode() == traversal) { + static TraversalMethod get(Traversal traversal) { + if (NONE.getMode().equals(traversal.getValue())) { return NONE; - } else if (DEEP.getMode() == traversal) { + } else if (DEEP.getMode().equals(traversal.getValue())) { return DEEP; - } else if (BREADTH.getMode() == traversal) { + } else if (BREADTH.getMode().equals(traversal.getValue())) { return BREADTH; } throw Exceptions.eee("unknown traversal", NullPointerException.class); @@ -44,5 +44,7 @@ static TraversalMode get(Traversal traversal) { * * @return Traversal */ - Traversal getMode(); + default String getMode() { + return "custom"; + } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/Operator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/Operator.java index a1bf1c6e..8c0a3bc2 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/Operator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/Operator.java @@ -2,20 +2,58 @@ import cc.allio.uno.core.api.Self; import cc.allio.uno.core.bean.ValueWrapper; +import cc.allio.uno.data.orm.dsl.ddl.*; +import cc.allio.uno.data.orm.dsl.dml.DeleteOperator; +import cc.allio.uno.data.orm.dsl.dml.InsertOperator; +import cc.allio.uno.data.orm.dsl.dml.QueryOperator; +import cc.allio.uno.data.orm.dsl.dml.UpdateOperator; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.opeartorgroup.WrapperOperator; import cc.allio.uno.data.orm.dsl.type.DBType; import java.lang.annotation.*; +import java.util.Collections; +import java.util.List; import java.util.Objects; import java.util.function.Supplier; import java.util.function.UnaryOperator; /** - * DSL操作 + * DSL Operator + * + *

+ * DSL means Domain Specific Language. description Data Operation. + *

+ * + *

+ * it fulfil before-current-catch-post model. + *

    + *
  1. the before {@link #getBeforeOperatorList()}
  2. + *
  3. the current
  4. + *
  5. the error compensate operator {@link #getCompensateOperatorList()}
  6. + *
  7. the success post operator {@link #getPostOperatorList()}
  8. + *
+ *

+ *

+ * through + *

* * @author j.x * @date 2023/4/12 19:44 * @since 1.1.4 + * @modify 1.1.9 + * @see DeleteOperator + * @see InsertOperator + * @see QueryOperator + * @see UpdateOperator + * @see AlterTableOperator + * @see CreateTableOperator + * @see DropTableOperator + * @see ExistTableOperator + * @see ShowColumnsOperator + * @see ShowTablesOperator + * @see UnrecognizedOperator + * @see Operators */ public interface Operator> extends Self { @@ -138,6 +176,45 @@ static Class> getHierarchicalType(Class> getBeforeOperatorList() { + return Collections.emptyList(); + } + + /** + * get current {@link Operator} after execute {@link Operator} list + * + * @return the post {@link Operator} list + */ + default List> getPostOperatorList() { + return Collections.emptyList(); + } + + /** + * when failure to execute current {@link Operator}, then in capture error execute compensate {@link Operator} list + * + * @return the compensation {@link Operator} list + */ + default List> getCompensateOperatorList() { + return Collections.emptyList(); + } + + /** + * from 'dsl' build new {@link Operator} + * + * @param dsl the dsl + * @return the {@link Operator} instance + */ + static Operator from(String dsl) { + return Operators.getUnrecognizedOperator().customize(dsl); + } + /** * Operator 分组注解 */ diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/OperatorKey.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/OperatorKey.java index 2c55bd89..419de106 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/OperatorKey.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/OperatorKey.java @@ -3,6 +3,7 @@ import cc.allio.uno.core.api.Key; import cc.allio.uno.core.env.Envs; import cc.allio.uno.core.util.StringUtils; +import cc.allio.uno.data.orm.executor.options.ExecutorOptions; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -34,6 +35,7 @@ public interface OperatorKey extends Key { * 获取系统配置下的operator key * * @return operator key or default DRUID_OPERATOR_KEY + * @see ExecutorOptions#setSystemDefault(boolean) */ static OperatorKey getSystemOperatorKey() { String operatorKey = Envs.getProperty(OPERATOR_METADATA_KEY); diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/UnrecognizedOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/UnrecognizedOperator.java new file mode 100644 index 00000000..cae37850 --- /dev/null +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/UnrecognizedOperator.java @@ -0,0 +1,11 @@ +package cc.allio.uno.data.orm.dsl; + +/** + * not belong to 'ddl' and 'dml' + * + * @author j.x + * @date 2024/7/25 18:33 + * @since 1.1.9 + */ +public interface UnrecognizedOperator> extends Operator { +} diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/AlterTableOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/AlterTableOperator.java index 1a3f5245..527c1dfd 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/AlterTableOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/AlterTableOperator.java @@ -3,7 +3,7 @@ import cc.allio.uno.core.api.Self; import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.helper.PojoWrapper; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import java.util.Arrays; import java.util.Collection; @@ -14,7 +14,7 @@ * * @author j.x * @date 2023/6/8 19:21 - * @see OperatorGroup + * @see Operators * @since 1.1.4 */ public interface AlterTableOperator> extends Operator, Self, TableOperator { diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/CreateTableOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/CreateTableOperator.java index 4c36a77b..05716062 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/CreateTableOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/CreateTableOperator.java @@ -1,7 +1,7 @@ package cc.allio.uno.data.orm.dsl.ddl; import cc.allio.uno.core.util.CollectionUtils; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.helper.PojoWrapper; import cc.allio.uno.data.orm.dsl.ColumnDef; import cc.allio.uno.data.orm.dsl.Operator; @@ -15,7 +15,7 @@ * * @author j.x * @date 2023/4/12 19:42 - * @see OperatorGroup + * @see Operators * @since 1.1.4 */ public interface CreateTableOperator> extends Operator, TableOperator { diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/DropTableOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/DropTableOperator.java index 6e039d85..8d713c34 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/DropTableOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/DropTableOperator.java @@ -1,7 +1,7 @@ package cc.allio.uno.data.orm.dsl.ddl; import cc.allio.uno.data.orm.dsl.Operator; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.TableOperator; /** @@ -9,7 +9,7 @@ * * @author j.x * @date 2023/4/16 12:52 - * @see OperatorGroup + * @see Operators * @since 1.1.4 */ public interface DropTableOperator> extends Operator, TableOperator { diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ExistTableOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ExistTableOperator.java index e9b0b43e..a9f0ea3a 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ExistTableOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ExistTableOperator.java @@ -1,6 +1,6 @@ package cc.allio.uno.data.orm.dsl.ddl; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.PrepareOperator; import cc.allio.uno.data.orm.dsl.TableOperator; @@ -10,7 +10,7 @@ * @author j.x * @date 2023/4/17 09:46 * @since 1.1.4 - * @see OperatorGroup + * @see Operators */ public interface ExistTableOperator> extends PrepareOperator, TableOperator { } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ShowColumnsOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ShowColumnsOperator.java index 85cb3d8b..c44f2bc6 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ShowColumnsOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ShowColumnsOperator.java @@ -1,7 +1,7 @@ package cc.allio.uno.data.orm.dsl.ddl; import cc.allio.uno.data.orm.dsl.DataBaseOperator; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.dml.QueryOperator; import cc.allio.uno.data.orm.dsl.PrepareOperator; import cc.allio.uno.data.orm.dsl.TableOperator; @@ -11,7 +11,7 @@ * * @author j.x * @date 2023/6/8 19:19 - * @see OperatorGroup + * @see Operators * @since 1.1.4 */ public interface ShowColumnsOperator> extends PrepareOperator, TableOperator, DataBaseOperator { diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ShowTablesOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ShowTablesOperator.java index 1f10a03e..4cf6f744 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ShowTablesOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/ddl/ShowTablesOperator.java @@ -2,14 +2,14 @@ import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.dml.QueryOperator; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; /** * Show Tables Operator * * @author j.x * @date 2024/1/4 16:56 - * @see OperatorGroup + * @see Operators * @since 1.1.7 */ public interface ShowTablesOperator> extends TableOperator, PrepareOperator, DataBaseOperator { diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/DeleteOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/DeleteOperator.java index 8cf60ac0..9d994217 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/DeleteOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/DeleteOperator.java @@ -1,6 +1,6 @@ package cc.allio.uno.data.orm.dsl.dml; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.PrepareOperator; import cc.allio.uno.data.orm.dsl.TableOperator; import cc.allio.uno.data.orm.dsl.WhereOperator; @@ -10,7 +10,7 @@ * * @author j.x * @date 2023/4/16 18:42 - * @see OperatorGroup + * @see Operators * @since 1.1.4 */ public interface DeleteOperator> extends PrepareOperator, TableOperator, WhereOperator { diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/InsertOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/InsertOperator.java index fe58e0e0..4b638143 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/InsertOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/InsertOperator.java @@ -4,7 +4,7 @@ import cc.allio.uno.core.util.id.IdGenerator; import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.helper.PojoWrapper; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import reactor.util.function.Tuple2; @@ -19,7 +19,7 @@ * * @author j.x * @date 2023/4/13 15:25 - * @see OperatorGroup + * @see Operators * @since 1.1.4 */ public interface InsertOperator> extends PrepareOperator, TableOperator { diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/QueryOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/QueryOperator.java index 7fe449b7..c98e3bf2 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/QueryOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/QueryOperator.java @@ -5,7 +5,7 @@ import cc.allio.uno.data.orm.dsl.Func; import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.helper.PojoWrapper; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.word.Distinct; import com.google.common.collect.Lists; @@ -17,7 +17,7 @@ * * @author j.x * @date 2023/4/12 23:02 - * @see OperatorGroup + * @see Operators * @since 1.1.4 */ public interface QueryOperator> extends PrepareOperator, TableOperator, WhereOperator { @@ -747,4 +747,4 @@ default T groupByOne(Collection fieldNames) { * @return self */ T tree(QueryOperator baseQuery, QueryOperator subQuery); -} \ No newline at end of file +} diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/UpdateOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/UpdateOperator.java index fb15aee9..d6df56e6 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/UpdateOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/UpdateOperator.java @@ -4,7 +4,7 @@ import cc.allio.uno.core.function.lambda.MethodReferenceColumn; import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.helper.PojoWrapper; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import com.google.common.collect.Maps; import reactor.util.function.Tuple2; import reactor.util.function.Tuples; @@ -18,7 +18,7 @@ * * @author j.x * @date 2023/4/16 15:19 - * @see OperatorGroup + * @see Operators * @since 1.1.4 */ public interface UpdateOperator> extends PrepareOperator, TableOperator, WhereOperator, Self { diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorAlterTableOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorAlterTableOperator.java index 22a975fd..89a00b61 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorAlterTableOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorAlterTableOperator.java @@ -7,6 +7,7 @@ import lombok.AllArgsConstructor; import java.util.Collection; +import java.util.List; import java.util.function.UnaryOperator; /** @@ -104,4 +105,19 @@ public MetaAcceptorSet obtainMetaAcceptorSet() { public > T getActual() { return (T) actual; } + + @Override + public List> getBeforeOperatorList() { + return actual.getBeforeOperatorList(); + } + + @Override + public List> getCompensateOperatorList() { + return actual.getCompensateOperatorList(); + } + + @Override + public List> getPostOperatorList() { + return actual.getPostOperatorList(); + } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorCreateTableOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorCreateTableOperator.java index 525afbe7..328e1041 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorCreateTableOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorCreateTableOperator.java @@ -9,6 +9,7 @@ import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; +import java.util.List; import java.util.function.UnaryOperator; /** @@ -91,4 +92,19 @@ public MetaAcceptorSet obtainMetaAcceptorSet() { public > T getActual() { return (T) actual; } + + @Override + public List> getBeforeOperatorList() { + return actual.getBeforeOperatorList(); + } + + @Override + public List> getCompensateOperatorList() { + return actual.getCompensateOperatorList(); + } + + @Override + public List> getPostOperatorList() { + return actual.getPostOperatorList(); + } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorDropTableOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorDropTableOperator.java index dd61073d..c9b5dc85 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorDropTableOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorDropTableOperator.java @@ -8,6 +8,7 @@ import jakarta.validation.constraints.NotNull; import lombok.AllArgsConstructor; +import java.util.List; import java.util.function.UnaryOperator; /** @@ -83,4 +84,19 @@ public MetaAcceptorSet obtainMetaAcceptorSet() { public > T getActual() { return (T) actual; } + + @Override + public List> getBeforeOperatorList() { + return actual.getBeforeOperatorList(); + } + + @Override + public List> getCompensateOperatorList() { + return actual.getCompensateOperatorList(); + } + + @Override + public List> getPostOperatorList() { + return actual.getPostOperatorList(); + } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorExistTableOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorExistTableOperator.java index 2292d0db..c2839a71 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorExistTableOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorExistTableOperator.java @@ -89,4 +89,19 @@ public MetaAcceptorSet obtainMetaAcceptorSet() { public > T getActual() { return (T) actual; } + + @Override + public List> getBeforeOperatorList() { + return actual.getBeforeOperatorList(); + } + + @Override + public List> getCompensateOperatorList() { + return actual.getCompensateOperatorList(); + } + + @Override + public List> getPostOperatorList() { + return actual.getPostOperatorList(); + } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorInsertOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorInsertOperator.java index 94ca717d..516b629f 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorInsertOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorInsertOperator.java @@ -112,4 +112,19 @@ public MetaAcceptorSet obtainMetaAcceptorSet() { public > T getActual() { return (T) actual; } + + @Override + public List> getBeforeOperatorList() { + return actual.getBeforeOperatorList(); + } + + @Override + public List> getCompensateOperatorList() { + return actual.getCompensateOperatorList(); + } + + @Override + public List> getPostOperatorList() { + return actual.getPostOperatorList(); + } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorQueryOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorQueryOperator.java index ef17756c..9a820105 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorQueryOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorQueryOperator.java @@ -332,4 +332,19 @@ public MetaAcceptorSet obtainMetaAcceptorSet() { public > T getActual() { return (T) actual; } + + @Override + public List> getBeforeOperatorList() { + return actual.getBeforeOperatorList(); + } + + @Override + public List> getCompensateOperatorList() { + return actual.getCompensateOperatorList(); + } + + @Override + public List> getPostOperatorList() { + return actual.getPostOperatorList(); + } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorSetOperatorGroup.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorSetOperatorGroup.java index c816dc8b..bf7968bc 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorSetOperatorGroup.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorSetOperatorGroup.java @@ -10,7 +10,7 @@ import lombok.Data; /** - * base on aspectj implementation {@link OperatorGroup}. + * base on aspectj implementation {@link Operators}. *

enhance {@link Operator#obtainMetaAcceptorSet()} load by proxy

* * @author j.x @@ -18,7 +18,7 @@ * @since 1.1.8 */ @Data -public class MetaAcceptorSetOperatorGroup implements OperatorGroup { +public class MetaAcceptorSetOperatorGroup implements Operators { private final OperatorKey key; private MetaAcceptorSet metaAcceptorSet; @@ -91,4 +91,9 @@ public AlterTableOperator alterTables(DBType dbType) { AlterTableOperator alterTableOperator = SPIOperatorHelper.lazyGet(AlterTableOperator.class, key, dbType); return new MetaAcceptorAlterTableOperator(alterTableOperator, metaAcceptorSet); } + + @Override + public UnrecognizedOperator unrecognized(DBType dbType) { + return SPIOperatorHelper.lazyGet(UnrecognizedOperator.class, key, dbType); + } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorShowColumnsOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorShowColumnsOperator.java index fd557b9c..47086189 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorShowColumnsOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorShowColumnsOperator.java @@ -99,4 +99,19 @@ public MetaAcceptorSet obtainMetaAcceptorSet() { public > T getActual() { return (T) actual; } + + @Override + public List> getBeforeOperatorList() { + return actual.getBeforeOperatorList(); + } + + @Override + public List> getCompensateOperatorList() { + return actual.getCompensateOperatorList(); + } + + @Override + public List> getPostOperatorList() { + return actual.getPostOperatorList(); + } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorShowTablesOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorShowTablesOperator.java index 9a47fd45..f6f071f9 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorShowTablesOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorShowTablesOperator.java @@ -105,4 +105,19 @@ public MetaAcceptorSet obtainMetaAcceptorSet() { public > T getActual() { return (T) actual; } + + @Override + public List> getBeforeOperatorList() { + return actual.getBeforeOperatorList(); + } + + @Override + public List> getCompensateOperatorList() { + return actual.getCompensateOperatorList(); + } + + @Override + public List> getPostOperatorList() { + return actual.getPostOperatorList(); + } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorUpdateOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorUpdateOperator.java index 35d886ba..02bada53 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorUpdateOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorUpdateOperator.java @@ -258,4 +258,19 @@ public MetaAcceptorSet obtainMetaAcceptorSet() { public > T getActual() { return (T) actual; } + + @Override + public List> getBeforeOperatorList() { + return actual.getBeforeOperatorList(); + } + + @Override + public List> getCompensateOperatorList() { + return actual.getCompensateOperatorList(); + } + + @Override + public List> getPostOperatorList() { + return actual.getPostOperatorList(); + } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/OperatorGroup.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/Operators.java similarity index 93% rename from uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/OperatorGroup.java rename to uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/Operators.java index 4c152deb..e669b587 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/OperatorGroup.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/Operators.java @@ -1,9 +1,6 @@ package cc.allio.uno.data.orm.dsl.opeartorgroup; -import cc.allio.uno.data.orm.dsl.MetaAcceptorSet; -import cc.allio.uno.data.orm.dsl.Operator; -import cc.allio.uno.data.orm.dsl.OperatorKey; -import cc.allio.uno.data.orm.dsl.SPIOperatorHelper; +import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.ddl.*; import cc.allio.uno.data.orm.dsl.dml.DeleteOperator; import cc.allio.uno.data.orm.dsl.dml.InsertOperator; @@ -19,7 +16,7 @@ * @see Operator * @since 1.1.4 */ -public interface OperatorGroup { +public interface Operators { // ======================== DML ======================== @@ -336,11 +333,34 @@ static > T getAlterTableOperator(Class alterT } /** - * base on operator key gain {@link OperatorGroup} + * base on {@link DBType#getSystemDbType()} get {@link UnrecognizedOperator} * - * @return {@link OperatorGroup} or null + * @return the {@link UnrecognizedOperator} instance */ - static OperatorGroup getOperatorGroup(OperatorKey operatorKey, MetaAcceptorSet metaAcceptorSet) { + default UnrecognizedOperator unrecognized() { + return unrecognized(DBType.getSystemDbType()); + } + + /** + * base on {@link DBType} get {@link UnrecognizedOperator} + * + * @return the {@link UnrecognizedOperator} instance + */ + UnrecognizedOperator unrecognized(DBType dbType); + + /** + * @see #getOperator(Class, OperatorKey, DBType) + */ + static > T getUnrecognizedOperator() { + return (T) getOperator(UnrecognizedOperator.class); + } + + /** + * base on operator key gain {@link Operators} + * + * @return {@link Operators} or null + */ + static Operators getOperatorGroup(OperatorKey operatorKey, MetaAcceptorSet metaAcceptorSet) { if (operatorKey != null) { return new MetaAcceptorSetOperatorGroup(operatorKey, metaAcceptorSet); } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/type/TypeRegistry.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/type/TypeRegistry.java index b6d60303..097a7006 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/type/TypeRegistry.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/type/TypeRegistry.java @@ -568,7 +568,7 @@ private void initUnknownTypes() { * * @param javaType javaType INSTANCE */ - void registerJavaType(JavaType javaType) { + public void registerJavaType(JavaType javaType) { javaTypes.put((Class>) javaType.getClass(), javaType); } @@ -577,7 +577,7 @@ void registerJavaType(JavaType javaType) { * * @param jdbcType jdbcType INSTANCE */ - void registerJdbcType(JdbcType jdbcType) { + public void registerJdbcType(JdbcType jdbcType) { jdbcTypes.put(jdbcType.getJdbcCode(), jdbcType); } @@ -588,7 +588,7 @@ void registerJdbcType(JdbcType jdbcType) { * @param jdbcType jdbc type * @param javaType java type */ - void registerRelation(JdbcType jdbcType, JavaType javaType) { + public void registerRelation(JdbcType jdbcType, JavaType javaType) { jdbcTypesMappings.put(jdbcType.getJdbcCode(), javaType); javaTypeMappings.put(javaType, jdbcType.getJdbcCode()); } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/AbstractCommandExecutor.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/AbstractCommandExecutor.java index 3494aadd..50c3022c 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/AbstractCommandExecutor.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/AbstractCommandExecutor.java @@ -19,6 +19,7 @@ import reactor.core.publisher.Mono; import java.util.List; +import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -41,7 +42,33 @@ protected AbstractCommandExecutor(ExecutorOptions options) { @Override public boolean bool(Operator operator, CommandType commandType, ResultSetHandler resultSetHandler) { - return aspect(operator, commandType, () -> doBool(operator, commandType, resultSetHandler)); + return aspect(operator, commandType, () -> aroundBool(operator, commandType, resultSetHandler)); + } + + /** + * wrap up {@link Operator}. realize before-execute-catch-post model + * + * @param operator the current {@link Operator} + * @param commandType the {@link CommandType} + * @param resultSetHandler the {@link ResultSetHandler} + * @return true 成功 false 失败 + * @throws DSLException invoke process has error + * @see #doBool(Operator, CommandType, ResultSetHandler) + */ + boolean aroundBool(Operator operator, CommandType commandType, ResultSetHandler resultSetHandler) { + Consumer> internalHandler = o -> doBool(o, CommandType.getByOperatorClass(o.getClass()), resultSetHandler); + // do before execute operator + doBefore(operator.getBeforeOperatorList(), internalHandler); + // do current operator + try { + return doBool(operator, commandType, resultSetHandler); + } catch (DSLException ex) { + // execute compensate operator + doCompensate(operator.getCompensateOperatorList(), internalHandler); + throw ex; + } finally { + doPost(operator.getPostOperatorList(), internalHandler); + } } /** @@ -74,17 +101,74 @@ protected boolean doBool(Operator operator, CommandType commandType, ResultSe yield manager.getDelete().exec(operator, resultSetHandler); } } - default -> throw new DSLException(String.format("unknown command type in bool %s, accepted " + - "'CREATE_TABLE', 'DELETE_TABLE', 'EXIST_TABLE', 'ALERT_TABLE', 'INSERT', 'UPDATE', 'DELETE'", commandType)); + default -> { + log.warn("unknown command type in bool {}, accepted " + + "'CREATE_TABLE', 'DELETE_TABLE', 'EXIST_TABLE', 'ALERT_TABLE', 'INSERT', 'UPDATE', 'DELETE'", commandType); + yield manager.getUnknown().exec(operator, resultSetHandler); + } }; } catch (Throwable ex) { throw new DSLException(String.format("exec operator %s has err", operator.getClass().getName()), ex); } } + /** + * 给定操作的切面并执行 + * + * @param operator operator + * @param commandType commandType + * @param operate 给定操作 + * @param 操作返回类型 + * @return 返回类结果 + */ + T aspect(Operator operator, CommandType commandType, Supplier operate) { + List interceptors = options.getInterceptors(); + InterceptorAttributes beforeAttributes = new InterceptorAttributes(this, operator, commandType); + var before = Mono.defer(() -> { + // before interceptor + List beforeInterceptors = interceptors.stream().map(BeforeInterceptor::new).collect(Collectors.toList()); + InterceptorChainImpl beforeChain = new InterceptorChainImpl(beforeInterceptors); + return beforeChain.proceed(new InterceptorChainContext(beforeAttributes)); + }); + var after = Mono.defer(() -> { + Mono result = Mono.fromSupplier(operate); + List afterInterceptors = interceptors.stream().map(AfterInterceptor::new).collect(Collectors.toList()); + InterceptorAttributes afterAttributes = new InterceptorAttributes(beforeAttributes, result); + InterceptorChainImpl afterChain = new InterceptorChainImpl(afterInterceptors); + return afterChain.proceed(new InterceptorChainContext(afterAttributes)).then(result); + }); + return before.then(after).block(); + } + @Override public List queryList(Operator queryOperator, CommandType commandType, ListResultSetHandler resultSetHandler) { - return aspect(queryOperator, commandType, () -> doQueryList(queryOperator, commandType, resultSetHandler)); + return aspect(queryOperator, commandType, () -> aroundQueryList(queryOperator, commandType, resultSetHandler)); + } + + /** + * wrap up {@link Operator}. realize before-execute-catch-post model + * + * @param operator the current {@link Operator} + * @param commandType the {@link CommandType} + * @param resultSetHandler the {@link ListResultSetHandler} + * @return true 成功 false 失败 + * @throws DSLException invoke process has error + * @see #doQueryList(Operator, CommandType, ListResultSetHandler) + */ + List aroundQueryList(Operator operator, CommandType commandType, ListResultSetHandler resultSetHandler) { + Consumer> internalHandler = o -> doQueryList(o, CommandType.getByOperatorClass(o.getClass()), resultSetHandler); + // do before execute operator + doBefore(operator.getBeforeOperatorList(), internalHandler); + // do current operator + try { + return doQueryList(operator, commandType, resultSetHandler); + } catch (DSLException ex) { + // execute compensate operator + doCompensate(operator.getCompensateOperatorList(), internalHandler); + throw ex; + } finally { + doPost(operator.getPostOperatorList(), internalHandler); + } } /** @@ -111,8 +195,10 @@ protected List doQueryList(Operator operator, CommandType commandType, manager.>getShowColumn().exec(operator, resultSetHandler); case SELECT -> manager.>getQuery().exec(operator, resultSetHandler); - default -> - throw new DSLException(String.format("unknown command type in queryList %s, accepted 'SHOW_TABLES', 'SHOW_COLUMNS', 'SELECT'", commandType)); + default -> { + log.warn("unknown command type in queryList {}, accepted 'SHOW_TABLES', 'SHOW_COLUMNS', 'SELECT'", commandType); + yield manager.>getUnknown().exec(operator, null); + } }; } catch (Throwable ex) { throw new DSLException("exec query list has err", ex); @@ -120,37 +206,71 @@ protected List doQueryList(Operator operator, CommandType commandType, } /** - * 给定操作的切面并执行 + * do before {@link Operator} * - * @param operator operator - * @param commandType commandType - * @param operate 给定操作 - * @param 操作返回类型 - * @return 返回类结果 + * @param beforeOperatorList the before {@link Operator} list + * @param handler the handler */ - T aspect(Operator operator, CommandType commandType, Supplier operate) { - List interceptors = options.getInterceptors(); - InterceptorAttributes beforeAttributes = new InterceptorAttributes(this, operator, commandType); - var before = Mono.defer(() -> { - // before interceptor - List beforeInterceptors = interceptors.stream().map(BeforeInterceptor::new).collect(Collectors.toList()); - InterceptorChainImpl beforeChain = new InterceptorChainImpl(beforeInterceptors); - return beforeChain.proceed(new InterceptorChainContext(beforeAttributes)); - }); - var after = Mono.defer(() -> { - Mono result = Mono.fromSupplier(operate); - List afterInterceptors = interceptors.stream().map(AfterInterceptor::new).collect(Collectors.toList()); - InterceptorAttributes afterAttributes = new InterceptorAttributes(beforeAttributes, result); - InterceptorChainImpl afterChain = new InterceptorChainImpl(afterInterceptors); - return afterChain.proceed(new InterceptorChainContext(afterAttributes)).then(result); - }); - return before.then(after).block(); + void doBefore(List> beforeOperatorList, Consumer> handler) { + for (Operator operator : beforeOperatorList) { + if (log.isDebugEnabled()) { + log.debug("it will be execute pre Operator {}", operator.getClass().getName()); + } + try { + handler.accept(operator); + } catch (Throwable ex) { + // ignore + log.warn("Failed to execute pre Operator", ex); + } + } } /** - * sub-class implementation, must be not null + * do post {@link Operator} + * + * @param postOperatorList the post {@link Operator} list + * @param handler the handler + */ + void doPost(List> postOperatorList, Consumer> handler) { + for (Operator postOperator : postOperatorList) { + if (log.isDebugEnabled()) { + log.debug("it will be execute post Operator {}", postOperator.getClass().getName()); + } + try { + handler.accept(postOperator); + } catch (Throwable ex) { + // ignore + log.warn("Failed to execute post Operator", ex); + } + } + } + + /** + * do catch compensation {@link Operator} + * + * @param compensateOperatorList the {@link Operator} list + * @param handler the handler + */ + void doCompensate(List> compensateOperatorList, Consumer> handler) { + // execute compensate operator + for (Operator compensateOperator : compensateOperatorList) { + if (log.isDebugEnabled()) { + log.debug("it will be execute compensate Operator {}", compensateOperator.getClass().getName()); + } + try { + handler.accept(compensateOperator); + } catch (Throwable ex) { + // ignore + log.warn("Failed to execute post Operator", ex); + } + } + } + + /** + * subclass implementation, must be not null * * @return InnerCommandExecutorManager */ protected abstract InnerCommandExecutorManager getInnerCommandExecutorManager(); + } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandExecutor.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandExecutor.java index 96da6996..f5900f1b 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandExecutor.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandExecutor.java @@ -4,7 +4,7 @@ import cc.allio.uno.core.util.CollectionUtils; import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.exception.DSLException; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.executor.handler.*; import cc.allio.uno.data.orm.executor.options.ExecutorKey; import cc.allio.uno.data.orm.executor.options.ExecutorOptions; @@ -109,9 +109,9 @@ default T checkCollectionIsOneAndGet(Collection collection) { /** * 获取DSL操作元数据。 * - * @return the {@link OperatorGroup} instance + * @return the {@link Operators} instance */ - OperatorGroup getOperatorGroup(); + Operators getOperatorGroup(); /** * 获取执行器参数 @@ -134,4 +134,4 @@ default T checkCollectionIsOneAndGet(Collection collection) { @interface Group { String value(); } -} \ No newline at end of file +} diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandType.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandType.java index 5f33d839..4e1955d9 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandType.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandType.java @@ -1,6 +1,7 @@ package cc.allio.uno.data.orm.executor; import cc.allio.uno.data.orm.dsl.Operator; +import cc.allio.uno.data.orm.dsl.UnrecognizedOperator; import cc.allio.uno.data.orm.dsl.ddl.*; import cc.allio.uno.data.orm.dsl.dml.DeleteOperator; import cc.allio.uno.data.orm.dsl.dml.InsertOperator; @@ -19,7 +20,7 @@ @Getter @AllArgsConstructor public enum CommandType { - UNKNOWN(null), + UNKNOWN(UnrecognizedOperator.class), ALERT_TABLE(AlterTableOperator.class), CREATE_TABLE(CreateTableOperator.class), DELETE_TABLE(DropTableOperator.class), @@ -39,7 +40,7 @@ public enum CommandType { * * @param o the operatorClass * @param the operator type - * @return CommandType or null + * @return CommandType or {@link #UNKNOWN} */ public static > CommandType getByOperatorClass(Class o) { if (o == null) { @@ -55,6 +56,6 @@ public static > CommandType getByOperatorClass(Class o) return commandType; } } - return null; + return UNKNOWN; } } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/internal/InnerCommandExecutorManager.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/internal/InnerCommandExecutorManager.java index 1938c870..58de631c 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/internal/InnerCommandExecutorManager.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/internal/InnerCommandExecutorManager.java @@ -1,6 +1,7 @@ package cc.allio.uno.data.orm.executor.internal; import cc.allio.uno.data.orm.dsl.Operator; +import cc.allio.uno.data.orm.dsl.UnrecognizedOperator; import cc.allio.uno.data.orm.dsl.ddl.*; import cc.allio.uno.data.orm.dsl.dml.DeleteOperator; import cc.allio.uno.data.orm.dsl.dml.InsertOperator; @@ -231,6 +232,18 @@ public > E ge return null; } + /** + * get {@link UnknownInnerCommandExecutor} if exist + * + * @return ATOInnerCommandExecutor instance or null + */ + public UnknownInnerCommandExecutor> getUnknown() { + if (commandExecutorMap.containsKey(CommandType.UNKNOWN)) { + return (UnknownInnerCommandExecutor>) commandExecutorMap.get(CommandType.UNKNOWN); + } + return null; + } + /** * get inner through operator type * diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/internal/UnknownInnerCommandExecutor.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/internal/UnknownInnerCommandExecutor.java new file mode 100644 index 00000000..f2870fcb --- /dev/null +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/internal/UnknownInnerCommandExecutor.java @@ -0,0 +1,19 @@ +package cc.allio.uno.data.orm.executor.internal; + +import cc.allio.uno.core.reflect.ReflectTools; +import cc.allio.uno.data.orm.dsl.UnrecognizedOperator; + +/** + * {@link UnrecognizedOperator} inner command executor + * + * @author j.x + * @date 2024/7/25 21:26 + * @since 1.1.9 + */ +public interface UnknownInnerCommandExecutor> extends InnerDefaultCommandExecutor { + + @Override + default Class getRealityOperatorType() { + return (Class) ReflectTools.getGenericType(this, UnrecognizedOperator.class); + } +} diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/options/ExecutorKey.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/options/ExecutorKey.java index ce6595ed..09995761 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/options/ExecutorKey.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/options/ExecutorKey.java @@ -76,6 +76,7 @@ static ExecutorKey returnKey(OperatorKey key) { * 获取系统默认executor key * * @return ExecutorKey + * @see ExecutorOptions#setSystemDefault(boolean) */ static ExecutorKey getSystemExecutorKey() { String executorKey = Envs.getProperty(DSL_EXECUTOR_TYPE_KEY); diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/options/ExecutorOptions.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/options/ExecutorOptions.java index 015d8965..0a31e269 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/options/ExecutorOptions.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/options/ExecutorOptions.java @@ -1,6 +1,7 @@ package cc.allio.uno.data.orm.executor.options; import cc.allio.uno.core.api.OptionalContext; +import cc.allio.uno.core.env.Envs; import cc.allio.uno.data.orm.dsl.MetaAcceptorSet; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.type.DBType; @@ -141,8 +142,23 @@ default boolean isSystemDefault() { /** * set system default + *

+ * it will be change system {@link OperatorKey} and {@link ExecutorKey} + *

*/ default void setSystemDefault(boolean systemDefault) { + if (systemDefault) { + OperatorKey operatorKey = getOperatorKey(); + if (operatorKey != null) { + Envs.setProperty(OperatorKey.OPERATOR_METADATA_KEY, operatorKey.key()); + } + + ExecutorKey executorKey = getExecutorKey(); + if (executorKey != null) { + Envs.setProperty(ExecutorKey.DSL_EXECUTOR_TYPE_KEY, executorKey.key()); + } + } + putAttribute(SYSTEM_DEFAULT_MARK, systemDefault); } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/query/BaseQueryFilter.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/query/BaseQueryFilter.java index 2de5ec1c..113e7e7b 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/query/BaseQueryFilter.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/query/BaseQueryFilter.java @@ -3,7 +3,7 @@ import cc.allio.uno.data.orm.dsl.Func; import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.dml.QueryOperator; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.word.Distinct; import cc.allio.uno.data.orm.dsl.type.DBType; @@ -28,7 +28,7 @@ public class BaseQueryFilter implements QueryFilter, QueryOperator baseQuery, QueryOperator subQuer queryOperator.tree(baseQuery, subQuery); return self(); } -} \ No newline at end of file +} diff --git a/uno-data/uno-data-api/src/test/java/cc/allio/uno/data/orm/dsl/operatorgroup/OperatorGroupTest.java b/uno-data/uno-data-api/src/test/java/cc/allio/uno/data/orm/dsl/operatorgroup/OperatorGroupTest.java index a5b01b7c..ba5b6fb6 100644 --- a/uno-data/uno-data-api/src/test/java/cc/allio/uno/data/orm/dsl/operatorgroup/OperatorGroupTest.java +++ b/uno-data/uno-data-api/src/test/java/cc/allio/uno/data/orm/dsl/operatorgroup/OperatorGroupTest.java @@ -4,7 +4,7 @@ import cc.allio.uno.data.orm.dsl.MetaAcceptorSetImpl; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.dml.InsertOperator; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.test.BaseTestCase; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -20,7 +20,7 @@ void init() { @Test void testObtainMetaAcceptor() { - OperatorGroup operatorGroup = OperatorGroup.getOperatorGroup(OperatorKey.REDIS, metaAcceptorSet); + Operators operatorGroup = Operators.getOperatorGroup(OperatorKey.REDIS, metaAcceptorSet); InsertOperator insert = operatorGroup.insert(); assertNotNull(insert); MetaAcceptorSet selfMetaAcceptorSet = insert.obtainMetaAcceptorSet(); diff --git a/uno-data/uno-data-db/src/main/java/cc/allio/uno/data/orm/executor/db/DbCommandExecutor.java b/uno-data/uno-data-db/src/main/java/cc/allio/uno/data/orm/executor/db/DbCommandExecutor.java index d88a74cb..f4e6a261 100644 --- a/uno-data/uno-data-db/src/main/java/cc/allio/uno/data/orm/executor/db/DbCommandExecutor.java +++ b/uno-data/uno-data-db/src/main/java/cc/allio/uno/data/orm/executor/db/DbCommandExecutor.java @@ -2,6 +2,7 @@ import cc.allio.uno.core.StringPool; import cc.allio.uno.core.api.Adapter; +import cc.allio.uno.core.type.Types; import cc.allio.uno.core.util.ClassUtils; import cc.allio.uno.core.util.id.IdGenerator; import cc.allio.uno.data.orm.dsl.ddl.ShowColumnsOperator; @@ -9,7 +10,7 @@ import cc.allio.uno.data.orm.dsl.dml.QueryOperator; import cc.allio.uno.data.orm.dsl.exception.DSLException; import cc.allio.uno.data.orm.dsl.helper.PojoWrapper; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.type.*; import cc.allio.uno.data.orm.executor.*; import cc.allio.uno.data.orm.dsl.*; @@ -57,7 +58,7 @@ public class DbCommandExecutor extends AbstractCommandExecutor implements Aggreg private final LanguageDriver languageDriver; private final DbMybatisConfiguration configuration; private final MybatisSQLCommandAdapter sqlCommandAdapter; - private final OperatorGroup operatorGroup; + private final Operators operatorGroup; private static final String PACKAGE_NAME = DbCommandExecutor.class.getPackage().getName(); public DbCommandExecutor(DbMybatisConfiguration configuration) { @@ -79,7 +80,7 @@ public DbCommandExecutor(ExecutorOptions options, DbMybatisConfiguration configu this.executor = new SimpleExecutor(configuration, tx); this.languageDriver = new RawLanguageDriver(); this.sqlCommandAdapter = new MybatisSQLCommandAdapter(); - this.operatorGroup = OperatorGroup.getOperatorGroup(OperatorKey.SQL, options); + this.operatorGroup = Operators.getOperatorGroup(OperatorKey.SQL, options); } @Override @@ -218,7 +219,7 @@ public ExecutorKey getKey() { } @Override - public OperatorGroup getOperatorGroup() { + public Operators getOperatorGroup() { return operatorGroup; } @@ -269,7 +270,8 @@ private ResultMap getResultMap(Configuration configuration, Class resultType) Class mapperType; if (ResultGroup.class.isAssignableFrom(resultType) || Table.class.isAssignableFrom(resultType) - || ColumnDef.class.isAssignableFrom(resultType)) { + || ColumnDef.class.isAssignableFrom(resultType) + || !Types.isBean(resultType)) { mapperType = ResultGroup.class; } else { mapperType = resultType; diff --git a/uno-data/uno-data-elasticsearch/src/main/java/cc/allio/uno/data/orm/executor/elasticsearch/EsCommandExecutor.java b/uno-data/uno-data-elasticsearch/src/main/java/cc/allio/uno/data/orm/executor/elasticsearch/EsCommandExecutor.java index c9c2e91a..13161fe9 100644 --- a/uno-data/uno-data-elasticsearch/src/main/java/cc/allio/uno/data/orm/executor/elasticsearch/EsCommandExecutor.java +++ b/uno-data/uno-data-elasticsearch/src/main/java/cc/allio/uno/data/orm/executor/elasticsearch/EsCommandExecutor.java @@ -1,7 +1,7 @@ package cc.allio.uno.data.orm.executor.elasticsearch; import cc.allio.uno.data.orm.dsl.exception.DSLException; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.executor.*; import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.executor.internal.InnerCommandExecutorManager; @@ -30,7 +30,7 @@ @Slf4j public class EsCommandExecutor extends AbstractCommandExecutor implements AggregateCommandExecutor { - private final OperatorGroup operatorGroup; + private final Operators operatorGroup; private final RestClient restClient; private final InnerCommandExecutorManager manager; @@ -39,7 +39,7 @@ public EsCommandExecutor(ExecutorOptions options, RestClientBuilder restClientBu this.restClient = restClientBuilder.build(); JsonpMapper mapper = new JacksonJsonpMapper(); RestClientTransport transport = new RestClientTransport(restClient, mapper); - this.operatorGroup = OperatorGroup.getOperatorGroup(OperatorKey.ELASTICSEARCH, options); + this.operatorGroup = Operators.getOperatorGroup(OperatorKey.ELASTICSEARCH, options); SPIInnerCommandScanner scanner = options.getScanner(); this.manager = scanner.scan(new ElasticsearchIndicesClient(transport), new ElasticsearchClient(transport)); } @@ -55,7 +55,7 @@ public ExecutorKey getKey() { } @Override - public OperatorGroup getOperatorGroup() { + public Operators getOperatorGroup() { return operatorGroup; } diff --git a/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/dsl/influxdb/dml/InfluxdbSQLWhereOperatorImpl.java b/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/dsl/influxdb/dml/InfluxdbSQLWhereOperatorImpl.java index 8bc498cc..b53c2537 100644 --- a/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/dsl/influxdb/dml/InfluxdbSQLWhereOperatorImpl.java +++ b/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/dsl/influxdb/dml/InfluxdbSQLWhereOperatorImpl.java @@ -1,7 +1,7 @@ package cc.allio.uno.data.orm.dsl.influxdb.dml; import cc.allio.uno.data.orm.dsl.DSLName; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.WhereOperator; import cc.allio.uno.data.orm.dsl.sql.dml.SQLQueryOperator; @@ -18,7 +18,7 @@ public class InfluxdbSQLWhereOperatorImpl> implements protected SQLQueryOperator sqlQueryOperator; public InfluxdbSQLWhereOperatorImpl() { - this.sqlQueryOperator = OperatorGroup.getQueryOperator(SQLQueryOperator.class, OperatorKey.SQL); + this.sqlQueryOperator = Operators.getQueryOperator(SQLQueryOperator.class, OperatorKey.SQL); } @Override diff --git a/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/executor/influxdb/InfluxdbCommandExecutor.java b/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/executor/influxdb/InfluxdbCommandExecutor.java index 2084fc28..362541c6 100644 --- a/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/executor/influxdb/InfluxdbCommandExecutor.java +++ b/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/executor/influxdb/InfluxdbCommandExecutor.java @@ -3,7 +3,7 @@ import cc.allio.uno.core.StringPool; import cc.allio.uno.core.util.template.ExpressionTemplate; import cc.allio.uno.data.orm.config.influxdb.InfluxdbProperties; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.Table; import cc.allio.uno.data.orm.dsl.influxdb.InfluxDbTableAcceptor; @@ -33,7 +33,7 @@ public class InfluxdbCommandExecutor extends AbstractCommandExecutor implements private final InfluxDBClient influxDBClient; private final InnerCommandExecutorManager manager; - private final OperatorGroup operatorGroup; + private final Operators operatorGroup; public InfluxdbCommandExecutor(ExecutorOptions options) { super(options); @@ -66,7 +66,7 @@ public InfluxdbCommandExecutor(ExecutorOptions options) { InfluxdbCommandExecutorAdaptation adaptation = new InfluxdbCommandExecutorAdaptation(influxDBClient, clientOptions); this.manager = scanner.scan(influxDBClient, clientOptions, adaptation); - this.operatorGroup = OperatorGroup.getOperatorGroup(OperatorKey.INFLUXDB, options); + this.operatorGroup = Operators.getOperatorGroup(OperatorKey.INFLUXDB, options); options.customizeMetaAcceptorSetter(Table.class, new InfluxDbTableAcceptor()); } @@ -85,7 +85,7 @@ public ExecutorKey getKey() { } @Override - public OperatorGroup getOperatorGroup() { + public Operators getOperatorGroup() { return operatorGroup; } diff --git a/uno-data/uno-data-mongodb/src/main/java/cc/allio/uno/data/orm/executor/mongodb/MongodbCommandExecutor.java b/uno-data/uno-data-mongodb/src/main/java/cc/allio/uno/data/orm/executor/mongodb/MongodbCommandExecutor.java index fdca1064..46e4c39c 100644 --- a/uno-data/uno-data-mongodb/src/main/java/cc/allio/uno/data/orm/executor/mongodb/MongodbCommandExecutor.java +++ b/uno-data/uno-data-mongodb/src/main/java/cc/allio/uno/data/orm/executor/mongodb/MongodbCommandExecutor.java @@ -2,7 +2,7 @@ import cc.allio.uno.core.util.StringUtils; import cc.allio.uno.core.util.template.ExpressionTemplate; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.executor.AbstractCommandExecutor; import cc.allio.uno.data.orm.executor.AggregateCommandExecutor; @@ -31,7 +31,7 @@ public class MongodbCommandExecutor extends AbstractCommandExecutor implements A private final MongoClient mongoClient; private final MongoDatabase database; - private final OperatorGroup operatorGroup; + private final Operators operatorGroup; private final InnerCommandExecutorManager manager; @@ -49,7 +49,7 @@ public MongodbCommandExecutor(ExecutorOptions options) { String databaseName = options.getDatabase(); this.mongoClient = MongoClients.create(url); this.database = mongoClient.getDatabase(databaseName); - this.operatorGroup = OperatorGroup.getOperatorGroup(OperatorKey.MONGODB, options); + this.operatorGroup = Operators.getOperatorGroup(OperatorKey.MONGODB, options); SPIInnerCommandScanner scanner = options.getScanner(); this.manager = scanner.scan(database, mongoClient); } @@ -65,7 +65,7 @@ public ExecutorKey getKey() { } @Override - public OperatorGroup getOperatorGroup() { + public Operators getOperatorGroup() { return operatorGroup; } diff --git a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongoAlterCollectionOperatorTest.java b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongoAlterCollectionOperatorTest.java index d06ce610..230597e8 100644 --- a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongoAlterCollectionOperatorTest.java +++ b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongoAlterCollectionOperatorTest.java @@ -1,6 +1,6 @@ package cc.allio.uno.data.orm.dsl.mongodb.ddl; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.Table; import cc.allio.uno.test.BaseTestCase; @@ -10,7 +10,7 @@ class MongoAlterCollectionOperatorTest extends BaseTestCase { @Test void testRename() { - MongodbAlterCollectionOperator alterTableOperator = OperatorGroup.getAlterTableOperator(MongodbAlterCollectionOperator.class, OperatorKey.MONGODB); + MongodbAlterCollectionOperator alterTableOperator = Operators.getAlterTableOperator(MongodbAlterCollectionOperator.class, OperatorKey.MONGODB); assertNotNull(alterTableOperator); alterTableOperator.from(Table.of("a")).rename(Table.of("b")); diff --git a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbCreateCollectionOperatorTest.java b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbCreateCollectionOperatorTest.java index 10625b90..de62e9f2 100644 --- a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbCreateCollectionOperatorTest.java +++ b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbCreateCollectionOperatorTest.java @@ -1,6 +1,6 @@ package cc.allio.uno.data.orm.dsl.mongodb.ddl; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.Table; import cc.allio.uno.test.BaseTestCase; @@ -10,7 +10,7 @@ public class MongodbCreateCollectionOperatorTest extends BaseTestCase { @Test void testCrate() { - MongodbCreateCollectionOperator createTableOperator = OperatorGroup.getCreateTableOperator(MongodbCreateCollectionOperator.class, OperatorKey.MONGODB); + MongodbCreateCollectionOperator createTableOperator = Operators.getCreateTableOperator(MongodbCreateCollectionOperator.class, OperatorKey.MONGODB); assertNotNull(createTableOperator); String dsl = createTableOperator.from(Table.of("dual")).getDSL(); diff --git a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbDropCollectionOperatorTest.java b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbDropCollectionOperatorTest.java index 4537206d..a9b4fcdb 100644 --- a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbDropCollectionOperatorTest.java +++ b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbDropCollectionOperatorTest.java @@ -1,6 +1,6 @@ package cc.allio.uno.data.orm.dsl.mongodb.ddl; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.Table; import cc.allio.uno.test.BaseTestCase; @@ -11,7 +11,7 @@ public class MongodbDropCollectionOperatorTest extends BaseTestCase { @Test void testDropCollection() { - MongodbDropCollectionOperator dropTableOperator = OperatorGroup.getDropTableOperator(MongodbDropCollectionOperator.class, OperatorKey.MONGODB); + MongodbDropCollectionOperator dropTableOperator = Operators.getDropTableOperator(MongodbDropCollectionOperator.class, OperatorKey.MONGODB); assertNotNull(dropTableOperator); diff --git a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbExistCollectionOperatorTest.java b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbExistCollectionOperatorTest.java index 4ee7ec7c..c9950812 100644 --- a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbExistCollectionOperatorTest.java +++ b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbExistCollectionOperatorTest.java @@ -1,6 +1,6 @@ package cc.allio.uno.data.orm.dsl.mongodb.ddl; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.Table; import cc.allio.uno.test.BaseTestCase; @@ -10,7 +10,7 @@ class MongodbExistCollectionOperatorTest extends BaseTestCase { @Test void testExistCollection() { - MongodbExistCollectionOperator existTableOperator = OperatorGroup.getExistTableOperator(MongodbExistCollectionOperator.class, OperatorKey.MONGODB); + MongodbExistCollectionOperator existTableOperator = Operators.getExistTableOperator(MongodbExistCollectionOperator.class, OperatorKey.MONGODB); assertNotNull(existTableOperator); diff --git a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbShowCollectionsOperatorTest.java b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbShowCollectionsOperatorTest.java index 8c1fec44..36df2133 100644 --- a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbShowCollectionsOperatorTest.java +++ b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/ddl/MongodbShowCollectionsOperatorTest.java @@ -1,6 +1,6 @@ package cc.allio.uno.data.orm.dsl.mongodb.ddl; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.test.BaseTestCase; import org.junit.jupiter.api.Test; @@ -9,7 +9,7 @@ class MongodbShowCollectionsOperatorTest extends BaseTestCase { @Test void testShowCollections() { - MongodbShowCollectionsOperator showTablesOperator = OperatorGroup.getShowTablesOperator(MongodbShowCollectionsOperator.class, OperatorKey.MONGODB); + MongodbShowCollectionsOperator showTablesOperator = Operators.getShowTablesOperator(MongodbShowCollectionsOperator.class, OperatorKey.MONGODB); assertNotNull(showTablesOperator); String dsl = showTablesOperator.from("dual1").from("dual2").getDSL(); diff --git a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbDeleteOperatorTest.java b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbDeleteOperatorTest.java index 062c61bc..888c17c8 100644 --- a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbDeleteOperatorTest.java +++ b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbDeleteOperatorTest.java @@ -1,6 +1,6 @@ package cc.allio.uno.data.orm.dsl.mongodb.dml; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.test.BaseTestCase; import org.junit.jupiter.api.Test; @@ -9,7 +9,7 @@ class MongodbDeleteOperatorTest extends BaseTestCase { @Test void testEqDelete() { - MongodbDeleteOperator deleteOperator = OperatorGroup.getDeleteOperator(MongodbDeleteOperator.class, OperatorKey.MONGODB); + MongodbDeleteOperator deleteOperator = Operators.getDeleteOperator(MongodbDeleteOperator.class, OperatorKey.MONGODB); assertNotNull(deleteOperator); @@ -20,7 +20,7 @@ void testEqDelete() { @Test void testEqAndLtAndGtDelete() { - MongodbDeleteOperator deleteOperator = OperatorGroup.getDeleteOperator(MongodbDeleteOperator.class, OperatorKey.MONGODB); + MongodbDeleteOperator deleteOperator = Operators.getDeleteOperator(MongodbDeleteOperator.class, OperatorKey.MONGODB); assertNotNull(deleteOperator); String dsl = deleteOperator.eq("a", "a").lt("b", "b").gt("c", "c").getDSL(); @@ -29,7 +29,7 @@ void testEqAndLtAndGtDelete() { @Test void testLikeDelete() { - MongodbDeleteOperator deleteOperator = OperatorGroup.getDeleteOperator(MongodbDeleteOperator.class, OperatorKey.MONGODB); + MongodbDeleteOperator deleteOperator = Operators.getDeleteOperator(MongodbDeleteOperator.class, OperatorKey.MONGODB); assertNotNull(deleteOperator); String dsl = deleteOperator.like("a", "a").$like("b", "b").getDSL(); @@ -38,7 +38,7 @@ void testLikeDelete() { @Test void testAlternateLogicalDelete() { - MongodbDeleteOperator deleteOperator = OperatorGroup.getDeleteOperator(MongodbDeleteOperator.class, OperatorKey.MONGODB); + MongodbDeleteOperator deleteOperator = Operators.getDeleteOperator(MongodbDeleteOperator.class, OperatorKey.MONGODB); assertNotNull(deleteOperator); String dsl = deleteOperator.eq("a", "a").or().eq("b", "b").nor().eq("c", "c").getDSL(); diff --git a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbInsertOperatorTest.java b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbInsertOperatorTest.java index 55859be6..c34351ff 100644 --- a/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbInsertOperatorTest.java +++ b/uno-data/uno-data-mongodb/src/test/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbInsertOperatorTest.java @@ -1,6 +1,6 @@ package cc.allio.uno.data.orm.dsl.mongodb.dml; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.test.BaseTestCase; import org.junit.jupiter.api.Test; @@ -10,7 +10,7 @@ class MongodbInsertOperatorTest extends BaseTestCase { @Test void testSimplyInsert() { - MongodbInsertOperator insertOperator = OperatorGroup.getInsertOperator(MongodbInsertOperator.class, OperatorKey.MONGODB); + MongodbInsertOperator insertOperator = Operators.getInsertOperator(MongodbInsertOperator.class, OperatorKey.MONGODB); String dsl = insertOperator.insert("a", "a", "b", "b").getDSL(); assertEquals("[ {\n" + " \"a\" : \"a\",\n" + @@ -21,7 +21,7 @@ void testSimplyInsert() { @Test void testBatchInsert() { - MongodbInsertOperator insertOperator = OperatorGroup.getInsertOperator(MongodbInsertOperator.class, OperatorKey.MONGODB); + MongodbInsertOperator insertOperator = Operators.getInsertOperator(MongodbInsertOperator.class, OperatorKey.MONGODB); for (int i = 0; i < 5; i++) { insertOperator.insert(Tuples.of("a" + i, "a" + i)); } @@ -42,7 +42,7 @@ void testBatchInsert() { @Test void testStrictFill() { - MongodbInsertOperator insertOperator = OperatorGroup.getInsertOperator(MongodbInsertOperator.class, OperatorKey.MONGODB); + MongodbInsertOperator insertOperator = Operators.getInsertOperator(MongodbInsertOperator.class, OperatorKey.MONGODB); String dsl = insertOperator.insert("a", "a").strictFill("a", "b").getDSL(); assertEquals("[ {\n" + diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/SQLUnrecognizedOperator.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/SQLUnrecognizedOperator.java new file mode 100644 index 00000000..8ad31c2f --- /dev/null +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/SQLUnrecognizedOperator.java @@ -0,0 +1,48 @@ +package cc.allio.uno.data.orm.dsl.sql; + +import cc.allio.uno.auto.service.AutoService; +import cc.allio.uno.data.orm.dsl.Operator; +import cc.allio.uno.data.orm.dsl.OperatorKey; +import cc.allio.uno.data.orm.dsl.UnrecognizedOperator; +import cc.allio.uno.data.orm.dsl.type.DBType; + +import java.util.function.UnaryOperator; + +@AutoService(UnrecognizedOperator.class) +@Operator.Group(OperatorKey.SQL_LITERAL) +public class SQLUnrecognizedOperator implements UnrecognizedOperator { + + private DBType dbType; + private String dsl; + + @Override + public String getDSL() { + return dsl; + } + + @Override + public SQLUnrecognizedOperator parse(String dsl) { + this.dsl = dsl; + return self(); + } + + @Override + public SQLUnrecognizedOperator customize(UnaryOperator operatorFunc) { + return operatorFunc.apply(new SQLUnrecognizedOperator()); + } + + @Override + public void reset() { + this.dsl = null; + } + + @Override + public void setDBType(DBType dbType) { + this.dbType = dbType; + } + + @Override + public DBType getDBType() { + return dbType; + } +} diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/DDLSQLSupport.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/DDLSQLSupport.java index 0a36933f..f6778e8b 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/DDLSQLSupport.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/DDLSQLSupport.java @@ -7,7 +7,11 @@ import cc.allio.uno.data.orm.dsl.type.DataType; import cc.allio.uno.data.orm.dsl.type.DruidDataTypeAdapter; import cc.allio.uno.data.orm.dsl.type.DruidDbTypeAdapter; +import com.alibaba.druid.DbType; import com.alibaba.druid.sql.ast.SQLDataType; +import com.alibaba.druid.sql.ast.expr.SQLCharExpr; +import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; +import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr; import com.alibaba.druid.sql.ast.expr.SQLValuableExpr; import com.alibaba.druid.sql.ast.statement.*; @@ -49,7 +53,10 @@ public static SQLExprTableSource createTableSource(Table table, DBType dbType) { public static SQLColumnDefinition createColumnDefinition(ColumnDef columnDef, DBType dbType) { var druidType = DruidDbTypeAdapter.getInstance().adapt(dbType); SQLColumnDefinition sqlColumnDefinition = new SQLColumnDefinition(); - sqlColumnDefinition.setComment(columnDef.getComment()); + // exclude pg DB type + if (dbType != DBType.POSTGRESQL) { + sqlColumnDefinition.setComment(columnDef.getComment()); + } sqlColumnDefinition.setName(columnDef.getDslName().format()); sqlColumnDefinition.setDbType(druidType); DataType dataType = columnDef.getDataType(); @@ -84,4 +91,38 @@ public static SQLColumnDefinition createColumnDefinition(ColumnDef columnDef, DB } return sqlColumnDefinition; } + + /** + * create druid {@link SQLCommentStatement} instance + * + * @param columnDef the {@link ColumnDef} instance + * @param table the {@link Table} instance + * @param dbType the {@link DbType} + * @return the {@link SQLCommentStatement} instance + */ + public static SQLCommentStatement createCommentStatement(ColumnDef columnDef, Table table, DbType dbType) { + String columnCommentInfo = columnDef.getComment(); + SQLCommentStatement columnComment = new SQLCommentStatement(); + SQLExprTableSource tableSource = new SQLExprTableSource(); + SQLPropertyExpr columnExpr = new SQLPropertyExpr(); + + // set comment from table + SQLPropertyExpr tableExpr = new SQLPropertyExpr(); + tableExpr.setOwner(new SQLIdentifierExpr(table.getSchema())); + tableExpr.setName(table.getName().format()); + + // set comment column name + columnExpr.setName(columnDef.getDslName().format()); + // set own + columnExpr.setOwner(tableExpr); + + tableSource.setExpr(columnExpr); + + columnComment.setComment(new SQLCharExpr(columnCommentInfo)); + columnComment.setOn(tableSource); + columnComment.setType(SQLCommentStatement.Type.COLUMN); + columnComment.setDbType(dbType); + + return columnComment; + } } diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLAlterTableOperator.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLAlterTableOperator.java index de0b11d4..1d383a08 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLAlterTableOperator.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLAlterTableOperator.java @@ -1,6 +1,7 @@ package cc.allio.uno.data.orm.dsl.sql.ddl; import cc.allio.uno.auto.service.AutoService; +import cc.allio.uno.core.util.StringUtils; import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.exception.DDLException; import cc.allio.uno.data.orm.dsl.sql.SQLSupport; @@ -13,8 +14,10 @@ import com.alibaba.druid.sql.ast.expr.SQLValuableExpr; import com.alibaba.druid.sql.ast.statement.*; import cc.allio.uno.data.orm.dsl.ddl.AlterTableOperator; +import com.google.common.collect.Lists; import java.util.Collection; +import java.util.List; import java.util.function.UnaryOperator; /** @@ -33,6 +36,8 @@ public class SQLAlterTableOperator implements AlterTableOperator commentColumnDefList = Lists.newArrayList(); + public SQLAlterTableOperator() { this(DBType.getSystemDbType()); } @@ -92,7 +97,12 @@ public DBType getDBType() { public SQLAlterTableOperator alertColumns(Collection columnDefs) { for (ColumnDef columnDef : columnDefs) { SQLColumnDefinition columnDefinition = new SQLColumnDefinition(); - columnDefinition.setComment(columnDef.getComment()); + String comment = columnDef.getComment(); + if (dbType == DBType.POSTGRESQL) { + commentColumnDefList.add(columnDef); + } else { + columnDefinition.setComment(comment); + } columnDefinition.setName(columnDef.getDslName().format()); columnDefinition.setDbType(druidDbType); if (columnDef.getDataType() != null) { @@ -122,8 +132,10 @@ public SQLAlterTableOperator alertColumns(Collection columnDefs) { @Override public SQLAlterTableOperator addColumns(Collection columnDefs) { for (ColumnDef columnDef : columnDefs) { + if (DBType.POSTGRESQL == dbType) { + commentColumnDefList.add(columnDef); + } SQLAlterTableAddColumn alterTableAddColumn = new SQLAlterTableAddColumn(); - alterTableAddColumn.toString(); SQLColumnDefinition columnDefinition = DDLSQLSupport.createColumnDefinition(columnDef, dbType); alterTableAddColumn.addColumn(columnDefinition); this.alterTableStatement.addItem(alterTableAddColumn); @@ -161,4 +173,18 @@ public SQLAlterTableOperator from(Table table) { public Table getTable() { return from; } + + @Override + public List> getPostOperatorList() { + List> commentOperatorList = Lists.newArrayList(); + for (ColumnDef columnDef : commentColumnDefList) { + String columnCommentInfo = columnDef.getComment(); + if (StringUtils.isNotBlank(columnCommentInfo)) { + SQLCommentStatement commentStatement = DDLSQLSupport.createCommentStatement(columnDef, from, druidDbType); + String columnCommentSQL = SQLUtils.toSQLString(commentStatement, druidDbType); + commentOperatorList.add(Operator.from(columnCommentSQL)); + } + } + return commentOperatorList; + } } diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLCreateTableOperator.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLCreateTableOperator.java index 372a3c8f..d12ee145 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLCreateTableOperator.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLCreateTableOperator.java @@ -1,6 +1,7 @@ package cc.allio.uno.data.orm.dsl.sql.ddl; import cc.allio.uno.auto.service.AutoService; +import cc.allio.uno.core.util.StringUtils; import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.sql.SQLSupport; import cc.allio.uno.data.orm.dsl.type.DBType; @@ -12,7 +13,9 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement; import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateTableStatement; import cc.allio.uno.data.orm.dsl.ddl.CreateTableOperator; +import com.google.common.collect.Lists; +import java.util.List; import java.util.function.UnaryOperator; /** @@ -30,6 +33,8 @@ public class SQLCreateTableOperator implements CreateTableOperator columnDefs = Lists.newArrayList(); public SQLCreateTableOperator() { this(DBType.getSystemDbType()); @@ -100,6 +105,7 @@ public Table getTable() { @Override public SQLCreateTableOperator column(ColumnDef columnDef) { + columnDefs.add(columnDef); SQLColumnDefinition columnDefinition = DDLSQLSupport.createColumnDefinition(columnDef, dbType); createTableStatement.addColumn(columnDefinition); return self(); @@ -107,7 +113,34 @@ public SQLCreateTableOperator column(ColumnDef columnDef) { @Override public SQLCreateTableOperator comment(String comment) { + this.comment = comment; createTableStatement.setComment(new SQLIdentifierExpr(comment)); return self(); } + + @Override + public List> getPostOperatorList() { + List> commentOperatorList = Lists.newArrayList(); + if (DBType.POSTGRESQL == dbType) { + if (StringUtils.isNotBlank(comment)) { + SQLCommentStatement tableComment = new SQLCommentStatement(); + tableComment.setComment(new SQLIdentifierExpr(comment)); + tableComment.setType(SQLCommentStatement.Type.TABLE); + SQLExprTableSource tableSource = DDLSQLSupport.createTableSource(table, dbType); + tableComment.setOn(tableSource); + String tableCommentSQL = SQLUtils.toSQLString(tableSource, druidType); + commentOperatorList.add(Operator.from(tableCommentSQL)); + } + + for (ColumnDef columnDef : columnDefs) { + String columnCommentInfo = columnDef.getComment(); + if (StringUtils.isNotBlank(columnCommentInfo)) { + SQLCommentStatement commentStatement = DDLSQLSupport.createCommentStatement(columnDef, table, druidType); + String columnCommentSQL = SQLUtils.toSQLString(commentStatement, druidType); + commentOperatorList.add(Operator.from(columnCommentSQL)); + } + } + } + return commentOperatorList; + } } diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLExistTableOperator.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLExistTableOperator.java index 60323d9c..be29b11b 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLExistTableOperator.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLExistTableOperator.java @@ -3,7 +3,7 @@ import cc.allio.uno.auto.service.AutoService; import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.exception.DSLException; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.sql.SQLSupport; import cc.allio.uno.data.orm.dsl.sql.dml.SQLQueryOperator; import cc.allio.uno.data.orm.dsl.type.DBType; @@ -36,7 +36,7 @@ public SQLExistTableOperator() { public SQLExistTableOperator(DBType dbType) { this.dbType = dbType; this.druidDbType = SQLSupport.translateDb(dbType); - this.queryOperator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL, dbType); + this.queryOperator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL, dbType); } @Override diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLShowColumnsOperator.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLShowColumnsOperator.java index fda97651..8512242f 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLShowColumnsOperator.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLShowColumnsOperator.java @@ -4,7 +4,7 @@ import cc.allio.uno.data.orm.dsl.*; import cc.allio.uno.data.orm.dsl.dml.QueryOperator; import cc.allio.uno.data.orm.dsl.exception.DSLException; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.sql.SQLSupport; import cc.allio.uno.data.orm.dsl.sql.dml.SQLQueryOperator; import cc.allio.uno.data.orm.dsl.type.DBType; @@ -59,7 +59,7 @@ public SQLShowColumnsOperator() { public SQLShowColumnsOperator(DBType dbType) { this.dbType = dbType; this.druidDbType = SQLSupport.translateDb(dbType); - this.queryOperator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL, dbType); + this.queryOperator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL, dbType); } @Override diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLShowTablesOperator.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLShowTablesOperator.java index 7ecdc6e6..fbe89ebc 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLShowTablesOperator.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLShowTablesOperator.java @@ -6,7 +6,7 @@ import cc.allio.uno.data.orm.dsl.ddl.ShowTablesOperator; import cc.allio.uno.data.orm.dsl.dml.QueryOperator; import cc.allio.uno.data.orm.dsl.exception.DSLException; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.sql.SQLSupport; import cc.allio.uno.data.orm.dsl.sql.dml.SQLQueryOperator; import cc.allio.uno.data.orm.dsl.type.DBType; @@ -46,7 +46,7 @@ public SQLShowTablesOperator() { public SQLShowTablesOperator(DBType dbType) { this.dbType = dbType; this.druidDbType = SQLSupport.translateDb(dbType); - this.queryOperator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL, dbType); + this.queryOperator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL, dbType); this.schema = "PUBLIC"; this.tables = Lists.newArrayList(); } diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/type/DruidDataTypeAdapter.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/type/DruidDataTypeAdapter.java index fd14abce..72a8e03a 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/type/DruidDataTypeAdapter.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/type/DruidDataTypeAdapter.java @@ -46,7 +46,15 @@ public SQLDataType adapt(DataType o) { Integer precision = dbSQLType.getPrecision(); Integer scale = dbSQLType.getScale(); switch (sqlTypeConstant) { - case DefaultDSLType.BIGINT, DefaultDSLType.SMALLINT, DefaultDSLType.TINYINT, DefaultDSLType.BIT, DefaultDSLType.INTEGER, DefaultDSLType.DOUBLE, DefaultDSLType.NUMBER, DefaultDSLType.FLOAT: + case DefaultDSLType.BIGINT, + DefaultDSLType.SMALLINT, + DefaultDSLType.TINYINT, + DefaultDSLType.BIT, + DefaultDSLType.INTEGER, + DefaultDSLType.INT, + DefaultDSLType.DOUBLE, + DefaultDSLType.NUMBER, + DefaultDSLType.FLOAT: if (precision == null) { return new SQLDataTypeImpl(dbSQLType.getName()); } else if (scale == null) { @@ -63,7 +71,9 @@ public SQLDataType adapt(DataType o) { decimalDataType.addArgument(new SQLIntegerExpr(dataType.getPrecision())); } return decimalDataType; - case DefaultDSLType.DATE, DefaultDSLType.TIME, DefaultDSLType.TIMESTAMP: + case DefaultDSLType.DATE, + DefaultDSLType.TIME, + DefaultDSLType.TIMESTAMP: SQLDataTypeImpl dateDataType = new SQLDataTypeImpl(dbSQLType.getName()); if (precision != null) { dateDataType.addArgument(new SQLIntegerExpr(precision)); diff --git a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/DDLSQLSupportTest.java b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/DDLSQLSupportTest.java new file mode 100644 index 00000000..9a71e1e6 --- /dev/null +++ b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/DDLSQLSupportTest.java @@ -0,0 +1,34 @@ +package cc.allio.uno.data.orm.dsl.ddl.sql; + +import cc.allio.uno.data.orm.dsl.ColumnDef; +import cc.allio.uno.data.orm.dsl.DSLName; +import cc.allio.uno.data.orm.dsl.Table; +import cc.allio.uno.data.orm.dsl.sql.ddl.DDLSQLSupport; +import cc.allio.uno.test.BaseTestCase; +import com.alibaba.druid.DbType; +import com.alibaba.druid.sql.SQLUtils; +import com.alibaba.druid.sql.ast.statement.SQLCommentStatement; +import org.junit.jupiter.api.Test; + +public class DDLSQLSupportTest extends BaseTestCase { + + @Test + void testCreateCommentStatement() { + + ColumnDef columnDef = + ColumnDef.builder() + .comment("测试") + .dslName(DSLName.of("test")) + .build(); + + Table table = new Table(); + table.setName(DSLName.of("dual")); + + SQLCommentStatement commentStatement = DDLSQLSupport.createCommentStatement(columnDef, table, DbType.postgresql); + + + String sqlString = SQLUtils.toSQLString(commentStatement); + + assertEquals("COMMENT ON COLUMN PUBLIC.dual.test IS '测试'", sqlString); + } +} diff --git a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLAlterTableOperatorTest.java b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLAlterTableOperatorTest.java index 9b755c5a..9f39a2c5 100644 --- a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLAlterTableOperatorTest.java +++ b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLAlterTableOperatorTest.java @@ -1,10 +1,9 @@ package cc.allio.uno.data.orm.dsl.ddl.sql; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.sql.ddl.SQLAlterTableOperator; import cc.allio.uno.data.orm.dsl.type.DBType; -import cc.allio.uno.data.test.model.Operators; import cc.allio.uno.test.BaseTestCase; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -13,12 +12,12 @@ public class SQLAlterTableOperatorTest extends BaseTestCase { - Operators.OperatorFeature feature; + cc.allio.uno.data.test.model.Operators.OperatorFeature feature; @BeforeEach void init() { - SQLAlterTableOperator alterTableOperator = OperatorGroup.getOperator(SQLAlterTableOperator.class, OperatorKey.SQL); - feature = Operators.feature(alterTableOperator); + SQLAlterTableOperator alterTableOperator = Operators.getOperator(SQLAlterTableOperator.class, OperatorKey.SQL); + feature = cc.allio.uno.data.test.model.Operators.feature(alterTableOperator); } @Test @@ -45,7 +44,6 @@ void testAddColumns() { "\tADD COLUMN id int8 PRIMARY KEY NOT NULL,\n" + "\tADD COLUMN create_by int8", dsl); }); - } @Test diff --git a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLCreateOperatorTest.java b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLCreateOperatorTest.java index b4e756af..3dffd7ae 100644 --- a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLCreateOperatorTest.java +++ b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLCreateOperatorTest.java @@ -2,7 +2,7 @@ import cc.allio.uno.data.orm.dsl.ColumnDef; import cc.allio.uno.data.orm.dsl.DSLName; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.ddl.CreateTableOperator; import cc.allio.uno.data.orm.dsl.type.DBType; @@ -16,7 +16,7 @@ public class SQLCreateOperatorTest extends BaseTestCase { @Test void testCreateTable() { - CreateTableOperator createTableOperator = OperatorGroup.getOperator(CreateTableOperator.class, OperatorKey.SQL); + CreateTableOperator createTableOperator = Operators.getOperator(CreateTableOperator.class, OperatorKey.SQL); String sql = createTableOperator.from("dual") .column( ColumnDef.builder() @@ -34,7 +34,7 @@ void testCreateTable() { @Test void testParseCreateTableSQL() { - CreateTableOperator createTableOperator = OperatorGroup.getOperator(CreateTableOperator.class, OperatorKey.SQL); + CreateTableOperator createTableOperator = Operators.getOperator(CreateTableOperator.class, OperatorKey.SQL); String sql = "CREATE TABLE dual (\n" + "\tname char(9) PRIMARY KEY NOT NULL UNIQUE\n" + ")"; @@ -46,7 +46,7 @@ void testParseCreateTableSQL() { @Test void testPgCreateComplexTypeTable() { - CreateTableOperator createTableOperator = OperatorGroup.getOperator(CreateTableOperator.class, OperatorKey.SQL, DBType.POSTGRESQL); + CreateTableOperator createTableOperator = Operators.getOperator(CreateTableOperator.class, OperatorKey.SQL, DBType.POSTGRESQL); createTableOperator.from("dual"); ColumnDef d1 = ColumnDef.builder() .dslName(DSLName.of("d1")) @@ -78,7 +78,7 @@ void testPgCreateComplexTypeTable() { @Test void testPgParsePojoCreateTableSQL() { - CreateTableOperator createTableOperator = OperatorGroup.getOperator(CreateTableOperator.class, OperatorKey.SQL, DBType.POSTGRESQL); + CreateTableOperator createTableOperator = Operators.getOperator(CreateTableOperator.class, OperatorKey.SQL, DBType.POSTGRESQL); String sql = createTableOperator.fromPojo(User.class).getDSL(); assertEquals("CREATE TABLE t_users (\n" + "\tid int8 PRIMARY KEY,\n" + diff --git a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLShowColumnsOperatorTest.java b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLShowColumnsOperatorTest.java index 82cb1228..e0bcaf42 100644 --- a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLShowColumnsOperatorTest.java +++ b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLShowColumnsOperatorTest.java @@ -1,6 +1,6 @@ package cc.allio.uno.data.orm.dsl.ddl.sql; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.sql.ddl.SQLShowColumnsOperator; import cc.allio.uno.data.orm.dsl.type.DBType; @@ -11,7 +11,7 @@ public class SQLShowColumnsOperatorTest extends BaseTestCase { @Test void testMySQLShoWColumns() { - SQLShowColumnsOperator showColumnsOperator = OperatorGroup.getOperator(SQLShowColumnsOperator.class, OperatorKey.SQL, DBType.MYSQL); + SQLShowColumnsOperator showColumnsOperator = Operators.getOperator(SQLShowColumnsOperator.class, OperatorKey.SQL, DBType.MYSQL); String dsl = showColumnsOperator.from("dual").getDSL(); assertEquals("SELECT *, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME\n" + "\t, ORDINAL_POSITION, COLUMN_DEFAULT, IS_NULLABLE, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH\n" + diff --git a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLShowTablesOperatorTest.java b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLShowTablesOperatorTest.java index 33b898d9..9ad9bde1 100644 --- a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLShowTablesOperatorTest.java +++ b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/SQLShowTablesOperatorTest.java @@ -1,6 +1,6 @@ package cc.allio.uno.data.orm.dsl.ddl.sql; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.sql.ddl.SQLShowTablesOperator; import cc.allio.uno.data.orm.dsl.type.DBType; @@ -11,7 +11,7 @@ public class SQLShowTablesOperatorTest extends BaseTestCase { @Test void testSQLLByH2() { - SQLShowTablesOperator operator = OperatorGroup.getOperator(SQLShowTablesOperator.class, OperatorKey.SQL); + SQLShowTablesOperator operator = Operators.getOperator(SQLShowTablesOperator.class, OperatorKey.SQL); String sql = operator.getDSL(); assertEquals("SELECT TABLE_CATALOG AS CATALOG, TABLE_SCHEMA AS SCHEMA, TABLE_NAME AS NAME, TABLE_TYPE AS TYPE\n" + "FROM INFORMATION_SCHEMA.TABLES\n" + @@ -21,7 +21,7 @@ void testSQLLByH2() { @Test void testSQLLByMySQL() { - SQLShowTablesOperator operator = OperatorGroup.getOperator(SQLShowTablesOperator.class, OperatorKey.SQL, DBType.MYSQL); + SQLShowTablesOperator operator = Operators.getOperator(SQLShowTablesOperator.class, OperatorKey.SQL, DBType.MYSQL); String sql = operator.database("da").getDSL(); assertEquals("SELECT TABLE_CATALOG AS CATALOG, TABLE_SCHEMA AS SCHEMA, TABLE_NAME AS NAME, TABLE_TYPE AS TYPE\n" + "FROM INFORMATION_SCHEMA.TABLES\n" + @@ -32,7 +32,7 @@ void testSQLLByMySQL() { @Test void testSQLLByPostgreSQL() { - SQLShowTablesOperator operator = OperatorGroup.getOperator(SQLShowTablesOperator.class, OperatorKey.SQL, DBType.POSTGRESQL); + SQLShowTablesOperator operator = Operators.getOperator(SQLShowTablesOperator.class, OperatorKey.SQL, DBType.POSTGRESQL); String sql = operator.getDSL(); assertEquals("SELECT TABLE_CATALOG AS CATALOG, TABLE_SCHEMA AS SCHEMA, TABLE_NAME AS NAME, TABLE_TYPE AS TYPE\n" + "FROM INFORMATION_SCHEMA.TABLES\n" + @@ -42,7 +42,7 @@ void testSQLLByPostgreSQL() { @Test void testDualShowTable() { - SQLShowTablesOperator operator = OperatorGroup.getOperator(SQLShowTablesOperator.class, OperatorKey.SQL, DBType.POSTGRESQL); + SQLShowTablesOperator operator = Operators.getOperator(SQLShowTablesOperator.class, OperatorKey.SQL, DBType.POSTGRESQL); String sql = operator.from("dual").getDSL(); assertEquals("SELECT TABLE_CATALOG AS CATALOG, TABLE_SCHEMA AS SCHEMA, TABLE_NAME AS NAME, TABLE_TYPE AS TYPE\n" + "FROM INFORMATION_SCHEMA.TABLES\n" + @@ -53,7 +53,7 @@ void testDualShowTable() { @Test void testCompositeShowTable() { - SQLShowTablesOperator operator = OperatorGroup.getOperator(SQLShowTablesOperator.class, OperatorKey.SQL, DBType.POSTGRESQL); + SQLShowTablesOperator operator = Operators.getOperator(SQLShowTablesOperator.class, OperatorKey.SQL, DBType.POSTGRESQL); String sql = operator.from("dualA").from("dualB").database("da").schema("db").getDSL(); assertEquals("SELECT TABLE_CATALOG AS CATALOG, TABLE_SCHEMA AS SCHEMA, TABLE_NAME AS NAME, TABLE_TYPE AS TYPE\n" + "FROM INFORMATION_SCHEMA.TABLES\n" + diff --git a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLDeleteOperatorTest.java b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLDeleteOperatorTest.java index cf2e6ef1..e97627d5 100644 --- a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLDeleteOperatorTest.java +++ b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLDeleteOperatorTest.java @@ -1,9 +1,8 @@ package cc.allio.uno.data.orm.dsl.dml.sql; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.sql.dml.SQLDeleteOperator; -import cc.allio.uno.data.test.model.Operators; import cc.allio.uno.data.test.model.User; import cc.allio.uno.test.BaseTestCase; import org.junit.jupiter.api.Test; @@ -12,14 +11,14 @@ public class SQLDeleteOperatorTest extends BaseTestCase { @Test void testSimplePojoInsert() { - SQLDeleteOperator deleteOperator = OperatorGroup.getOperator(SQLDeleteOperator.class, OperatorKey.SQL); + SQLDeleteOperator deleteOperator = Operators.getOperator(SQLDeleteOperator.class, OperatorKey.SQL); String sql = deleteOperator.from(User.class).from(User.class).getDSL(); assertEquals("DELETE FROM PUBLIC.t_users", sql); } @Test void testComplexCondition() { - SQLDeleteOperator deleteOperator = OperatorGroup.getOperator(SQLDeleteOperator.class, OperatorKey.SQL); + SQLDeleteOperator deleteOperator = Operators.getOperator(SQLDeleteOperator.class, OperatorKey.SQL); String sql = deleteOperator.from("dual") .eq("a", "a") .or() @@ -37,8 +36,8 @@ void testComplexCondition() { @Test void testParseSQL() { - SQLDeleteOperator deleteOperator = OperatorGroup.getOperator(SQLDeleteOperator.class, OperatorKey.SQL); - Operators.thenRest(() -> { + SQLDeleteOperator deleteOperator = Operators.getOperator(SQLDeleteOperator.class, OperatorKey.SQL); + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String sql = "DELETE FROM PUBLIC.dual\n" + "WHERE (a = 'a'\n" + "\t\tOR b IN ('b1', 'b2'))\n" + diff --git a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLInsertOperatorTest.java b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLInsertOperatorTest.java index fdaf6bc4..30f2d274 100644 --- a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLInsertOperatorTest.java +++ b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLInsertOperatorTest.java @@ -1,9 +1,8 @@ package cc.allio.uno.data.orm.dsl.dml.sql; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.sql.dml.SQLInsertOperator; -import cc.allio.uno.data.test.model.Operators; import cc.allio.uno.test.BaseTestCase; import com.google.common.collect.Lists; import jakarta.persistence.Table; @@ -15,7 +14,7 @@ public class SQLInsertOperatorTest extends BaseTestCase { @Test void testInsert() { - SQLInsertOperator insertOperator = OperatorGroup.getOperator(SQLInsertOperator.class, OperatorKey.SQL); + SQLInsertOperator insertOperator = Operators.getOperator(SQLInsertOperator.class, OperatorKey.SQL); String sql = insertOperator.from("test") .insert("x", "2") .getDSL(); @@ -32,7 +31,7 @@ void testInsert() { @Test void testNotEqualityInsertColumn() { - SQLInsertOperator insertOperator = OperatorGroup.getOperator(SQLInsertOperator.class, OperatorKey.SQL); + SQLInsertOperator insertOperator = Operators.getOperator(SQLInsertOperator.class, OperatorKey.SQL); String sql = insertOperator.from("dual") .insert("a1", null, "a2", "2") .insert("a1", null) @@ -43,9 +42,9 @@ void testNotEqualityInsertColumn() { @Test void testNullValueInsert() { - SQLInsertOperator insertOperator = OperatorGroup.getOperator(SQLInsertOperator.class, OperatorKey.SQL); + SQLInsertOperator insertOperator = Operators.getOperator(SQLInsertOperator.class, OperatorKey.SQL); - Operators.thenRest(() -> { + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String sql = insertOperator.from("dual") .insert("x", null) .getDSL(); @@ -54,7 +53,7 @@ void testNullValueInsert() { return insertOperator; }); - Operators.thenRest(() -> { + cc.allio.uno.data.test.model.Operators.thenRest(() -> { // test multi Null values String sql = insertOperator.from("dual") .insert("a", null, "b", null) @@ -67,8 +66,8 @@ void testNullValueInsert() { @Test void testStrictSingleValueClause() { - SQLInsertOperator insertOperator = OperatorGroup.getOperator(SQLInsertOperator.class, OperatorKey.SQL); - new Operators(insertOperator) + SQLInsertOperator insertOperator = Operators.getOperator(SQLInsertOperator.class, OperatorKey.SQL); + new cc.allio.uno.data.test.model.Operators(insertOperator) .then(() -> { // column不存在 String sql = insertOperator.from("dual") @@ -93,8 +92,8 @@ void testStrictSingleValueClause() { @Test void testStrictMultiValueClause() { - SQLInsertOperator insertOperator = OperatorGroup.getOperator(SQLInsertOperator.class, OperatorKey.SQL); - new Operators(insertOperator) + SQLInsertOperator insertOperator = Operators.getOperator(SQLInsertOperator.class, OperatorKey.SQL); + new cc.allio.uno.data.test.model.Operators(insertOperator) .then(() -> { // column不存在 String sql = insertOperator.from("dual") @@ -120,7 +119,7 @@ void testStrictMultiValueClause() { @Test void testParse() { - SQLInsertOperator insertOperator = OperatorGroup.getOperator(SQLInsertOperator.class, OperatorKey.SQL); + SQLInsertOperator insertOperator = Operators.getOperator(SQLInsertOperator.class, OperatorKey.SQL); String oriSQL = "INSERT INTO PUBLIC.t_user (name, age)\n" + "VALUES ('21', 2), ('xc', 2)"; insertOperator.parse(oriSQL); diff --git a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLQueryOperatorTest.java b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLQueryOperatorTest.java index fe9d4bc0..c4e1fb8f 100644 --- a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLQueryOperatorTest.java +++ b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLQueryOperatorTest.java @@ -1,9 +1,8 @@ package cc.allio.uno.data.orm.dsl.dml.sql; import cc.allio.uno.data.orm.dsl.*; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.sql.dml.SQLQueryOperator; -import cc.allio.uno.data.test.model.Operators; import cc.allio.uno.test.BaseTestCase; import org.junit.jupiter.api.Test; @@ -11,14 +10,14 @@ public class SQLQueryOperatorTest extends BaseTestCase { @Test void testSelect() { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.selectAll().getDSL(); assertEquals("SELECT *", sql); } @Test void testFunc() { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.select("z") .min("z") .getDSL(); @@ -27,7 +26,7 @@ void testFunc() { @Test void testSimpleWhere() { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.select("z").from("dual").like("x", "zxc").getDSL(); assertEquals("SELECT z\n" + "FROM PUBLIC.dual\n" + @@ -36,7 +35,7 @@ void testSimpleWhere() { @Test void testMultiWhere() { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.select("z").from("dual").like("a", "a").eq("b", "b").getDSL(); assertEquals("SELECT z\n" + "FROM PUBLIC.dual\n" + @@ -46,7 +45,7 @@ void testMultiWhere() { @Test void testLogicPredicateOr() { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.select("z").from("dual").or().eq("a", "a").eq("b", "b").getDSL(); assertEquals("SELECT z\n" + "FROM PUBLIC.dual\n" + @@ -56,7 +55,7 @@ void testLogicPredicateOr() { @Test void testMultiLogicPredicate() { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.select("z").from("dual").or().eq("a", "a").eq("b", "b").and().eq("d", "d").getDSL(); assertEquals("SELECT z\n" + "FROM PUBLIC.dual\n" + @@ -67,7 +66,7 @@ void testMultiLogicPredicate() { @Test void testSubTable() { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.leftJoin(Table.of("dual1"), Table.of("dual2"), BinaryCondition.of("dual1.cc", "dual2.aa", TokenOperator.EQUALITY)) .leftJoinThen("dual", "dual3", BinaryCondition.of("dual.xx", "dual3.xx", TokenOperator.EQUALITY)) .getDSL(); @@ -79,7 +78,7 @@ void testSubTable() { @Test void testOrder() { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.select("a") .from("dual") .orderBy("a", OrderCondition.DESC) @@ -91,7 +90,7 @@ void testOrder() { @Test void testGroup() { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.select("z") .from("dual") .groupByOne("z") @@ -103,8 +102,8 @@ void testGroup() { @Test void testLimit() { - Operators.thenRest(() -> { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + cc.allio.uno.data.test.model.Operators.thenRest(() -> { + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.select("z") .from("dual") .page(1L, 10L) @@ -116,8 +115,8 @@ void testLimit() { }); // test pg - Operators.thenRest(() -> { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + cc.allio.uno.data.test.model.Operators.thenRest(() -> { + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.select("z") .from("dual") .page(1L, 10L) @@ -131,8 +130,8 @@ void testLimit() { @Test void testIn() { - Operators.thenRest(() -> { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + cc.allio.uno.data.test.model.Operators.thenRest(() -> { + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String sql = operator.select("z") .from("dual") .in("t1", "2", "2") @@ -147,8 +146,8 @@ void testIn() { @Test void testParse() { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); - Operators.thenRest(() -> { + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String s1 = "SELECT *\n" + "FROM dual"; String s1p = operator.parse(s1).getDSL(); @@ -156,7 +155,7 @@ void testParse() { return operator; }); - Operators.thenRest(() -> { + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String s2 = "SELECT z\n" + "FROM PUBLIC.dual\n" + "WHERE x LIKE 'zxc'"; @@ -165,7 +164,7 @@ void testParse() { return operator; }); - Operators.thenRest(() -> { + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String s3 = "SELECT z\n" + "FROM PUBLIC.dual\n" + "WHERE a LIKE 'a'\n" + @@ -175,7 +174,7 @@ void testParse() { return operator; }); - Operators.thenRest(() -> { + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String s4 = "SELECT z\n" + "FROM PUBLIC.dual\n" + "WHERE a = 'a'\n" + @@ -185,7 +184,7 @@ void testParse() { return operator; }); - Operators.thenRest(() -> { + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String s5 = "SELECT z\n" + "FROM PUBLIC.dual\n" + "WHERE (a = 'a'\n" + @@ -196,7 +195,7 @@ void testParse() { return operator; }); - Operators.thenRest(() -> { + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String s7 = "SELECT a\n" + "FROM PUBLIC.dual\n" + "ORDER BY a DESC"; @@ -205,7 +204,7 @@ void testParse() { return operator; }); - Operators.thenRest(() -> { + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String s8 = "SELECT z\n" + "FROM PUBLIC.dual\n" + "GROUP BY z"; @@ -214,7 +213,7 @@ void testParse() { return operator; }); - Operators.thenRest(() -> { + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String s9 = "SELECT z\n" + "FROM PUBLIC.dual\n" + "LIMIT 10, 0"; @@ -231,7 +230,7 @@ void testRecursive() { " UNION (SELECT sub.* FROM ((SELECT *\n" + "FROM org\n" + ") sub INNER JOIN biz_tree P ON P.ID = sub.parent_id))) SELECT * FROM biz_tree"; - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String dsl = operator.parse(sql).getDSL(); assertEquals("WITH RECURSIVE biz_tree AS (\n" + "\t\tSELECT *\n" + @@ -250,7 +249,7 @@ void testRecursive() { @Test void testPeelWhere() { - SQLQueryOperator operator = OperatorGroup.getOperator(SQLQueryOperator.class, OperatorKey.SQL); + SQLQueryOperator operator = Operators.getOperator(SQLQueryOperator.class, OperatorKey.SQL); String whereDSL = operator.eq("a", "a").getWhereDSL(); assertEquals("a = 'a'", whereDSL); diff --git a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLUpdateOperatorTest.java b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLUpdateOperatorTest.java index 266ad0cb..0e202259 100644 --- a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLUpdateOperatorTest.java +++ b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/dml/sql/SQLUpdateOperatorTest.java @@ -1,9 +1,8 @@ package cc.allio.uno.data.orm.dsl.dml.sql; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.dsl.OperatorKey; import cc.allio.uno.data.orm.dsl.sql.dml.SQLUpdateOperator; -import cc.allio.uno.data.test.model.Operators; import cc.allio.uno.data.test.model.User; import cc.allio.uno.test.BaseTestCase; import org.junit.jupiter.api.Test; @@ -12,7 +11,7 @@ public class SQLUpdateOperatorTest extends BaseTestCase { @Test void testSimplePojoInsert() { - SQLUpdateOperator updateOperator = OperatorGroup.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); + SQLUpdateOperator updateOperator = Operators.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); User user = new User(); user.setName("a"); String sql = updateOperator.from(User.class).updatePojo(user).getDSL(); @@ -22,7 +21,7 @@ void testSimplePojoInsert() { @Test void testUpdateWherePrepareValue() { - SQLUpdateOperator updateOperator = OperatorGroup.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); + SQLUpdateOperator updateOperator = Operators.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); updateOperator.eq("eq1", "eq1"); updateOperator.update("t11", "t11"); @@ -50,7 +49,7 @@ void testUpdateWherePrepareValue() { @Test void testSimpleUpdate() { - SQLUpdateOperator updateOperator = OperatorGroup.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); + SQLUpdateOperator updateOperator = Operators.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); User user = new User(); user.setName("test"); String sql = updateOperator.from(User.class).updatePojo(user).getDSL(); @@ -60,7 +59,7 @@ void testSimpleUpdate() { @Test void testWhereUpdate() { - SQLUpdateOperator updateOperator = OperatorGroup.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); + SQLUpdateOperator updateOperator = Operators.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); String sql = updateOperator.from("dual").update("a", "a").eq("a", "a").getDSL(); assertEquals("UPDATE PUBLIC.dual\n" + "SET a = 'a'\n" + @@ -69,7 +68,7 @@ void testWhereUpdate() { @Test void testComplexWhereUpdate() { - SQLUpdateOperator updateOperator = OperatorGroup.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); + SQLUpdateOperator updateOperator = Operators.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); String sql = updateOperator.from("dual").update("a", "a") .eq("a", "a") .eq("b", "b") @@ -88,9 +87,9 @@ void testComplexWhereUpdate() { @Test void testStrictFill() { - SQLUpdateOperator updateOperator = OperatorGroup.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); + SQLUpdateOperator updateOperator = Operators.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); - new Operators(updateOperator) + new cc.allio.uno.data.test.model.Operators(updateOperator) .then(() -> { String sql = updateOperator.from("dual") .update("a", null) @@ -121,8 +120,8 @@ void testStrictFill() { @Test void testParse() { - SQLUpdateOperator updateOperator = OperatorGroup.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); - Operators.thenRest(() -> { + SQLUpdateOperator updateOperator = Operators.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String sql = "UPDATE PUBLIC.dual\n" + "SET a = 'a'\n" + "WHERE a = 'a'\n" + @@ -132,7 +131,7 @@ void testParse() { return updateOperator; }); - Operators.thenRest(() -> { + cc.allio.uno.data.test.model.Operators.thenRest(() -> { String sql = "UPDATE PUBLIC.dual\n" + "SET a = 'a'\n" + "WHERE a = 'a'\n" + @@ -148,7 +147,7 @@ void testParse() { @Test void testStrictModelUpdate() { - SQLUpdateOperator updateOperator = OperatorGroup.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); + SQLUpdateOperator updateOperator = Operators.getOperator(SQLUpdateOperator.class, OperatorKey.SQL); User user = new User(); user.setId(1L); String sql = updateOperator.updatePojo(user).getDSL(); diff --git a/uno-data/uno-data-test/src/main/java/cc/allio/uno/data/test/executor/FakeCommandExecutor.java b/uno-data/uno-data-test/src/main/java/cc/allio/uno/data/test/executor/FakeCommandExecutor.java index 69c112ea..018ec08d 100644 --- a/uno-data/uno-data-test/src/main/java/cc/allio/uno/data/test/executor/FakeCommandExecutor.java +++ b/uno-data/uno-data-test/src/main/java/cc/allio/uno/data/test/executor/FakeCommandExecutor.java @@ -2,7 +2,7 @@ import cc.allio.uno.core.exception.Exceptions; import cc.allio.uno.data.orm.dsl.Operator; -import cc.allio.uno.data.orm.dsl.opeartorgroup.OperatorGroup; +import cc.allio.uno.data.orm.dsl.opeartorgroup.Operators; import cc.allio.uno.data.orm.executor.AggregateCommandExecutor; import cc.allio.uno.data.orm.executor.CommandType; import cc.allio.uno.data.orm.executor.handler.ListResultSetHandler; @@ -36,7 +36,7 @@ public ExecutorKey getKey() { } @Override - public OperatorGroup getOperatorGroup() { + public Operators getOperatorGroup() { return null; }