Skip to content

Commit

Permalink
Merge pull request #26 from ClearXs/1.1.x
Browse files Browse the repository at this point in the history
feat: improvement Tree Traversal and add Before-Post-Compensate Opera…
  • Loading branch information
ClearXs committed Jul 26, 2024
2 parents c9996a4 + 6b60751 commit bb9aff2
Show file tree
Hide file tree
Showing 71 changed files with 862 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T extends TraversalElement<T>> void doTraversal(T e, Visitor<T> visitor) {
Expand All @@ -28,7 +28,7 @@ public <T extends TraversalElement<T>> void doTraversal(T e, Visitor<T> visitor)
}

@Override
public Traversal getMode() {
return Traversal.BREADTH;
public String getMode() {
return Traversal.BREADTH.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T extends TraversalElement<T>> void doTraversal(T e, Visitor<T> visitor) {
Expand All @@ -36,7 +36,7 @@ private <T extends TraversalElement<T>> void deepAccept(List<T> childrens, Deque
}

@Override
public Traversal getMode() {
return Traversal.DEEP;
public String getMode() {
return Traversal.DEEP.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,17 @@ default void accept(Visitor<T> visitor) {
* @param visitor visitor
* @param traversal 遍历原则
*/
void accept(Visitor<T> visitor, Traversal traversal);
default void accept(Visitor<T> visitor, Traversal traversal) {
accept(visitor, TraversalMethod.get(traversal));
}

/**
* 树的访问
*
* @param visitor visitor
* @param method traversal method
*/
void accept(Visitor<T> visitor, TraversalMethod method);

/**
* 获取Sentinel结点
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T extends TraversalElement<T>> void doTraversal(T e, Visitor<T> 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();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package cc.allio.uno.core.datastructure.tree;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* 规则树遍历方式
* <ul>
Expand All @@ -8,6 +11,13 @@
* <li>{@link #BREADTH}:广度优先</li>
* </ul>
*/
@AllArgsConstructor
@Getter
public enum Traversal {
NONE, DEEP, BREADTH;

NONE("NONE"),
DEEP("NONE"),
BREADTH("NONE");

private final String value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
public abstract class TraversalElement<T extends TraversalElement<T>> implements Element<T> {

@Override
public void accept(Visitor<T> visitor, Traversal traversal) {
TraversalMode.get(traversal).doTraversal((T) this, visitor);
public void accept(Visitor<T> visitor, TraversalMethod method) {
method.doTraversal((T) this, visitor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
* @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();

/**
* 根据遍历的方式获取对应的遍历实例
*
* @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);
Expand All @@ -44,5 +44,7 @@ static TraversalMode get(Traversal traversal) {
*
* @return Traversal
*/
Traversal getMode();
default String getMode() {
return "custom";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
* <p>
* DSL means Domain Specific Language. description Data Operation.
* </p>
*
* <p>
* it fulfil before-current-catch-post model.
* <ol>
* <li>the before {@link #getBeforeOperatorList()}</li>
* <li>the current</li>
* <li>the error compensate operator {@link #getCompensateOperatorList()}</li>
* <li>the success post operator {@link #getPostOperatorList()} </li>
* </ol>
* </p>
* <p>
* through
* </p>
*
* @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<T extends Operator<T>> extends Self<T> {

Expand Down Expand Up @@ -138,6 +176,45 @@ static Class<? extends Operator<?>> getHierarchicalType(Class<? extends Operator
return operatorType;
}

// ----------------------- executing enhance -----------------------

/**
* get current {@link Operator} before execute {@link Operator} list
*
* @return the pre {@link Operator} list
*/
default List<Operator<?>> getBeforeOperatorList() {
return Collections.emptyList();
}

/**
* get current {@link Operator} after execute {@link Operator} list
*
* @return the post {@link Operator} list
*/
default List<Operator<?>> 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<Operator<?>> 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 分组注解
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T extends UnrecognizedOperator<T>> extends Operator<T> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +14,7 @@
*
* @author j.x
* @date 2023/6/8 19:21
* @see OperatorGroup
* @see Operators
* @since 1.1.4
*/
public interface AlterTableOperator<T extends AlterTableOperator<T>> extends Operator<T>, Self<T>, TableOperator<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,7 +15,7 @@
*
* @author j.x
* @date 2023/4/12 19:42
* @see OperatorGroup
* @see Operators
* @since 1.1.4
*/
public interface CreateTableOperator<T extends CreateTableOperator<T>> extends Operator<T>, TableOperator<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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;

/**
* Drop Operator
*
* @author j.x
* @date 2023/4/16 12:52
* @see OperatorGroup
* @see Operators
* @since 1.1.4
*/
public interface DropTableOperator<T extends DropTableOperator<T>> extends Operator<T>, TableOperator<T> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -10,7 +10,7 @@
* @author j.x
* @date 2023/4/17 09:46
* @since 1.1.4
* @see OperatorGroup
* @see Operators
*/
public interface ExistTableOperator<T extends ExistTableOperator<T>> extends PrepareOperator<T>, TableOperator<T> {
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +11,7 @@
*
* @author j.x
* @date 2023/6/8 19:19
* @see OperatorGroup
* @see Operators
* @since 1.1.4
*/
public interface ShowColumnsOperator<T extends ShowColumnsOperator<T>> extends PrepareOperator<T>, TableOperator<T>, DataBaseOperator<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends ShowTablesOperator<T>> extends TableOperator<T>, PrepareOperator<T>, DataBaseOperator<T> {
Expand Down
Loading

0 comments on commit bb9aff2

Please sign in to comment.