This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 9d5edbb  add owner t oken and combination token (#10059)
9d5edbb is described below

commit 9d5edbb414b8a8511e191cc3fa15e8ca54c85dae
Author: huanghao495430759 <[email protected]>
AuthorDate: Tue Apr 13 04:31:23 2021 -0500

    add owner t oken and combination token (#10059)
    
    * add CombinationalSQLToken.
    
    add OwnerToken to save column's owner information.
    
    Co-authored-by: huanghao-jk <[email protected]>
---
 .../token/pojo/generic/CombinationalSQLToken.java  | 60 ++++++++++++++++
 .../rewrite/sql/token/pojo/generic/OwnerToken.java | 79 ++++++++++++++++++++++
 2 files changed, 139 insertions(+)

diff --git 
a/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/CombinationalSQLToken.java
 
b/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/CombinationalSQLToken.java
new file mode 100644
index 0000000..4929c2e
--- /dev/null
+++ 
b/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/CombinationalSQLToken.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic;
+
+import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
+import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.Substitutable;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+/**
+ * Combinational sql token.
+ */
+public final class CombinationalSQLToken extends SQLToken implements 
Substitutable {
+
+    private final Collection<SQLToken> sqlTokens = new LinkedList<>();
+
+    private final int stopIndex;
+
+    public CombinationalSQLToken(final int startIndex, final int stopIndex) {
+        super(startIndex);
+        this.stopIndex = stopIndex;
+    }
+
+    /**
+     * add sql token.
+     * @param sqlToken sql token
+     */
+    public void addSQLToken(final SQLToken sqlToken) {
+        this.sqlTokens.add(sqlToken);
+    }
+
+    /**
+     * get sql tokens.
+     * @return sql tokens
+     */
+    public Collection<SQLToken> getSQLTokens() {
+        return sqlTokens;
+    }
+
+    @Override
+    public int getStopIndex() {
+        return stopIndex;
+    }
+}
diff --git 
a/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/OwnerToken.java
 
b/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/OwnerToken.java
new file mode 100644
index 0000000..638c48e
--- /dev/null
+++ 
b/shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/pojo/generic/OwnerToken.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic;
+
+import lombok.Getter;
+import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.RouteUnitAware;
+import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
+import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.Substitutable;
+import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.QuoteCharacter;
+
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Owner token.
+ */
+public final class OwnerToken extends SQLToken implements Substitutable, 
RouteUnitAware {
+
+    @Getter
+    private final int stopIndex;
+
+    private final String ownerName;
+
+    private final String tableName;
+
+    private final QuoteCharacter quoteCharacter;
+
+    public OwnerToken(final int startIndex, final int stopIndex, final String 
ownerName, final String tableName, final QuoteCharacter quoteCharacter) {
+        super(startIndex);
+        this.stopIndex = stopIndex;
+        this.ownerName = ownerName;
+        this.tableName = tableName;
+        this.quoteCharacter = quoteCharacter;
+    }
+
+    @Override
+    public String toString(final RouteUnit routeUnit) {
+        if (Objects.nonNull(ownerName) && tableName.equals(ownerName)) {
+            Set<String> actualTableNames = 
routeUnit.getActualTableNames(tableName);
+            String actualTableName = actualTableNames.isEmpty() ? 
tableName.toLowerCase() : actualTableNames.iterator().next();
+            return getQuoteCharacter().wrap(actualTableName) + ".";
+        }
+        return toString();
+    }
+
+    @Override
+    public String toString() {
+        return Objects.isNull(ownerName) ? "" : 
getQuoteCharacter().wrap(ownerName) + ".";
+    }
+
+    @Override
+    public int getStopIndex() {
+        return stopIndex;
+    }
+
+    /**
+     * get QuoteCharacter.
+     * @return column QuoteCharacter
+     */
+    public QuoteCharacter getQuoteCharacter() {
+        return Objects.nonNull(quoteCharacter) ? quoteCharacter : 
QuoteCharacter.NONE;
+    }
+}

Reply via email to