- * Licensed 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.
- *
Ignore interrupt and connection invalid exception.
- *
- * @param cause to be handled exception
- */
- public static void handleException(final Exception cause) {
- if (null == cause) {
- return;
- }
- if (isIgnoredException(cause) || null != cause.getCause() && isIgnoredException(cause.getCause())) {
- log.debug("Ignored exception for: {}", cause.getMessage());
- } else if (cause instanceof InterruptedException) {
- Thread.currentThread().interrupt();
- } else {
- throw new RegistryCenterException(cause);
- }
- }
-
- private static boolean isIgnoredException(final Throwable cause) {
- return cause instanceof ConnectionLossException || cause instanceof NoNodeException || cause instanceof NodeExistsException;
- }
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/NativeZookeeperRegistryCenter.java b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/NativeZookeeperRegistryCenter.java
deleted file mode 100644
index 2cc8ba1224b52..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/NativeZookeeperRegistryCenter.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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 io.shardingsphere.orchestration.reg.zookeeper.natived.client.action;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-
-/**
- * One action contains a group operation.
- *
- * @author lidongbo
- */
-public interface IGroupAction {
-
- /**
- * Create target node and all need created.
- *
- * @param key key
- * @param value value
- * @param createMode create mode
- * @throws KeeperException zookeeper exception
- * @throws InterruptedException interrupted exception
- */
- void createAllNeedPath(String key, String value, CreateMode createMode) throws KeeperException, InterruptedException;
-
- /**
- * Delete target node and children nodes.
- *
- * @param key key
- * @throws KeeperException zookeeper exception
- * @throws InterruptedException interrupted exception
- */
- void deleteAllChildren(String key) throws KeeperException, InterruptedException;
-
- /**
- * Delete the current node with force and delete the super node whose only child node is current node recursively.
- *
- * @param key key
- * @throws KeeperException zookeeper exception
- * @throws InterruptedException interrupted exception
- */
- void deleteCurrentBranch(String key) throws KeeperException, InterruptedException;
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/action/IProvider.java b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/action/IProvider.java
deleted file mode 100644
index 161f6d78cee9b..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/action/IProvider.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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 io.shardingsphere.orchestration.reg.zookeeper.natived.client.election;
-
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.action.IProvider;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.utility.PathUtil;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.utility.ZookeeperConstants;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.section.WatcherCreator;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.section.ZookeeperEventListener;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.WatchedEvent;
-
-/**
- * Competition of node write permission.
- * It is not recommended to be used as a global variable.
- *
- * @author lidongbo
- */
-@Slf4j
-public abstract class LeaderElection {
-
- private int retryCount = ZookeeperConstants.NODE_ELECTION_RETRY;
-
- private boolean done;
-
- /**
- * Listener will be register when the contention of the path is unsuccessful.
- *
- * @param nodeBeContend node be contend
- * @param provider provider
- * @throws KeeperException zookeeper exception
- * @throws InterruptedException interrupted exception
- */
- public void executeContention(final String nodeBeContend, final IProvider provider) throws KeeperException, InterruptedException {
- boolean canBegin;
- final String realNode = provider.getRealPath(nodeBeContend);
- String contendNode = PathUtil.getRealPath(realNode, ZookeeperConstants.CHANGING_KEY);
- canBegin = contend(contendNode, provider, new ZookeeperEventListener(contendNode) {
-
- @Override
- public void process(final WatchedEvent event) {
- try {
- retryCount--;
- if (retryCount < 0) {
- return;
- }
- executeContention(realNode, provider);
- } catch (final KeeperException | InterruptedException ex) {
- log.error("Listener Exception executeContention:{}", ex.getMessage(), ex);
- }
- }
- });
- if (canBegin) {
- try {
- action();
- done = true;
- callback();
- } catch (final KeeperException | InterruptedException ex) {
- log.error("action Exception executeContention:{}", ex.getMessage(), ex);
- }
- provider.delete(contendNode);
- }
- }
-
- private boolean contend(final String node, final IProvider provider, final ZookeeperEventListener zookeeperEventListener) throws KeeperException, InterruptedException {
- boolean result = false;
- try {
- // TODO EPHEMERAL_SEQUENTIAL check index value
- provider.create(node, ZookeeperConstants.CLIENT_ID, CreateMode.EPHEMERAL);
- result = true;
- } catch (final KeeperException.NodeExistsException ex) {
- log.info("contend not result");
- // TODO or changing_key node value == current client id
- provider.exists(node, WatcherCreator.deleteWatcher(zookeeperEventListener));
- }
- return result;
- }
-
- /**
- * Wait done.
- */
- public void waitDone() {
- while (!done) {
- try {
- Thread.sleep(10L);
- } catch (final InterruptedException ex) {
- log.error("waitDone:{}", ex.getMessage(), ex);
- }
- }
- }
-
- /**
- * Contend execute.
- *
- * @throws KeeperException zookeeper exception
- * @throws InterruptedException interrupted exception
- */
- public abstract void action() throws KeeperException, InterruptedException;
-
- /**
- * Callback.
- */
- public void callback() {
- }
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/retry/AsyncRetryCenter.java b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/retry/AsyncRetryCenter.java
deleted file mode 100644
index a2b21f2f70238..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/retry/AsyncRetryCenter.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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.
- *
- * Licensed 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 io.shardingsphere.orchestration.reg.zookeeper.natived.client.retry;
-
-import lombok.RequiredArgsConstructor;
-
-import java.util.Random;
-
-/**
- * Delay policy executor.
- *
- * @author lidongbo
- */
-@RequiredArgsConstructor
-public final class DelayPolicyExecutor {
-
- private final DelayRetryPolicy delayRetryPolicy;
-
- private final Random random = new Random();
-
- private int executeCount;
-
- private long executeTick = System.currentTimeMillis();
-
- /**
- * Has next.
- *
- * @return has next
- */
- public boolean hasNext() {
- return executeCount < delayRetryPolicy.getRetryCount();
- }
-
- /**
- * Next execute tick.
- *
- * @return next execute tick
- */
- public long getNextTick() {
- return executeTick;
- }
-
- /**
- * Next.
- */
- public void next() {
- executeCount++;
- long sleep = delayRetryPolicy.getBaseDelay() * Math.max(1, this.random.nextInt(1 << delayRetryPolicy.getRetryCount() + 1));
- if (sleep < delayRetryPolicy.getDelayUpperBound()) {
- executeTick += sleep;
- } else {
- executeTick += delayRetryPolicy.getDelayUpperBound();
- }
- }
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/retry/DelayRetryPolicy.java b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/retry/DelayRetryPolicy.java
deleted file mode 100644
index 0187fc21b0d8c..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/retry/DelayRetryPolicy.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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 io.shardingsphere.orchestration.reg.zookeeper.natived.client.retry;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
-/**
- * Delay policy.
- *
- * @author lidongbo
- */
-@RequiredArgsConstructor
-@Getter
-public class DelayRetryPolicy {
-
- private static final long BASE_DELAY = 10;
-
- private static final int BASE_COUNT = 3;
-
- private static final int RETRY_COUNT_BOUND = 29;
-
- private final int retryCount;
-
- private final long baseDelay;
-
- private final long delayUpperBound;
-
- public DelayRetryPolicy(final long baseDelay) {
- this(RETRY_COUNT_BOUND, baseDelay, Integer.MAX_VALUE);
- }
-
- /**
- * Default delay policy.
- *
- * @return delay policy
- */
- public static DelayRetryPolicy defaultDelayPolicy() {
- return new DelayRetryPolicy(BASE_COUNT, BASE_DELAY, Integer.MAX_VALUE);
- }
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/retry/RetryCallable.java b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/retry/RetryCallable.java
deleted file mode 100644
index ded980ce40c8a..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/retry/RetryCallable.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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 io.shardingsphere.orchestration.reg.zookeeper.natived.client.utility;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Stack;
-
-/**
- * Path util.
- *
- * @author lidongbo
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class PathUtil {
-
- /**
- * Get real path.
- *
- * @param root root
- * @param path path
- * @return real path
- */
- public static String getRealPath(final String root, final String path) {
- return adjustPath(root, path);
- }
-
- private static String adjustPath(final String root, final String path) {
- if (Strings.isNullOrEmpty(path)) {
- throw new IllegalArgumentException("path should have content!");
- }
- String rootPath = root;
- if (!root.startsWith(ZookeeperConstants.PATH_SEPARATOR)) {
- rootPath = ZookeeperConstants.PATH_SEPARATOR + root;
- }
- String realPath = path;
- if (!path.startsWith(ZookeeperConstants.PATH_SEPARATOR)) {
- realPath = ZookeeperConstants.PATH_SEPARATOR + path;
- }
- if (!realPath.startsWith(rootPath)) {
- return rootPath + realPath;
- }
- return realPath;
- }
-
- /**
- * Get path nodes, child to root.
- *
- * @param root root
- * @param path path
- * @return all path nodes
- */
- public static Stack getPathReverseNodes(final String root, final String path) {
- String realPath = adjustPath(root, path);
- Stack pathStack = new Stack<>();
- int index = 1;
- int position = realPath.indexOf(ZookeeperConstants.PATH_SEPARATOR, index);
- do {
- pathStack.push(realPath.substring(0, position));
- index = position + 1;
- position = realPath.indexOf(ZookeeperConstants.PATH_SEPARATOR, index);
- }
- while (position > -1);
- pathStack.push(realPath);
- return pathStack;
- }
-
- /**
- * Get path nodes.
- *
- * @param root root
- * @param path path
- * @return all path nodes
- */
- public static List getPathOrderNodes(final String root, final String path) {
- String realPath = adjustPath(root, path);
- List paths = new ArrayList<>();
- int index = 1;
- int position = realPath.indexOf(ZookeeperConstants.PATH_SEPARATOR, index);
-
- do {
- paths.add(realPath.substring(0, position));
- index = position + 1;
- position = realPath.indexOf(ZookeeperConstants.PATH_SEPARATOR, index);
- }
- while (position > -1);
- paths.add(realPath);
- return paths;
- }
-
- /**
- * Get path nodes.
- *
- * @param path path
- * @return all path nodes
- */
- public static List getShortPathNodes(final String path) {
- String realPath = checkPath(path);
- List paths = new ArrayList<>();
- char[] chars = realPath.toCharArray();
- StringBuilder builder = new StringBuilder(ZookeeperConstants.PATH_SEPARATOR);
- for (int i = 1; i < chars.length; i++) {
- if (chars[i] == ZookeeperConstants.PATH_SEPARATOR.charAt(0)) {
- paths.add(builder.toString());
- builder = new StringBuilder(ZookeeperConstants.PATH_SEPARATOR);
- continue;
- }
- builder.append(chars[i]);
- if (i == chars.length - 1) {
- paths.add(builder.toString());
- }
- }
- return paths;
- }
-
- /**
- * Ignore invalid char and // /./ /../.
- * code consult zookeeper
- *
- * @param key key
- * @return real path
- * @throws IllegalArgumentException IllegalArgumentException
- */
- // CHECKSTYLE:OFF
- public static String checkPath(final String key) {
- // CHECKSTYLE:ON
- Preconditions.checkNotNull(key, "path should not be null");
-
- String path = key;
- if (path.charAt(0) != 47 || path.charAt(path.length() - 1) == 47) {
- path = ZookeeperConstants.PATH_SEPARATOR + path;
- }
-
- if (path.charAt(path.length() - 1) == 47) {
- path = ZookeeperConstants.PATH_SEPARATOR + path;
- }
-
- char previous = 47;
- char[] chars = path.toCharArray();
- StringBuilder builder = new StringBuilder();
- builder.append(previous);
-
- for (int i = 1; i < chars.length; ++i) {
- char c = chars[i];
- if (c == 0 || (c == 47 && previous == 47)) {
- continue;
- }
- if (c == 46) {
- // ignore /./ /../
- boolean preWarn = previous == 47 || (previous == 46 && chars[i - 2] == 47);
- if (previous == 47 && (i + 1 == chars.length || chars[i + 1] == 47)) {
- // CHECKSTYLE:OFF
- i++;
- continue;
- }
- if ((previous == 46 && chars[i - 2] == 47) && (i + 1 == chars.length || chars[i + 1] == 47)) {
- i += 2;
- continue;
- }
- }
-
- if (c > 0 && c < 31 || c > 127 && c < 159 || c > '\ud800' && c < '\uf8ff' || c > '\ufff0' && c < '\uffff') {
- // CHECKSTYLE:ON
- continue;
- }
-
- builder.append(c);
- previous = c;
- }
- return builder.toString();
- }
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/utility/ZookeeperConstants.java b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/utility/ZookeeperConstants.java
deleted file mode 100644
index 84de60548c1fb..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/utility/ZookeeperConstants.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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 io.shardingsphere.orchestration.reg.zookeeper.natived.client.utility;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import java.nio.charset.Charset;
-
-/**
- * Zookeeper client constants.
- *
- * @author lidongbo
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ZookeeperConstants {
-
- public static final int VERSION = -1;
-
- public static final int WAIT = 60 * 1000;
-
- public static final byte[] NOTHING_DATA = new byte[0];
-
- public static final String NOTHING_VALUE = "";
-
- public static final Charset UTF_8 = Charset.forName("UTF-8");
-
- public static final String PATH_SEPARATOR = "/";
-
- public static final String GLOBAL_LISTENER_KEY = "globalListener";
-
- public static final String ROOT_INIT_PATH = "/InitValue";
-
- public static final byte[] CHANGING_VALUE = new byte[]{'c'};
-
- public static final byte[] RELEASE_VALUE = new byte[]{'r'};
-
- public static final String CHANGING_KEY = "CHANGING_KEY";
-
- public static final long THREAD_PERIOD = 3000L;
-
- public static final long THREAD_INITIAL_DELAY = 1000L;
-
- public static final int NODE_ELECTION_RETRY = 3;
-
- public static final String CLIENT_ID = "1";
-
- public static final boolean WATCHED = true;
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/CacheClient.java b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/CacheClient.java
deleted file mode 100644
index 37e2a9a7ced12..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/CacheClient.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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 io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.provider;
-
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.action.IProvider;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.election.LeaderElection;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.utility.PathUtil;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.utility.ZookeeperConstants;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.base.Holder;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.transaction.BaseTransaction;
-import lombok.AccessLevel;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.zookeeper.AsyncCallback;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.Watcher;
-import org.apache.zookeeper.data.ACL;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Stack;
-
-/**
- * Base provider.
- *
- * @author lidongbo
- */
-@RequiredArgsConstructor
-@Slf4j
-public class BaseProvider implements IProvider {
-
- @Getter
- private final String rootNode;
-
- @Getter
- private final Holder holder;
-
- @Getter(value = AccessLevel.PROTECTED)
- private final boolean watched;
-
- @Getter(value = AccessLevel.PROTECTED)
- private final List authorities;
-
- @Override
- public final String getDataString(final String key) throws KeeperException, InterruptedException {
- return new String(getData(key));
- }
-
- @Override
- public final byte[] getData(final String key) throws KeeperException, InterruptedException {
- return holder.getZooKeeper().getData(key, watched, null);
- }
-
- @Override
- public final void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) {
- holder.getZooKeeper().getData(key, watched, callback, ctx);
- }
-
- @Override
- public final boolean exists(final String key) throws KeeperException, InterruptedException {
- return null != holder.getZooKeeper().exists(key, watched);
- }
-
- @Override
- public final boolean exists(final String key, final Watcher watcher) throws KeeperException, InterruptedException {
- return null != holder.getZooKeeper().exists(key, watcher);
- }
-
- @Override
- public final List getChildren(final String key) throws KeeperException, InterruptedException {
- return holder.getZooKeeper().getChildren(key, watched);
- }
-
- @Override
- public final void create(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException {
- if (exists(key)) {
- return;
- }
- holder.getZooKeeper().create(key, value.getBytes(ZookeeperConstants.UTF_8), authorities, createMode);
- }
-
- @Override
- public final boolean update(final String key, final String value) throws KeeperException, InterruptedException {
- if (exists(key)) {
- holder.getZooKeeper().setData(key, value.getBytes(ZookeeperConstants.UTF_8), ZookeeperConstants.VERSION);
- return true;
- }
- return false;
- }
-
- @Override
- public final void delete(final String key) throws KeeperException, InterruptedException {
- holder.getZooKeeper().delete(key, ZookeeperConstants.VERSION);
- }
-
- @Override
- public final void delete(final String key, final AsyncCallback.VoidCallback callback, final Object ctx) {
- holder.getZooKeeper().delete(key, ZookeeperConstants.VERSION, callback, ctx);
- }
-
- @Override
- public final String getRealPath(final String path) {
- return PathUtil.getRealPath(rootNode, path);
- }
-
- @Override
- public final List getNecessaryPaths(final String key) {
- List nodes = PathUtil.getPathOrderNodes(rootNode, key);
- nodes.remove(rootNode);
- return nodes;
- }
-
- @Override
- public final Stack getDeletingPaths(final String key) {
- return PathUtil.getPathReverseNodes(rootNode, key);
- }
-
- @Override
- public final void executeContention(final LeaderElection election) throws KeeperException, InterruptedException {
- this.executeContention(rootNode, election);
- }
-
- private void executeContention(final String nodeBeCompete, final LeaderElection election) throws KeeperException, InterruptedException {
- election.executeContention(nodeBeCompete, this);
- }
-
- @Override
- public final void resetConnection() {
- try {
- holder.reset();
- } catch (final InterruptedException | IOException ex) {
- log.error("resetConnection Exception: {}", ex.getMessage(), ex);
- }
- }
-
- @Override
- public BaseTransaction transaction() {
- return new BaseTransaction();
- }
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/provider/TransactionProvider.java b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/provider/TransactionProvider.java
deleted file mode 100644
index 93f003f7fa966..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/provider/TransactionProvider.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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 io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.provider;
-
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.action.ITransactionProvider;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.utility.ZookeeperConstants;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.base.Holder;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.transaction.BaseTransaction;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.transaction.ZooKeeperTransaction;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.data.ACL;
-
-import java.util.List;
-
-/**
- * Provider with transaction.
- *
- * @author lidongbo
- */
-public final class TransactionProvider extends BaseProvider implements ITransactionProvider {
-
- public TransactionProvider(final String rootNode, final Holder holder, final boolean watched, final List authorities) {
- super(rootNode, holder, watched, authorities);
- }
-
- @Override
- public void createInTransaction(final String key, final String value, final CreateMode createMode, final BaseTransaction transaction) {
- transaction.create(key, value.getBytes(ZookeeperConstants.UTF_8), getAuthorities(), createMode);
- }
-
- @Override
- public BaseTransaction transaction() {
- return new ZooKeeperTransaction(getRootNode(), getHolder());
- }
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/section/ClientContext.java b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/section/ClientContext.java
deleted file mode 100644
index dccc3093c4162..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/section/ClientContext.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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 io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.strategy;
-
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.action.ContentionCallback;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.action.IProvider;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.election.LeaderElection;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.utility.PathUtil;
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.utility.ZookeeperConstants;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.zookeeper.AsyncCallback;
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-
-import java.util.List;
-import java.util.Stack;
-
-/**
- * The contention strategy is effective only when all the clients of the node which be competitive are using contention strategy.
- *
- * @author lidongbo
- */
-@Slf4j
-public class ContentionStrategy extends UsualStrategy {
-
- public ContentionStrategy(final IProvider provider) {
- super(provider);
- }
-
- /*
- * Don't use this if you don't have to use it.
- */
- @Override
- public final void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) throws KeeperException, InterruptedException {
- getProvider().executeContention(new LeaderElection() {
-
- @Override
- public void action() throws KeeperException, InterruptedException {
- getProvider().getData(getProvider().getRealPath(key), callback, ctx);
- }
- });
- }
-
- @Override
- public final void createCurrentOnly(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException {
- LeaderElection election = buildCreateElection(key, value, createMode, null);
- getProvider().executeContention(election);
- election.waitDone();
- }
-
- private LeaderElection buildCreateElection(final String key, final String value, final CreateMode createMode, final ContentionCallback contentionCallback) {
- return new LeaderElection() {
-
- @Override
- public void action() throws KeeperException, InterruptedException {
- getProvider().create(getProvider().getRealPath(key), value, createMode);
- }
-
- @Override
- public void callback() {
- if (null != contentionCallback) {
- contentionCallback.processResult();
- }
- }
- };
- }
-
- @Override
- public final void update(final String key, final String value) throws KeeperException, InterruptedException {
- LeaderElection election = buildUpdateElection(key, value, null);
- getProvider().executeContention(election);
- election.waitDone();
- }
-
- private LeaderElection buildUpdateElection(final String key, final String value, final ContentionCallback contentionCallback) {
- return new LeaderElection() {
-
- @Override
- public void action() throws KeeperException, InterruptedException {
- getProvider().update(getProvider().getRealPath(key), value);
- }
-
- @Override
- public void callback() {
- if (null != contentionCallback) {
- contentionCallback.processResult();
- }
- }
- };
- }
-
- @Override
- public final void deleteOnlyCurrent(final String key) throws KeeperException, InterruptedException {
- LeaderElection election = buildDeleteElection(key, null);
- getProvider().executeContention(election);
- election.waitDone();
- }
-
- @Override
- public final void deleteOnlyCurrent(final String key, final AsyncCallback.VoidCallback callback, final Object ctx) throws KeeperException, InterruptedException {
- getProvider().executeContention(new LeaderElection() {
-
- @Override
- public void action() throws KeeperException, InterruptedException {
- getProvider().delete(getProvider().getRealPath(key), callback, ctx);
- }
- });
- }
-
- private LeaderElection buildDeleteElection(final String key, final ContentionCallback contentionCallback) {
- return new LeaderElection() {
-
- @Override
- public void action() throws KeeperException, InterruptedException {
- getProvider().delete(getProvider().getRealPath(key));
- }
-
- @Override
- public void callback() {
- if (null != contentionCallback) {
- contentionCallback.processResult();
- }
- }
- };
- }
-
- @Override
- public void createAllNeedPath(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException {
- LeaderElection election = buildCreateAllNeedElection(key, value, createMode, null);
- getProvider().executeContention(election);
- election.waitDone();
- }
-
- private LeaderElection buildCreateAllNeedElection(final String key, final String value, final CreateMode createMode, final ContentionCallback contentionCallback) {
- return new LeaderElection() {
-
- @Override
- public void action() throws KeeperException, InterruptedException {
- createBegin(getProvider().getRealPath(key), value, createMode);
- }
-
- @Override
- public void callback() {
- if (null != contentionCallback) {
- contentionCallback.processResult();
- }
- }
- };
- }
-
- private void createBegin(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException {
- // TODO start with /
- if (!key.contains(ZookeeperConstants.PATH_SEPARATOR)) {
- getProvider().create(key, value, createMode);
- return;
- }
- List nodes = getProvider().getNecessaryPaths(key);
- for (int i = 0; i < nodes.size(); i++) {
- if (getProvider().exists(nodes.get(i))) {
- continue;
- }
- if (i == nodes.size() - 1) {
- getProvider().create(nodes.get(i), value, createMode);
- } else {
- getProvider().create(nodes.get(i), ZookeeperConstants.NOTHING_VALUE, createMode);
- }
- }
- }
-
- @Override
- public void deleteAllChildren(final String key) throws KeeperException, InterruptedException {
- getProvider().executeContention(new LeaderElection() {
-
- @Override
- public void action() throws KeeperException, InterruptedException {
- deleteChildren(getProvider().getRealPath(key), true);
- }
- });
- }
-
- private void deleteChildren(final String key, final boolean deleteCurrentNode) throws KeeperException, InterruptedException {
- List children = getProvider().getChildren(key);
- for (String aChildren : children) {
- String child = PathUtil.getRealPath(key, aChildren);
- if (!getProvider().exists(child)) {
- continue;
- }
- deleteChildren(child, true);
- }
- if (deleteCurrentNode) {
- getProvider().delete(key);
- }
- }
-
- @Override
- public void deleteCurrentBranch(final String key) throws KeeperException, InterruptedException {
- getProvider().executeContention(new LeaderElection() {
-
- @Override
- public void action() throws KeeperException, InterruptedException {
- deleteBranch(getProvider().getRealPath(key));
- }
- });
- }
-
- private void deleteBranch(final String key) throws KeeperException, InterruptedException {
- deleteChildren(key, false);
- Stack pathStack = getProvider().getDeletingPaths(key);
- while (!pathStack.empty()) {
- String node = pathStack.pop();
- // contrast cache
- if (getProvider().exists(node)) {
- try {
- getProvider().delete(node);
- } catch (KeeperException.NotEmptyException e) {
- log.warn("deleteBranch {} exist other children: {}", node, this.getChildren(node));
- return;
- }
- }
- log.info("deleteBranch node not exist: {}", node);
- }
- }
-
- //TODO Use arbitrary competitive nodes
- //IExecStrategy convert to ContentionStrategy
- /*public void createCurrentOnly(final String key, final String value, final CreateMode createMode, final ContentionCallback callback) throws KeeperException, InterruptedException {
- getProvider().executeContention(buildCreateElection(key, value, createMode, callback));
- }
-
- public void update(final String key, final String value, final ContentionCallback callback) throws KeeperException, InterruptedException {
- getProvider().executeContention(buildUpdateElection(key, value, null));
- }
-
- public void deleteOnlyCurrent(final String key, final ContentionCallback callback) throws KeeperException, InterruptedException {
- getProvider().executeContention(buildDeleteElection(key, null));
- }*/
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/strategy/SyncRetryStrategy.java b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/strategy/SyncRetryStrategy.java
deleted file mode 100644
index 8f8f5f9ee6ab9..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/strategy/SyncRetryStrategy.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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 io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.transaction;
-
-import org.apache.zookeeper.CreateMode;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.OpResult;
-import org.apache.zookeeper.data.ACL;
-
-import java.util.List;
-
-/**
- * Base transaction.
- *
- * @author lidongbo
- */
-public class BaseTransaction {
-
- /**
- * Create target node.
- *
- * @param path key
- * @param data value
- * @param acl acl
- * @param createMode create mode
- * @return zookeeper transaction
- */
- public ZooKeeperTransaction create(final String path, final byte[] data, final List acl, final CreateMode createMode) {
- throw new UnsupportedOperationException("check zk version!");
- }
-
- /**
- * Delete target node.
- *
- * @param path key
- * @return zookeeper transaction
- */
- public ZooKeeperTransaction delete(final String path) {
- throw new UnsupportedOperationException("check zk version!");
- }
-
- /**
- * Delete target node.
- *
- * @param path key
- * @param version version
- * @return zookeeper transaction
- */
- public ZooKeeperTransaction delete(final String path, final int version) {
- throw new UnsupportedOperationException("check zk version!");
- }
-
- /**
- * Check target node.
- *
- * @param path key
- * @return zookeeper transaction
- */
- public ZooKeeperTransaction check(final String path) {
- throw new UnsupportedOperationException("check zk version!");
- }
-
-
- /**
- * Check target node.
- *
- * @param path key
- * @param version version
- * @return zookeeper transaction
- */
- public ZooKeeperTransaction check(final String path, final int version) {
- throw new UnsupportedOperationException("check zk version!");
- }
-
- /**
- * Update target node.
- *
- * @param path key
- * @param data data
- * @return zookeeper transaction
- */
- public ZooKeeperTransaction setData(final String path, final byte[] data) {
- throw new UnsupportedOperationException("check zk version!");
- }
-
- /**
- * Update target node.
- *
- * @param path key
- * @param data data
- * @param version version
- * @return zookeeper transaction
- */
- public ZooKeeperTransaction setData(final String path, final byte[] data, final int version) {
- throw new UnsupportedOperationException("check zk version!");
- }
-
- /**
- * Commit.
- *
- * @return operation result
- * @throws KeeperException zookeeper exception
- * @throws InterruptedException interrupted exception
- */
- public List commit() throws InterruptedException, KeeperException {
- throw new UnsupportedOperationException("check zk version!");
- }
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/transaction/ZooKeeperTransaction.java b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/transaction/ZooKeeperTransaction.java
deleted file mode 100644
index 2d99e7b2c512d..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/main/java/io/shardingsphere/orchestration/reg/zookeeper/natived/client/zookeeper/transaction/ZooKeeperTransaction.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2016-2018 shardingsphere.io.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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.
- *
- * Licensed 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 io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.base;
-
-import io.shardingsphere.orchestration.reg.zookeeper.natived.client.zookeeper.section.ZookeeperEventListener;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.zookeeper.WatchedEvent;
-
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-@Slf4j
-public final class TestSupport {
-
- public static final String AUTH = "digest";
-
- public static final String SERVERS = "localhost:3181";
-
- public static final int SESSION_TIMEOUT = 200000;
-
- public static final String ROOT = "test";
-
- /**
- * Test exec.
- *
- * @return listener ZookeeperEventListener
- */
- public static ZookeeperEventListener buildListener() {
- return new ZookeeperEventListener() {
-
- @Override
- public void process(final WatchedEvent event) {
- log.debug(event.toString());
- }
- };
- }
-}
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/test/resources/logback-test.xml b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/test/resources/logback-test.xml
deleted file mode 100644
index 0ac5601568948..0000000000000
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-native-zookeeper/src/test/resources/logback-test.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
- [%-5level] %d{HH:mm:ss.SSS} [%thread] %logger{36} - %msg%n
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-zookeeper-curator/pom.xml b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-zookeeper-curator/pom.xml
index c1b0d55d6c893..11f7fcb4f0273 100644
--- a/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-zookeeper-curator/pom.xml
+++ b/sharding-orchestration/sharding-orchestration-reg/sharding-orchestration-reg-zookeeper-curator/pom.xml
@@ -29,5 +29,10 @@
org.apache.curatorcurator-recipes
+
+
+ org.apache.curator
+ curator-test
+
From 768b740cacc29e75213762fa45a56dadc03ad719 Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Thu, 18 Oct 2018 22:29:07 +0800
Subject: [PATCH 03/10] use initShardingMetaData
---
.../shardingsphere/shardingproxy/runtime/GlobalRegistry.java | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java
index a104c077b42d1..19648c9365a9f 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java
@@ -35,6 +35,7 @@
import io.shardingsphere.orchestration.internal.event.state.ProxyDisabledStateEventBusEvent;
import io.shardingsphere.orchestration.internal.rule.OrchestrationMasterSlaveRule;
import io.shardingsphere.orchestration.internal.rule.OrchestrationShardingRule;
+import io.shardingsphere.shardingproxy.backend.BackendExecutorContext;
import io.shardingsphere.shardingproxy.runtime.nio.BackendNIOConfiguration;
import lombok.AccessLevel;
import lombok.Getter;
@@ -125,6 +126,7 @@ public void init(final YamlServerConfiguration serverConfig, final Map
Date: Thu, 18 Oct 2018 22:29:20 +0800
Subject: [PATCH 04/10] delete ShardingProxy()
---
.../shardingsphere/shardingproxy/frontend/ShardingProxy.java | 4 ----
1 file changed, 4 deletions(-)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/frontend/ShardingProxy.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/frontend/ShardingProxy.java
index 7edc83a17f262..65158e970b4fc 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/frontend/ShardingProxy.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/frontend/ShardingProxy.java
@@ -54,10 +54,6 @@ public final class ShardingProxy {
private EventLoopGroup userGroup;
- public ShardingProxy() {
- GLOBAL_REGISTRY.initShardingMetaData(backendExecutorContext.getExecuteEngine());
- }
-
/**
* Start Sharding-Proxy.
*
From da5558ca9a086e667ab698bd176287de8ec57ad1 Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Thu, 18 Oct 2018 22:29:53 +0800
Subject: [PATCH 05/10] use private
---
.../shardingproxy/runtime/GlobalRegistry.java | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java
index 19648c9365a9f..763fc0dc9e225 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java
@@ -148,12 +148,7 @@ private void initServerConfiguration(final YamlServerConfiguration serverConfig)
authentication = serverConfig.getAuthentication();
}
- /**
- * Initialize sharding meta data.
- *
- * @param executeEngine sharding execute engine
- */
- public void initShardingMetaData(final ShardingExecuteEngine executeEngine) {
+ private void initShardingMetaData(final ShardingExecuteEngine executeEngine) {
for (ShardingSchema each : shardingSchemas.values()) {
each.initShardingMetaData(executeEngine);
}
From cde48bcf57b3ed616e39fd63563cd464289f3965 Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Thu, 18 Oct 2018 22:39:23 +0800
Subject: [PATCH 06/10] add author
---
.../io/shardingsphere/shardingproxy/frontend/ShardingProxy.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/frontend/ShardingProxy.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/frontend/ShardingProxy.java
index 65158e970b4fc..b1b50a53c7593 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/frontend/ShardingProxy.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/frontend/ShardingProxy.java
@@ -41,6 +41,7 @@
* @author zhangliang
* @author xiaoyu
* @author wangkai
+ * @author panjuan
*/
public final class ShardingProxy {
From 29d02669a8870b96fa83a3926f0ac811b20439ee Mon Sep 17 00:00:00 2001
From: tristaZero
Date: Thu, 18 Oct 2018 22:39:59 +0800
Subject: [PATCH 07/10] java doc
---
.../io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java
index 763fc0dc9e225..549cae2bfeaa7 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/runtime/GlobalRegistry.java
@@ -53,6 +53,7 @@
* Global registry.
*
* @author chenqingyang
+ * @author panjuan
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
From 400324fd80fe70f8a032eab03b1e3a0a7308053b Mon Sep 17 00:00:00 2001
From: terrymanu
Date: Thu, 18 Oct 2018 23:24:52 +0800
Subject: [PATCH 08/10] add comparable for SQLToken
---
.../core/parsing/SQLJudgeEngine.java | 10 +-
.../clause/InsertColumnsClauseParser.java | 6 +-
.../parser/clause/InsertSetClauseParser.java | 4 +-
.../clause/InsertValuesClauseParser.java | 2 +-
.../parser/clause/SelectListClauseParser.java | 2 +-
.../clause/TableReferencesClauseParser.java | 6 +-
.../clause/UpdateSetItemsClauseParser.java | 2 +-
.../parser/clause/WhereClauseParser.java | 4 +-
.../expression/AliasExpressionParser.java | 2 +-
.../expression/BasicExpressionParser.java | 2 +-
.../mysql/clause/MySQLLimitClauseParser.java | 10 +-
.../dialect/mysql/sql/MySQLShowParser.java | 10 +-
.../clause/PostgreSQLLimitClauseParser.java | 4 +-
.../clause/SQLServerTopClauseParser.java | 2 +-
.../parser/sql/AbstractSQLStatement.java | 13 +-
.../core/parsing/parser/sql/SQLStatement.java | 13 +-
.../index/AbstractCreateIndexParser.java | 2 +-
.../drop/index/AbstractDropIndexParser.java | 4 +-
.../sql/dml/insert/AbstractInsertParser.java | 2 +-
.../sql/dml/insert/InsertStatement.java | 8 +-
.../sql/dql/select/AbstractSelectParser.java | 4 +-
.../sql/dql/select/SelectStatement.java | 9 +-
.../parser/token/GeneratedKeyToken.java | 11 +-
.../core/parsing/parser/token/IndexToken.java | 13 +-
.../parser/token/InsertColumnToken.java | 11 +-
.../parser/token/InsertValuesToken.java | 11 +-
.../core/parsing/parser/token/ItemsToken.java | 10 +-
.../parsing/parser/token/OffsetToken.java | 11 +-
.../parsing/parser/token/OrderByToken.java | 11 +-
.../parsing/parser/token/RemoveToken.java | 11 +-
.../parsing/parser/token/RowCountToken.java | 11 +-
.../core/parsing/parser/token/SQLToken.java | 19 +-
.../parsing/parser/token/SchemaToken.java | 13 +-
.../core/parsing/parser/token/TableToken.java | 12 +-
.../core/rewrite/SQLRewriteEngine.java | 22 +--
.../TableBroadcastRoutingEngine.java | 7 +-
.../optimizer/InsertOptimizeEngineTest.java | 4 +-
.../integrate/asserts/SQLStatementAssert.java | 2 +-
.../token/GeneratedKeyTokenAssert.java | 6 +-
.../asserts/token/IndexTokenAssert.java | 6 +-
.../token/InsertValuesTokenAssert.java | 6 +-
.../asserts/token/ItemsTokenAssert.java | 6 +-
.../asserts/token/OffsetTokenAssert.java | 6 +-
.../asserts/token/OrderByTokenAssert.java | 6 +-
.../asserts/token/RowCountTokenAssert.java | 6 +-
.../asserts/token/SchemaTokenAssert.java | 5 +-
.../asserts/token/TableTokenAssert.java | 5 +-
.../integrate/asserts/token/TokenAssert.java | 4 +-
.../core/rewrite/SQLRewriteEngineTest.java | 166 +++++++++---------
.../TableBroadcastRoutingEngineTest.java | 2 +-
.../backend/BackendHandlerFactory.java | 7 +-
.../rewrite/MasterSlaveSQLRewriteEngine.java | 27 +--
52 files changed, 279 insertions(+), 279 deletions(-)
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLJudgeEngine.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLJudgeEngine.java
index 4dad01a143ae6..5db73834f07db 100755
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLJudgeEngine.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/SQLJudgeEngine.java
@@ -161,7 +161,7 @@ private DALStatement parseShowTables(final LexerEngine lexerEngine) {
DALStatement result = new ShowTablesStatement();
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
- result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
+ result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
}
return result;
}
@@ -172,7 +172,7 @@ private DALStatement parseShowColumnsFields(final LexerEngine lexerEngine) {
parseSingleTableWithSchema(lexerEngine, result);
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
- result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
+ result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
}
return result;
}
@@ -182,7 +182,7 @@ private void parseSingleTableWithSchema(final LexerEngine lexerEngine, final SQL
String literals = lexerEngine.getCurrentToken().getLiterals();
lexerEngine.nextToken();
if (lexerEngine.skipIfEqual(Symbol.DOT)) {
- sqlStatement.getSqlTokens().add(new SchemaToken(beginPosition, literals, null));
+ sqlStatement.addSQLToken(new SchemaToken(beginPosition, literals, null));
lexerEngine.nextToken();
}
}
@@ -193,7 +193,7 @@ private DALStatement parseShowIndex(final LexerEngine lexerEngine) {
parseSingleTableWithSchema(lexerEngine, result);
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
- result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
+ result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
}
return result;
}
@@ -203,7 +203,7 @@ private DALStatement parseShowTableStatus(final LexerEngine lexerEngine) {
lexerEngine.nextToken();
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
- result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
+ result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), null));
}
return result;
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertColumnsClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertColumnsClauseParser.java
index f02b00333de2e..616329150527f 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertColumnsClauseParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertColumnsClauseParser.java
@@ -105,7 +105,7 @@ private Collection parseWithoutColumn(
final InsertStatement insertStatement, final ShardingTableMetaData shardingTableMetaData, final String tableName, final Optional generateKeyColumn) {
int count = 0;
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length() - 1;
- insertStatement.getSqlTokens().add(new InsertColumnToken(beginPosition, "("));
+ insertStatement.addSQLToken(new InsertColumnToken(beginPosition, "("));
ItemsToken columnsToken = new ItemsToken(beginPosition);
columnsToken.setFirstOfItemsSpecial(true);
Collection result = new LinkedList<>();
@@ -119,8 +119,8 @@ private Collection parseWithoutColumn(
count++;
}
}
- insertStatement.getSqlTokens().add(columnsToken);
- insertStatement.getSqlTokens().add(new InsertColumnToken(beginPosition, ")"));
+ insertStatement.addSQLToken(columnsToken);
+ insertStatement.addSQLToken(new InsertColumnToken(beginPosition, ")"));
insertStatement.setColumnsListLastPosition(beginPosition);
return result;
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertSetClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertSetClauseParser.java
index dd21f9186c637..3cf0315e19d94 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertSetClauseParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertSetClauseParser.java
@@ -77,7 +77,7 @@ public void parse(final InsertStatement insertStatement) {
removeUnnecessaryToken(insertStatement);
insertStatement.setGenerateKeyColumnIndex(-1);
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
- insertStatement.getSqlTokens().add(new InsertValuesToken(beginPosition, insertStatement.getTables().getSingleTableName()));
+ insertStatement.addSQLToken(new InsertValuesToken(beginPosition, insertStatement.getTables().getSingleTableName()));
String tableName = insertStatement.getTables().getSingleTableName();
Optional generateKeyColumn = shardingRule.getGenerateKeyColumn(tableName);
int count = 0;
@@ -111,7 +111,7 @@ public void parse(final InsertStatement insertStatement) {
}
private void removeUnnecessaryToken(final InsertStatement insertStatement) {
- Iterator sqlTokens = insertStatement.getSqlTokens().iterator();
+ Iterator sqlTokens = insertStatement.getSQLTokens().iterator();
while (sqlTokens.hasNext()) {
SQLToken sqlToken = sqlTokens.next();
if (sqlToken instanceof InsertColumnToken || sqlToken instanceof ItemsToken) {
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertValuesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertValuesClauseParser.java
index 806e444bd4324..06d9dff104209 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertValuesClauseParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertValuesClauseParser.java
@@ -91,7 +91,7 @@ private void parseValues(final InsertStatement insertStatement) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
int endPosition;
int startParametersIndex;
- insertStatement.getSqlTokens().add(new InsertValuesToken(beginPosition, insertStatement.getTables().getSingleTableName()));
+ insertStatement.addSQLToken(new InsertValuesToken(beginPosition, insertStatement.getTables().getSingleTableName()));
do {
beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
startParametersIndex = insertStatement.getParametersIndex();
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/SelectListClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/SelectListClauseParser.java
index a94a31cf3c90d..bd5a29bde1923 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/SelectListClauseParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/SelectListClauseParser.java
@@ -121,7 +121,7 @@ private SelectItem parseCommonOrStarSelectItem(final SelectStatement selectState
} else if (lexerEngine.equalAny(Symbol.DOT)) {
String tableName = SQLUtil.getExactlyValue(literals);
if (shardingRule.tryFindTableRuleByLogicTable(tableName).isPresent() || shardingRule.findBindingTableRule(tableName).isPresent()) {
- selectStatement.getSqlTokens().add(new TableToken(position, 0, literals));
+ selectStatement.addSQLToken(new TableToken(position, 0, literals));
}
result.append(lexerEngine.getCurrentToken().getLiterals());
lexerEngine.nextToken();
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/TableReferencesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/TableReferencesClauseParser.java
index 39b7bf459c415..8a1a1638ba1e0 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/TableReferencesClauseParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/TableReferencesClauseParser.java
@@ -103,7 +103,7 @@ protected final void parseTableFactor(final SQLStatement sqlStatement, final boo
}
if (isSingleTableOnly || shardingRule.tryFindTableRuleByLogicTable(tableName).isPresent() || shardingRule.findBindingTableRule(tableName).isPresent()
|| shardingRule.getShardingDataSourceNames().getDataSourceNames().contains(shardingRule.getShardingDataSourceNames().getDefaultDataSourceName())) {
- sqlStatement.getSqlTokens().add(new TableToken(beginPosition, skippedSchemaNameLength, literals));
+ sqlStatement.addSQLToken(new TableToken(beginPosition, skippedSchemaNameLength, literals));
sqlStatement.getTables().add(new Table(tableName, aliasExpressionParser.parseTableAlias(sqlStatement, true, tableName)));
} else {
aliasExpressionParser.parseTableAlias();
@@ -125,7 +125,7 @@ private void parseForceIndex(final String tableName, final SQLStatement sqlState
Preconditions.checkState(!Symbol.RIGHT_PAREN.getLiterals().equals(literals), "There is an error in the vicinity of the force index syntax.");
if (shardingRule.isLogicIndex(literals, tableName)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - literals.length();
- sqlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, tableName));
+ sqlStatement.addSQLToken(new IndexToken(beginPosition, literals, tableName));
}
lexerEngine.nextToken();
} while (lexerEngine.skipIfEqual(Symbol.COMMA));
@@ -192,7 +192,7 @@ public final void parseSingleTableWithoutAlias(final SQLStatement sqlStatement)
literals = lexerEngine.getCurrentToken().getLiterals();
lexerEngine.nextToken();
}
- sqlStatement.getSqlTokens().add(new TableToken(beginPosition, skippedSchemaNameLength, literals));
+ sqlStatement.addSQLToken(new TableToken(beginPosition, skippedSchemaNameLength, literals));
sqlStatement.getTables().add(new Table(SQLUtil.getExactlyValue(literals), Optional.absent()));
}
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/UpdateSetItemsClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/UpdateSetItemsClauseParser.java
index b8bc1b419896f..f68172c241b25 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/UpdateSetItemsClauseParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/UpdateSetItemsClauseParser.java
@@ -71,7 +71,7 @@ private void parseSetColumn(final DMLStatement updateStatement) {
lexerEngine.nextToken();
if (lexerEngine.skipIfEqual(Symbol.DOT)) {
if (updateStatement.getTables().getSingleTableName().equalsIgnoreCase(SQLUtil.getExactlyValue(literals))) {
- updateStatement.getSqlTokens().add(new TableToken(beginPosition - literals.length(), 0, literals));
+ updateStatement.addSQLToken(new TableToken(beginPosition - literals.length(), 0, literals));
}
lexerEngine.nextToken();
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/WhereClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/WhereClauseParser.java
index f45cbd7f8a1f0..d38398136de57 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/WhereClauseParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/WhereClauseParser.java
@@ -294,7 +294,7 @@ private void parseRowCountCondition(final SelectStatement selectStatement, final
if (sqlExpression instanceof SQLNumberExpression) {
int rowCount = ((SQLNumberExpression) sqlExpression).getNumber().intValue();
selectStatement.getLimit().setRowCount(new LimitValue(rowCount, -1, includeRowCount));
- selectStatement.getSqlTokens().add(new RowCountToken(endPosition - String.valueOf(rowCount).length(), rowCount));
+ selectStatement.addSQLToken(new RowCountToken(endPosition - String.valueOf(rowCount).length(), rowCount));
} else if (sqlExpression instanceof SQLPlaceholderExpression) {
selectStatement.getLimit().setRowCount(new LimitValue(-1, ((SQLPlaceholderExpression) sqlExpression).getIndex(), includeRowCount));
}
@@ -308,7 +308,7 @@ private void parseOffsetCondition(final SelectStatement selectStatement, final b
if (sqlExpression instanceof SQLNumberExpression) {
int offset = ((SQLNumberExpression) sqlExpression).getNumber().intValue();
selectStatement.getLimit().setOffset(new LimitValue(offset, -1, includeOffset));
- selectStatement.getSqlTokens().add(new OffsetToken(
+ selectStatement.addSQLToken(new OffsetToken(
lexerEngine.getCurrentToken().getEndPosition() - String.valueOf(offset).length() - lexerEngine.getCurrentToken().getLiterals().length(), offset));
} else if (sqlExpression instanceof SQLPlaceholderExpression) {
selectStatement.getLimit().setOffset(new LimitValue(-1, ((SQLPlaceholderExpression) sqlExpression).getIndex(), includeOffset));
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/expression/AliasExpressionParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/expression/AliasExpressionParser.java
index 3c7e0b54213c2..2503f937e5fcb 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/expression/AliasExpressionParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/expression/AliasExpressionParser.java
@@ -66,7 +66,7 @@ private Optional parseAlias(final SQLStatement sqlStatement, final boole
String literals = lexerEngine.getCurrentToken().getLiterals();
String alias = SQLUtil.getExactlyValue(literals);
if (setTableToken && alias.equals(tableName)) {
- sqlStatement.getSqlTokens().add(new TableToken(beginPosition, 0, literals));
+ sqlStatement.addSQLToken(new TableToken(beginPosition, 0, literals));
}
lexerEngine.nextToken();
return Optional.of(SQLUtil.getExactlyValue(literals));
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/expression/BasicExpressionParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/expression/BasicExpressionParser.java
index eb6a52a86b211..1ab4917cbcb17 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/expression/BasicExpressionParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/expression/BasicExpressionParser.java
@@ -131,7 +131,7 @@ private void skipRestCompositeExpression(final SQLStatement sqlStatement) {
private void setTableToken(final SQLStatement sqlStatement, final int beginPosition, final SQLPropertyExpression propertyExpr) {
String owner = propertyExpr.getOwner().getName();
if (sqlStatement.getTables().getTableNames().contains(SQLUtil.getExactlyValue(propertyExpr.getOwner().getName()))) {
- sqlStatement.getSqlTokens().add(new TableToken(beginPosition - owner.length(), 0, owner));
+ sqlStatement.addSQLToken(new TableToken(beginPosition - owner.length(), 0, owner));
}
}
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLLimitClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLLimitClauseParser.java
index 89bacb7d8c51b..ef702435aedb0 100755
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLLimitClauseParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLLimitClauseParser.java
@@ -77,7 +77,7 @@ public void parse(final SelectStatement selectStatement) {
if (isParameterForValue) {
selectStatement.increaseParametersIndex();
} else {
- selectStatement.getSqlTokens().add(new RowCountToken(valueBeginPosition, value));
+ selectStatement.addSQLToken(new RowCountToken(valueBeginPosition, value));
}
Limit limit = new Limit(DatabaseType.MySQL);
limit.setRowCount(new LimitValue(value, valueIndex, false));
@@ -104,12 +104,12 @@ private Limit getLimitWithComma(final int index, final int valueBeginPosition, f
if (isParameterForValue) {
selectStatement.increaseParametersIndex();
} else {
- selectStatement.getSqlTokens().add(new OffsetToken(valueBeginPosition, value));
+ selectStatement.addSQLToken(new OffsetToken(valueBeginPosition, value));
}
if (isParameterForRowCount) {
selectStatement.increaseParametersIndex();
} else {
- selectStatement.getSqlTokens().add(new RowCountToken(rowCountBeginPosition, rowCountValue));
+ selectStatement.addSQLToken(new RowCountToken(rowCountBeginPosition, rowCountValue));
}
Limit result = new Limit(DatabaseType.MySQL);
result.setRowCount(new LimitValue(rowCountValue, rowCountIndex, false));
@@ -136,12 +136,12 @@ private Limit getLimitWithOffset(final int index, final int valueBeginPosition,
if (isParameterForOffset) {
selectStatement.increaseParametersIndex();
} else {
- selectStatement.getSqlTokens().add(new OffsetToken(offsetBeginPosition, offsetValue));
+ selectStatement.addSQLToken(new OffsetToken(offsetBeginPosition, offsetValue));
}
if (isParameterForValue) {
selectStatement.increaseParametersIndex();
} else {
- selectStatement.getSqlTokens().add(new RowCountToken(valueBeginPosition, value));
+ selectStatement.addSQLToken(new RowCountToken(valueBeginPosition, value));
}
Limit result = new Limit(DatabaseType.MySQL);
result.setRowCount(new LimitValue(value, index, false));
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLShowParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLShowParser.java
index cc39eedae633b..21fecd75e3840 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLShowParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLShowParser.java
@@ -91,13 +91,13 @@ private DALStatement parseShowTableStatus() {
if (lexerEngine.equalAny(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
lexerEngine.nextToken();
- result.getSqlTokens().add(new RemoveToken(beginPosition, lexerEngine.getCurrentToken().getEndPosition()));
+ result.addSQLToken(new RemoveToken(beginPosition, lexerEngine.getCurrentToken().getEndPosition()));
}
lexerEngine.nextToken();
if (lexerEngine.skipIfEqual(DefaultKeyword.LIKE)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length() - 1;
String literals = lexerEngine.getCurrentToken().getLiterals();
- result.getSqlTokens().add(new TableToken(beginPosition, 0, literals));
+ result.addSQLToken(new TableToken(beginPosition, 0, literals));
result.getTables().add(new Table(SQLUtil.getExactlyValue(literals), Optional.absent()));
}
return result;
@@ -108,7 +108,7 @@ private DALStatement parseShowTables() {
if (lexerEngine.equalAny(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
lexerEngine.nextToken();
- result.getSqlTokens().add(new RemoveToken(beginPosition, lexerEngine.getCurrentToken().getEndPosition()));
+ result.addSQLToken(new RemoveToken(beginPosition, lexerEngine.getCurrentToken().getEndPosition()));
}
return result;
}
@@ -119,7 +119,7 @@ private DALStatement parseShowColumnsFields() {
tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
- result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), result.getTables().getSingleTableName()));
+ result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), result.getTables().getSingleTableName()));
}
return result;
}
@@ -136,7 +136,7 @@ private DALStatement parseShowIndex() {
tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
if (lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN)) {
int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length();
- result.getSqlTokens().add(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), result.getTables().getSingleTableName()));
+ result.addSQLToken(new SchemaToken(beginPosition, lexerEngine.getCurrentToken().getLiterals(), result.getTables().getSingleTableName()));
}
return result;
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLLimitClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLLimitClauseParser.java
index 68ce57620ae87..51a957a98dc7b 100755
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLLimitClauseParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLLimitClauseParser.java
@@ -77,7 +77,7 @@ private Optional buildRowCount(final SelectStatement selectStatement
if (lexerEngine.equalAny(Literals.INT, Literals.FLOAT)) {
rowCountValue = NumberUtil.roundHalfUp(lexerEngine.getCurrentToken().getLiterals());
valueBeginPosition = valueBeginPosition - (rowCountValue + "").length();
- selectStatement.getSqlTokens().add(new RowCountToken(valueBeginPosition, rowCountValue));
+ selectStatement.addSQLToken(new RowCountToken(valueBeginPosition, rowCountValue));
} else if (lexerEngine.equalAny(Symbol.QUESTION)) {
rowCountIndex = parameterIndex++;
selectStatement.setParametersIndex(parameterIndex);
@@ -98,7 +98,7 @@ private Optional buildOffset(final SelectStatement selectStatement)
if (lexerEngine.equalAny(Literals.INT, Literals.FLOAT)) {
offsetValue = NumberUtil.roundHalfUp(lexerEngine.getCurrentToken().getLiterals());
offsetBeginPosition = offsetBeginPosition - (offsetValue + "").length();
- selectStatement.getSqlTokens().add(new OffsetToken(offsetBeginPosition, offsetValue));
+ selectStatement.addSQLToken(new OffsetToken(offsetBeginPosition, offsetValue));
} else if (lexerEngine.equalAny(Symbol.QUESTION)) {
offsetIndex = parameterIndex++;
selectStatement.setParametersIndex(parameterIndex);
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerTopClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerTopClauseParser.java
index 67c458ddc5901..234393361e37c 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerTopClauseParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerTopClauseParser.java
@@ -69,7 +69,7 @@ public void parse(final SelectStatement selectStatement) {
if (sqlExpression instanceof SQLNumberExpression) {
int rowCount = ((SQLNumberExpression) sqlExpression).getNumber().intValue();
rowCountValue = new LimitValue(rowCount, -1, false);
- selectStatement.getSqlTokens().add(new RowCountToken(beginPosition, rowCount));
+ selectStatement.addSQLToken(new RowCountToken(beginPosition, rowCount));
} else if (sqlExpression instanceof SQLPlaceholderExpression) {
rowCountValue = new LimitValue(-1, ((SQLPlaceholderExpression) sqlExpression).getIndex(), false);
} else {
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/AbstractSQLStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/AbstractSQLStatement.java
index 551a50b632be9..0867db540a026 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/AbstractSQLStatement.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/AbstractSQLStatement.java
@@ -21,11 +21,13 @@
import io.shardingsphere.core.parsing.parser.context.condition.Conditions;
import io.shardingsphere.core.parsing.parser.context.table.Tables;
import io.shardingsphere.core.parsing.parser.token.SQLToken;
+import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -46,13 +48,20 @@ public abstract class AbstractSQLStatement implements SQLStatement {
private final Conditions conditions = new Conditions();
+ @Getter(AccessLevel.NONE)
private final List sqlTokens = new LinkedList<>();
private int parametersIndex;
@Override
- public final SQLType getType() {
- return type;
+ public final void addSQLToken(final SQLToken sqlToken) {
+ sqlTokens.add(sqlToken);
+ }
+
+ @Override
+ public final List getSQLTokens() {
+ Collections.sort(sqlTokens);
+ return sqlTokens;
}
@Override
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLStatement.java
index 5bf1d5ea7fba7..76f44c965c8be 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLStatement.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/SQLStatement.java
@@ -53,11 +53,18 @@ public interface SQLStatement {
Conditions getConditions();
/**
- * Get SQL Tokens.
+ * Add SQL token.
+ *
+ * @param sqlToken SQL token
+ */
+ void addSQLToken(SQLToken sqlToken);
+
+ /**
+ * Get SQL tokens.
*
- * @return SQL Tokens
+ * @return SQL tokens
*/
- List getSqlTokens();
+ List getSQLTokens();
/**
* Get index of parameters.
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/index/AbstractCreateIndexParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/index/AbstractCreateIndexParser.java
index 8282df1aa7e93..0b2cf455248d0 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/index/AbstractCreateIndexParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/index/AbstractCreateIndexParser.java
@@ -79,6 +79,6 @@ private void parseIndex(final DDLStatement ddlStatement) {
lexerEngine.skipUntil(DefaultKeyword.ON);
lexerEngine.nextToken();
String tableName = lexerEngine.getCurrentToken().getLiterals();
- ddlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, tableName));
+ ddlStatement.addSQLToken(new IndexToken(beginPosition, literals, tableName));
}
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/index/AbstractDropIndexParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/index/AbstractDropIndexParser.java
index cad59726011e8..be6c0efe6d610 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/index/AbstractDropIndexParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/index/AbstractDropIndexParser.java
@@ -75,9 +75,9 @@ private void parseIndex(final DDLStatement ddlStatement) {
lexerEngine.skipUntil(DefaultKeyword.ON);
if (lexerEngine.skipIfEqual(DefaultKeyword.ON)) {
tableReferencesClauseParser.parseSingleTableWithoutAlias(ddlStatement);
- ddlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, ddlStatement.getTables().getSingleTableName()));
+ ddlStatement.addSQLToken(new IndexToken(beginPosition, literals, ddlStatement.getTables().getSingleTableName()));
} else {
- ddlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, ""));
+ ddlStatement.addSQLToken(new IndexToken(beginPosition, literals, ""));
}
}
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/insert/AbstractInsertParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/insert/AbstractInsertParser.java
index 5acf4c12f8a59..f1f18452d1b42 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/insert/AbstractInsertParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/insert/AbstractInsertParser.java
@@ -87,7 +87,7 @@ private void processGeneratedKey(final InsertStatement insertStatement) {
} else {
ItemsToken columnsToken = new ItemsToken(insertStatement.getColumnsListLastPosition());
columnsToken.getItems().add(generateKeyColumn.get().getName());
- insertStatement.getSqlTokens().add(columnsToken);
+ insertStatement.addSQLToken(columnsToken);
}
}
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/insert/InsertStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/insert/InsertStatement.java
index ba14455c74863..e46cdea232e0b 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/insert/InsertStatement.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/insert/InsertStatement.java
@@ -61,12 +61,12 @@ public final class InsertStatement extends DMLStatement {
* @return items token list.
*/
public List getItemsTokens() {
- List itemsTokens = new ArrayList<>();
- for (SQLToken each : getSqlTokens()) {
+ List result = new ArrayList<>();
+ for (SQLToken each : getSQLTokens()) {
if (each instanceof ItemsToken) {
- itemsTokens.add((ItemsToken) each);
+ result.add((ItemsToken) each);
}
}
- return itemsTokens;
+ return result;
}
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dql/select/AbstractSelectParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dql/select/AbstractSelectParser.java
index 4ae74504dd468..3d554c695a156 100755
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dql/select/AbstractSelectParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dql/select/AbstractSelectParser.java
@@ -134,7 +134,7 @@ private void appendDerivedColumns(final SelectStatement selectStatement) {
appendDerivedOrderColumns(itemsToken, selectStatement.getOrderByItems(), selectStatement);
appendDerivedGroupColumns(itemsToken, selectStatement.getGroupByItems(), selectStatement);
if (!itemsToken.getItems().isEmpty()) {
- selectStatement.getSqlTokens().add(itemsToken);
+ selectStatement.addSQLToken(itemsToken);
}
}
@@ -231,7 +231,7 @@ private boolean isSameQualifiedName(final SelectItem selectItem, final OrderItem
private void appendDerivedOrderBy(final SelectStatement selectStatement) {
if (!selectStatement.getGroupByItems().isEmpty() && selectStatement.getOrderByItems().isEmpty()) {
selectStatement.getOrderByItems().addAll(selectStatement.getGroupByItems());
- selectStatement.getSqlTokens().add(new OrderByToken(selectStatement.getGroupByLastPosition()));
+ selectStatement.addSQLToken(new OrderByToken(selectStatement.getGroupByLastPosition()));
}
}
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dql/select/SelectStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dql/select/SelectStatement.java
index 60996d301a269..eec53999250d1 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dql/select/SelectStatement.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dql/select/SelectStatement.java
@@ -263,7 +263,7 @@ private SelectStatement processLimitForSubQuery() {
private List getLimitTokens(final SelectStatement selectStatement) {
List result = new LinkedList<>();
- for (SQLToken each : selectStatement.getSqlTokens()) {
+ for (SQLToken each : selectStatement.getSQLTokens()) {
if (each instanceof RowCountToken || each instanceof OffsetToken) {
result.add(each);
}
@@ -274,16 +274,17 @@ private List getLimitTokens(final SelectStatement selectStatement) {
private void resetLimitTokens(final SelectStatement selectStatement, final List limitSQLTokens) {
int count = 0;
List toBeRemovedIndexes = new LinkedList<>();
- for (SQLToken each : selectStatement.getSqlTokens()) {
+ List sqlTokens = selectStatement.getSQLTokens();
+ for (SQLToken each : sqlTokens) {
if (each instanceof RowCountToken || each instanceof OffsetToken) {
toBeRemovedIndexes.add(count);
}
count++;
}
for (int each : toBeRemovedIndexes) {
- selectStatement.getSqlTokens().remove(each);
+ sqlTokens.remove(each);
}
- selectStatement.getSqlTokens().addAll(limitSQLTokens);
+ sqlTokens.addAll(limitSQLTokens);
}
private void processItems(final SelectStatement subQueryStatement) {
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/GeneratedKeyToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/GeneratedKeyToken.java
index f3259d88595b6..6fdcde21b9657 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/GeneratedKeyToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/GeneratedKeyToken.java
@@ -17,17 +17,14 @@
package io.shardingsphere.core.parsing.parser.token;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
/**
* Generated key token.
*
* @author zhangliang
*/
-@RequiredArgsConstructor
-@Getter
-public final class GeneratedKeyToken implements SQLToken {
+public final class GeneratedKeyToken extends SQLToken {
- private final int beginPosition;
+ public GeneratedKeyToken(final int beginPosition) {
+ super(beginPosition);
+ }
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/IndexToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/IndexToken.java
index e6d74d83eac4b..ad4fb2bb6cb3d 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/IndexToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/IndexToken.java
@@ -19,7 +19,6 @@
import io.shardingsphere.core.util.SQLUtil;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import lombok.ToString;
/**
@@ -27,18 +26,20 @@
*
* @author caohao
*/
-@RequiredArgsConstructor
@ToString
-public final class IndexToken implements SQLToken {
-
- @Getter
- private final int beginPosition;
+public final class IndexToken extends SQLToken {
@Getter
private final String originalLiterals;
private final String tableName;
+ public IndexToken(final int beginPosition, final String originalLiterals, final String tableName) {
+ super(beginPosition);
+ this.originalLiterals = originalLiterals;
+ this.tableName = tableName;
+ }
+
/**
* Get index name.
*
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/InsertColumnToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/InsertColumnToken.java
index a17b1471e06b1..091236c05f9ff 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/InsertColumnToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/InsertColumnToken.java
@@ -18,7 +18,6 @@
package io.shardingsphere.core.parsing.parser.token;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import lombok.ToString;
/**
@@ -26,12 +25,14 @@
*
* @author panjuan
*/
-@RequiredArgsConstructor
@Getter
@ToString
-public final class InsertColumnToken implements SQLToken {
-
- private final int beginPosition;
+public final class InsertColumnToken extends SQLToken {
private final String columnName;
+
+ public InsertColumnToken(final int beginPosition, final String columnName) {
+ super(beginPosition);
+ this.columnName = columnName;
+ }
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/InsertValuesToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/InsertValuesToken.java
index cdbb1e6aa96c6..0a710f0f84b91 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/InsertValuesToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/InsertValuesToken.java
@@ -18,18 +18,19 @@
package io.shardingsphere.core.parsing.parser.token;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
/**
* Insert values token.
*
* @author maxiaoguang
*/
-@RequiredArgsConstructor
@Getter
-public final class InsertValuesToken implements SQLToken {
-
- private final int beginPosition;
+public final class InsertValuesToken extends SQLToken {
private final String tableName;
+
+ public InsertValuesToken(final int beginPosition, final String tableName) {
+ super(beginPosition);
+ this.tableName = tableName;
+ }
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/ItemsToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/ItemsToken.java
index 23bd70a2a217b..6c7bd363606ed 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/ItemsToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/ItemsToken.java
@@ -18,7 +18,6 @@
package io.shardingsphere.core.parsing.parser.token;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@@ -31,15 +30,16 @@
* @author zhangliang
* @author panjuan
*/
-@RequiredArgsConstructor
@Getter
@ToString
-public final class ItemsToken implements SQLToken {
-
- private final int beginPosition;
+public final class ItemsToken extends SQLToken {
@Setter
private boolean isFirstOfItemsSpecial;
private final List items = new LinkedList<>();
+
+ public ItemsToken(final int beginPosition) {
+ super(beginPosition);
+ }
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/OffsetToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/OffsetToken.java
index 163393c367d0e..79e505a0ef7ef 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/OffsetToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/OffsetToken.java
@@ -18,18 +18,19 @@
package io.shardingsphere.core.parsing.parser.token;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
/**
* Offset token for limit.
*
* @author zhangliang
*/
-@RequiredArgsConstructor
@Getter
-public final class OffsetToken implements SQLToken {
-
- private final int beginPosition;
+public final class OffsetToken extends SQLToken {
private final int offset;
+
+ public OffsetToken(final int beginPosition, final int offset) {
+ super(beginPosition);
+ this.offset = offset;
+ }
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/OrderByToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/OrderByToken.java
index c430323e61a6e..ad424bdcf58fa 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/OrderByToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/OrderByToken.java
@@ -17,17 +17,14 @@
package io.shardingsphere.core.parsing.parser.token;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-
/**
* Order by token.
*
* @author zhangliang
*/
-@RequiredArgsConstructor
-@Getter
-public final class OrderByToken implements SQLToken {
+public final class OrderByToken extends SQLToken {
- private final int beginPosition;
+ public OrderByToken(final int beginPosition) {
+ super(beginPosition);
+ }
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/RemoveToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/RemoveToken.java
index fbe368f99e3da..cb8eaf38d4e8d 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/RemoveToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/RemoveToken.java
@@ -18,7 +18,6 @@
package io.shardingsphere.core.parsing.parser.token;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import lombok.ToString;
/**
@@ -26,12 +25,14 @@
*
* @author zhangliang
*/
-@RequiredArgsConstructor
@Getter
@ToString
-public final class RemoveToken implements SQLToken {
-
- private final int beginPosition;
+public final class RemoveToken extends SQLToken {
private final int endPosition;
+
+ public RemoveToken(final int beginPosition, final int endPosition) {
+ super(beginPosition);
+ this.endPosition = endPosition;
+ }
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/RowCountToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/RowCountToken.java
index 286d54e21886c..272b3bcdb0013 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/RowCountToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/RowCountToken.java
@@ -18,18 +18,19 @@
package io.shardingsphere.core.parsing.parser.token;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
/**
* Row count token for limit.
*
* @author zhangliang
*/
-@RequiredArgsConstructor
@Getter
-public final class RowCountToken implements SQLToken {
-
- private final int beginPosition;
+public final class RowCountToken extends SQLToken {
private final int rowCount;
+
+ public RowCountToken(final int beginPosition, final int rowCount) {
+ super(beginPosition);
+ this.rowCount = rowCount;
+ }
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/SQLToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/SQLToken.java
index b0af6c88d0275..2ed268a33f2ea 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/SQLToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/SQLToken.java
@@ -17,17 +17,22 @@
package io.shardingsphere.core.parsing.parser.token;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
/**
* SQL Token.
*
* @author zhangliang
*/
-public interface SQLToken {
+@RequiredArgsConstructor
+@Getter
+public abstract class SQLToken implements Comparable {
+
+ private final int beginPosition;
- /**
- * Get begin position.
- *
- * @return begin position
- */
- int getBeginPosition();
+ @Override
+ public final int compareTo(final SQLToken sqlToken) {
+ return beginPosition - sqlToken.getBeginPosition();
+ }
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/SchemaToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/SchemaToken.java
index 6da840ec90db1..4dae2a6584e49 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/SchemaToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/SchemaToken.java
@@ -19,7 +19,6 @@
import io.shardingsphere.core.util.SQLUtil;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import lombok.ToString;
/**
@@ -27,18 +26,20 @@
*
* @author zhangliang
*/
-@RequiredArgsConstructor
@ToString
-public final class SchemaToken implements SQLToken {
-
- @Getter
- private final int beginPosition;
+public final class SchemaToken extends SQLToken {
@Getter
private final String originalLiterals;
private final String tableName;
+ public SchemaToken(final int beginPosition, final String originalLiterals, final String tableName) {
+ super(beginPosition);
+ this.originalLiterals = originalLiterals;
+ this.tableName = tableName;
+ }
+
/**
* Get schema name.
*
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/TableToken.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/TableToken.java
index b3110c6adf770..7cda74e059c67 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/TableToken.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/token/TableToken.java
@@ -19,7 +19,6 @@
import io.shardingsphere.core.util.SQLUtil;
import lombok.Getter;
-import lombok.RequiredArgsConstructor;
import lombok.ToString;
/**
@@ -27,17 +26,20 @@
*
* @author zhangliang
*/
-@RequiredArgsConstructor
@Getter
@ToString
-public final class TableToken implements SQLToken {
-
- private final int beginPosition;
+public final class TableToken extends SQLToken {
private final int skippedSchemaNameLength;
private final String originalLiterals;
+ public TableToken(final int beginPosition, final int skippedSchemaNameLength, final String originalLiterals) {
+ super(beginPosition);
+ this.skippedSchemaNameLength = skippedSchemaNameLength;
+ this.originalLiterals = originalLiterals;
+ }
+
/**
* Get table name.
*
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLRewriteEngine.java b/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLRewriteEngine.java
index 79900f957a629..c0aefa989f752 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLRewriteEngine.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLRewriteEngine.java
@@ -20,6 +20,7 @@
import com.google.common.base.Optional;
import com.google.common.base.Strings;
import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
import io.shardingsphere.core.optimizer.condition.ShardingConditions;
import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
import io.shardingsphere.core.parsing.parser.context.OrderItem;
@@ -38,7 +39,6 @@
import io.shardingsphere.core.parsing.parser.token.SQLToken;
import io.shardingsphere.core.parsing.parser.token.SchemaToken;
import io.shardingsphere.core.parsing.parser.token.TableToken;
-import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData;
import io.shardingsphere.core.rewrite.placeholder.IndexPlaceholder;
import io.shardingsphere.core.rewrite.placeholder.InsertValuesPlaceholder;
import io.shardingsphere.core.rewrite.placeholder.SchemaPlaceholder;
@@ -50,10 +50,7 @@
import io.shardingsphere.core.rule.ShardingRule;
import io.shardingsphere.core.util.SQLUtil;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -74,10 +71,10 @@ public final class SQLRewriteEngine {
private final DatabaseType databaseType;
- private final List sqlTokens = new LinkedList<>();
-
private final SQLStatement sqlStatement;
+ private final List sqlTokens;
+
private final ShardingConditions shardingConditions;
private final List
*/
-package io.shardingsphere.shardingproxy.rewrite;
+package io.shardingsphere.core.rewrite;
import io.shardingsphere.core.metadata.ShardingMetaData;
import io.shardingsphere.core.parsing.parser.sql.SQLStatement;
import io.shardingsphere.core.parsing.parser.token.SQLToken;
import io.shardingsphere.core.parsing.parser.token.SchemaToken;
-import io.shardingsphere.core.rewrite.SQLBuilder;
import io.shardingsphere.core.rewrite.placeholder.SchemaPlaceholder;
import io.shardingsphere.core.rule.MasterSlaveRule;
+import java.util.Collections;
import java.util.List;
/**
@@ -40,8 +40,6 @@ public final class MasterSlaveSQLRewriteEngine {
private final String originalSQL;
- private final SQLStatement sqlStatement;
-
private final List sqlTokens;
private final ShardingMetaData metaData;
@@ -51,13 +49,12 @@ public final class MasterSlaveSQLRewriteEngine {
*
* @param masterSlaveRule master slave rule
* @param originalSQL original SQL
- * @param sqlStatement sql statement
+ * @param sqlStatement SQL statement
* @param metaData meta data
*/
public MasterSlaveSQLRewriteEngine(final MasterSlaveRule masterSlaveRule, final String originalSQL, final SQLStatement sqlStatement, final ShardingMetaData metaData) {
this.masterSlaveRule = masterSlaveRule;
this.originalSQL = originalSQL;
- this.sqlStatement = sqlStatement;
sqlTokens = sqlStatement.getSQLTokens();
this.metaData = metaData;
}
@@ -71,7 +68,7 @@ public String rewrite() {
if (sqlTokens.isEmpty()) {
return originalSQL;
}
- SQLBuilder result = new SQLBuilder(null);
+ SQLBuilder result = new SQLBuilder(Collections.emptyList());
int count = 0;
for (SQLToken each : sqlTokens) {
if (0 == count) {
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/wrapper/PreparedStatementExecutorWrapper.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/wrapper/PreparedStatementExecutorWrapper.java
index 3f093956eb6ee..23485cc654188 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/wrapper/PreparedStatementExecutorWrapper.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/wrapper/PreparedStatementExecutorWrapper.java
@@ -20,12 +20,12 @@
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.parsing.SQLJudgeEngine;
import io.shardingsphere.core.parsing.parser.sql.SQLStatement;
+import io.shardingsphere.core.rewrite.MasterSlaveSQLRewriteEngine;
import io.shardingsphere.core.routing.PreparedStatementRoutingEngine;
import io.shardingsphere.core.routing.RouteUnit;
import io.shardingsphere.core.routing.SQLRouteResult;
import io.shardingsphere.core.routing.SQLUnit;
import io.shardingsphere.core.routing.router.masterslave.MasterSlaveRouter;
-import io.shardingsphere.shardingproxy.rewrite.MasterSlaveSQLRewriteEngine;
import io.shardingsphere.shardingproxy.runtime.GlobalRegistry;
import io.shardingsphere.shardingproxy.runtime.ShardingSchema;
import lombok.RequiredArgsConstructor;
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/wrapper/StatementExecutorWrapper.java b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/wrapper/StatementExecutorWrapper.java
index bedec3c89f85b..73bd94ef818d9 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/wrapper/StatementExecutorWrapper.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/shardingproxy/backend/jdbc/wrapper/StatementExecutorWrapper.java
@@ -20,12 +20,12 @@
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.parsing.SQLJudgeEngine;
import io.shardingsphere.core.parsing.parser.sql.SQLStatement;
+import io.shardingsphere.core.rewrite.MasterSlaveSQLRewriteEngine;
import io.shardingsphere.core.routing.RouteUnit;
import io.shardingsphere.core.routing.SQLRouteResult;
import io.shardingsphere.core.routing.SQLUnit;
import io.shardingsphere.core.routing.StatementRoutingEngine;
import io.shardingsphere.core.routing.router.masterslave.MasterSlaveRouter;
-import io.shardingsphere.shardingproxy.rewrite.MasterSlaveSQLRewriteEngine;
import io.shardingsphere.shardingproxy.runtime.GlobalRegistry;
import io.shardingsphere.shardingproxy.runtime.ShardingSchema;
import lombok.RequiredArgsConstructor;
From f1886bd3f45de843f9554cd80905be531e101b66 Mon Sep 17 00:00:00 2001
From: terrymanu
Date: Thu, 18 Oct 2018 23:34:57 +0800
Subject: [PATCH 10/10] refactor rewrite
---
.../rewrite/MasterSlaveSQLRewriteEngine.java | 4 +-
.../core/rewrite/SQLRewriteEngine.java | 70 +++++++++----------
2 files changed, 37 insertions(+), 37 deletions(-)
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/rewrite/MasterSlaveSQLRewriteEngine.java b/sharding-core/src/main/java/io/shardingsphere/core/rewrite/MasterSlaveSQLRewriteEngine.java
index c42ab61686d0c..268c859feaab9 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/rewrite/MasterSlaveSQLRewriteEngine.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/rewrite/MasterSlaveSQLRewriteEngine.java
@@ -75,14 +75,14 @@ public String rewrite() {
result.appendLiterals(originalSQL.substring(0, each.getBeginPosition()));
}
if (each instanceof SchemaToken) {
- appendSchemaPlaceholder(originalSQL, result, (SchemaToken) each, count, sqlTokens);
+ appendSchemaPlaceholder(originalSQL, result, (SchemaToken) each, count);
}
count++;
}
return result.toSQL(masterSlaveRule, metaData.getDataSource());
}
- private void appendSchemaPlaceholder(final String sql, final SQLBuilder sqlBuilder, final SchemaToken schemaToken, final int count, final List sqlTokens) {
+ private void appendSchemaPlaceholder(final String sql, final SQLBuilder sqlBuilder, final SchemaToken schemaToken, final int count) {
sqlBuilder.appendPlaceholder(new SchemaPlaceholder(schemaToken.getSchemaName().toLowerCase(), null));
int beginPosition = schemaToken.getBeginPosition() + schemaToken.getOriginalLiterals().length();
int endPosition = sqlTokens.size() - 1 == count ? sql.length() : sqlTokens.get(count + 1).getBeginPosition();
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLRewriteEngine.java b/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLRewriteEngine.java
index c0aefa989f752..e7bd9ed3e5cda 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLRewriteEngine.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLRewriteEngine.java
@@ -118,44 +118,44 @@ public SQLBuilder rewrite(final boolean isRewriteLimit) {
result.appendLiterals(originalSQL.substring(0, each.getBeginPosition()));
}
if (each instanceof TableToken) {
- appendTablePlaceholder(result, (TableToken) each, count, sqlTokens);
+ appendTablePlaceholder(result, (TableToken) each, count);
} else if (each instanceof SchemaToken) {
- appendSchemaPlaceholder(result, (SchemaToken) each, count, sqlTokens);
+ appendSchemaPlaceholder(result, (SchemaToken) each, count);
} else if (each instanceof IndexToken) {
- appendIndexPlaceholder(result, (IndexToken) each, count, sqlTokens);
+ appendIndexPlaceholder(result, (IndexToken) each, count);
} else if (each instanceof ItemsToken) {
- appendItemsToken(result, (ItemsToken) each, count, sqlTokens);
+ appendItemsToken(result, (ItemsToken) each, count);
} else if (each instanceof InsertValuesToken) {
- appendInsertValuesToken(result, (InsertValuesToken) each, count, sqlTokens);
+ appendInsertValuesToken(result, (InsertValuesToken) each, count);
} else if (each instanceof RowCountToken) {
- appendLimitRowCount(result, (RowCountToken) each, count, sqlTokens, isRewriteLimit);
+ appendLimitRowCount(result, (RowCountToken) each, count, isRewriteLimit);
} else if (each instanceof OffsetToken) {
- appendLimitOffsetToken(result, (OffsetToken) each, count, sqlTokens, isRewriteLimit);
+ appendLimitOffsetToken(result, (OffsetToken) each, count, isRewriteLimit);
} else if (each instanceof OrderByToken) {
- appendOrderByToken(result, count, sqlTokens);
+ appendOrderByToken(result, count);
} else if (each instanceof InsertColumnToken) {
- appendSymbolToken(result, (InsertColumnToken) each, count, sqlTokens);
+ appendSymbolToken(result, (InsertColumnToken) each, count);
} else if (each instanceof RemoveToken) {
- appendRest(result, count, sqlTokens, ((RemoveToken) each).getEndPosition());
+ appendRest(result, count, ((RemoveToken) each).getEndPosition());
}
count++;
}
return result;
}
- private void appendTablePlaceholder(final SQLBuilder sqlBuilder, final TableToken tableToken, final int count, final List sqlTokens) {
+ private void appendTablePlaceholder(final SQLBuilder sqlBuilder, final TableToken tableToken, final int count) {
sqlBuilder.appendPlaceholder(new TablePlaceholder(tableToken.getTableName().toLowerCase(), tableToken.getOriginalLiterals()));
int beginPosition = tableToken.getBeginPosition() + tableToken.getSkippedSchemaNameLength() + tableToken.getOriginalLiterals().length();
- appendRest(sqlBuilder, count, sqlTokens, beginPosition);
+ appendRest(sqlBuilder, count, beginPosition);
}
- private void appendSchemaPlaceholder(final SQLBuilder sqlBuilder, final SchemaToken schemaToken, final int count, final List sqlTokens) {
+ private void appendSchemaPlaceholder(final SQLBuilder sqlBuilder, final SchemaToken schemaToken, final int count) {
sqlBuilder.appendPlaceholder(new SchemaPlaceholder(schemaToken.getSchemaName().toLowerCase(), schemaToken.getTableName().toLowerCase()));
int beginPosition = schemaToken.getBeginPosition() + schemaToken.getOriginalLiterals().length();
- appendRest(sqlBuilder, count, sqlTokens, beginPosition);
+ appendRest(sqlBuilder, count, beginPosition);
}
- private void appendIndexPlaceholder(final SQLBuilder sqlBuilder, final IndexToken indexToken, final int count, final List sqlTokens) {
+ private void appendIndexPlaceholder(final SQLBuilder sqlBuilder, final IndexToken indexToken, final int count) {
String indexName = indexToken.getIndexName().toLowerCase();
String logicTableName = indexToken.getTableName().toLowerCase();
if (Strings.isNullOrEmpty(logicTableName)) {
@@ -163,10 +163,10 @@ private void appendIndexPlaceholder(final SQLBuilder sqlBuilder, final IndexToke
}
sqlBuilder.appendPlaceholder(new IndexPlaceholder(indexName, logicTableName));
int beginPosition = indexToken.getBeginPosition() + indexToken.getOriginalLiterals().length();
- appendRest(sqlBuilder, count, sqlTokens, beginPosition);
+ appendRest(sqlBuilder, count, beginPosition);
}
- private void appendItemsToken(final SQLBuilder sqlBuilder, final ItemsToken itemsToken, final int count, final List sqlTokens) {
+ private void appendItemsToken(final SQLBuilder sqlBuilder, final ItemsToken itemsToken, final int count) {
for (int i = 0; i < itemsToken.getItems().size(); i++) {
if (itemsToken.isFirstOfItemsSpecial() && 0 == i) {
sqlBuilder.appendLiterals(SQLUtil.getOriginalValue(itemsToken.getItems().get(i), databaseType));
@@ -175,15 +175,15 @@ private void appendItemsToken(final SQLBuilder sqlBuilder, final ItemsToken item
sqlBuilder.appendLiterals(SQLUtil.getOriginalValue(itemsToken.getItems().get(i), databaseType));
}
}
- appendRest(sqlBuilder, count, sqlTokens, itemsToken.getBeginPosition());
+ appendRest(sqlBuilder, count, itemsToken.getBeginPosition());
}
- private void appendInsertValuesToken(final SQLBuilder sqlBuilder, final InsertValuesToken insertValuesToken, final int count, final List sqlTokens) {
+ private void appendInsertValuesToken(final SQLBuilder sqlBuilder, final InsertValuesToken insertValuesToken, final int count) {
sqlBuilder.appendPlaceholder(new InsertValuesPlaceholder(insertValuesToken.getTableName().toLowerCase(), shardingConditions));
- appendRest(sqlBuilder, count, sqlTokens, ((InsertStatement) sqlStatement).getInsertValuesListLastPosition());
+ appendRest(sqlBuilder, count, ((InsertStatement) sqlStatement).getInsertValuesListLastPosition());
}
- private void appendLimitRowCount(final SQLBuilder sqlBuilder, final RowCountToken rowCountToken, final int count, final List sqlTokens, final boolean isRewrite) {
+ private void appendLimitRowCount(final SQLBuilder sqlBuilder, final RowCountToken rowCountToken, final int count, final boolean isRewrite) {
SelectStatement selectStatement = (SelectStatement) sqlStatement;
Limit limit = selectStatement.getLimit();
if (!isRewrite) {
@@ -194,16 +194,16 @@ private void appendLimitRowCount(final SQLBuilder sqlBuilder, final RowCountToke
sqlBuilder.appendLiterals(String.valueOf(limit.isNeedRewriteRowCount() ? rowCountToken.getRowCount() + limit.getOffsetValue() : rowCountToken.getRowCount()));
}
int beginPosition = rowCountToken.getBeginPosition() + String.valueOf(rowCountToken.getRowCount()).length();
- appendRest(sqlBuilder, count, sqlTokens, beginPosition);
+ appendRest(sqlBuilder, count, beginPosition);
}
- private void appendLimitOffsetToken(final SQLBuilder sqlBuilder, final OffsetToken offsetToken, final int count, final List sqlTokens, final boolean isRewrite) {
+ private void appendLimitOffsetToken(final SQLBuilder sqlBuilder, final OffsetToken offsetToken, final int count, final boolean isRewrite) {
sqlBuilder.appendLiterals(isRewrite ? "0" : String.valueOf(offsetToken.getOffset()));
int beginPosition = offsetToken.getBeginPosition() + String.valueOf(offsetToken.getOffset()).length();
- appendRest(sqlBuilder, count, sqlTokens, beginPosition);
+ appendRest(sqlBuilder, count, beginPosition);
}
- private void appendOrderByToken(final SQLBuilder sqlBuilder, final int count, final List sqlTokens) {
+ private void appendOrderByToken(final SQLBuilder sqlBuilder, final int count) {
SelectStatement selectStatement = (SelectStatement) sqlStatement;
StringBuilder orderByLiterals = new StringBuilder();
orderByLiterals.append(" ").append(DefaultKeyword.ORDER).append(" ").append(DefaultKeyword.BY).append(" ");
@@ -220,15 +220,15 @@ private void appendOrderByToken(final SQLBuilder sqlBuilder, final int count, fi
orderByLiterals.append(" ");
sqlBuilder.appendLiterals(orderByLiterals.toString());
int beginPosition = ((SelectStatement) sqlStatement).getGroupByLastPosition();
- appendRest(sqlBuilder, count, sqlTokens, beginPosition);
+ appendRest(sqlBuilder, count, beginPosition);
}
- private void appendSymbolToken(final SQLBuilder sqlBuilder, final InsertColumnToken insertColumnToken, final int count, final List sqlTokens) {
+ private void appendSymbolToken(final SQLBuilder sqlBuilder, final InsertColumnToken insertColumnToken, final int count) {
sqlBuilder.appendLiterals(insertColumnToken.getColumnName());
- appendRest(sqlBuilder, count, sqlTokens, insertColumnToken.getBeginPosition());
+ appendRest(sqlBuilder, count, insertColumnToken.getBeginPosition());
}
- private void appendRest(final SQLBuilder sqlBuilder, final int count, final List sqlTokens, final int beginPosition) {
+ private void appendRest(final SQLBuilder sqlBuilder, final int count, final int beginPosition) {
int endPosition = sqlTokens.size() - 1 == count ? originalSQL.length() : sqlTokens.get(count + 1).getBeginPosition();
sqlBuilder.appendLiterals(originalSQL.substring(beginPosition, endPosition));
}
@@ -247,12 +247,12 @@ public SQLUnit generateSQL(final TableUnit tableUnit, final SQLBuilder sqlBuilde
private Map getTableTokens(final TableUnit tableUnit) {
Map result = new HashMap<>();
- for (RoutingTable routingTable : tableUnit.getRoutingTables()) {
- String logicTableName = routingTable.getLogicTableName().toLowerCase();
- result.put(logicTableName, routingTable.getActualTableName());
+ for (RoutingTable each : tableUnit.getRoutingTables()) {
+ String logicTableName = each.getLogicTableName().toLowerCase();
+ result.put(logicTableName, each.getActualTableName());
Optional bindingTableRule = shardingRule.findBindingTableRule(logicTableName);
if (bindingTableRule.isPresent()) {
- result.putAll(getBindingTableTokens(tableUnit.getDataSourceName(), routingTable, bindingTableRule.get()));
+ result.putAll(getBindingTableTokens(tableUnit.getDataSourceName(), each, bindingTableRule.get()));
}
}
return result;
@@ -260,8 +260,8 @@ private Map getTableTokens(final TableUnit tableUnit) {
private Map getBindingTableTokens(final String dataSourceName, final RoutingTable routingTable, final BindingTableRule bindingTableRule) {
Map result = new HashMap<>();
- for (String eachTable : sqlStatement.getTables().getTableNames()) {
- String tableName = eachTable.toLowerCase();
+ for (String each : sqlStatement.getTables().getTableNames()) {
+ String tableName = each.toLowerCase();
if (!tableName.equals(routingTable.getLogicTableName().toLowerCase()) && bindingTableRule.hasLogicTable(tableName)) {
result.put(tableName, bindingTableRule.getBindingActualTable(dataSourceName, tableName, routingTable.getActualTableName()));
}