From 1c79b48fd9383f77cc551b1db0df84f19bfd4e04 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Sun, 29 Jul 2018 18:01:21 +0800 Subject: [PATCH 001/198] remove transaction event holder. --- .../spi/TransactionEventHolder.java | 48 ------------------- .../transaction/spi/TransactionManager.java | 2 +- 2 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionEventHolder.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionEventHolder.java b/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionEventHolder.java deleted file mode 100644 index 098d89812a029..0000000000000 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionEventHolder.java +++ /dev/null @@ -1,48 +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.core.transaction.spi; - -import io.shardingsphere.core.transaction.event.TransactionEvent; - -/** - * Hold transaction event for current thread. - * - * @author zhaojun - */ -public class TransactionEventHolder { - - private static Class transactionEvent; - - /** - * Set transactionEvent. - * - * @param clazz class type of TransactionEvent - */ - public static synchronized void set(final Class clazz) { - transactionEvent = clazz; - } - - /** - * Get transactionEvent class type. - * - * @return transactionEvent class type - */ - public static Class get() { - return transactionEvent; - } -} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java b/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java index f47639a4fd800..ef2db799a9462 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java @@ -55,7 +55,7 @@ public interface TransactionManager { /** * Obtain the status of the transaction associated with the current thread. * - * @return The transaction status. + * @return The transaction status. *

* If no transaction is associated with the current thread, this method returns the Status.NoTransaction value *

From bf8b53cc8ea5cfd3c7ea49be431111eedb3fb0ca Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 11:47:02 +0800 Subject: [PATCH 002/198] refactor AtomikosUserTransaction to hungry mode. --- .../transaction/xa/AtomikosUserTransaction.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java index bd05b40e2ee29..117f8671f8918 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java @@ -18,30 +18,25 @@ package io.shardingsphere.transaction.xa; import com.atomikos.icatch.jta.UserTransactionManager; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; /** * Hold singleton atomikos userTransaction. * * @author zhaojun */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class AtomikosUserTransaction { - // TODO why not new here? - private static volatile UserTransactionManager transactionManager; + private static final UserTransactionManager TRANSACTION_MANAGER = new UserTransactionManager(); /** - * Get singleton {@code UserTransactionManager} lazily. + * Get singleton of {@code UserTransactionManager}. * * @return {@code UserTransactionManager} */ public static UserTransactionManager getInstance() { - if (null == transactionManager) { - synchronized (AtomikosUserTransaction.class) { - if (null == transactionManager) { - transactionManager = new UserTransactionManager(); - } - } - } - return transactionManager; + return TRANSACTION_MANAGER; } } From 80c4b659bd9ecb9245ace2d519a1e78fdaaed54e Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 12:55:17 +0800 Subject: [PATCH 003/198] add sharding-event and sharding-transaction module. --- pom.xml | 2 ++ sharding-event/pom.xml | 40 +++++++++++++++++++++++++++++++++++ sharding-transaction/pom.xml | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 sharding-event/pom.xml create mode 100644 sharding-transaction/pom.xml diff --git a/pom.xml b/pom.xml index 10858af2be5c5..0dbf47ff58782 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,8 @@ sharding-opentracing sharding-proxy sharding-sql-test + sharding-transaction + sharding-event diff --git a/sharding-event/pom.xml b/sharding-event/pom.xml new file mode 100644 index 0000000000000..cb414ad1d518f --- /dev/null +++ b/sharding-event/pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + + sharding-sphere + io.shardingsphere + 3.0.0.M2-SNAPSHOT + + sharding-event + ${project.artifactId} + + + + com.google.guava + guava + + + org.projectlombok + lombok + + + org.slf4j + slf4j-api + + + ch.qos.logback + logback-classic + + + junit + junit + + + org.mockito + mockito-core + + + \ No newline at end of file diff --git a/sharding-transaction/pom.xml b/sharding-transaction/pom.xml new file mode 100644 index 0000000000000..44b3245248fd0 --- /dev/null +++ b/sharding-transaction/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + sharding-sphere + io.shardingsphere + 3.0.0.M2-SNAPSHOT + + + sharding-transaction + ${project.artifactId} + + + + com.google.guava + guava + + + org.projectlombok + lombok + + + org.slf4j + slf4j-api + + + ch.qos.logback + logback-classic + + + junit + junit + + + org.mockito + mockito-core + + + \ No newline at end of file From a4fe245c45334219b2b7dbefb4aec60e9f09a9e0 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 12:58:54 +0800 Subject: [PATCH 004/198] remove sharding-event module, event module can't been common now. --- pom.xml | 1 - sharding-event/pom.xml | 40 ---------------------------------------- 2 files changed, 41 deletions(-) delete mode 100644 sharding-event/pom.xml diff --git a/pom.xml b/pom.xml index 0dbf47ff58782..d243c91a22ccb 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,6 @@ sharding-proxy sharding-sql-test sharding-transaction - sharding-event diff --git a/sharding-event/pom.xml b/sharding-event/pom.xml deleted file mode 100644 index cb414ad1d518f..0000000000000 --- a/sharding-event/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - 4.0.0 - - sharding-sphere - io.shardingsphere - 3.0.0.M2-SNAPSHOT - - sharding-event - ${project.artifactId} - - - - com.google.guava - guava - - - org.projectlombok - lombok - - - org.slf4j - slf4j-api - - - ch.qos.logback - logback-classic - - - junit - junit - - - org.mockito - mockito-core - - - \ No newline at end of file From e00e0192a2bc25668289cdb1c62f6b679c7e89c9 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 14:10:45 +0800 Subject: [PATCH 005/198] move xa transaction to transaction module. --- sharding-transaction/pom.xml | 23 ++++++++++ .../TransactionEventBusInstance.java | 42 +++++++++++++++++++ .../transaction/TransactionLoader.java | 5 +-- .../transaction/WeakXaTransactionManager.java | 2 +- .../xa/AtomikosTransactionManager.java | 0 .../xa/AtomikosUserTransaction.java | 0 6 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java rename {sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core => sharding-transaction/src/main/java/io/shardingsphere}/transaction/TransactionLoader.java (92%) rename {sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core => sharding-transaction/src/main/java/io/shardingsphere}/transaction/WeakXaTransactionManager.java (98%) rename {sharding-jdbc-transaction-parent/sharding-jdbc-transaction => sharding-transaction}/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java (100%) rename {sharding-jdbc-transaction-parent/sharding-jdbc-transaction => sharding-transaction}/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java (100%) diff --git a/sharding-transaction/pom.xml b/sharding-transaction/pom.xml index 44b3245248fd0..425710ba68a5a 100644 --- a/sharding-transaction/pom.xml +++ b/sharding-transaction/pom.xml @@ -37,5 +37,28 @@ org.mockito mockito-core + + + io.shardingsphere + sharding-core + ${project.parent.version} + + + + com.atomikos + transactions + + + com.atomikos + transactions-jta + + + com.atomikos + transactions-jdbc + + + javax.transaction + jta + \ No newline at end of file diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java new file mode 100644 index 0000000000000..c703d9867573b --- /dev/null +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java @@ -0,0 +1,42 @@ +/* + * 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.transaction; + +import com.google.common.eventbus.EventBus; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * Event bus for singleton instance. + * + * @author zhangliang + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class TransactionEventBusInstance { + + private static final EventBus INSTANCE = new EventBus(); + + /** + * Get event bus instance. + * + * @return event bus instance + */ + public static EventBus getInstance() { + return INSTANCE; + } +} diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/TransactionLoader.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java similarity index 92% rename from sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/TransactionLoader.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java index c5e0d89beef52..24d706058d60d 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/TransactionLoader.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.core.jdbc.core.transaction; +package io.shardingsphere.transaction; import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.transaction.TransactionContext; @@ -24,7 +24,6 @@ import io.shardingsphere.core.transaction.event.XaTransactionEvent; import io.shardingsphere.core.transaction.listener.TransactionListener; import io.shardingsphere.core.transaction.spi.TransactionManager; -import io.shardingsphere.core.util.EventBusInstance; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -53,7 +52,7 @@ public static void load() { break; default: } - EventBusInstance.getInstance().register(TransactionListener.getInstance()); + TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance()); } private static void doXaTransactionConfiguration() { diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java similarity index 98% rename from sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java index 52bde5e99f3a9..1d9de86da573d 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.core.jdbc.core.transaction; +package io.shardingsphere.transaction; import io.shardingsphere.core.transaction.event.TransactionEvent; import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent; diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java similarity index 100% rename from sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java similarity index 100% rename from sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java From 5f7ac5b6c2681fdac5c3363cee31bac6ffac3b3e Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 15:03:39 +0800 Subject: [PATCH 006/198] using sharding-transaction, refactor proxy and jdbc. --- sharding-jdbc/pom.xml | 5 +++++ .../jdbc/adapter/AbstractConnectionAdapter.java | 6 +++--- .../jdbc/adapter/AbstractDataSourceAdapter.java | 2 +- sharding-proxy/pom.xml | 2 +- .../jdbc/transaction/XaTransactionEngine.java | 6 +++--- .../shardingsphere/proxy/config/RuleRegistry.java | 4 ++-- ...phere.transaction.common.spi.TransactionManager} | 0 .../transaction}/ProxyTransactionLoader.java | 9 ++++----- .../transaction/TransactionLoader.java | 13 +++++++------ .../transaction/common}/TransactionContext.java | 8 ++++---- .../common}/TransactionContextHolder.java | 2 +- .../transaction/common}/event/TransactionEvent.java | 2 +- .../common}/event/TransactionEventFactory.java | 4 ++-- .../common}/event/WeakXaTransactionEvent.java | 2 +- .../common}/event/XaTransactionEvent.java | 2 +- .../common}/listener/TransactionListener.java | 8 ++++---- .../transaction/common}/spi/TransactionManager.java | 5 ++--- .../{ => weakxa}/WeakXaTransactionManager.java | 8 ++++---- .../transaction/xa/AtomikosTransactionManager.java | 4 ++-- 19 files changed, 48 insertions(+), 44 deletions(-) rename sharding-proxy/src/main/resources/META-INF/services/{io.shardingsphere.core.transaction.spi.TransactionManager => io.shardingsphere.transaction.common.spi.TransactionManager} (100%) rename {sharding-proxy/src/main/java/io/shardingsphere/proxy/util => sharding-transaction/src/main/java/io/shardingsphere/transaction}/ProxyTransactionLoader.java (85%) rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/TransactionContext.java (84%) rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/TransactionContextHolder.java (96%) rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/event/TransactionEvent.java (96%) rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/event/TransactionEventFactory.java (92%) rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/event/WeakXaTransactionEvent.java (96%) rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/event/XaTransactionEvent.java (96%) rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/listener/TransactionListener.java (88%) rename {sharding-core/src/main/java/io/shardingsphere/core/transaction => sharding-transaction/src/main/java/io/shardingsphere/transaction/common}/spi/TransactionManager.java (93%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => weakxa}/WeakXaTransactionManager.java (91%) diff --git a/sharding-jdbc/pom.xml b/sharding-jdbc/pom.xml index 12be6706e4c23..6d36058f3a317 100644 --- a/sharding-jdbc/pom.xml +++ b/sharding-jdbc/pom.xml @@ -14,6 +14,11 @@ sharding-core ${project.version} + + io.shardingsphere + sharding-transaction + ${project.version} + org.projectlombok diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index 458200532d65d..674a8c02e74b9 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -22,9 +22,9 @@ import io.shardingsphere.core.hint.HintManagerHolder; import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection; import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager; -import io.shardingsphere.core.transaction.event.TransactionEvent; -import io.shardingsphere.core.transaction.event.TransactionEventFactory; -import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.common.event.TransactionEventFactory; +import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; import io.shardingsphere.core.util.EventBusInstance; import javax.sql.DataSource; diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java index a078f0912180d..6614587377c8f 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java @@ -19,8 +19,8 @@ import com.google.common.base.Preconditions; import io.shardingsphere.core.constant.DatabaseType; -import io.shardingsphere.core.jdbc.core.transaction.TransactionLoader; import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationDataSource; +import io.shardingsphere.transaction.TransactionLoader; import lombok.Getter; import javax.sql.DataSource; diff --git a/sharding-proxy/pom.xml b/sharding-proxy/pom.xml index 40e7e9ec6a9a4..aa01e36a67b46 100644 --- a/sharding-proxy/pom.xml +++ b/sharding-proxy/pom.xml @@ -24,7 +24,7 @@ io.shardingsphere - sharding-jdbc-transaction + sharding-transaction ${project.version} diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java index eabcdd9d6aebf..4d9f5b8ce1cc6 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java @@ -19,9 +19,9 @@ import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; -import io.shardingsphere.core.transaction.TransactionContext; -import io.shardingsphere.core.transaction.TransactionContextHolder; -import io.shardingsphere.core.transaction.event.XaTransactionEvent; +import io.shardingsphere.transaction.common.TransactionContext; +import io.shardingsphere.transaction.common.TransactionContextHolder; +import io.shardingsphere.transaction.common.event.XaTransactionEvent; import io.shardingsphere.core.util.EventBusInstance; import io.shardingsphere.proxy.config.RuleRegistry; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 61c3e7b2b7e1a..8d88692a1f977 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -30,13 +30,13 @@ import io.shardingsphere.core.rule.MasterSlaveRule; import io.shardingsphere.core.rule.ProxyAuthority; import io.shardingsphere.core.rule.ShardingRule; -import io.shardingsphere.core.transaction.spi.TransactionManager; +import io.shardingsphere.transaction.common.spi.TransactionManager; import io.shardingsphere.jdbc.orchestration.internal.OrchestrationProxyConfiguration; import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent; import io.shardingsphere.proxy.backend.constant.ProxyMode; import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource; import io.shardingsphere.proxy.metadata.ProxyShardingMetaData; -import io.shardingsphere.proxy.util.ProxyTransactionLoader; +import io.shardingsphere.transaction.ProxyTransactionLoader; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.core.transaction.spi.TransactionManager b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager similarity index 100% rename from sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.core.transaction.spi.TransactionManager rename to sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/ProxyTransactionLoader.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java similarity index 85% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/util/ProxyTransactionLoader.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java index b38904c0dc790..a4f277808ed8b 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/ProxyTransactionLoader.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java @@ -15,12 +15,11 @@ *

*/ -package io.shardingsphere.proxy.util; +package io.shardingsphere.transaction; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.core.transaction.listener.TransactionListener; -import io.shardingsphere.core.transaction.spi.TransactionManager; -import io.shardingsphere.core.util.EventBusInstance; +import io.shardingsphere.transaction.common.listener.TransactionListener; +import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -51,7 +50,7 @@ public static TransactionManager load(final TransactionType transactionType) { break; default: } - EventBusInstance.getInstance().register(TransactionListener.getInstance()); + TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance()); return result; } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java index 24d706058d60d..1aa818c10f5d3 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java @@ -18,12 +18,13 @@ package io.shardingsphere.transaction; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.core.transaction.TransactionContext; -import io.shardingsphere.core.transaction.TransactionContextHolder; -import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent; -import io.shardingsphere.core.transaction.event.XaTransactionEvent; -import io.shardingsphere.core.transaction.listener.TransactionListener; -import io.shardingsphere.core.transaction.spi.TransactionManager; +import io.shardingsphere.transaction.common.TransactionContext; +import io.shardingsphere.transaction.common.TransactionContextHolder; +import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.XaTransactionEvent; +import io.shardingsphere.transaction.common.listener.TransactionListener; +import io.shardingsphere.transaction.common.spi.TransactionManager; +import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java similarity index 84% rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContext.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java index 1581ce6c831d3..6dff8a5832162 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContext.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java @@ -15,12 +15,12 @@ *

*/ -package io.shardingsphere.core.transaction; +package io.shardingsphere.transaction.common; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.core.transaction.event.TransactionEvent; -import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent; -import io.shardingsphere.core.transaction.spi.TransactionManager; +import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.Getter; /** diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContextHolder.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java similarity index 96% rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContextHolder.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java index bbbf6acffc99c..676869ce12e4d 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/TransactionContextHolder.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.core.transaction; +package io.shardingsphere.transaction.common; /** * Hold transaction context for current thread. diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java similarity index 96% rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEvent.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java index dce58732d9554..5c02c1b41c74a 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEvent.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.core.transaction.event; +package io.shardingsphere.transaction.common.event; import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEventFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java similarity index 92% rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEventFactory.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java index 530b3587e3543..133914168c293 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/TransactionEventFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java @@ -15,10 +15,10 @@ *

*/ -package io.shardingsphere.core.transaction.event; +package io.shardingsphere.transaction.common.event; import io.shardingsphere.core.constant.TCLType; -import io.shardingsphere.core.transaction.TransactionContextHolder; +import io.shardingsphere.transaction.common.TransactionContextHolder; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java similarity index 96% rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java index e002128cc9df9..f1bb7bcec60c4 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.core.transaction.event; +package io.shardingsphere.transaction.common.event; import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/XaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java similarity index 96% rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/event/XaTransactionEvent.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java index 1791d557a47b4..67c9dd5ecd15c 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/XaTransactionEvent.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.core.transaction.event; +package io.shardingsphere.transaction.common.event; import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/listener/TransactionListener.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java similarity index 88% rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/listener/TransactionListener.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java index eae664f4c0b99..5e131b22bc517 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/listener/TransactionListener.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java @@ -15,13 +15,13 @@ *

*/ -package io.shardingsphere.core.transaction.listener; +package io.shardingsphere.transaction.common.listener; import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; -import io.shardingsphere.core.transaction.TransactionContextHolder; -import io.shardingsphere.core.transaction.event.TransactionEvent; -import io.shardingsphere.core.transaction.spi.TransactionManager; +import io.shardingsphere.transaction.common.TransactionContextHolder; +import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java similarity index 93% rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java index ef2db799a9462..6c06cd29f172a 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java @@ -15,10 +15,9 @@ *

*/ -package io.shardingsphere.core.transaction.spi; - -import io.shardingsphere.core.transaction.event.TransactionEvent; +package io.shardingsphere.transaction.common.spi; +import io.shardingsphere.transaction.common.event.TransactionEvent; import java.sql.SQLException; /** diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java similarity index 91% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java index 1d9de86da573d..3c8de3438a966 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/WeakXaTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java @@ -15,11 +15,11 @@ *

*/ -package io.shardingsphere.transaction; +package io.shardingsphere.transaction.weakxa; -import io.shardingsphere.core.transaction.event.TransactionEvent; -import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent; -import io.shardingsphere.core.transaction.spi.TransactionManager; +import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.spi.TransactionManager; import java.sql.Connection; import java.sql.SQLException; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java index 12d5ab2cf0333..290552baf7211 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java @@ -18,8 +18,8 @@ package io.shardingsphere.transaction.xa; import com.atomikos.icatch.jta.UserTransactionManager; -import io.shardingsphere.core.transaction.event.TransactionEvent; -import io.shardingsphere.core.transaction.spi.TransactionManager; +import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.common.spi.TransactionManager; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; From 4e256c2f958d97691cc7b4b74597aa42bd21a49f Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 16:33:00 +0800 Subject: [PATCH 007/198] add transaction configuration interface. --- .../config/JDBCTransactionConfiguration.java | 54 +++++++++++++++++++ .../config/TransactionConfiguration.java | 41 ++++++++++++++ .../TransactionConfigurationAdapter.java | 44 +++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java new file mode 100644 index 0000000000000..8c72b52dc3c3d --- /dev/null +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -0,0 +1,54 @@ +/* + * 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.transaction.common.config; + +import com.google.common.base.Optional; +import io.shardingsphere.core.constant.TransactionType; +import io.shardingsphere.transaction.common.TransactionContext; +import io.shardingsphere.transaction.common.TransactionContextHolder; +import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.XaTransactionEvent; +import io.shardingsphere.transaction.common.spi.TransactionManager; +import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager; + +/** + * JDBC transaction configuration. + * + * @author zhaojun + */ +public class JDBCTransactionConfiguration extends TransactionConfigurationAdapter { + + @Override + public void configTransactionContext(final TransactionType transactionType) { + switch (transactionType) { + case XA: + doXaTransactionConfiguration(); + break; + case BASE: + break; + default: + } + } + + private void doXaTransactionConfiguration() { + Optional transactionManager = doSPIConfiguration(); + TransactionContext transactionContext = transactionManager.isPresent() ? new TransactionContext(transactionManager.get(), TransactionType.XA, XaTransactionEvent.class) + : new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class); + TransactionContextHolder.set(transactionContext); + } +} diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java new file mode 100644 index 0000000000000..867b3da9d5d0b --- /dev/null +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java @@ -0,0 +1,41 @@ +/* + * 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.transaction.common.config; + +import io.shardingsphere.core.constant.TransactionType; + +/** + * Execute transaction manager configuration. + * + * @author zhaojun + */ +public interface TransactionConfiguration { + + /** + * Config transaction context, then binding to current thread. + * + * @param transactionType transaction type + */ + void configTransactionContext(TransactionType transactionType); + + /** + * Subscribe transaction event using listener, register into event bus. + */ + void registerListener(); + +} diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java new file mode 100644 index 0000000000000..7ffa67dbc61e1 --- /dev/null +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java @@ -0,0 +1,44 @@ +/* + * 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.transaction.common.config; + +import com.google.common.base.Optional; +import io.shardingsphere.transaction.TransactionEventBusInstance; +import io.shardingsphere.transaction.common.listener.TransactionListener; +import io.shardingsphere.transaction.common.spi.TransactionManager; + +import java.util.Iterator; +import java.util.ServiceLoader; + +/** + * Abstract transaction manager configuration. + * + * @author zhaojun + */ +public abstract class TransactionConfigurationAdapter implements TransactionConfiguration { + + @Override + public void registerListener() { + TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance()); + } + + protected Optional doSPIConfiguration() { + Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator(); + return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.absent(); + } +} From 6c4dfd1ca493b43d543de60fb598f721330fba5c Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 16:48:18 +0800 Subject: [PATCH 008/198] refactor AbstractDataSource Adapter using JDBCTransactionConfiguration. --- .../jdbc/adapter/AbstractDataSourceAdapter.java | 6 ++++-- .../config/JDBCTransactionConfiguration.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java index 6614587377c8f..b7c6fb7aee224 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java @@ -20,7 +20,8 @@ import com.google.common.base.Preconditions; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationDataSource; -import io.shardingsphere.transaction.TransactionLoader; +import io.shardingsphere.transaction.common.TransactionContextHolder; +import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration; import lombok.Getter; import javax.sql.DataSource; @@ -38,7 +39,8 @@ public abstract class AbstractDataSourceAdapter extends AbstractUnsupportedOperationDataSource { static { - TransactionLoader.load(); + JDBCTransactionConfiguration.getInstance().configTransactionContext(TransactionContextHolder.get().getTransactionType()); + JDBCTransactionConfiguration.getInstance().registerListener(); } @Getter diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java index 8c72b52dc3c3d..bac5eff38abed 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -25,14 +25,28 @@ import io.shardingsphere.transaction.common.event.XaTransactionEvent; import io.shardingsphere.transaction.common.spi.TransactionManager; import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; /** * JDBC transaction configuration. * * @author zhaojun */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class JDBCTransactionConfiguration extends TransactionConfigurationAdapter { + private static final JDBCTransactionConfiguration CONFIGURATION = new JDBCTransactionConfiguration(); + + /** + * Get singleton instance of {@code JDBCTransactionConfiguration}. + * + * @return JDBC transaction configuration + */ + public static JDBCTransactionConfiguration getInstance() { + return CONFIGURATION; + } + @Override public void configTransactionContext(final TransactionType transactionType) { switch (transactionType) { From 1bc352d73a2ac5906c768bfb8fb5c308f87c283b Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 16:57:13 +0800 Subject: [PATCH 009/198] create transaction context using factory. --- .../common/TransactionContextFactory.java | 54 +++++++++++++++++++ .../config/JDBCTransactionConfiguration.java | 8 ++- 2 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java new file mode 100644 index 0000000000000..4e7083b620c48 --- /dev/null +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java @@ -0,0 +1,54 @@ +/* + * 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.transaction.common; + +import io.shardingsphere.core.constant.TransactionType; +import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.XaTransactionEvent; +import io.shardingsphere.transaction.common.spi.TransactionManager; +import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * Transaction context factory. + * + * @author zhaojun + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class TransactionContextFactory { + + /** + * Create transaction context of XA. + * + * @param transactionManager transaction manager + * @return XA transaction context + */ + public static TransactionContext newXAContext(final TransactionManager transactionManager) { + return new TransactionContext(transactionManager, TransactionType.XA, XaTransactionEvent.class); + } + + /** + * Create transaction context of weak XA. + * + * @return weak XA transaction context + */ + public static TransactionContext newWeakXAContext() { + return new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class); + } +} diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java index bac5eff38abed..da3e5194793a9 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -20,11 +20,9 @@ import com.google.common.base.Optional; import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.common.TransactionContext; +import io.shardingsphere.transaction.common.TransactionContextFactory; import io.shardingsphere.transaction.common.TransactionContextHolder; -import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; -import io.shardingsphere.transaction.common.event.XaTransactionEvent; import io.shardingsphere.transaction.common.spi.TransactionManager; -import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -61,8 +59,8 @@ public void configTransactionContext(final TransactionType transactionType) { private void doXaTransactionConfiguration() { Optional transactionManager = doSPIConfiguration(); - TransactionContext transactionContext = transactionManager.isPresent() ? new TransactionContext(transactionManager.get(), TransactionType.XA, XaTransactionEvent.class) - : new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class); + TransactionContext transactionContext = transactionManager.isPresent() + ? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newWeakXAContext(); TransactionContextHolder.set(transactionContext); } } From 159b1d79b2ffd28f90a41e1035d98231daa617f9 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 17:02:27 +0800 Subject: [PATCH 010/198] move configTransactionContext to TransactionConfigurationAdapter. --- .../config/JDBCTransactionConfiguration.java | 14 +------------- .../config/TransactionConfigurationAdapter.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java index da3e5194793a9..1dd88adf7f7f9 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -18,7 +18,6 @@ package io.shardingsphere.transaction.common.config; import com.google.common.base.Optional; -import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.common.TransactionContext; import io.shardingsphere.transaction.common.TransactionContextFactory; import io.shardingsphere.transaction.common.TransactionContextHolder; @@ -46,18 +45,7 @@ public static JDBCTransactionConfiguration getInstance() { } @Override - public void configTransactionContext(final TransactionType transactionType) { - switch (transactionType) { - case XA: - doXaTransactionConfiguration(); - break; - case BASE: - break; - default: - } - } - - private void doXaTransactionConfiguration() { + protected void doXaTransactionConfiguration() { Optional transactionManager = doSPIConfiguration(); TransactionContext transactionContext = transactionManager.isPresent() ? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newWeakXAContext(); diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java index 7ffa67dbc61e1..ed20f114206e8 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java @@ -18,6 +18,7 @@ package io.shardingsphere.transaction.common.config; import com.google.common.base.Optional; +import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.TransactionEventBusInstance; import io.shardingsphere.transaction.common.listener.TransactionListener; import io.shardingsphere.transaction.common.spi.TransactionManager; @@ -32,11 +33,25 @@ */ public abstract class TransactionConfigurationAdapter implements TransactionConfiguration { + @Override + public void configTransactionContext(final TransactionType transactionType) { + switch (transactionType) { + case XA: + doXaTransactionConfiguration(); + break; + case BASE: + break; + default: + } + } + @Override public void registerListener() { TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance()); } + protected abstract void doXaTransactionConfiguration(); + protected Optional doSPIConfiguration() { Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator(); return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.absent(); From 9902b61e07a7617fb2699b0ae7fcbe33add2f310 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 17:20:42 +0800 Subject: [PATCH 011/198] add proxy transaction configuration. --- .../config/JDBCTransactionConfiguration.java | 4 +- .../config/ProxyTransactionConfiguration.java | 53 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java index 1dd88adf7f7f9..52f9b92366584 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -33,7 +33,7 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class JDBCTransactionConfiguration extends TransactionConfigurationAdapter { - private static final JDBCTransactionConfiguration CONFIGURATION = new JDBCTransactionConfiguration(); + private static final JDBCTransactionConfiguration CONFIG = new JDBCTransactionConfiguration(); /** * Get singleton instance of {@code JDBCTransactionConfiguration}. @@ -41,7 +41,7 @@ public class JDBCTransactionConfiguration extends TransactionConfigurationAdapte * @return JDBC transaction configuration */ public static JDBCTransactionConfiguration getInstance() { - return CONFIGURATION; + return CONFIG; } @Override diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java new file mode 100644 index 0000000000000..a911a84355d9b --- /dev/null +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java @@ -0,0 +1,53 @@ +/* + * 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.transaction.common.config; + +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import io.shardingsphere.transaction.common.TransactionContextFactory; +import io.shardingsphere.transaction.common.TransactionContextHolder; +import io.shardingsphere.transaction.common.spi.TransactionManager; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * Sharding proxy transaction configuration. + * + * @author zhaojun + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ProxyTransactionConfiguration extends TransactionConfigurationAdapter { + + private static final ProxyTransactionConfiguration CONFIG = new ProxyTransactionConfiguration(); + + /** + * Get singleton instance of {@code ProxyTransactionConfiguration}. + * + * @return proxy transaction configuration + */ + public static ProxyTransactionConfiguration getInstance() { + return CONFIG; + } + + @Override + protected void doXaTransactionConfiguration() { + Optional transactionManager = doSPIConfiguration(); + Preconditions.checkState(transactionManager.isPresent(), "there is no XA transaction manager existing, please prepare exactly one(Atomikos or Narayana) using SPI."); + TransactionContextHolder.set(TransactionContextFactory.newXAContext(transactionManager.get())); + } +} From fd03ce41238125e4128f53389de8d1f31cfce11d Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 17:30:00 +0800 Subject: [PATCH 012/198] add transaction manager result for TransactionConfiguration. --- .../common/config/JDBCTransactionConfiguration.java | 3 ++- .../common/config/ProxyTransactionConfiguration.java | 3 ++- .../common/config/TransactionConfiguration.java | 4 +++- .../common/config/TransactionConfigurationAdapter.java | 8 +++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java index 52f9b92366584..27e5b53fbcba4 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -45,10 +45,11 @@ public static JDBCTransactionConfiguration getInstance() { } @Override - protected void doXaTransactionConfiguration() { + protected TransactionManager doXaTransactionConfiguration() { Optional transactionManager = doSPIConfiguration(); TransactionContext transactionContext = transactionManager.isPresent() ? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newWeakXAContext(); TransactionContextHolder.set(transactionContext); + return transactionContext.getTransactionManager(); } } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java index a911a84355d9b..fd4bce1f46a49 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java @@ -45,9 +45,10 @@ public static ProxyTransactionConfiguration getInstance() { } @Override - protected void doXaTransactionConfiguration() { + protected TransactionManager doXaTransactionConfiguration() { Optional transactionManager = doSPIConfiguration(); Preconditions.checkState(transactionManager.isPresent(), "there is no XA transaction manager existing, please prepare exactly one(Atomikos or Narayana) using SPI."); TransactionContextHolder.set(TransactionContextFactory.newXAContext(transactionManager.get())); + return transactionManager.get(); } } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java index 867b3da9d5d0b..3a8b276fc3808 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java @@ -18,6 +18,7 @@ package io.shardingsphere.transaction.common.config; import io.shardingsphere.core.constant.TransactionType; +import io.shardingsphere.transaction.common.spi.TransactionManager; /** * Execute transaction manager configuration. @@ -30,8 +31,9 @@ public interface TransactionConfiguration { * Config transaction context, then binding to current thread. * * @param transactionType transaction type + * @return transaction manager */ - void configTransactionContext(TransactionType transactionType); + TransactionManager configTransactionContext(TransactionType transactionType); /** * Subscribe transaction event using listener, register into event bus. diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java index ed20f114206e8..7093de5c1f817 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java @@ -34,15 +34,17 @@ public abstract class TransactionConfigurationAdapter implements TransactionConfiguration { @Override - public void configTransactionContext(final TransactionType transactionType) { + public TransactionManager configTransactionContext(final TransactionType transactionType) { + TransactionManager result = null; switch (transactionType) { case XA: - doXaTransactionConfiguration(); + result = doXaTransactionConfiguration(); break; case BASE: break; default: } + return result; } @Override @@ -50,7 +52,7 @@ public void registerListener() { TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance()); } - protected abstract void doXaTransactionConfiguration(); + protected abstract TransactionManager doXaTransactionConfiguration(); protected Optional doSPIConfiguration() { Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator(); From 140c20e3e409e39a0cfae461b4a3921e04870dc9 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 17:31:18 +0800 Subject: [PATCH 013/198] refactor RuleRegister using ProxyTransactionConfiguration. --- .../java/io/shardingsphere/proxy/config/RuleRegistry.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 8d88692a1f977..927e4065f9cf9 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -30,13 +30,13 @@ import io.shardingsphere.core.rule.MasterSlaveRule; import io.shardingsphere.core.rule.ProxyAuthority; import io.shardingsphere.core.rule.ShardingRule; -import io.shardingsphere.transaction.common.spi.TransactionManager; import io.shardingsphere.jdbc.orchestration.internal.OrchestrationProxyConfiguration; import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent; import io.shardingsphere.proxy.backend.constant.ProxyMode; import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource; import io.shardingsphere.proxy.metadata.ProxyShardingMetaData; -import io.shardingsphere.transaction.ProxyTransactionLoader; +import io.shardingsphere.transaction.common.config.ProxyTransactionConfiguration; +import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -112,7 +112,8 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE)); - transactionManager = ProxyTransactionLoader.load(transactionType); + transactionManager = ProxyTransactionConfiguration.getInstance().configTransactionContext(transactionType); + ProxyTransactionConfiguration.getInstance().registerListener(); maxWorkingThreads = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MAX_WORKING_THREADS); proxyBackendUseNio = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_USE_NIO); proxyBackendSimpleDbConnections = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_SIMPLE_DB_CONNECTIONS); From b674da61a49129dc6b8d408e204db450f88438e7 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 17:38:33 +0800 Subject: [PATCH 014/198] refactor XaTransactionEngine using ProxyTransactionConfiguration. --- .../backend/jdbc/transaction/XaTransactionEngine.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java index 4d9f5b8ce1cc6..7b1af949a348b 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java @@ -19,11 +19,11 @@ import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; -import io.shardingsphere.transaction.common.TransactionContext; +import io.shardingsphere.proxy.config.RuleRegistry; +import io.shardingsphere.transaction.TransactionEventBusInstance; +import io.shardingsphere.transaction.common.TransactionContextFactory; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.common.event.XaTransactionEvent; -import io.shardingsphere.core.util.EventBusInstance; -import io.shardingsphere.proxy.config.RuleRegistry; import javax.transaction.Status; import java.sql.SQLException; @@ -45,8 +45,8 @@ public XaTransactionEngine(final String sql) { public boolean execute() throws SQLException { Optional tclType = parseSQL(); if (tclType.isPresent() && isInTransaction(tclType.get())) { - TransactionContextHolder.set(new TransactionContext(RULE_REGISTRY.getTransactionManager(), RULE_REGISTRY.getTransactionType(), XaTransactionEvent.class)); - EventBusInstance.getInstance().post(new XaTransactionEvent(tclType.get(), getSql())); + TransactionContextHolder.set(TransactionContextFactory.newXAContext(RULE_REGISTRY.getTransactionManager())); + TransactionEventBusInstance.getInstance().post(new XaTransactionEvent(tclType.get(), getSql())); return true; } return false; From 61d0f83257487f7cebc49c4669cf2c4a8f98b51e Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 17:43:43 +0800 Subject: [PATCH 015/198] move EventBus to sharding-core for common using. --- .../core/util/EventBusInstance.java | 0 .../jdbc/transaction/XaTransactionEngine.java | 4 +- .../TransactionEventBusInstance.java | 42 ------------------- .../TransactionConfigurationAdapter.java | 4 +- 4 files changed, 4 insertions(+), 46 deletions(-) rename {sharding-jdbc => sharding-core}/src/main/java/io/shardingsphere/core/util/EventBusInstance.java (100%) delete mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/util/EventBusInstance.java b/sharding-core/src/main/java/io/shardingsphere/core/util/EventBusInstance.java similarity index 100% rename from sharding-jdbc/src/main/java/io/shardingsphere/core/util/EventBusInstance.java rename to sharding-core/src/main/java/io/shardingsphere/core/util/EventBusInstance.java diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java index 7b1af949a348b..3dae64ee20f36 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java @@ -19,8 +19,8 @@ import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; +import io.shardingsphere.core.util.EventBusInstance; import io.shardingsphere.proxy.config.RuleRegistry; -import io.shardingsphere.transaction.TransactionEventBusInstance; import io.shardingsphere.transaction.common.TransactionContextFactory; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.common.event.XaTransactionEvent; @@ -46,7 +46,7 @@ public boolean execute() throws SQLException { Optional tclType = parseSQL(); if (tclType.isPresent() && isInTransaction(tclType.get())) { TransactionContextHolder.set(TransactionContextFactory.newXAContext(RULE_REGISTRY.getTransactionManager())); - TransactionEventBusInstance.getInstance().post(new XaTransactionEvent(tclType.get(), getSql())); + EventBusInstance.getInstance().post(new XaTransactionEvent(tclType.get(), getSql())); return true; } return false; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java deleted file mode 100644 index c703d9867573b..0000000000000 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionEventBusInstance.java +++ /dev/null @@ -1,42 +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.transaction; - -import com.google.common.eventbus.EventBus; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -/** - * Event bus for singleton instance. - * - * @author zhangliang - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class TransactionEventBusInstance { - - private static final EventBus INSTANCE = new EventBus(); - - /** - * Get event bus instance. - * - * @return event bus instance - */ - public static EventBus getInstance() { - return INSTANCE; - } -} diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java index 7093de5c1f817..525b2a7396ed6 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java @@ -19,7 +19,7 @@ import com.google.common.base.Optional; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.TransactionEventBusInstance; +import io.shardingsphere.core.util.EventBusInstance; import io.shardingsphere.transaction.common.listener.TransactionListener; import io.shardingsphere.transaction.common.spi.TransactionManager; @@ -49,7 +49,7 @@ public TransactionManager configTransactionContext(final TransactionType transac @Override public void registerListener() { - TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance()); + EventBusInstance.getInstance().register(TransactionListener.getInstance()); } protected abstract TransactionManager doXaTransactionConfiguration(); From 6c6e9634ea95c17c27645fd6ad428c8c0a191ab6 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 18:05:54 +0800 Subject: [PATCH 016/198] add log for transactionConfiguration when existing more than one SPI implement. --- .../config/TransactionConfigurationAdapter.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java index 525b2a7396ed6..ffdb2258d317e 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java @@ -18,12 +18,14 @@ package io.shardingsphere.transaction.common.config; import com.google.common.base.Optional; +import com.google.common.collect.Lists; import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.util.EventBusInstance; import io.shardingsphere.transaction.common.listener.TransactionListener; import io.shardingsphere.transaction.common.spi.TransactionManager; +import lombok.extern.slf4j.Slf4j; -import java.util.Iterator; +import java.util.List; import java.util.ServiceLoader; /** @@ -31,6 +33,7 @@ * * @author zhaojun */ +@Slf4j public abstract class TransactionConfigurationAdapter implements TransactionConfiguration { @Override @@ -55,7 +58,10 @@ public void registerListener() { protected abstract TransactionManager doXaTransactionConfiguration(); protected Optional doSPIConfiguration() { - Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator(); - return iterator.hasNext() ? Optional.of(iterator.next()) : Optional.absent(); + List transactionManagerList = Lists.newArrayList(ServiceLoader.load(TransactionManager.class).iterator()); + if (transactionManagerList.size() > 1) { + log.info("there is more than one transaction manger existing, chosen first one default."); + } + return transactionManagerList.isEmpty() ? Optional.absent() : Optional.of(transactionManagerList.get(0)); } } From 72d99b1181780bea65e7c39a3a8237aeb3fbf9bf Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 18:15:21 +0800 Subject: [PATCH 017/198] add transaction context for jdbc connection adapter. --- .../core/jdbc/adapter/AbstractConnectionAdapter.java | 6 +++++- .../transaction/common/TransactionContextHolder.java | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index 674a8c02e74b9..d5fa32626b918 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -22,10 +22,12 @@ import io.shardingsphere.core.hint.HintManagerHolder; import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection; import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager; +import io.shardingsphere.core.util.EventBusInstance; +import io.shardingsphere.transaction.common.TransactionContextHolder; +import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration; import io.shardingsphere.transaction.common.event.TransactionEvent; import io.shardingsphere.transaction.common.event.TransactionEventFactory; import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; -import io.shardingsphere.core.util.EventBusInstance; import javax.sql.DataSource; import java.sql.Connection; @@ -62,6 +64,7 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera * @throws SQLException SQL exception */ public final Connection getConnection(final String dataSourceName) throws SQLException { + JDBCTransactionConfiguration.getInstance().configTransactionContext(TransactionContextHolder.get().getTransactionType()); if (cachedConnections.containsKey(dataSourceName)) { return cachedConnections.get(dataSourceName); } @@ -106,6 +109,7 @@ public void close() throws SQLException { closed = true; HintManagerHolder.clear(); MasterVisitedManager.clear(); + TransactionContextHolder.clear(); Collection exceptions = new LinkedList<>(); for (Connection each : cachedConnections.values()) { try { diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java index 676869ce12e4d..802892695294f 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextHolder.java @@ -48,4 +48,11 @@ public static TransactionContext get() { public static void set(final TransactionContext context) { CONTEXT.set(context); } + + /** + * Clear transaction context for current thread. + */ + public static void clear() { + CONTEXT.remove(); + } } From 0c8e9494348e1aa3905186de3b01907a0c9b1643 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 18:34:10 +0800 Subject: [PATCH 018/198] add local cache for transaction configuration adapter. --- .../TransactionConfigurationAdapter.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java index ffdb2258d317e..399134254388d 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java @@ -25,7 +25,9 @@ import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.extern.slf4j.Slf4j; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.ServiceLoader; /** @@ -36,12 +38,14 @@ @Slf4j public abstract class TransactionConfigurationAdapter implements TransactionConfiguration { + private static final Map> SPI_RESOURCE = new HashMap<>(); + @Override public TransactionManager configTransactionContext(final TransactionType transactionType) { TransactionManager result = null; switch (transactionType) { case XA: - result = doXaTransactionConfiguration(); + result = doXaTransactionConfiguration(transactionType); break; case BASE: break; @@ -55,13 +59,20 @@ public void registerListener() { EventBusInstance.getInstance().register(TransactionListener.getInstance()); } - protected abstract TransactionManager doXaTransactionConfiguration(); + protected abstract TransactionManager doXaTransactionConfiguration(TransactionType transactionType); - protected Optional doSPIConfiguration() { - List transactionManagerList = Lists.newArrayList(ServiceLoader.load(TransactionManager.class).iterator()); - if (transactionManagerList.size() > 1) { - log.info("there is more than one transaction manger existing, chosen first one default."); + protected Optional doSPIConfiguration(final TransactionType transactionType) { + if (SPI_RESOURCE.containsKey(transactionType)) { + return SPI_RESOURCE.get(transactionType); + } + synchronized (SPI_RESOURCE) { + List transactionManagerList = Lists.newArrayList(ServiceLoader.load(TransactionManager.class).iterator()); + if (transactionManagerList.size() > 1) { + log.info("there is more than one transaction manger existing, chosen first one default."); + } + Optional transactionManager = transactionManagerList.isEmpty() ? Optional.absent() : Optional.of(transactionManagerList.get(0)); + SPI_RESOURCE.put(transactionType, transactionManager); + return transactionManager; } - return transactionManagerList.isEmpty() ? Optional.absent() : Optional.of(transactionManagerList.get(0)); } } From 3b66870f1a5d61456136cf462d6d51b08a9e4d91 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 18:36:53 +0800 Subject: [PATCH 019/198] resolve compile error for JDBC and Proxy transaction configuration. --- .../common/config/JDBCTransactionConfiguration.java | 5 +++-- .../common/config/ProxyTransactionConfiguration.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java index 27e5b53fbcba4..f29a8581901e8 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -18,6 +18,7 @@ package io.shardingsphere.transaction.common.config; import com.google.common.base.Optional; +import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.common.TransactionContext; import io.shardingsphere.transaction.common.TransactionContextFactory; import io.shardingsphere.transaction.common.TransactionContextHolder; @@ -45,8 +46,8 @@ public static JDBCTransactionConfiguration getInstance() { } @Override - protected TransactionManager doXaTransactionConfiguration() { - Optional transactionManager = doSPIConfiguration(); + protected TransactionManager doXaTransactionConfiguration(final TransactionType transactionType) { + Optional transactionManager = doSPIConfiguration(transactionType); TransactionContext transactionContext = transactionManager.isPresent() ? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newWeakXAContext(); TransactionContextHolder.set(transactionContext); diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java index fd4bce1f46a49..e30d7b17b07e0 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java @@ -19,6 +19,7 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; +import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.common.TransactionContextFactory; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.common.spi.TransactionManager; @@ -45,8 +46,8 @@ public static ProxyTransactionConfiguration getInstance() { } @Override - protected TransactionManager doXaTransactionConfiguration() { - Optional transactionManager = doSPIConfiguration(); + protected TransactionManager doXaTransactionConfiguration(final TransactionType transactionType) { + Optional transactionManager = doSPIConfiguration(transactionType); Preconditions.checkState(transactionManager.isPresent(), "there is no XA transaction manager existing, please prepare exactly one(Atomikos or Narayana) using SPI."); TransactionContextHolder.set(TransactionContextFactory.newXAContext(transactionManager.get())); return transactionManager.get(); From 8d0e0761f1df0cf567dbc45667d0bd8c25e90136 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 18:59:22 +0800 Subject: [PATCH 020/198] remove unused class. --- .../transaction/ProxyTransactionLoader.java | 62 ----------------- .../transaction/TransactionLoader.java | 69 ------------------- 2 files changed, 131 deletions(-) delete mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java delete mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.java deleted file mode 100644 index a4f277808ed8b..0000000000000 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/ProxyTransactionLoader.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. - *

- */ - -package io.shardingsphere.transaction; - -import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.common.listener.TransactionListener; -import io.shardingsphere.transaction.common.spi.TransactionManager; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Iterator; -import java.util.ServiceLoader; - -/** - * Transaction manager loader via SPI. - * - * @author zhaojun - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ProxyTransactionLoader { - - /** - * Create transaction manager via SPI. - * - * @param transactionType transaction type - * @return transaction manager - */ - public static TransactionManager load(final TransactionType transactionType) { - TransactionManager result = null; - switch (transactionType) { - case XA: - result = doXaTransactionConfiguration(); - break; - case BASE: - break; - default: - } - TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance()); - return result; - } - - // TODO if read more transaction manager, log chosen one, if no transaction manager, throw exception - private static TransactionManager doXaTransactionConfiguration() { - Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator(); - return iterator.hasNext() ? iterator.next() : null; - } -} diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java deleted file mode 100644 index 1aa818c10f5d3..0000000000000 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/TransactionLoader.java +++ /dev/null @@ -1,69 +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.transaction; - -import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.common.TransactionContext; -import io.shardingsphere.transaction.common.TransactionContextHolder; -import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; -import io.shardingsphere.transaction.common.event.XaTransactionEvent; -import io.shardingsphere.transaction.common.listener.TransactionListener; -import io.shardingsphere.transaction.common.spi.TransactionManager; -import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.Iterator; -import java.util.ServiceLoader; - -/** - * Loader Transaction spi with ServiceLoader. - * - * @author zhaojun - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class TransactionLoader { - - /** - * Using ServiceLoader to dynamic load spi transaction. - * - */ - public static void load() { - TransactionContext transactionContext = TransactionContextHolder.get(); - switch (transactionContext.getTransactionType()) { - case XA: - doXaTransactionConfiguration(); - break; - case BASE: - break; - default: - } - TransactionEventBusInstance.getInstance().register(TransactionListener.getInstance()); - } - - private static void doXaTransactionConfiguration() { - Iterator iterator = ServiceLoader.load(TransactionManager.class).iterator(); - TransactionContext transactionContext; - if (iterator.hasNext()) { - transactionContext = new TransactionContext(iterator.next(), TransactionType.XA, XaTransactionEvent.class); - } else { - transactionContext = new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class); - } - TransactionContextHolder.set(transactionContext); - } -} From cbbd4f6de564fdffa8971d18245788b5a220b3f3 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 19:16:39 +0800 Subject: [PATCH 021/198] Merge branch 'dev' of https://github.com/sharding-sphere/sharding-sphere into sharding-proxy-xa-transaction # Conflicts: # sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java # sharding-proxy/src/main/java/io/shardingsphere/proxy/util/ProxyTransactionLoader.java --- .../io/shardingsphere/proxy/config/RuleRegistry.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 18fc685979014..26c21eb5ceaa7 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -24,19 +24,19 @@ import io.shardingsphere.core.constant.ShardingProperties; import io.shardingsphere.core.constant.ShardingPropertiesConstant; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData; +import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.rule.DataSourceParameter; import io.shardingsphere.core.rule.MasterSlaveRule; import io.shardingsphere.core.rule.ProxyAuthority; import io.shardingsphere.core.rule.ShardingRule; -import io.shardingsphere.core.transaction.spi.TransactionManager; import io.shardingsphere.jdbc.orchestration.internal.OrchestrationProxyConfiguration; import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent; import io.shardingsphere.proxy.backend.constant.ProxyMode; import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource; import io.shardingsphere.proxy.metadata.ProxyShardingTableMetaData; -import io.shardingsphere.proxy.util.ProxyTransactionLoader; +import io.shardingsphere.transaction.common.config.ProxyTransactionConfiguration; +import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -112,7 +112,8 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE)); - transactionManager = ProxyTransactionLoader.load(transactionType); + transactionManager = ProxyTransactionConfiguration.getInstance().configTransactionContext(transactionType); + ProxyTransactionConfiguration.getInstance().registerListener(); maxWorkingThreads = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MAX_WORKING_THREADS); proxyBackendUseNio = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_USE_NIO); proxyBackendSimpleDbConnections = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_SIMPLE_DB_CONNECTIONS); From f2330692202c1f4e32abdf19c38c562544c829b8 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 30 Jul 2018 19:18:03 +0800 Subject: [PATCH 022/198] config file revert. --- .../src/main/resources/conf/config.yaml | 199 ++++++------------ sharding-proxy/src/main/resources/logback.xml | 4 +- 2 files changed, 69 insertions(+), 134 deletions(-) diff --git a/sharding-proxy/src/main/resources/conf/config.yaml b/sharding-proxy/src/main/resources/conf/config.yaml index 723ddb7048472..9bb12cfdd3c72 100644 --- a/sharding-proxy/src/main/resources/conf/config.yaml +++ b/sharding-proxy/src/main/resources/conf/config.yaml @@ -1,142 +1,77 @@ ################## ################## # Here you can configure the rules for the proxy. # -# We provide two kinds of configurations for example. The one is the configuration of Sharding rule, -# and the other is the configuration of master-slave rule. -# If you want to use Sharding, please refer to the first one, and if you only want to use master-slave, -# please refer to the second one. +# We provide two kinds of configurations for example. This one is the configuration of Sharding rule, +# If you want to use Sharding, please refer to the this one, and if you only want to use master-slave, +# please refer to config_master_slave.yaml. # ################## ################## - # The example of Sharding rule. -dataSources: - ds_0: - url: jdbc:mysql://127.0.0.1:3306/ds_trans_0?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 - ds_1: - url: jdbc:mysql://127.0.0.1:3306/ds_trans_1?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 - ds_2: - url: jdbc:mysql://127.0.0.1:3306/ds_trans_2?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 - ds_3: - url: jdbc:mysql://127.0.0.1:3306/ds_trans_3?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 - ds_4: - url: jdbc:mysql://127.0.0.1:3306/ds_trans_4?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 - ds_5: - url: jdbc:mysql://127.0.0.1:3306/ds_trans_5?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 - ds_6: - url: jdbc:mysql://127.0.0.1:3306/ds_trans_6?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 - ds_7: - url: jdbc:mysql://127.0.0.1:3306/ds_trans_7?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 - ds_8: - url: jdbc:mysql://127.0.0.1:3306/ds_trans_8?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 - ds_9: - url: jdbc:mysql://127.0.0.1:3306/ds_trans_9?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 -shardingRule: - tables: - t_order: - actualDataNodes: ds_${0..1}.t_order_${0..1} - tableStrategy: - inline: - shardingColumn: order_id - algorithmExpression: t_order_${order_id % 2} - keyGeneratorColumnName: order_id - t_order_item: - actualDataNodes: ds_${0..1}.t_order_item_${0..1} - tableStrategy: - inline: - shardingColumn: order_id - algorithmExpression: t_order_item_${order_id % 2} - bindingTables: - - t_order,t_order_item - defaultDatabaseStrategy: - inline: - shardingColumn: user_id - algorithmExpression: ds_${user_id % 2} - defaultTableStrategy: - none: - defaultKeyGeneratorClassName: io.shardingsphere.core.keygen.DefaultKeyGenerator +#dataSources: +# ds_0: +# url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false +# username: root +# password: +# autoCommit: true +# connectionTimeout: 30000 +# idleTimeout: 60000 +# maxLifetime: 1800000 +# maximumPoolSize: 65 +# ds_1: +# url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false +# username: root +# password: +# autoCommit: true +# connectionTimeout: 30000 +# idleTimeout: 60000 +# maxLifetime: 1800000 +# maximumPoolSize: 65 +# +#shardingRule: +# tables: +# t_order: +# actualDataNodes: ds_${0..1}.t_order_${0..1} +# tableStrategy: +# inline: +# shardingColumn: order_id +# algorithmExpression: t_order_${order_id % 2} +# keyGeneratorColumnName: order_id +# t_order_item: +# actualDataNodes: ds_${0..1}.t_order_item_${0..1} +# tableStrategy: +# inline: +# shardingColumn: order_id +# algorithmExpression: t_order_item_${order_id % 2} +# bindingTables: +# - t_order,t_order_item +# defaultDatabaseStrategy: +# inline: +# shardingColumn: user_id +# algorithmExpression: ds_${user_id % 2} +# defaultTableStrategy: +# none: +# defaultKeyGeneratorClassName: io.shardingsphere.core.keygen.DefaultKeyGenerator +# +# props: +# # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database. +# # The benefit of this approach is saving memory for Proxy by Stream ResultSet. +# # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. +# # Meanwhile, the cost of the memory will be increased. +# proxy.mode: MEMORY_STRICTLY +# proxy.transaction.mode: NONE +# proxy.max.working.threads: 16 +# sql.show: false - props: - # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database. - # The benefit of this approach is saving memory for Proxy by Stream ResultSet. - # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. - # Meanwhile, the cost of the memory will be increased. - proxy.mode: CONNECTION_STRICTLY - proxy.transaction.mode: NONE - proxy.max.working.threads: 16 - sql.show: false +#orchestration: +# name: orchestration_ds +# type: SHARDING +# overwrite: true +# zookeeper: +# namespace: orchestration +# serverLists: localhost:2181 -proxyAuthority: - username: root - password: root \ No newline at end of file +#proxyAuthority: +# username: root +# password: root \ No newline at end of file diff --git a/sharding-proxy/src/main/resources/logback.xml b/sharding-proxy/src/main/resources/logback.xml index 733a52031a8c7..35eedd49dc958 100644 --- a/sharding-proxy/src/main/resources/logback.xml +++ b/sharding-proxy/src/main/resources/logback.xml @@ -9,9 +9,9 @@ - + - + From b9e2ff16fa0e934164bdf43c74f28d5aad18034a Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Tue, 31 Jul 2018 10:28:12 +0800 Subject: [PATCH 023/198] adjust weakXATransaction manager package. --- .../transaction/common/TransactionContextFactory.java | 2 +- .../transaction/{weakxa => xa}/WeakXaTransactionManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{weakxa => xa}/WeakXaTransactionManager.java (98%) diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java index 4e7083b620c48..5330433b4f6c8 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java @@ -21,7 +21,7 @@ import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; import io.shardingsphere.transaction.common.event.XaTransactionEvent; import io.shardingsphere.transaction.common.spi.TransactionManager; -import io.shardingsphere.transaction.weakxa.WeakXaTransactionManager; +import io.shardingsphere.transaction.xa.WeakXaTransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java similarity index 98% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java index 3c8de3438a966..412d10eea3a0b 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/weakxa/WeakXaTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.transaction.weakxa; +package io.shardingsphere.transaction.xa; import io.shardingsphere.transaction.common.event.TransactionEvent; import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; From 91f1de4e22ef23c08a59d3f1c533d2611dcb5f04 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Tue, 31 Jul 2018 10:33:43 +0800 Subject: [PATCH 024/198] adjust transaction event package. --- .../core/jdbc/adapter/AbstractConnectionAdapter.java | 6 +++--- .../proxy/backend/jdbc/transaction/XaTransactionEngine.java | 2 +- .../transaction/common/TransactionContext.java | 4 ++-- .../transaction/common/TransactionContextFactory.java | 4 ++-- .../transaction/common/listener/TransactionListener.java | 2 +- .../transaction/common/spi/TransactionManager.java | 2 +- .../transaction/{common => }/event/TransactionEvent.java | 2 +- .../{common => }/event/TransactionEventFactory.java | 2 +- .../{common => }/event/WeakXaTransactionEvent.java | 2 +- .../transaction/{common => }/event/XaTransactionEvent.java | 2 +- .../transaction/xa/AtomikosTransactionManager.java | 2 +- .../transaction/xa/WeakXaTransactionManager.java | 4 ++-- 12 files changed, 17 insertions(+), 17 deletions(-) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common => }/event/TransactionEvent.java (96%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common => }/event/TransactionEventFactory.java (96%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common => }/event/WeakXaTransactionEvent.java (96%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common => }/event/XaTransactionEvent.java (96%) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index d5fa32626b918..d49b06288aaf3 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -25,9 +25,9 @@ import io.shardingsphere.core.util.EventBusInstance; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration; -import io.shardingsphere.transaction.common.event.TransactionEvent; -import io.shardingsphere.transaction.common.event.TransactionEventFactory; -import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.event.TransactionEvent; +import io.shardingsphere.transaction.event.TransactionEventFactory; +import io.shardingsphere.transaction.event.WeakXaTransactionEvent; import javax.sql.DataSource; import java.sql.Connection; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java index 3dae64ee20f36..dfe74505d9b35 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java @@ -23,7 +23,7 @@ import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.transaction.common.TransactionContextFactory; import io.shardingsphere.transaction.common.TransactionContextHolder; -import io.shardingsphere.transaction.common.event.XaTransactionEvent; +import io.shardingsphere.transaction.event.XaTransactionEvent; import javax.transaction.Status; import java.sql.SQLException; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java index 6dff8a5832162..bcf80b4a98aec 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java @@ -18,8 +18,8 @@ package io.shardingsphere.transaction.common; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.common.event.TransactionEvent; -import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.event.TransactionEvent; +import io.shardingsphere.transaction.event.WeakXaTransactionEvent; import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.Getter; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java index 5330433b4f6c8..4801dab71c81d 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java @@ -18,8 +18,8 @@ package io.shardingsphere.transaction.common; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; -import io.shardingsphere.transaction.common.event.XaTransactionEvent; +import io.shardingsphere.transaction.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.event.XaTransactionEvent; import io.shardingsphere.transaction.common.spi.TransactionManager; import io.shardingsphere.transaction.xa.WeakXaTransactionManager; import lombok.AccessLevel; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java index 5e131b22bc517..837e5aac1d74d 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java @@ -20,7 +20,7 @@ import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; import io.shardingsphere.transaction.common.TransactionContextHolder; -import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.event.TransactionEvent; import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java index 6c06cd29f172a..98dd54bd3696f 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java @@ -17,7 +17,7 @@ package io.shardingsphere.transaction.common.spi; -import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.event.TransactionEvent; import java.sql.SQLException; /** diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java similarity index 96% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java index 5c02c1b41c74a..c0b1321420bcf 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.transaction.common.event; +package io.shardingsphere.transaction.event; import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java similarity index 96% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java index 133914168c293..0148059ff18b4 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.transaction.common.event; +package io.shardingsphere.transaction.event; import io.shardingsphere.core.constant.TCLType; import io.shardingsphere.transaction.common.TransactionContextHolder; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java similarity index 96% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java index f1bb7bcec60c4..006875de72479 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.transaction.common.event; +package io.shardingsphere.transaction.event; import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java similarity index 96% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java index 67c9dd5ecd15c..202ed83b8e07b 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.transaction.common.event; +package io.shardingsphere.transaction.event; import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java index 290552baf7211..dd79210cbf1c8 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java @@ -18,7 +18,7 @@ package io.shardingsphere.transaction.xa; import com.atomikos.icatch.jta.UserTransactionManager; -import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.event.TransactionEvent; import io.shardingsphere.transaction.common.spi.TransactionManager; import javax.transaction.HeuristicMixedException; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java index 412d10eea3a0b..5162d80904e46 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java @@ -17,8 +17,8 @@ package io.shardingsphere.transaction.xa; -import io.shardingsphere.transaction.common.event.TransactionEvent; -import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.event.TransactionEvent; +import io.shardingsphere.transaction.event.WeakXaTransactionEvent; import io.shardingsphere.transaction.common.spi.TransactionManager; import java.sql.Connection; From 1305d45baa9f15ce9a8024849ff32fccd6604264 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Tue, 31 Jul 2018 10:55:06 +0800 Subject: [PATCH 025/198] move xa and base transaction to api package. --- .../java/io/shardingsphere/proxy/config/RuleRegistry.java | 2 +- .../io.shardingsphere.transaction.api.TransactionManager | 1 + ...o.shardingsphere.transaction.common.spi.TransactionManager | 1 - .../transaction/{common/spi => api}/TransactionManager.java | 2 +- .../transaction/{ => api}/xa/AtomikosTransactionManager.java | 4 ++-- .../transaction/{ => api}/xa/AtomikosUserTransaction.java | 2 +- .../transaction/{ => api}/xa/WeakXaTransactionManager.java | 4 ++-- .../shardingsphere/transaction/common/TransactionContext.java | 2 +- .../transaction/common/TransactionContextFactory.java | 4 ++-- .../common/config/JDBCTransactionConfiguration.java | 2 +- .../common/config/ProxyTransactionConfiguration.java | 2 +- .../transaction/common/config/TransactionConfiguration.java | 2 +- .../common/config/TransactionConfigurationAdapter.java | 4 ++-- .../{common => }/listener/TransactionListener.java | 4 ++-- 14 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager delete mode 100644 sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common/spi => api}/TransactionManager.java (97%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => api}/xa/AtomikosTransactionManager.java (95%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => api}/xa/AtomikosUserTransaction.java (96%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => api}/xa/WeakXaTransactionManager.java (96%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common => }/listener/TransactionListener.java (94%) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 26c21eb5ceaa7..17adc18de1fa7 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -35,8 +35,8 @@ import io.shardingsphere.proxy.backend.constant.ProxyMode; import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource; import io.shardingsphere.proxy.metadata.ProxyShardingTableMetaData; +import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.config.ProxyTransactionConfiguration; -import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager new file mode 100644 index 0000000000000..c41e2fba94e9e --- /dev/null +++ b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager @@ -0,0 +1 @@ +io.shardingsphere.transaction.api.xa.AtomikosTransactionManager \ No newline at end of file diff --git a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager deleted file mode 100644 index bfa7798479eba..0000000000000 --- a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.common.spi.TransactionManager +++ /dev/null @@ -1 +0,0 @@ -io.shardingsphere.transaction.xa.AtomikosTransactionManager \ No newline at end of file diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java similarity index 97% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java index 98dd54bd3696f..645e8d0277fab 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/spi/TransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.transaction.common.spi; +package io.shardingsphere.transaction.api; import io.shardingsphere.transaction.event.TransactionEvent; import java.sql.SQLException; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java similarity index 95% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java index dd79210cbf1c8..47162618d7a61 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java @@ -15,11 +15,11 @@ *

*/ -package io.shardingsphere.transaction.xa; +package io.shardingsphere.transaction.api.xa; import com.atomikos.icatch.jta.UserTransactionManager; +import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.event.TransactionEvent; -import io.shardingsphere.transaction.common.spi.TransactionManager; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosUserTransaction.java similarity index 96% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosUserTransaction.java index 117f8671f8918..137c89ad32787 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosUserTransaction.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.transaction.xa; +package io.shardingsphere.transaction.api.xa; import com.atomikos.icatch.jta.UserTransactionManager; import lombok.AccessLevel; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java similarity index 96% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java index 5162d80904e46..5ad04464918ef 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/xa/WeakXaTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java @@ -15,11 +15,11 @@ *

*/ -package io.shardingsphere.transaction.xa; +package io.shardingsphere.transaction.api.xa; +import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.event.TransactionEvent; import io.shardingsphere.transaction.event.WeakXaTransactionEvent; -import io.shardingsphere.transaction.common.spi.TransactionManager; import java.sql.Connection; import java.sql.SQLException; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java index bcf80b4a98aec..3779ad40b353c 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java @@ -18,9 +18,9 @@ package io.shardingsphere.transaction.common; import io.shardingsphere.core.constant.TransactionType; +import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.event.TransactionEvent; import io.shardingsphere.transaction.event.WeakXaTransactionEvent; -import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.Getter; /** diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java index 4801dab71c81d..c562bcb857c38 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java @@ -18,10 +18,10 @@ package io.shardingsphere.transaction.common; import io.shardingsphere.core.constant.TransactionType; +import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.event.WeakXaTransactionEvent; import io.shardingsphere.transaction.event.XaTransactionEvent; -import io.shardingsphere.transaction.common.spi.TransactionManager; -import io.shardingsphere.transaction.xa.WeakXaTransactionManager; +import io.shardingsphere.transaction.api.xa.WeakXaTransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java index f29a8581901e8..486b7a6823e88 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -19,10 +19,10 @@ import com.google.common.base.Optional; import io.shardingsphere.core.constant.TransactionType; +import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.TransactionContext; import io.shardingsphere.transaction.common.TransactionContextFactory; import io.shardingsphere.transaction.common.TransactionContextHolder; -import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java index e30d7b17b07e0..e63ef806d52bf 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java @@ -20,9 +20,9 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; import io.shardingsphere.core.constant.TransactionType; +import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.TransactionContextFactory; import io.shardingsphere.transaction.common.TransactionContextHolder; -import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java index 3a8b276fc3808..76533870eba55 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java @@ -18,7 +18,7 @@ package io.shardingsphere.transaction.common.config; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.common.spi.TransactionManager; +import io.shardingsphere.transaction.api.TransactionManager; /** * Execute transaction manager configuration. diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java index 399134254388d..9d0bddc090ca3 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java @@ -21,8 +21,8 @@ import com.google.common.collect.Lists; import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.util.EventBusInstance; -import io.shardingsphere.transaction.common.listener.TransactionListener; -import io.shardingsphere.transaction.common.spi.TransactionManager; +import io.shardingsphere.transaction.api.TransactionManager; +import io.shardingsphere.transaction.listener.TransactionListener; import lombok.extern.slf4j.Slf4j; import java.util.HashMap; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java similarity index 94% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java index 837e5aac1d74d..08530020d9e14 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java @@ -15,13 +15,13 @@ *

*/ -package io.shardingsphere.transaction.common.listener; +package io.shardingsphere.transaction.listener; import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; +import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.event.TransactionEvent; -import io.shardingsphere.transaction.common.spi.TransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; From bed9514cec4cfeff7e0db4b6c2e9b386cad007fb Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Tue, 31 Jul 2018 11:05:11 +0800 Subject: [PATCH 026/198] adjust transaction common package. --- .../core/jdbc/adapter/AbstractConnectionAdapter.java | 6 +++--- .../proxy/backend/jdbc/transaction/XaTransactionEngine.java | 2 +- .../shardingsphere/transaction/api/TransactionManager.java | 2 +- .../transaction/api/xa/AtomikosTransactionManager.java | 2 +- .../transaction/api/xa/WeakXaTransactionManager.java | 4 ++-- .../transaction/common/TransactionContext.java | 4 ++-- .../transaction/common/TransactionContextFactory.java | 4 ++-- .../common/config/TransactionConfigurationAdapter.java | 2 +- .../transaction/{ => common}/event/TransactionEvent.java | 2 +- .../{ => common}/event/TransactionEventFactory.java | 2 +- .../{ => common}/event/WeakXaTransactionEvent.java | 2 +- .../transaction/{ => common}/event/XaTransactionEvent.java | 2 +- .../{ => common}/listener/TransactionListener.java | 4 ++-- 13 files changed, 19 insertions(+), 19 deletions(-) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => common}/event/TransactionEvent.java (96%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => common}/event/TransactionEventFactory.java (96%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => common}/event/WeakXaTransactionEvent.java (96%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => common}/event/XaTransactionEvent.java (96%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{ => common}/listener/TransactionListener.java (94%) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index d49b06288aaf3..d5fa32626b918 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -25,9 +25,9 @@ import io.shardingsphere.core.util.EventBusInstance; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration; -import io.shardingsphere.transaction.event.TransactionEvent; -import io.shardingsphere.transaction.event.TransactionEventFactory; -import io.shardingsphere.transaction.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.common.event.TransactionEventFactory; +import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; import javax.sql.DataSource; import java.sql.Connection; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java index dfe74505d9b35..3dae64ee20f36 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java @@ -23,7 +23,7 @@ import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.transaction.common.TransactionContextFactory; import io.shardingsphere.transaction.common.TransactionContextHolder; -import io.shardingsphere.transaction.event.XaTransactionEvent; +import io.shardingsphere.transaction.common.event.XaTransactionEvent; import javax.transaction.Status; import java.sql.SQLException; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java index 645e8d0277fab..8dc49da1ea869 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java @@ -17,7 +17,7 @@ package io.shardingsphere.transaction.api; -import io.shardingsphere.transaction.event.TransactionEvent; +import io.shardingsphere.transaction.common.event.TransactionEvent; import java.sql.SQLException; /** diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java index 47162618d7a61..bde3f3fa4e16c 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java @@ -19,7 +19,7 @@ import com.atomikos.icatch.jta.UserTransactionManager; import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.event.TransactionEvent; +import io.shardingsphere.transaction.common.event.TransactionEvent; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java index 5ad04464918ef..6025dba35b4e1 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java @@ -18,8 +18,8 @@ package io.shardingsphere.transaction.api.xa; import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.event.TransactionEvent; -import io.shardingsphere.transaction.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; import java.sql.Connection; import java.sql.SQLException; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java index 3779ad40b353c..58941d29bd2ac 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java @@ -19,8 +19,8 @@ import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.event.TransactionEvent; -import io.shardingsphere.transaction.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; import lombok.Getter; /** diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java index c562bcb857c38..15aa2f4ec5be9 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java @@ -19,8 +19,8 @@ import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.event.WeakXaTransactionEvent; -import io.shardingsphere.transaction.event.XaTransactionEvent; +import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.XaTransactionEvent; import io.shardingsphere.transaction.api.xa.WeakXaTransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java index 9d0bddc090ca3..8f661a53fffe8 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java @@ -22,7 +22,7 @@ import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.util.EventBusInstance; import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.listener.TransactionListener; +import io.shardingsphere.transaction.common.listener.TransactionListener; import lombok.extern.slf4j.Slf4j; import java.util.HashMap; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java similarity index 96% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java index c0b1321420bcf..5c02c1b41c74a 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEvent.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEvent.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.transaction.event; +package io.shardingsphere.transaction.common.event; import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java similarity index 96% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java index 0148059ff18b4..133914168c293 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/TransactionEventFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.transaction.event; +package io.shardingsphere.transaction.common.event; import io.shardingsphere.core.constant.TCLType; import io.shardingsphere.transaction.common.TransactionContextHolder; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java similarity index 96% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java index 006875de72479..f1bb7bcec60c4 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/WeakXaTransactionEvent.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.transaction.event; +package io.shardingsphere.transaction.common.event; import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java similarity index 96% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java index 202ed83b8e07b..67c9dd5ecd15c 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/event/XaTransactionEvent.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/XaTransactionEvent.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.transaction.event; +package io.shardingsphere.transaction.common.event; import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java similarity index 94% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java index 08530020d9e14..2c19bbd9b9ad3 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/listener/TransactionListener.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java @@ -15,13 +15,13 @@ *

*/ -package io.shardingsphere.transaction.listener; +package io.shardingsphere.transaction.common.listener; import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.TransactionContextHolder; -import io.shardingsphere.transaction.event.TransactionEvent; +import io.shardingsphere.transaction.common.event.TransactionEvent; import lombok.AccessLevel; import lombok.NoArgsConstructor; From d6d5137d58b6f37b69cab38d73be7ae50467c92e Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Tue, 31 Jul 2018 11:10:04 +0800 Subject: [PATCH 027/198] add saga transaction manager for package placeholder. --- .../api/base/SagaTransactionManager.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java new file mode 100644 index 0000000000000..396d8695b70ef --- /dev/null +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java @@ -0,0 +1,51 @@ +/* + * 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.transaction.api.base; + +import io.shardingsphere.transaction.api.TransactionManager; +import io.shardingsphere.transaction.common.event.TransactionEvent; + +import java.sql.SQLException; + +/** + * Saga transaction manager for sharding-sphere. + * + * @author zhaojun + */ +public class SagaTransactionManager implements TransactionManager { + + @Override + public void begin(final TransactionEvent transactionEvent) throws SQLException { + + } + + @Override + public void commit(final TransactionEvent transactionEvent) throws SQLException { + + } + + @Override + public void rollback(final TransactionEvent transactionEvent) throws SQLException { + + } + + @Override + public int getStatus() throws SQLException { + return 0; + } +} From c266830346316c77e4bd7b4e6b7b2315443b2ce6 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Tue, 31 Jul 2018 11:16:28 +0800 Subject: [PATCH 028/198] make WeakXaTransactionManager is singleton. --- .../api/xa/WeakXaTransactionManager.java | 14 ++++++++++++++ .../common/TransactionContextFactory.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java index 6025dba35b4e1..bdc90c2bc5aeb 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java @@ -20,6 +20,8 @@ import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.event.TransactionEvent; import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import java.sql.Connection; import java.sql.SQLException; @@ -31,8 +33,20 @@ * * @author zhaojun */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class WeakXaTransactionManager implements TransactionManager { + private static final WeakXaTransactionManager TRANSACTION_MANAGER = new WeakXaTransactionManager(); + + /** + * Get singleton instance of {@code WeakXaTransactionManager}. + * + * @return weak XA transaction manager + */ + public static WeakXaTransactionManager getInstance() { + return TRANSACTION_MANAGER; + } + @Override public void begin(final TransactionEvent transactionEvent) throws SQLException { WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java index 15aa2f4ec5be9..90a7a3baba612 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java @@ -49,6 +49,6 @@ public static TransactionContext newXAContext(final TransactionManager transacti * @return weak XA transaction context */ public static TransactionContext newWeakXAContext() { - return new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class); + return new TransactionContext(WeakXaTransactionManager.getInstance(), TransactionType.XA, WeakXaTransactionEvent.class); } } From a6b6a7bb1585380b0b3d4cac22e0cc76e4bd28d5 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Fri, 3 Aug 2018 17:54:15 +0800 Subject: [PATCH 029/198] move it to core module. --- .../main/java/io/shardingsphere/core}/constant/ProxyMode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename {sharding-proxy/src/main/java/io/shardingsphere/proxy/backend => sharding-core/src/main/java/io/shardingsphere/core}/constant/ProxyMode.java (94%) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/ProxyMode.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ProxyMode.java similarity index 94% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/ProxyMode.java rename to sharding-core/src/main/java/io/shardingsphere/core/constant/ProxyMode.java index 975b318f81289..b09a4797acd90 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/ProxyMode.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/ProxyMode.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.proxy.backend.constant; +package io.shardingsphere.core.constant; import lombok.Getter; import lombok.RequiredArgsConstructor; From 40465bcc40c0d344a579bed7e175029b539d5ee1 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Fri, 3 Aug 2018 17:55:01 +0800 Subject: [PATCH 030/198] change import position. --- .../proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java | 2 +- .../main/java/io/shardingsphere/proxy/config/RuleRegistry.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java index ea523d354959c..b99fe86658050 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java @@ -17,7 +17,7 @@ package io.shardingsphere.proxy.backend.jdbc.execute; -import io.shardingsphere.proxy.backend.constant.ProxyMode; +import io.shardingsphere.core.constant.ProxyMode; import io.shardingsphere.proxy.backend.jdbc.connection.BackendConnection; import io.shardingsphere.proxy.backend.jdbc.execute.memory.ConnectionStrictlyExecuteEngine; import io.shardingsphere.proxy.backend.jdbc.execute.stream.MemoryStrictlyExecuteEngine; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index a64c2594e9496..6b2b41c1eb28b 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -35,7 +35,7 @@ import io.shardingsphere.core.transaction.spi.TransactionManager; import io.shardingsphere.jdbc.orchestration.internal.OrchestrationProxyConfiguration; import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent; -import io.shardingsphere.proxy.backend.constant.ProxyMode; +import io.shardingsphere.core.constant.ProxyMode; import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource; import io.shardingsphere.proxy.util.ProxyTransactionLoader; import lombok.AccessLevel; From d1b93fb050be404612e3633356d17645e337b4bb Mon Sep 17 00:00:00 2001 From: tristaZero Date: Sun, 5 Aug 2018 19:43:44 +0800 Subject: [PATCH 031/198] change ProxyMode usagek --- .../core/jdbc/core/datasource/ShardingDataSource.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java index 8c535618ff91a..ca7ca8f0fb95b 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java @@ -20,6 +20,7 @@ import io.shardingsphere.core.api.ConfigMapContext; import io.shardingsphere.core.api.config.MasterSlaveRuleConfiguration; import io.shardingsphere.core.api.config.ShardingRuleConfiguration; +import io.shardingsphere.core.constant.ProxyMode; import io.shardingsphere.core.constant.ShardingProperties; import io.shardingsphere.core.constant.ShardingPropertiesConstant; import io.shardingsphere.core.executor.ExecutorEngine; @@ -72,6 +73,7 @@ public ShardingDataSource(final Map dataSourceMap, final Sha ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData( new TableMetaDataInitializer(executorEngine.getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule)); boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); + ProxyMode proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL); } From f87cd914437686aeb09b3cff2a26e8f8cef18731 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Sun, 5 Aug 2018 21:16:49 +0800 Subject: [PATCH 032/198] add ExecutorEngineFactory.java --- .../core/executor/ExecutorEngineFactory.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java new file mode 100644 index 0000000000000..96f6f3c81933c --- /dev/null +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java @@ -0,0 +1,44 @@ +/* + * 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.core.executor; + +import io.shardingsphere.core.constant.ProxyMode; +import io.shardingsphere.core.executor.type.connection.ConnectionStrictlyExecutorEngine; +import io.shardingsphere.core.executor.type.memory.MemoryStrictlyExecutorEngine; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * JDBC execute engine factory. + * + * @author panjuan + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ExecutorEngineFactory { + + /** + * Create instance for execute engine. + * + * @param proxyMode proxy mode + * @param executorSize executor size + * @return instance for text protocol + */ + public static ExecutorEngine createTextProtocolInstance(final ProxyMode proxyMode, final int executorSize) { + return ProxyMode.MEMORY_STRICTLY == proxyMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); + } +} From 210b6d75fec21cb2a8dbe118a9fdbdef3d86426f Mon Sep 17 00:00:00 2001 From: tristaZero Date: Sun, 5 Aug 2018 21:16:59 +0800 Subject: [PATCH 033/198] add MemoryQueryResult.java --- .../type/connection/MemoryQueryResult.java | 133 ++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java new file mode 100644 index 0000000000000..8ca08596fe603 --- /dev/null +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java @@ -0,0 +1,133 @@ +/* + * 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.core.executor.type.connection; + +import io.shardingsphere.core.merger.QueryResult; + +import java.io.InputStream; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * Query result for memory loading. + * + * @author zhangliang + */ +public final class MemoryQueryResult implements QueryResult { + + private final Map columnLabelAndIndexMap; + + private final Iterator> resultData; + + private List currentRow; + + public MemoryQueryResult(final ResultSet resultSet) throws SQLException { + columnLabelAndIndexMap = getMetaData(resultSet.getMetaData()); + resultData = getResultData(resultSet); + } + + private Map getMetaData(final ResultSetMetaData resultSetMetaData) throws SQLException { + Map result = new HashMap<>(); + for (int columnIndex = 1; columnIndex <= resultSetMetaData.getColumnCount(); columnIndex++) { + result.put(resultSetMetaData.getColumnLabel(columnIndex), columnIndex); + } + return result; + } + + private Iterator> getResultData(final ResultSet resultSet) throws SQLException { + Collection> result = new LinkedList<>(); + while (resultSet.next()) { + List row = new ArrayList<>(columnLabelAndIndexMap.size()); + for (int columnIndex = 1; columnIndex <= resultSet.getMetaData().getColumnCount(); columnIndex++) { + row.add(resultSet.getObject(columnIndex)); + } + result.add(row); + } + return result.iterator(); + } + + @Override + public boolean next() { + if (resultData.hasNext()) { + currentRow = resultData.next(); + return true; + } + currentRow = null; + return false; + } + + @Override + public Object getValue(final int columnIndex, final Class type) { + return currentRow.get(columnIndex - 1); + } + + @Override + public Object getValue(final String columnLabel, final Class type) { + return currentRow.get(columnLabelAndIndexMap.get(columnLabel)); + } + + @Override + public Object getCalendarValue(final int columnIndex, final Class type, final Calendar calendar) { + return currentRow.get(columnIndex - 1); + } + + @Override + public Object getCalendarValue(final String columnLabel, final Class type, final Calendar calendar) { + return currentRow.get(columnLabelAndIndexMap.get(columnLabel)); + } + + @Override + public InputStream getInputStream(final int columnIndex, final String type) { + return (InputStream) currentRow.get(columnIndex - 1); + } + + @Override + public InputStream getInputStream(final String columnLabel, final String type) { + return (InputStream) currentRow.get(columnLabelAndIndexMap.get(columnLabel)); + } + + @Override + public boolean wasNull() { + return null == currentRow; + } + + @Override + public int getColumnCount() { + return columnLabelAndIndexMap.size(); + } + + @Override + public String getColumnLabel(final int columnIndex) throws SQLException { + for (Entry entry : columnLabelAndIndexMap.entrySet()) { + if (columnIndex == entry.getValue()) { + return entry.getKey(); + } + } + throw new SQLException("Column index out of range", "9999"); + } +} From 28314e87fba9667f3d364d6ee77c2c64c9e488aa Mon Sep 17 00:00:00 2001 From: tristaZero Date: Sun, 5 Aug 2018 21:17:11 +0800 Subject: [PATCH 034/198] modify ExecutorEngine --- .../core/executor/ExecutorEngine.java | 45 ++----------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java index 2e066f42257e4..257adf89dbec1 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java @@ -17,8 +17,6 @@ package io.shardingsphere.core.executor; -import com.google.common.collect.Lists; -import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.ThreadFactoryBuilder; @@ -35,15 +33,11 @@ import lombok.extern.slf4j.Slf4j; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -57,7 +51,7 @@ * @author panjuan */ @Slf4j -public final class ExecutorEngine implements AutoCloseable { +public abstract class ExecutorEngine implements AutoCloseable { private static final ThreadPoolExecutor SHUTDOWN_EXECUTOR = new ThreadPoolExecutor( 0, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(10), new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Sharding-JDBC-ExecutorEngineCloseTimer").build()); @@ -88,11 +82,8 @@ public List execute( } OverallExecutionEvent event = new OverallExecutionEvent(sqlType, baseStatementUnits.size()); EventBusInstance.getInstance().post(event); - Iterator iterator = baseStatementUnits.iterator(); try { - T firstOutput = syncExecute(sqlType, iterator.next(), executeCallback); - List> restFutures = asyncExecute(sqlType, Lists.newArrayList(iterator), executeCallback); - List result = buildResultList(firstOutput, restFutures); + List result = getExecuteResults(sqlType, baseStatementUnits, executeCallback); event.setEventExecutionType(EventExecutionType.EXECUTE_SUCCESS); EventBusInstance.getInstance().post(event); return result; @@ -107,28 +98,9 @@ public List execute( } } - private List> asyncExecute( - final SQLType sqlType, final Collection baseStatementUnits, final ExecuteCallback executeCallback) { - List> result = new ArrayList<>(baseStatementUnits.size()); - final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown(); - final Map dataMap = ExecutorDataMap.getDataMap(); - for (final BaseStatementUnit each : baseStatementUnits) { - result.add(executorService.submit(new Callable() { - - @Override - public T call() throws Exception { - return executeInternal(sqlType, each, executeCallback, isExceptionThrown, dataMap); - } - })); - } - return result; - } - - private T syncExecute(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback) throws Exception { - return executeInternal(sqlType, baseStatementUnit, executeCallback, ExecutorExceptionHandler.isExceptionThrown(), ExecutorDataMap.getDataMap()); - } + protected abstract List getExecuteResults(SQLType sqlType, Collection baseStatementUnits, ExecuteCallback executeCallback) throws Exception; - private T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback, + protected T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback, final boolean isExceptionThrown, final Map dataMap) throws Exception { synchronized (baseStatementUnit.getStatement().getConnection()) { T result; @@ -160,15 +132,6 @@ private T executeInternal(final SQLType sqlType, final BaseStatementUnit bas } } - private List buildResultList(final T firstOutput, final List> restResultFutures) throws ExecutionException, InterruptedException { - List result = new LinkedList<>(); - result.add(firstOutput); - for (ListenableFuture each : restResultFutures) { - result.add(each.get()); - } - return result; - } - private AbstractExecutionEvent getExecutionEvent(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final List parameters) { AbstractExecutionEvent result; if (SQLType.DQL == sqlType) { From c68e81542949f9215b1d040bcc68ce848df5cdcc Mon Sep 17 00:00:00 2001 From: tristaZero Date: Sun, 5 Aug 2018 21:17:50 +0800 Subject: [PATCH 035/198] add MemoryStrictlyExecutorEngine.java --- .../memory/MemoryStrictlyExecutorEngine.java | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java new file mode 100644 index 0000000000000..901cf10a8c130 --- /dev/null +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java @@ -0,0 +1,86 @@ +/* + * 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.core.executor.type.memory; + +import com.google.common.collect.Lists; +import com.google.common.util.concurrent.ListenableFuture; +import io.shardingsphere.core.constant.SQLType; +import io.shardingsphere.core.executor.BaseStatementUnit; +import io.shardingsphere.core.executor.ExecuteCallback; +import io.shardingsphere.core.executor.ExecutorEngine; +import io.shardingsphere.core.executor.threadlocal.ExecutorDataMap; +import io.shardingsphere.core.executor.threadlocal.ExecutorExceptionHandler; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; + +/** + * Memory strictly execute engine. + * + * @author panjuan + */ +public final class MemoryStrictlyExecutorEngine extends ExecutorEngine { + + public MemoryStrictlyExecutorEngine(final int executorSize) { + super(executorSize); + } + + @Override + protected List getExecuteResults(final SQLType sqlType, final Collection baseStatementUnits, final ExecuteCallback executeCallback) throws Exception { + Iterator iterator = baseStatementUnits.iterator(); + T firstOutput = syncExecute(sqlType, iterator.next(), executeCallback); + List> restFutures = asyncExecute(sqlType, Lists.newArrayList(iterator), executeCallback); + return buildResultList(firstOutput, restFutures); + } + + private List> asyncExecute( + final SQLType sqlType, final Collection baseStatementUnits, final ExecuteCallback executeCallback) { + List> result = new ArrayList<>(baseStatementUnits.size()); + final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown(); + final Map dataMap = ExecutorDataMap.getDataMap(); + for (final BaseStatementUnit each : baseStatementUnits) { + result.add(getExecutorService().submit(new Callable() { + + @Override + public T call() throws Exception { + return executeInternal(sqlType, each, executeCallback, isExceptionThrown, dataMap); + } + })); + } + return result; + } + + private T syncExecute(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback) throws Exception { + return executeInternal(sqlType, baseStatementUnit, executeCallback, ExecutorExceptionHandler.isExceptionThrown(), ExecutorDataMap.getDataMap()); + } + + private List buildResultList(final T firstOutput, final List> restResultFutures) throws ExecutionException, InterruptedException { + List result = new LinkedList<>(); + result.add(firstOutput); + for (ListenableFuture each : restResultFutures) { + result.add(each.get()); + } + return result; + } +} From 0de63304add597540968ee0c81543f53aaa87898 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Sun, 5 Aug 2018 21:18:01 +0800 Subject: [PATCH 036/198] add StreamQueryResult.java --- .../type/memory/StreamQueryResult.java | 216 ++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java new file mode 100644 index 0000000000000..56ec8ef4df0cb --- /dev/null +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java @@ -0,0 +1,216 @@ +/* + * 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.core.executor.type.memory; + +import io.shardingsphere.core.merger.QueryResult; +import lombok.RequiredArgsConstructor; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Blob; +import java.sql.Clob; +import java.sql.Date; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLXML; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; + +/** + * Query result for stream loading. + * + * @author zhangliang + */ +@RequiredArgsConstructor +public final class StreamQueryResult implements QueryResult { + + private final ResultSet resultSet; + + @Override + public boolean next() throws SQLException { + return resultSet.next(); + } + + @Override + public Object getValue(final int columnIndex, final Class type) throws SQLException { + Object result; + if (Object.class == type) { + result = resultSet.getObject(columnIndex); + } else if (boolean.class == type) { + result = resultSet.getBoolean(columnIndex); + } else if (byte.class == type) { + result = resultSet.getByte(columnIndex); + } else if (short.class == type) { + result = resultSet.getShort(columnIndex); + } else if (int.class == type) { + result = resultSet.getInt(columnIndex); + } else if (long.class == type) { + result = resultSet.getLong(columnIndex); + } else if (float.class == type) { + result = resultSet.getFloat(columnIndex); + } else if (double.class == type) { + result = resultSet.getDouble(columnIndex); + } else if (String.class == type) { + result = resultSet.getString(columnIndex); + } else if (BigDecimal.class == type) { + result = resultSet.getBigDecimal(columnIndex); + } else if (byte[].class == type) { + result = resultSet.getBytes(columnIndex); + } else if (Date.class == type) { + result = resultSet.getDate(columnIndex); + } else if (Time.class == type) { + result = resultSet.getTime(columnIndex); + } else if (Timestamp.class == type) { + result = resultSet.getTimestamp(columnIndex); + } else if (URL.class == type) { + result = resultSet.getURL(columnIndex); + } else if (Blob.class == type) { + result = resultSet.getBlob(columnIndex); + } else if (Clob.class == type) { + result = resultSet.getClob(columnIndex); + } else if (SQLXML.class == type) { + result = resultSet.getSQLXML(columnIndex); + } else if (Reader.class == type) { + result = resultSet.getCharacterStream(columnIndex); + } else { + result = resultSet.getObject(columnIndex); + } + return result; + } + + @Override + public Object getValue(final String columnLabel, final Class type) throws SQLException { + Object result; + if (Object.class == type) { + result = resultSet.getObject(columnLabel); + } else if (boolean.class == type) { + result = resultSet.getBoolean(columnLabel); + } else if (byte.class == type) { + result = resultSet.getByte(columnLabel); + } else if (short.class == type) { + result = resultSet.getShort(columnLabel); + } else if (int.class == type) { + result = resultSet.getInt(columnLabel); + } else if (long.class == type) { + result = resultSet.getLong(columnLabel); + } else if (float.class == type) { + result = resultSet.getFloat(columnLabel); + } else if (double.class == type) { + result = resultSet.getDouble(columnLabel); + } else if (String.class == type) { + result = resultSet.getString(columnLabel); + } else if (BigDecimal.class == type) { + result = resultSet.getBigDecimal(columnLabel); + } else if (byte[].class == type) { + result = resultSet.getBytes(columnLabel); + } else if (Date.class == type) { + result = resultSet.getDate(columnLabel); + } else if (Time.class == type) { + result = resultSet.getTime(columnLabel); + } else if (Timestamp.class == type) { + result = resultSet.getTimestamp(columnLabel); + } else if (URL.class == type) { + result = resultSet.getURL(columnLabel); + } else if (Blob.class == type) { + result = resultSet.getBlob(columnLabel); + } else if (Clob.class == type) { + result = resultSet.getClob(columnLabel); + } else if (SQLXML.class == type) { + result = resultSet.getSQLXML(columnLabel); + } else if (Reader.class == type) { + result = resultSet.getCharacterStream(columnLabel); + } else { + result = resultSet.getObject(columnLabel); + } + return result; + } + + @Override + public Object getCalendarValue(final int columnIndex, final Class type, final Calendar calendar) throws SQLException { + if (Date.class == type) { + return resultSet.getDate(columnIndex, calendar); + } + if (Time.class == type) { + return resultSet.getTime(columnIndex, calendar); + } + if (Timestamp.class == type) { + return resultSet.getTimestamp(columnIndex, calendar); + } + throw new SQLException(String.format("Unsupported type: %s", type)); + } + + @Override + public Object getCalendarValue(final String columnLabel, final Class type, final Calendar calendar) throws SQLException { + if (Date.class == type) { + return resultSet.getDate(columnLabel, calendar); + } + if (Time.class == type) { + return resultSet.getTime(columnLabel, calendar); + } + if (Timestamp.class == type) { + return resultSet.getTimestamp(columnLabel, calendar); + } + throw new SQLException(String.format("Unsupported type: %s", type)); + } + + @Override + public InputStream getInputStream(final int columnIndex, final String type) throws SQLException { + switch (type) { + case "Ascii": + return resultSet.getAsciiStream(columnIndex); + case "Unicode": + return resultSet.getUnicodeStream(columnIndex); + case "Binary": + return resultSet.getBinaryStream(columnIndex); + default: + throw new SQLException(String.format("Unsupported type: %s", type)); + } + } + + @Override + public InputStream getInputStream(final String columnLabel, final String type) throws SQLException { + switch (type) { + case "Ascii": + return resultSet.getAsciiStream(columnLabel); + case "Unicode": + return resultSet.getUnicodeStream(columnLabel); + case "Binary": + return resultSet.getBinaryStream(columnLabel); + default: + throw new SQLException(String.format("Unsupported type: %s", type)); + } + } + + @Override + public boolean wasNull() throws SQLException { + return resultSet.wasNull(); + } + + @Override + public int getColumnCount() throws SQLException { + return resultSet.getMetaData().getColumnCount(); + } + + @Override + public String getColumnLabel(final int columnIndex) throws SQLException { + return resultSet.getMetaData().getColumnLabel(columnIndex); + } +} From cc57f6c64f799cec7b29c6ab2ce4b505ded7d78c Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 06:03:34 +0800 Subject: [PATCH 037/198] change function name to getResultList --- .../executor/type/memory/MemoryStrictlyExecutorEngine.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java index 901cf10a8c130..4430e4f417e12 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java @@ -51,7 +51,7 @@ protected List getExecuteResults(final SQLType sqlType, final Collection< Iterator iterator = baseStatementUnits.iterator(); T firstOutput = syncExecute(sqlType, iterator.next(), executeCallback); List> restFutures = asyncExecute(sqlType, Lists.newArrayList(iterator), executeCallback); - return buildResultList(firstOutput, restFutures); + return getResultList(firstOutput, restFutures); } private List> asyncExecute( @@ -75,7 +75,7 @@ private T syncExecute(final SQLType sqlType, final BaseStatementUnit baseSta return executeInternal(sqlType, baseStatementUnit, executeCallback, ExecutorExceptionHandler.isExceptionThrown(), ExecutorDataMap.getDataMap()); } - private List buildResultList(final T firstOutput, final List> restResultFutures) throws ExecutionException, InterruptedException { + private List getResultList(final T firstOutput, final List> restResultFutures) throws ExecutionException, InterruptedException { List result = new LinkedList<>(); result.add(firstOutput); for (ListenableFuture each : restResultFutures) { From 46a92f3be0add0faa8e5a043c3a6d7c8dfaa78c7 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 12:01:58 +0800 Subject: [PATCH 038/198] modify cachedConnections --- .../adapter/AbstractConnectionAdapter.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index 458200532d65d..67cc0548ee685 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -33,9 +33,9 @@ import java.sql.SQLException; import java.sql.SQLWarning; import java.util.Collection; -import java.util.HashMap; import java.util.LinkedList; import java.util.Map; +import java.util.concurrent.CopyOnWriteArrayList; /** * Adapter for {@code Connection}. @@ -44,7 +44,7 @@ */ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOperationConnection { - private final Map cachedConnections = new HashMap<>(); + private final Collection cachedConnections = new CopyOnWriteArrayList<>(); private boolean autoCommit = true; @@ -62,13 +62,10 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera * @throws SQLException SQL exception */ public final Connection getConnection(final String dataSourceName) throws SQLException { - if (cachedConnections.containsKey(dataSourceName)) { - return cachedConnections.get(dataSourceName); - } DataSource dataSource = getDataSourceMap().get(dataSourceName); Preconditions.checkState(null != dataSource, "Missing the data source name: '%s'", dataSourceName); Connection result = dataSource.getConnection(); - cachedConnections.put(dataSourceName, result); + cachedConnections.add(result); replayMethodsInvocation(result); return result; } @@ -76,7 +73,7 @@ public final Connection getConnection(final String dataSourceName) throws SQLExc protected abstract Map getDataSourceMap(); protected void removeCache(final Connection connection) { - cachedConnections.values().remove(connection); + cachedConnections.remove(connection); } @Override @@ -107,7 +104,7 @@ public void close() throws SQLException { HintManagerHolder.clear(); MasterVisitedManager.clear(); Collection exceptions = new LinkedList<>(); - for (Connection each : cachedConnections.values()) { + for (Connection each : cachedConnections) { try { each.close(); } catch (final SQLException ex) { @@ -131,24 +128,24 @@ public final boolean isReadOnly() { public final void setReadOnly(final boolean readOnly) throws SQLException { this.readOnly = readOnly; recordMethodInvocation(Connection.class, "setReadOnly", new Class[] {boolean.class}, new Object[] {readOnly}); - for (Connection each : cachedConnections.values()) { + for (Connection each : cachedConnections) { each.setReadOnly(readOnly); } } @Override public final int getTransactionIsolation() throws SQLException { - if (cachedConnections.values().isEmpty()) { + if (cachedConnections.isEmpty()) { return transactionIsolation; } - return cachedConnections.values().iterator().next().getTransactionIsolation(); + return cachedConnections.iterator().next().getTransactionIsolation(); } @Override public final void setTransactionIsolation(final int level) throws SQLException { transactionIsolation = level; recordMethodInvocation(Connection.class, "setTransactionIsolation", new Class[] {int.class}, new Object[] {level}); - for (Connection each : cachedConnections.values()) { + for (Connection each : cachedConnections) { each.setTransactionIsolation(level); } } From 354535d070f3ea4d8978218ea8e3b519fd5b341d Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 12:02:09 +0800 Subject: [PATCH 039/198] reuse cachedConnections --- .../core/transaction/event/WeakXaTransactionEvent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java b/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java index e002128cc9df9..220d2ea91ac63 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/transaction/event/WeakXaTransactionEvent.java @@ -24,7 +24,7 @@ import lombok.Setter; import java.sql.Connection; -import java.util.Map; +import java.util.Collection; /** * Weak XA transaction event. @@ -35,7 +35,7 @@ @Setter public final class WeakXaTransactionEvent extends TransactionEvent { - private Map cachedConnections; + private Collection cachedConnections; private boolean autoCommit = true; From 2b9edced94a96f2c934b754de03bdc296d87e3c3 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 12:02:15 +0800 Subject: [PATCH 040/198] modify cachedConnections --- .../jdbc/core/transaction/WeakXaTransactionManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java index 52bde5e99f3a9..02c71260275fc 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java @@ -36,7 +36,7 @@ public final class WeakXaTransactionManager implements TransactionManager { @Override public void begin(final TransactionEvent transactionEvent) throws SQLException { WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent; - for (Connection each : weakXaTransactionEvent.getCachedConnections().values()) { + for (Connection each : weakXaTransactionEvent.getCachedConnections()) { each.setAutoCommit(weakXaTransactionEvent.isAutoCommit()); } } @@ -45,7 +45,7 @@ public void begin(final TransactionEvent transactionEvent) throws SQLException { public void commit(final TransactionEvent transactionEvent) throws SQLException { WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent; Collection exceptions = new LinkedList<>(); - for (Connection each : weakXaTransactionEvent.getCachedConnections().values()) { + for (Connection each : weakXaTransactionEvent.getCachedConnections()) { try { each.commit(); } catch (final SQLException ex) { @@ -59,7 +59,7 @@ public void commit(final TransactionEvent transactionEvent) throws SQLException public void rollback(final TransactionEvent transactionEvent) throws SQLException { WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent; Collection exceptions = new LinkedList<>(); - for (Connection each : weakXaTransactionEvent.getCachedConnections().values()) { + for (Connection each : weakXaTransactionEvent.getCachedConnections()) { try { each.rollback(); } catch (final SQLException ex) { From ca59be50ea5c4010d6285bdc857b7c4e0c02d8bb Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 12:17:10 +0800 Subject: [PATCH 041/198] renew proxy mode --- .../core/jdbc/core/datasource/ShardingDataSource.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java index ca7ca8f0fb95b..5cac8709ae3c3 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java @@ -24,6 +24,8 @@ import io.shardingsphere.core.constant.ShardingProperties; import io.shardingsphere.core.constant.ShardingPropertiesConstant; import io.shardingsphere.core.executor.ExecutorEngine; +import io.shardingsphere.core.executor.type.connection.ConnectionStrictlyExecutorEngine; +import io.shardingsphere.core.executor.type.memory.MemoryStrictlyExecutorEngine; import io.shardingsphere.core.jdbc.adapter.AbstractDataSourceAdapter; import io.shardingsphere.core.jdbc.core.ShardingContext; import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; @@ -48,6 +50,7 @@ * * @author zhangliang * @author zhaojun + * @author panjuan */ public class ShardingDataSource extends AbstractDataSourceAdapter implements AutoCloseable { @@ -69,11 +72,11 @@ public ShardingDataSource(final Map dataSourceMap, final Sha } shardingProperties = new ShardingProperties(null == props ? new Properties() : props); int executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); - executorEngine = new ExecutorEngine(executorSize); ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData( new TableMetaDataInitializer(executorEngine.getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule)); boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); ProxyMode proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); + executorEngine = ProxyMode.MEMORY_STRICTLY == proxyMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL); } @@ -88,9 +91,11 @@ public void renew(final Map newDataSourceMap, final Sharding ShardingProperties newShardingProperties = new ShardingProperties(null == newProps ? new Properties() : newProps); int originalExecutorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); int newExecutorSize = newShardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); - if (originalExecutorSize != newExecutorSize) { + ProxyMode originalProxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); + ProxyMode newProxyMode = ProxyMode.valueOf(newShardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); + if (originalExecutorSize != newExecutorSize || originalProxyMode != newProxyMode) { ExecutorEngine originalExecutorEngine = executorEngine; - executorEngine = new ExecutorEngine(newExecutorSize); + executorEngine = ProxyMode.MEMORY_STRICTLY == newProxyMode ? new MemoryStrictlyExecutorEngine(newExecutorSize) : new ConnectionStrictlyExecutorEngine(newExecutorSize); originalExecutorEngine.close(); } boolean newShowSQL = newShardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); From b28c9fb674449a4306f3462ef18e669c519f02fc Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 12:25:39 +0800 Subject: [PATCH 042/198] MySQLResultCache => FutureRegistry --- .../backend/netty/NettyBackendHandler.java | 20 +- .../netty/future/FutureRegistry.java} | 155 +++++++------- .../netty/future}/SynchronizedFuture.java | 194 +++++++++--------- .../netty/mysql/MySQLBackendHandler.java | 6 +- 4 files changed, 188 insertions(+), 187 deletions(-) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/{util/MySQLResultCache.java => backend/netty/future/FutureRegistry.java} (58%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/{util => backend/netty/future}/SynchronizedFuture.java (94%) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java index 026792c74fbea..f5fec55c2c25c 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java @@ -33,7 +33,9 @@ import io.shardingsphere.core.routing.StatementRoutingEngine; import io.shardingsphere.core.routing.router.masterslave.MasterSlaveRouter; import io.shardingsphere.proxy.backend.AbstractBackendHandler; +import io.shardingsphere.proxy.backend.BackendExecutorContext; import io.shardingsphere.proxy.backend.ResultPacket; +import io.shardingsphere.proxy.backend.netty.future.FutureRegistry; import io.shardingsphere.proxy.backend.netty.mysql.MySQLQueryResult; import io.shardingsphere.proxy.config.ProxyTableMetaDataConnectionManager; import io.shardingsphere.proxy.config.RuleRegistry; @@ -44,9 +46,7 @@ import io.shardingsphere.proxy.transport.mysql.packet.command.query.text.query.ComQueryPacket; import io.shardingsphere.proxy.transport.mysql.packet.generic.ErrPacket; import io.shardingsphere.proxy.transport.mysql.packet.generic.OKPacket; -import io.shardingsphere.proxy.backend.BackendExecutorContext; -import io.shardingsphere.proxy.util.MySQLResultCache; -import io.shardingsphere.proxy.util.SynchronizedFuture; +import io.shardingsphere.proxy.backend.netty.future.SynchronizedFuture; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -101,10 +101,10 @@ protected CommandResponsePackets execute0() throws InterruptedException, Executi private CommandResponsePackets executeForMasterSlave() throws InterruptedException, ExecutionException, TimeoutException { String dataSourceName = new MasterSlaveRouter(RULE_REGISTRY.getMasterSlaveRule(), RULE_REGISTRY.isShowSQL()).route(sql).iterator().next(); synchronizedFuture = new SynchronizedFuture(1); - MySQLResultCache.getInstance().putFuture(connectionId, synchronizedFuture); - executeCommand(dataSourceName, sql); + FutureRegistry.getInstance().put(connectionId, synchronizedFuture); + executeSQL(dataSourceName, sql); List queryResults = synchronizedFuture.get(RULE_REGISTRY.getBackendNIOConfig().getConnectionTimeoutSeconds(), TimeUnit.SECONDS); - MySQLResultCache.getInstance().deleteFuture(connectionId); + FutureRegistry.getInstance().delete(connectionId); List packets = new LinkedList<>(); for (QueryResult each : queryResults) { packets.add(((MySQLQueryResult) each).getCommandResponsePackets()); @@ -120,12 +120,12 @@ private CommandResponsePackets executeForSharding() throws InterruptedException, return new CommandResponsePackets(new OKPacket(1)); } synchronizedFuture = new SynchronizedFuture(routeResult.getExecutionUnits().size()); - MySQLResultCache.getInstance().putFuture(connectionId, synchronizedFuture); + FutureRegistry.getInstance().put(connectionId, synchronizedFuture); for (SQLExecutionUnit each : routeResult.getExecutionUnits()) { - executeCommand(each.getDataSource(), each.getSqlUnit().getSql()); + executeSQL(each.getDataSource(), each.getSqlUnit().getSql()); } List queryResults = synchronizedFuture.get(RULE_REGISTRY.getBackendNIOConfig().getConnectionTimeoutSeconds(), TimeUnit.SECONDS); - MySQLResultCache.getInstance().deleteFuture(connectionId); + FutureRegistry.getInstance().delete(connectionId); List packets = Lists.newArrayListWithCapacity(queryResults.size()); for (QueryResult each : queryResults) { @@ -149,7 +149,7 @@ private CommandResponsePackets executeForSharding() throws InterruptedException, return result; } - private void executeCommand(final String dataSourceName, final String sql) throws InterruptedException, ExecutionException, TimeoutException { + private void executeSQL(final String dataSourceName, final String sql) throws InterruptedException, ExecutionException, TimeoutException { if (!channelMap.containsKey(dataSourceName)) { channelMap.put(dataSourceName, new ArrayList()); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/MySQLResultCache.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/FutureRegistry.java similarity index 58% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/util/MySQLResultCache.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/FutureRegistry.java index a37e276e0d5b2..68d411662fde8 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/MySQLResultCache.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/FutureRegistry.java @@ -1,77 +1,78 @@ -/* - * 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.proxy.util; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -import java.util.concurrent.TimeUnit; - -/** - * Cache for synchronized future. - * - * @author wangkai - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class MySQLResultCache { - - private static final MySQLResultCache INSTANCE = new MySQLResultCache(); - - //TODO expire time should be set. - private final Cache resultCache = CacheBuilder.newBuilder().expireAfterWrite(60, TimeUnit.SECONDS).build(); - - /** - * Get instance of MySQL result cache. - * - * @return instance of MySQL result cache - */ - public static MySQLResultCache getInstance() { - return INSTANCE; - } - - /** - * Put synchronized future by connection id. - * - * @param connectionId MySQL connection id - * @param synchronizedFuture multiple result set - */ - public void putFuture(final int connectionId, final SynchronizedFuture synchronizedFuture) { - resultCache.put(connectionId, synchronizedFuture); - } - - /** - * Get synchronized future by connection id. - * - * @param connectionId MySQL connection id - * @return multiple result set - */ - public SynchronizedFuture getFuture(final int connectionId) { - return resultCache.getIfPresent(connectionId); - } - - /** - * Delete synchronized future by connection id. - * - * @param connectionId MySQL connection id - */ - public void deleteFuture(final int connectionId) { - resultCache.invalidate(connectionId); - } -} +/* + * 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.proxy.backend.netty.future; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.concurrent.TimeUnit; + +/** + * Future registry. + * + * @author wangkai + * @author zhangliang + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class FutureRegistry { + + private static final FutureRegistry INSTANCE = new FutureRegistry(); + + //TODO expire time should be set. + private final Cache resultCache = CacheBuilder.newBuilder().expireAfterWrite(60, TimeUnit.SECONDS).build(); + + /** + * Get instance of future registry. + * + * @return instance of future registry + */ + public static FutureRegistry getInstance() { + return INSTANCE; + } + + /** + * Put synchronized future by connection ID. + * + * @param connectionId database connection ID + * @param synchronizedFuture synchronized future + */ + public void put(final int connectionId, final SynchronizedFuture synchronizedFuture) { + resultCache.put(connectionId, synchronizedFuture); + } + + /** + * Get synchronized future by connection ID. + * + * @param connectionId database connection ID + * @return synchronized future + */ + public SynchronizedFuture get(final int connectionId) { + return resultCache.getIfPresent(connectionId); + } + + /** + * Delete synchronized future by connection ID. + * + * @param connectionId database connection ID + */ + public void delete(final int connectionId) { + resultCache.invalidate(connectionId); + } +} diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/SynchronizedFuture.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java similarity index 94% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/util/SynchronizedFuture.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java index c5921b6abf09d..0baff8fe1a3a1 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/SynchronizedFuture.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java @@ -1,97 +1,97 @@ -/* - * 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.proxy.util; - -import com.google.common.collect.Lists; -import io.shardingsphere.core.merger.QueryResult; -import lombok.extern.slf4j.Slf4j; - -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -/** - * Synchronized future for get multiple netty returns. - * - * @author wangkai - * @author linjiaqi - */ -@Slf4j -public class SynchronizedFuture implements Future> { - - private final CountDownLatch latch; - - private final List responses; - - private boolean isDone; - - public SynchronizedFuture(final int resultSize) { - latch = new CountDownLatch(resultSize); - responses = Lists.newArrayListWithCapacity(resultSize); - } - - @Override - public boolean cancel(final boolean mayInterruptIfRunning) { - return false; - } - - @Override - public boolean isCancelled() { - return false; - } - - @Override - public boolean isDone() { - return isDone; - } - - @Override - public List get() throws InterruptedException { - latch.await(); - return responses; - } - - /** - * Get responses for waiting time. - * - * @param timeout wait timeout - * @param unit time unit - * @return responses - */ - @Override - public List get(final long timeout, final TimeUnit unit) { - try { - latch.await(timeout, unit); - isDone = true; - } catch (final InterruptedException ex) { - log.error(ex.getMessage(), ex); - } - return responses; - } - - /** - * Set response and count down. - * - * @param response SQL command result - */ - public void setResponse(final QueryResult response) { - responses.add(response); - latch.countDown(); - } -} +/* + * 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.proxy.backend.netty.future; + +import com.google.common.collect.Lists; +import io.shardingsphere.core.merger.QueryResult; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +/** + * Synchronized future for get multiple netty returns. + * + * @author wangkai + * @author linjiaqi + */ +@Slf4j +public class SynchronizedFuture implements Future> { + + private final CountDownLatch latch; + + private final List responses; + + private boolean isDone; + + public SynchronizedFuture(final int resultSize) { + latch = new CountDownLatch(resultSize); + responses = Lists.newArrayListWithCapacity(resultSize); + } + + @Override + public boolean cancel(final boolean mayInterruptIfRunning) { + return false; + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public boolean isDone() { + return isDone; + } + + @Override + public List get() throws InterruptedException { + latch.await(); + return responses; + } + + /** + * Get responses for waiting time. + * + * @param timeout wait timeout + * @param unit time unit + * @return responses + */ + @Override + public List get(final long timeout, final TimeUnit unit) { + try { + latch.await(timeout, unit); + isDone = true; + } catch (final InterruptedException ex) { + log.error(ex.getMessage(), ex); + } + return responses; + } + + /** + * Set response and count down. + * + * @param response SQL command result + */ + public void setResponse(final QueryResult response) { + responses.add(response); + latch.countDown(); + } +} diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLBackendHandler.java index c94403c0b052c..77cfa0c037eb6 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLBackendHandler.java @@ -35,7 +35,7 @@ import io.shardingsphere.proxy.transport.mysql.packet.generic.OKPacket; import io.shardingsphere.proxy.transport.mysql.packet.handshake.HandshakePacket; import io.shardingsphere.proxy.transport.mysql.packet.handshake.HandshakeResponse41Packet; -import io.shardingsphere.proxy.util.MySQLResultCache; +import io.shardingsphere.proxy.backend.netty.future.FutureRegistry; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -190,8 +190,8 @@ private byte[] securePasswordAuthentication(final byte[] password, final byte[] private void setResponse(final ChannelHandlerContext context) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); - if (MySQLResultCache.getInstance().getFuture(connectionId) != null) { - MySQLResultCache.getInstance().getFuture(connectionId).setResponse(resultMap.get(connectionId)); + if (FutureRegistry.getInstance().get(connectionId) != null) { + FutureRegistry.getInstance().get(connectionId).setResponse(resultMap.get(connectionId)); } } } From a84ce0b27a9147bd517ebe6152a9ef8297a4645c Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 12:31:13 +0800 Subject: [PATCH 043/198] use Map> baseStatementUnitGroups --- .../shardingsphere/core/executor/ExecutorEngine.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java index 257adf89dbec1..940aadfda1715 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java @@ -69,21 +69,21 @@ public ExecutorEngine(final int executorSize) { * Execute. * * @param sqlType SQL type - * @param baseStatementUnits statement execute unitS + * @param baseStatementUnitGroups statement execute unitS * @param executeCallback prepared statement execute callback * @param class type of return value * @return execute result * @throws SQLException SQL exception */ public List execute( - final SQLType sqlType, final Collection baseStatementUnits, final ExecuteCallback executeCallback) throws SQLException { - if (baseStatementUnits.isEmpty()) { + final SQLType sqlType, final Map> baseStatementUnitGroups, final ExecuteCallback executeCallback) throws SQLException { + if (baseStatementUnitGroups.isEmpty()) { return Collections.emptyList(); } - OverallExecutionEvent event = new OverallExecutionEvent(sqlType, baseStatementUnits.size()); + OverallExecutionEvent event = new OverallExecutionEvent(sqlType, baseStatementUnitGroups.size()); EventBusInstance.getInstance().post(event); try { - List result = getExecuteResults(sqlType, baseStatementUnits, executeCallback); + List result = getExecuteResults(sqlType, baseStatementUnitGroups, executeCallback); event.setEventExecutionType(EventExecutionType.EXECUTE_SUCCESS); EventBusInstance.getInstance().post(event); return result; @@ -98,7 +98,7 @@ public List execute( } } - protected abstract List getExecuteResults(SQLType sqlType, Collection baseStatementUnits, ExecuteCallback executeCallback) throws Exception; + protected abstract List getExecuteResults(SQLType sqlType, Map> baseStatementUnitGroups, ExecuteCallback executeCallback) throws Exception; protected T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback, final boolean isExceptionThrown, final Map dataMap) throws Exception { From 9ea1afba01947b3e2fffd4200b4ee92a3c8a5ecc Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 12:35:03 +0800 Subject: [PATCH 044/198] reverse --- .../core/executor/ExecutorEngine.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java index 940aadfda1715..4b0c08da66b18 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java @@ -35,6 +35,7 @@ import java.sql.SQLException; import java.util.Collection; import java.util.Collections; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -69,21 +70,22 @@ public ExecutorEngine(final int executorSize) { * Execute. * * @param sqlType SQL type - * @param baseStatementUnitGroups statement execute unitS + * @param baseStatementUnits statement execute unitS * @param executeCallback prepared statement execute callback * @param class type of return value * @return execute result * @throws SQLException SQL exception */ public List execute( - final SQLType sqlType, final Map> baseStatementUnitGroups, final ExecuteCallback executeCallback) throws SQLException { - if (baseStatementUnitGroups.isEmpty()) { + final SQLType sqlType, final Collection baseStatementUnits, final ExecuteCallback executeCallback) throws SQLException { + if (baseStatementUnits.isEmpty()) { return Collections.emptyList(); } - OverallExecutionEvent event = new OverallExecutionEvent(sqlType, baseStatementUnitGroups.size()); + OverallExecutionEvent event = new OverallExecutionEvent(sqlType, baseStatementUnits.size()); EventBusInstance.getInstance().post(event); + Iterator iterator = baseStatementUnits.iterator(); try { - List result = getExecuteResults(sqlType, baseStatementUnitGroups, executeCallback); + List result = getExecuteResults(sqlType, baseStatementUnits, executeCallback); event.setEventExecutionType(EventExecutionType.EXECUTE_SUCCESS); EventBusInstance.getInstance().post(event); return result; @@ -98,9 +100,9 @@ public List execute( } } - protected abstract List getExecuteResults(SQLType sqlType, Map> baseStatementUnitGroups, ExecuteCallback executeCallback) throws Exception; + protected abstract List getExecuteResults(SQLType sqlType, Collection baseStatementUnits, ExecuteCallback executeCallback); - protected T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback, + protected T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback, final boolean isExceptionThrown, final Map dataMap) throws Exception { synchronized (baseStatementUnit.getStatement().getConnection()) { T result; From b3971b6ffa213dd0d4d888b898c4514e565768fe Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Mon, 6 Aug 2018 12:35:15 +0800 Subject: [PATCH 045/198] #1099, change FrontendExecutorContext to UserGroupContext --- .../proxy/frontend/ShardingProxy.java | 8 ++++--- ...utorContext.java => UserGroupContext.java} | 22 +++++++++---------- .../common/executor/ExecutorGroup.java | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/{FrontendExecutorContext.java => UserGroupContext.java} (53%) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java index 588fb65d752f4..99629d5fe463d 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java @@ -48,14 +48,14 @@ public final class ShardingProxy { private static final RuleRegistry RULE_REGISTRY = RuleRegistry.getInstance(); - private final FrontendExecutorContext frontendExecutorContext = FrontendExecutorContext.getInstance(); - private final BackendExecutorContext backendExecutorContext = BackendExecutorContext.getInstance(); private EventLoopGroup bossGroup; private EventLoopGroup workerGroup; + private final UserGroupContext userGroupContext = UserGroupContext.getInstance(); + public ShardingProxy() { RULE_REGISTRY.initShardingMetaData(backendExecutorContext.getExecutorService()); } @@ -84,7 +84,7 @@ public void start(final int port) throws InterruptedException, MalformedURLExcep } finally { workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); - frontendExecutorContext.getExecutorService().shutdown(); + userGroupContext.getUserGroup().shutdownGracefully(); backendExecutorContext.getExecutorService().shutdown(); if (RULE_REGISTRY.getBackendNIOConfig().isUseNIO()) { ShardingProxyClient.getInstance().stop(); @@ -102,6 +102,7 @@ private EventLoopGroup createEventLoopGroup() { private void groupsEpoll(final ServerBootstrap bootstrap) { workerGroup = new EpollEventLoopGroup(RULE_REGISTRY.getExecutorSize()); + userGroupContext.setUserGroup(new EpollEventLoopGroup(RULE_REGISTRY.getExecutorSize())); bootstrap.group(bossGroup, workerGroup) .channel(EpollServerSocketChannel.class) .option(EpollChannelOption.SO_BACKLOG, 128) @@ -114,6 +115,7 @@ private void groupsEpoll(final ServerBootstrap bootstrap) { private void groupsNio(final ServerBootstrap bootstrap) { workerGroup = new NioEventLoopGroup(RULE_REGISTRY.getExecutorSize()); + userGroupContext.setUserGroup(new NioEventLoopGroup(RULE_REGISTRY.getExecutorSize())); bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 128) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/FrontendExecutorContext.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/UserGroupContext.java similarity index 53% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/FrontendExecutorContext.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/UserGroupContext.java index 2eb7e842101ff..9557d9272c63c 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/FrontendExecutorContext.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/UserGroupContext.java @@ -17,31 +17,29 @@ package io.shardingsphere.proxy.frontend; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; -import io.shardingsphere.proxy.config.RuleRegistry; +import io.netty.channel.EventLoopGroup; import lombok.Getter; - -import java.util.concurrent.Executors; +import lombok.Setter; /** - * Frontend executor context. + * User group context. * * @author zhangyonglun */ -public final class FrontendExecutorContext { +public final class UserGroupContext { - private static final FrontendExecutorContext INSTANCE = new FrontendExecutorContext(); + private static final UserGroupContext INSTANCE = new UserGroupContext(); @Getter - private final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(RuleRegistry.getInstance().getExecutorSize())); + @Setter + private EventLoopGroup userGroup; /** - * Get frontend executor context instance. + * Get user group context instance. * - * @return instance of frontend executor context + * @return instance of user group context */ - public static FrontendExecutorContext getInstance() { + public static UserGroupContext getInstance() { return INSTANCE; } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java index 109c9c6e9d155..8d02443af3682 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java @@ -20,7 +20,7 @@ import io.netty.channel.ChannelId; import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.proxy.config.RuleRegistry; -import io.shardingsphere.proxy.frontend.FrontendExecutorContext; +import io.shardingsphere.proxy.frontend.UserGroupContext; import lombok.RequiredArgsConstructor; import java.util.concurrent.ExecutorService; @@ -44,6 +44,6 @@ public final class ExecutorGroup { */ public ExecutorService getExecutorService() { return TransactionType.XA.equals(RULE_REGISTRY.getTransactionType()) ? ChannelThreadExecutorGroup.getInstance().get(channelId) - : FrontendExecutorContext.getInstance().getExecutorService(); + : UserGroupContext.getInstance().getUserGroup(); } } From 4cc45d3f708078453a8275d965879d80725b4b64 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 12:40:09 +0800 Subject: [PATCH 046/198] refactor NettyBackendHandler --- .../backend/netty/NettyBackendHandler.java | 22 ++++++++++--------- .../netty/future/SynchronizedFuture.java | 6 ++--- .../backend/netty/mysql/MySQLQueryResult.java | 1 + 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java index f5fec55c2c25c..9cbd33b27ea14 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java @@ -17,7 +17,6 @@ package io.shardingsphere.proxy.backend.netty; -import com.google.common.collect.Lists; import io.netty.channel.Channel; import io.netty.channel.pool.SimpleChannelPool; import io.shardingsphere.core.constant.DatabaseType; @@ -36,6 +35,7 @@ import io.shardingsphere.proxy.backend.BackendExecutorContext; import io.shardingsphere.proxy.backend.ResultPacket; import io.shardingsphere.proxy.backend.netty.future.FutureRegistry; +import io.shardingsphere.proxy.backend.netty.future.SynchronizedFuture; import io.shardingsphere.proxy.backend.netty.mysql.MySQLQueryResult; import io.shardingsphere.proxy.config.ProxyTableMetaDataConnectionManager; import io.shardingsphere.proxy.config.RuleRegistry; @@ -46,7 +46,6 @@ import io.shardingsphere.proxy.transport.mysql.packet.command.query.text.query.ComQueryPacket; import io.shardingsphere.proxy.transport.mysql.packet.generic.ErrPacket; import io.shardingsphere.proxy.transport.mysql.packet.generic.OKPacket; -import io.shardingsphere.proxy.backend.netty.future.SynchronizedFuture; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -126,8 +125,7 @@ private CommandResponsePackets executeForSharding() throws InterruptedException, } List queryResults = synchronizedFuture.get(RULE_REGISTRY.getBackendNIOConfig().getConnectionTimeoutSeconds(), TimeUnit.SECONDS); FutureRegistry.getInstance().delete(connectionId); - - List packets = Lists.newArrayListWithCapacity(queryResults.size()); + List packets = new ArrayList<>(queryResults.size()); for (QueryResult each : queryResults) { MySQLQueryResult queryResult = (MySQLQueryResult) each; if (0 == currentSequenceId) { @@ -138,13 +136,10 @@ private CommandResponsePackets executeForSharding() throws InterruptedException, } packets.add(queryResult.getCommandResponsePackets()); } - CommandResponsePackets result = merge(routeResult.getSqlStatement(), packets, queryResults); SQLStatement sqlStatement = routeResult.getSqlStatement(); - if (!RULE_REGISTRY.isMasterSlaveOnly() && SQLType.DDL == sqlStatement.getType() && !sqlStatement.getTables().isEmpty()) { - String logicTableName = sqlStatement.getTables().getSingleTableName(); - TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( - BackendExecutorContext.getInstance().getExecutorService(), new ProxyTableMetaDataConnectionManager(RULE_REGISTRY.getBackendDataSource())); - RULE_REGISTRY.getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, RULE_REGISTRY.getShardingRule())); + CommandResponsePackets result = merge(sqlStatement, packets, queryResults); + if (SQLType.DDL == sqlStatement.getType() && !sqlStatement.getTables().isEmpty()) { + refreshTableMetaData(sqlStatement.getTables().getSingleTableName()); } return result; } @@ -201,6 +196,13 @@ private CommandResponsePackets mergeDQLorDAL(final SQLStatement sqlStatement, fi return packets.get(0); } + // TODO :jiaqi use sql packet to refresh meta data + private void refreshTableMetaData(final String logicTableName) { + TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( + BackendExecutorContext.getInstance().getExecutorService(), new ProxyTableMetaDataConnectionManager(RULE_REGISTRY.getBackendDataSource())); + RULE_REGISTRY.getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, RULE_REGISTRY.getShardingRule())); + } + @Override public boolean next() throws SQLException { if (null == mergedResult || !mergedResult.next()) { diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java index 0baff8fe1a3a1..477b359cd7028 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/future/SynchronizedFuture.java @@ -17,10 +17,10 @@ package io.shardingsphere.proxy.backend.netty.future; -import com.google.common.collect.Lists; import io.shardingsphere.core.merger.QueryResult; import lombok.extern.slf4j.Slf4j; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; @@ -33,7 +33,7 @@ * @author linjiaqi */ @Slf4j -public class SynchronizedFuture implements Future> { +public final class SynchronizedFuture implements Future> { private final CountDownLatch latch; @@ -43,7 +43,7 @@ public class SynchronizedFuture implements Future> { public SynchronizedFuture(final int resultSize) { latch = new CountDownLatch(resultSize); - responses = Lists.newArrayListWithCapacity(resultSize); + responses = new ArrayList<>(resultSize); } @Override diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLQueryResult.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLQueryResult.java index a36c6e5160b59..285d28b5127d6 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLQueryResult.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLQueryResult.java @@ -45,6 +45,7 @@ */ @Slf4j public final class MySQLQueryResult implements QueryResult { + @Getter private final CommandResponsePackets commandResponsePackets; From 157ccc18014fd31a21f47a0c150d01fc9e7847cc Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Mon, 6 Aug 2018 12:52:08 +0800 Subject: [PATCH 047/198] #1099, worker group and user group share the acceptor.size configuration --- .../core/constant/ShardingPropertiesConstant.java | 11 +++++++++++ .../io/shardingsphere/proxy/config/RuleRegistry.java | 3 +++ .../shardingsphere/proxy/frontend/ShardingProxy.java | 8 ++++---- sharding-proxy/src/main/resources/conf/config.yaml | 1 + .../src/main/resources/conf/config_master_slave.yaml | 1 + sharding-proxy/src/test/resources/conf/config.yaml | 1 + 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java index d421c3593643e..fc2a8cd3b0aef 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java @@ -42,6 +42,17 @@ public enum ShardingPropertiesConstant { */ SQL_SHOW("sql.show", Boolean.FALSE.toString(), boolean.class), + /** + * Worker group or user group thread max size. + * + *

+ * Worker group accept tcp connection. + * User group accept MySQL command. + * Default: CPU cores * 2. + *

+ */ + ACCEPTOR_SIZE("acceptor.size", String.valueOf(Runtime.getRuntime().availableProcessors() * 2), int.class), + /** * Worker thread max size. * diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 9962a74e13256..cd64f2e14ae7f 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -75,6 +75,8 @@ public final class RuleRegistry { private ConnectionMode connectionMode; + private int acceptorSize; + private int executorSize; private BackendNIOConfiguration backendNIOConfig; @@ -108,6 +110,7 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE)); transactionManager = ProxyTransactionLoader.load(transactionType); + acceptorSize = shardingProperties.getValue(ShardingPropertiesConstant.ACCEPTOR_SIZE); executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); // TODO :jiaqi force off use NIO for backend, this feature is not complete yet boolean useNIO = false; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java index 99629d5fe463d..88553689c9a70 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java @@ -101,8 +101,8 @@ private EventLoopGroup createEventLoopGroup() { } private void groupsEpoll(final ServerBootstrap bootstrap) { - workerGroup = new EpollEventLoopGroup(RULE_REGISTRY.getExecutorSize()); - userGroupContext.setUserGroup(new EpollEventLoopGroup(RULE_REGISTRY.getExecutorSize())); + workerGroup = new EpollEventLoopGroup(RULE_REGISTRY.getAcceptorSize()); + userGroupContext.setUserGroup(new EpollEventLoopGroup(RULE_REGISTRY.getAcceptorSize())); bootstrap.group(bossGroup, workerGroup) .channel(EpollServerSocketChannel.class) .option(EpollChannelOption.SO_BACKLOG, 128) @@ -114,8 +114,8 @@ private void groupsEpoll(final ServerBootstrap bootstrap) { } private void groupsNio(final ServerBootstrap bootstrap) { - workerGroup = new NioEventLoopGroup(RULE_REGISTRY.getExecutorSize()); - userGroupContext.setUserGroup(new NioEventLoopGroup(RULE_REGISTRY.getExecutorSize())); + workerGroup = new NioEventLoopGroup(RULE_REGISTRY.getAcceptorSize()); + userGroupContext.setUserGroup(new NioEventLoopGroup(RULE_REGISTRY.getAcceptorSize())); bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 128) diff --git a/sharding-proxy/src/main/resources/conf/config.yaml b/sharding-proxy/src/main/resources/conf/config.yaml index 4c0f1905bee9c..7400815a5048d 100644 --- a/sharding-proxy/src/main/resources/conf/config.yaml +++ b/sharding-proxy/src/main/resources/conf/config.yaml @@ -61,6 +61,7 @@ # # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. # # Meanwhile, the cost of the memory will be increased. # connection.mode: MEMORY_STRICTLY +# acceptor.size: 16 # The default value is available processors count * 2. # executor.size: 16 # The default value is available processors count. # sql.show: false # diff --git a/sharding-proxy/src/main/resources/conf/config_master_slave.yaml b/sharding-proxy/src/main/resources/conf/config_master_slave.yaml index 8a2be1004bc8c..e005afaeb829a 100644 --- a/sharding-proxy/src/main/resources/conf/config_master_slave.yaml +++ b/sharding-proxy/src/main/resources/conf/config_master_slave.yaml @@ -40,6 +40,7 @@ # # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. # # Meanwhile, the cost of the memory will be increased. # connection.mode: MEMORY_STRICTLY +# acceptor.size: 16 # The default value is available processors count * 2. # executor.size: 16 # The default value is available processors count. # sql.show: false diff --git a/sharding-proxy/src/test/resources/conf/config.yaml b/sharding-proxy/src/test/resources/conf/config.yaml index 86ff83e56a32c..1196350abf6fc 100644 --- a/sharding-proxy/src/test/resources/conf/config.yaml +++ b/sharding-proxy/src/test/resources/conf/config.yaml @@ -45,6 +45,7 @@ shardingRule: props: connection.mode: MEMORY_STRICTLY + acceptor.size: 16 executor.size: 16 sql.show: false From 7f74a9e4a662d9cd2e1dc096de15e4c71d5fd3ac Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 12:55:41 +0800 Subject: [PATCH 048/198] add ProxyMode proxyMode. --- .../io/shardingsphere/core/jdbc/core/ShardingContext.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java index cf7c16191e7e8..1ec523da155f1 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.jdbc.core; import io.shardingsphere.core.constant.DatabaseType; +import io.shardingsphere.core.constant.ProxyMode; import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.executor.ExecutorEngine; import io.shardingsphere.core.metadata.ShardingMetaData; @@ -54,15 +55,18 @@ public final class ShardingContext { private final boolean showSQL; + private final ProxyMode proxyMode; + private final ShardingMetaData metaData; public ShardingContext(final Map dataSourceMap, final ShardingRule shardingRule, - final DatabaseType databaseType, final ExecutorEngine executorEngine, final ShardingTableMetaData shardingTableMetaData, final boolean showSQL) { + final DatabaseType databaseType, final ExecutorEngine executorEngine, final ShardingTableMetaData shardingTableMetaData, final boolean showSQL, final ProxyMode proxyMode) { this.dataSourceMap = dataSourceMap; this.shardingRule = shardingRule; this.databaseType = databaseType; this.executorEngine = executorEngine; this.showSQL = showSQL; + this.proxyMode = proxyMode; metaData = new ShardingMetaData(new ShardingDataSourceMetaData(getDataSourceURLs(dataSourceMap), shardingRule, databaseType), shardingTableMetaData); } From 8c475fc1a9d10ed258278048590995c72ce92f4a Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 12:56:39 +0800 Subject: [PATCH 049/198] new ShardingContext --- .../core/jdbc/core/datasource/ShardingDataSource.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java index 5cac8709ae3c3..15d0273327e76 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java @@ -77,7 +77,7 @@ public ShardingDataSource(final Map dataSourceMap, final Sha boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); ProxyMode proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); executorEngine = ProxyMode.MEMORY_STRICTLY == proxyMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); - shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL); + shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL, proxyMode); } /** @@ -102,7 +102,7 @@ public void renew(final Map newDataSourceMap, final Sharding ShardingTableMetaData shardingMetaData = new ShardingTableMetaData( new TableMetaDataInitializer(executorEngine.getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(newDataSourceMap)).load(newShardingRule)); shardingProperties = newShardingProperties; - shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, shardingMetaData, newShowSQL); + shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, shardingMetaData, newShowSQL, newProxyMode); } @Override From 3ea817aea89217e6a19ca4107b1c9f1e91858957 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 12:59:44 +0800 Subject: [PATCH 050/198] add getStatementUnitsForMemoryStrictly() --- .../core/statement/ShardingStatement.java | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java index b24c45ff2891a..99ba311049a9c 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.jdbc.core.statement; import com.google.common.base.Optional; +import io.shardingsphere.core.constant.ProxyMode; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.executor.type.statement.StatementExecutor; import io.shardingsphere.core.executor.type.statement.StatementUnit; @@ -49,13 +50,16 @@ import lombok.AccessLevel; import lombok.Getter; +import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; /** * Statement that support sharding. @@ -209,14 +213,38 @@ public boolean execute(final String sql, final String[] columnNames) throws SQLE private StatementExecutor generateExecutor(final String sql) throws SQLException { clearPrevious(); sqlRoute(sql); - Collection statementUnits = new LinkedList<>(); + if (ProxyMode.MEMORY_STRICTLY == connection.getShardingContext().getProxyMode()) { + return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), getStatementUnitsForMemoryStrictly()); + } + return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), getStatementUnitsForConnectionStrictly()); + } + + private Collection getStatementUnitsForConnectionStrictly() throws SQLException { + Collection result = new LinkedList<>(); + Map connectionMap = new LinkedHashMap<>(); + for (SQLExecutionUnit each : routeResult.getExecutionUnits()) { + String dataSourceName = each.getDataSource(); + if (null == connectionMap.get(dataSourceName)) { + connectionMap.put(dataSourceName, connection.getConnection(each.getDataSource())); + } + Statement statement = connectionMap.get(dataSourceName).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); + replayMethodsInvocation(statement); + result.add(new StatementUnit(each, statement)); + routedStatements.add(statement); + } + return result; + } + + private Collection getStatementUnitsForMemoryStrictly() throws SQLException { + Collection result = new LinkedList<>(); for (SQLExecutionUnit each : routeResult.getExecutionUnits()) { - Statement statement = connection.getConnection(each.getDataSource()).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); + String dataSourceName = each.getDataSource(); + Statement statement = connection.getConnection(dataSourceName).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); replayMethodsInvocation(statement); - statementUnits.add(new StatementUnit(each, statement)); + result.add(new StatementUnit(each, statement)); routedStatements.add(statement); } - return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), statementUnits); + return result; } private void clearPrevious() throws SQLException { From ecbfa6f68bc8a7d0903bca52d5f1bdd5f96ff440 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 13:41:29 +0800 Subject: [PATCH 051/198] add getPreparedStatementUnitsForMemoryStrictly() --- .../statement/ShardingPreparedStatement.java | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java index e179de57181e9..00fb01076b462 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java @@ -20,6 +20,7 @@ import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.Iterators; +import io.shardingsphere.core.constant.ProxyMode; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementExecutor; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementUnit; @@ -60,8 +61,10 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Objects; /** @@ -177,10 +180,33 @@ public boolean execute() throws SQLException { } private Collection route() throws SQLException { - Collection result = new LinkedList<>(); sqlRoute(); + if (ProxyMode.MEMORY_STRICTLY == connection.getShardingContext().getProxyMode()) { + return getPreparedStatementUnitsForMemoryStrictly(); + } + return getPreparedStatementUnitsForConnectionStrictly(); + } + + private Collection getPreparedStatementUnitsForConnectionStrictly() throws SQLException { + Collection result = new LinkedList<>(); + Map connectionMap = new LinkedHashMap<>(); + for (SQLExecutionUnit each : routeResult.getExecutionUnits()) { + String dataSourceName = each.getDataSource(); + if (null == connectionMap.get(dataSourceName)) { + connectionMap.put(dataSourceName, connection.getConnection(each.getDataSource())); + } + PreparedStatement preparedStatement = generatePreparedStatement(connectionMap.get(dataSourceName), each.getSqlUnit().getSql()); + routedStatements.add(preparedStatement); + replaySetParameter(preparedStatement, each.getSqlUnit().getParameterSets().get(0)); + result.add(new PreparedStatementUnit(each, preparedStatement)); + } + return result; + } + + private Collection getPreparedStatementUnitsForMemoryStrictly() throws SQLException { + Collection result = new LinkedList<>(); for (SQLExecutionUnit each : routeResult.getExecutionUnits()) { - PreparedStatement preparedStatement = generatePreparedStatement(each); + PreparedStatement preparedStatement = generatePreparedStatement(connection.getConnection(each.getDataSource()), each.getSqlUnit().getSql()); routedStatements.add(preparedStatement); replaySetParameter(preparedStatement, each.getSqlUnit().getParameterSets().get(0)); result.add(new PreparedStatementUnit(each, preparedStatement)); @@ -188,10 +214,9 @@ private Collection route() throws SQLException { return result; } - private PreparedStatement generatePreparedStatement(final SQLExecutionUnit sqlExecutionUnit) throws SQLException { - Connection connection = this.connection.getConnection(sqlExecutionUnit.getDataSource()); - return returnGeneratedKeys ? connection.prepareStatement(sqlExecutionUnit.getSqlUnit().getSql(), Statement.RETURN_GENERATED_KEYS) - : connection.prepareStatement(sqlExecutionUnit.getSqlUnit().getSql(), resultSetType, resultSetConcurrency, resultSetHoldability); + private PreparedStatement generatePreparedStatement(final Connection connection, final String sql) throws SQLException { + return returnGeneratedKeys ? connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS) + : connection.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); } private void sqlRoute() { @@ -265,7 +290,8 @@ public boolean apply(final BatchPreparedStatementUnit input) { preparedBatchStatement.get().getSqlExecutionUnit().getSqlUnit().getParameterSets().add(sqlExecutionUnit.getSqlUnit().getParameterSets().get(0)); return preparedBatchStatement.get(); } - BatchPreparedStatementUnit result = new BatchPreparedStatementUnit(sqlExecutionUnit, generatePreparedStatement(sqlExecutionUnit)); + BatchPreparedStatementUnit result = new BatchPreparedStatementUnit(sqlExecutionUnit, generatePreparedStatement(connection.getConnection(sqlExecutionUnit.getDataSource()), + sqlExecutionUnit.getSqlUnit().getSql())); batchStatementUnits.add(result); return result; } From f51b1c8e956ff33797a7f09f9b4a2dadd96e487d Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 14:02:51 +0800 Subject: [PATCH 052/198] ShardingProxyClient => BackendNettyClient --- ...oxyClient.java => BackendNettyClient.java} | 48 +++++++++---------- ...BackendNettyClientChannelInitializer.java} | 4 +- .../backend/netty/NettyBackendHandler.java | 4 +- .../netty/NettyChannelPoolHandler.java | 2 +- .../proxy/frontend/ShardingProxy.java | 6 +-- 5 files changed, 32 insertions(+), 32 deletions(-) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/{ShardingProxyClient.java => BackendNettyClient.java} (84%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/{ClientHandlerInitializer.java => BackendNettyClientChannelInitializer.java} (90%) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/ShardingProxyClient.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClient.java similarity index 84% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/ShardingProxyClient.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClient.java index d604da46bc9cc..a19a21c629d0e 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/ShardingProxyClient.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClient.java @@ -34,26 +34,30 @@ import io.netty.channel.socket.nio.NioSocketChannel; import io.shardingsphere.core.rule.DataSourceParameter; import io.shardingsphere.proxy.config.RuleRegistry; +import lombok.AccessLevel; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import java.net.MalformedURLException; import java.net.URL; import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; /** - * Sharding-Proxy Client. + * Backend connection client for netty. * * @author wangkai * @author linjiaqi */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) @Slf4j -public final class ShardingProxyClient { +public final class BackendNettyClient { - private static final ShardingProxyClient INSTANCE = new ShardingProxyClient(); + private static final BackendNettyClient INSTANCE = new BackendNettyClient(); private static final RuleRegistry RULE_REGISTRY = RuleRegistry.getInstance(); @@ -71,23 +75,28 @@ public final class ShardingProxyClient { private ChannelPoolMap poolMap; /** - * Start Sharding-Proxy. + * Get instance of backend connection client for netty. * - * @throws MalformedURLException url is illegal. + * @return instance of backend connection client for netty + */ + public static BackendNettyClient getInstance() { + return INSTANCE; + } + + /** + * Start backend connection client for netty. + * + * @throws MalformedURLException URL is illegal * @throws InterruptedException interrupted exception */ public void start() throws MalformedURLException, InterruptedException { Map dataSourceConfigurationMap = RULE_REGISTRY.getDataSourceConfigurationMap(); - for (Map.Entry each : dataSourceConfigurationMap.entrySet()) { + for (Entry each : dataSourceConfigurationMap.entrySet()) { URL url = new URL(each.getValue().getUrl().replaceAll("jdbc:mysql:", "http:")); - final String ip = url.getHost(); - final int port = url.getPort(); - final String database = url.getPath().substring(1); - final String username = (each.getValue()).getUsername(); - final String password = (each.getValue()).getPassword(); - dataSourceConfigMap.put(each.getKey(), new DataSourceConfig(ip, port, database, username, password)); + dataSourceConfigMap.put(each.getKey(), new DataSourceConfig(url.getHost(), url.getPort(), url.getPath().substring(1), each.getValue().getUsername(), each.getValue().getPassword())); } - final Bootstrap bootstrap = new Bootstrap(); + Bootstrap bootstrap = new Bootstrap(); + // TODO :jiaqi where to init workerGroup? if (workerGroup instanceof EpollEventLoopGroup) { groupsEpoll(bootstrap); } else { @@ -97,10 +106,10 @@ public void start() throws MalformedURLException, InterruptedException { } /** - * Stop Sharding-Proxy. + * Stop backend connection client for netty. */ public void stop() { - if (workerGroup != null) { + if (null != workerGroup) { workerGroup.shutdownGracefully(); } } @@ -149,13 +158,4 @@ protected SimpleChannelPool newPool(final String datasourceName) { } } } - - /** - * Get instance of sharding-proxy client. - * - * @return instance of sharding-proxy client - */ - public static ShardingProxyClient getInstance() { - return INSTANCE; - } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/ClientHandlerInitializer.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClientChannelInitializer.java similarity index 90% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/ClientHandlerInitializer.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClientChannelInitializer.java index 3e7b009240eab..3465ea940cb0f 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/ClientHandlerInitializer.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClientChannelInitializer.java @@ -25,13 +25,13 @@ import lombok.RequiredArgsConstructor; /** - * Channel initializer. + * Channel initializer for backend connection netty client. * * @author wangkai * @author linjiaqi */ @RequiredArgsConstructor -public final class ClientHandlerInitializer extends ChannelInitializer { +public final class BackendNettyClientChannelInitializer extends ChannelInitializer { private final DataSourceConfig dataSourceConfig; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java index 9cbd33b27ea14..8ea145e3c798f 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java @@ -148,7 +148,7 @@ private void executeSQL(final String dataSourceName, final String sql) throws In if (!channelMap.containsKey(dataSourceName)) { channelMap.put(dataSourceName, new ArrayList()); } - SimpleChannelPool pool = ShardingProxyClient.getInstance().getPoolMap().get(dataSourceName); + SimpleChannelPool pool = BackendNettyClient.getInstance().getPoolMap().get(dataSourceName); Channel channel = pool.acquire().get(RULE_REGISTRY.getBackendNIOConfig().getConnectionTimeoutSeconds(), TimeUnit.SECONDS); channelMap.get(dataSourceName).add(channel); ChannelRegistry.getInstance().putConnectionId(channel.id().asShortText(), connectionId); @@ -208,7 +208,7 @@ public boolean next() throws SQLException { if (null == mergedResult || !mergedResult.next()) { for (Entry> entry : channelMap.entrySet()) { for (Channel each : entry.getValue()) { - ShardingProxyClient.getInstance().getPoolMap().get(entry.getKey()).release(each); + BackendNettyClient.getInstance().getPoolMap().get(entry.getKey()).release(each); } } return false; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyChannelPoolHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyChannelPoolHandler.java index 90880b8237347..b7f09c089ee5f 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyChannelPoolHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyChannelPoolHandler.java @@ -46,6 +46,6 @@ public void channelAcquired(final Channel channel) { @Override public void channelCreated(final Channel channel) { log.info("channelCreated. Channel ID: {}" + channel.id().asShortText()); - channel.pipeline().addLast(new ClientHandlerInitializer(dataSourceConfig)); + channel.pipeline().addLast(new BackendNettyClientChannelInitializer(dataSourceConfig)); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java index 588fb65d752f4..1cfb073f6887d 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java @@ -30,7 +30,7 @@ import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import io.shardingsphere.proxy.backend.netty.ShardingProxyClient; +import io.shardingsphere.proxy.backend.netty.BackendNettyClient; import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.frontend.common.netty.ServerHandlerInitializer; import io.shardingsphere.proxy.backend.BackendExecutorContext; @@ -70,7 +70,7 @@ public ShardingProxy() { public void start(final int port) throws InterruptedException, MalformedURLException { try { if (RULE_REGISTRY.getBackendNIOConfig().isUseNIO()) { - ShardingProxyClient.getInstance().start(); + BackendNettyClient.getInstance().start(); } ServerBootstrap bootstrap = new ServerBootstrap(); bossGroup = createEventLoopGroup(); @@ -87,7 +87,7 @@ public void start(final int port) throws InterruptedException, MalformedURLExcep frontendExecutorContext.getExecutorService().shutdown(); backendExecutorContext.getExecutorService().shutdown(); if (RULE_REGISTRY.getBackendNIOConfig().isUseNIO()) { - ShardingProxyClient.getInstance().stop(); + BackendNettyClient.getInstance().stop(); } } } From ecf467052d6ac0338b90fd4756e4195bd97aedf9 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Mon, 6 Aug 2018 14:04:41 +0800 Subject: [PATCH 053/198] for #1099, make backend thread pool infinite by default --- .../core/constant/ShardingPropertiesConstant.java | 2 +- .../proxy/backend/BackendExecutorContext.java | 8 +++++++- sharding-proxy/src/main/resources/conf/config.yaml | 2 +- .../src/main/resources/conf/config_master_slave.yaml | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java index fc2a8cd3b0aef..21a8c009fce88 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java @@ -62,7 +62,7 @@ public enum ShardingPropertiesConstant { * Default: same with CPU cores. *

*/ - EXECUTOR_SIZE("executor.size", String.valueOf(Runtime.getRuntime().availableProcessors()), int.class), + EXECUTOR_SIZE("executor.size", String.valueOf(0), int.class), /** * Connection mode of connected to databases. diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/BackendExecutorContext.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/BackendExecutorContext.java index 41d3ad7fe1b2f..8197becc317be 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/BackendExecutorContext.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/BackendExecutorContext.java @@ -19,6 +19,7 @@ import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import io.shardingsphere.proxy.config.RuleRegistry; import lombok.Getter; import java.util.concurrent.Executors; @@ -33,7 +34,12 @@ public final class BackendExecutorContext { private static final BackendExecutorContext INSTANCE = new BackendExecutorContext(); @Getter - private final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); + private final ListeningExecutorService executorService; + + private BackendExecutorContext() { + int executorSize = RuleRegistry.getInstance().getExecutorSize(); + executorService = 0 == executorSize ? MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()) : MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(executorSize)); + } /** * Get backend executor context instance. diff --git a/sharding-proxy/src/main/resources/conf/config.yaml b/sharding-proxy/src/main/resources/conf/config.yaml index 7400815a5048d..a8f824c6f5b0c 100644 --- a/sharding-proxy/src/main/resources/conf/config.yaml +++ b/sharding-proxy/src/main/resources/conf/config.yaml @@ -62,7 +62,7 @@ # # Meanwhile, the cost of the memory will be increased. # connection.mode: MEMORY_STRICTLY # acceptor.size: 16 # The default value is available processors count * 2. -# executor.size: 16 # The default value is available processors count. +# executor.size: 16 # Infinite by default. # sql.show: false # #orchestration: diff --git a/sharding-proxy/src/main/resources/conf/config_master_slave.yaml b/sharding-proxy/src/main/resources/conf/config_master_slave.yaml index e005afaeb829a..5206ab54849b9 100644 --- a/sharding-proxy/src/main/resources/conf/config_master_slave.yaml +++ b/sharding-proxy/src/main/resources/conf/config_master_slave.yaml @@ -41,7 +41,7 @@ # # Meanwhile, the cost of the memory will be increased. # connection.mode: MEMORY_STRICTLY # acceptor.size: 16 # The default value is available processors count * 2. -# executor.size: 16 # The default value is available processors count. +# executor.size: 16 # Infinite by default. # sql.show: false #orchestration: From 008f5f08ee359a81b90cb05ac7ed8fef258b6a0b Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 14:07:46 +0800 Subject: [PATCH 054/198] throws Exception --- .../java/io/shardingsphere/core/executor/ExecutorEngine.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java index 4b0c08da66b18..db4ff1cdf5c7f 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java @@ -100,9 +100,9 @@ public List execute( } } - protected abstract List getExecuteResults(SQLType sqlType, Collection baseStatementUnits, ExecuteCallback executeCallback); + protected abstract List getExecuteResults(SQLType sqlType, Collection baseStatementUnits, ExecuteCallback executeCallback) throws Exception; - protected T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback, + protected T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback, final boolean isExceptionThrown, final Map dataMap) throws Exception { synchronized (baseStatementUnit.getStatement().getConnection()) { T result; From c894fe588f514ec197d8f1e33f002075dd4f2b93 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 14:08:28 +0800 Subject: [PATCH 055/198] refactor backend.netty's package structure --- .../proxy/backend/netty/NettyBackendHandler.java | 3 ++- .../backend/netty/{ => client}/BackendNettyClient.java | 2 +- .../{ => client}/BackendNettyClientChannelInitializer.java | 2 +- .../netty/{ => client}/CommandResponsePacketsHandler.java | 2 +- .../proxy/backend/netty/{ => client}/DataSourceConfig.java | 2 +- .../netty/{ => client}/NettyBackendHandlerFactory.java | 4 ++-- .../backend/netty/{ => client}/NettyChannelPoolHandler.java | 4 +++- .../netty/{ => client}/mysql/MySQLBackendHandler.java | 6 +++--- .../backend/netty/{ => client}/mysql/MySQLQueryResult.java | 2 +- .../io/shardingsphere/proxy/frontend/ShardingProxy.java | 2 +- 10 files changed, 16 insertions(+), 13 deletions(-) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/{ => client}/BackendNettyClient.java (99%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/{ => client}/BackendNettyClientChannelInitializer.java (96%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/{ => client}/CommandResponsePacketsHandler.java (96%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/{ => client}/DataSourceConfig.java (94%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/{ => client}/NettyBackendHandlerFactory.java (91%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/{ => client}/NettyChannelPoolHandler.java (88%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/{ => client}/mysql/MySQLBackendHandler.java (97%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/{ => client}/mysql/MySQLQueryResult.java (99%) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java index 8ea145e3c798f..08c227b7fb9ab 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java @@ -34,9 +34,10 @@ import io.shardingsphere.proxy.backend.AbstractBackendHandler; import io.shardingsphere.proxy.backend.BackendExecutorContext; import io.shardingsphere.proxy.backend.ResultPacket; +import io.shardingsphere.proxy.backend.netty.client.BackendNettyClient; import io.shardingsphere.proxy.backend.netty.future.FutureRegistry; import io.shardingsphere.proxy.backend.netty.future.SynchronizedFuture; -import io.shardingsphere.proxy.backend.netty.mysql.MySQLQueryResult; +import io.shardingsphere.proxy.backend.netty.client.mysql.MySQLQueryResult; import io.shardingsphere.proxy.config.ProxyTableMetaDataConnectionManager; import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.runtime.ChannelRegistry; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClient.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java similarity index 99% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClient.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java index a19a21c629d0e..b58a9576cac28 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClient.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.proxy.backend.netty; +package io.shardingsphere.proxy.backend.netty.client; import com.google.common.collect.Maps; import io.netty.bootstrap.Bootstrap; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClientChannelInitializer.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java similarity index 96% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClientChannelInitializer.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java index 3465ea940cb0f..5a52fbb94a3c5 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/BackendNettyClientChannelInitializer.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.proxy.backend.netty; +package io.shardingsphere.proxy.backend.netty.client; import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/CommandResponsePacketsHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/CommandResponsePacketsHandler.java similarity index 96% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/CommandResponsePacketsHandler.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/CommandResponsePacketsHandler.java index 4dc6d6a41170e..f892280253ff3 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/CommandResponsePacketsHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/CommandResponsePacketsHandler.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.proxy.backend.netty; +package io.shardingsphere.proxy.backend.netty.client; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/DataSourceConfig.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/DataSourceConfig.java similarity index 94% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/DataSourceConfig.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/DataSourceConfig.java index 3a98e89e55e47..c6ec899d55149 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/DataSourceConfig.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/DataSourceConfig.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.proxy.backend.netty; +package io.shardingsphere.proxy.backend.netty.client; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandlerFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java similarity index 91% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandlerFactory.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java index ed045acad6f54..ecddc38efd6de 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandlerFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java @@ -15,10 +15,10 @@ *

*/ -package io.shardingsphere.proxy.backend.netty; +package io.shardingsphere.proxy.backend.netty.client; import io.shardingsphere.core.constant.DatabaseType; -import io.shardingsphere.proxy.backend.netty.mysql.MySQLBackendHandler; +import io.shardingsphere.proxy.backend.netty.client.mysql.MySQLBackendHandler; /** * Backend handler factory for netty. diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyChannelPoolHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java similarity index 88% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyChannelPoolHandler.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java index b7f09c089ee5f..b4cd1fe3c20de 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyChannelPoolHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java @@ -15,10 +15,12 @@ *

*/ -package io.shardingsphere.proxy.backend.netty; +package io.shardingsphere.proxy.backend.netty.client; import io.netty.channel.Channel; import io.netty.channel.pool.ChannelPoolHandler; +import io.shardingsphere.proxy.backend.netty.client.BackendNettyClientChannelInitializer; +import io.shardingsphere.proxy.backend.netty.client.DataSourceConfig; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLBackendHandler.java similarity index 97% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLBackendHandler.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLBackendHandler.java index 77cfa0c037eb6..123d48be7dec5 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLBackendHandler.java @@ -15,14 +15,14 @@ *

*/ -package io.shardingsphere.proxy.backend.netty.mysql; +package io.shardingsphere.proxy.backend.netty.client.mysql; import com.google.common.collect.Maps; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.shardingsphere.proxy.backend.constant.AuthType; -import io.shardingsphere.proxy.backend.netty.CommandResponsePacketsHandler; -import io.shardingsphere.proxy.backend.netty.DataSourceConfig; +import io.shardingsphere.proxy.backend.netty.client.CommandResponsePacketsHandler; +import io.shardingsphere.proxy.backend.netty.client.DataSourceConfig; import io.shardingsphere.proxy.runtime.ChannelRegistry; import io.shardingsphere.proxy.transport.mysql.constant.CapabilityFlag; import io.shardingsphere.proxy.transport.mysql.constant.PacketHeader; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLQueryResult.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLQueryResult.java similarity index 99% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLQueryResult.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLQueryResult.java index 285d28b5127d6..079e040a0f401 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/mysql/MySQLQueryResult.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLQueryResult.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.proxy.backend.netty.mysql; +package io.shardingsphere.proxy.backend.netty.client.mysql; import com.google.common.collect.Lists; import io.shardingsphere.core.merger.QueryResult; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java index 1cfb073f6887d..cd2b165c7fe9d 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java @@ -30,7 +30,7 @@ import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; -import io.shardingsphere.proxy.backend.netty.BackendNettyClient; +import io.shardingsphere.proxy.backend.netty.client.BackendNettyClient; import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.frontend.common.netty.ServerHandlerInitializer; import io.shardingsphere.proxy.backend.BackendExecutorContext; From 3e3359ecf985277e8a6ebad906ce49c2da7367e4 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 14:18:00 +0800 Subject: [PATCH 056/198] add asyncExecute() --- .../ConnectionStrictlyExecutorEngine.java | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/ConnectionStrictlyExecutorEngine.java diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/ConnectionStrictlyExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/ConnectionStrictlyExecutorEngine.java new file mode 100644 index 0000000000000..9448baeb48997 --- /dev/null +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/ConnectionStrictlyExecutorEngine.java @@ -0,0 +1,107 @@ +/* + * 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.core.executor.type.connection; + +import com.google.common.util.concurrent.ListenableFuture; +import io.shardingsphere.core.constant.SQLType; +import io.shardingsphere.core.executor.BaseStatementUnit; +import io.shardingsphere.core.executor.ExecuteCallback; +import io.shardingsphere.core.executor.ExecutorEngine; +import io.shardingsphere.core.executor.threadlocal.ExecutorDataMap; +import io.shardingsphere.core.executor.threadlocal.ExecutorExceptionHandler; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; + +/** + * Connection strictly execute engine. + * + * @author panjuan + */ +public final class ConnectionStrictlyExecutorEngine extends ExecutorEngine { + + public ConnectionStrictlyExecutorEngine(final int executorSize) { + super(executorSize); + } + + @Override + protected List getExecuteResults(final SQLType sqlType, final Collection baseStatementUnits, final ExecuteCallback executeCallback) throws Exception { + Map> baseStatementUnitGroups = getBaseStatementUnitGroups(baseStatementUnits); + Collection firstOutputs = syncExecute(sqlType, baseStatementUnitGroups.remove(baseStatementUnitGroups.keySet().iterator().next()), executeCallback); + Collection>> restResultFutures = asyncExecute(sqlType, baseStatementUnitGroups, executeCallback); + return getResultList(firstOutputs, restResultFutures); + } + + private Map> getBaseStatementUnitGroups(final Collection baseStatementUnits) { + Map> result = new LinkedHashMap<>(baseStatementUnits.size(), 1); + for (BaseStatementUnit each : baseStatementUnits) { + String dataSourceName = each.getSqlExecutionUnit().getDataSource(); + if (!result.keySet().contains(dataSourceName)) { + result.put(dataSourceName, new LinkedList()); + } + result.get(dataSourceName).add(each); + } + return result; + } + + private Collection>> asyncExecute( + final SQLType sqlType, final Map> baseStatementUnitGroups, final ExecuteCallback executeCallback) { + Collection>> result = new ArrayList<>(baseStatementUnitGroups.size()); + final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown(); + final Map dataMap = ExecutorDataMap.getDataMap(); + for (Map.Entry> entry : baseStatementUnitGroups.entrySet()) { + final Collection baseStatementUnits = entry.getValue(); + result.add(getExecutorService().submit(new Callable>() { + @Override + public Collection call() throws Exception { + Collection result = new LinkedList<>(); + for (BaseStatementUnit each : baseStatementUnits) { + result.add(executeInternal(sqlType, each, executeCallback, isExceptionThrown, dataMap)); + } + return result; + } + })); + } + return result; + } + + private Collection syncExecute(final SQLType sqlType, final Collection baseStatementUnits, final ExecuteCallback executeCallback) throws Exception { + Collection result = new LinkedList<>(); + for (BaseStatementUnit each : baseStatementUnits) { + result.add(executeInternal(sqlType, each, executeCallback, ExecutorExceptionHandler.isExceptionThrown(), ExecutorDataMap.getDataMap())); + } + return result; + } + + private List getResultList(final Collection firstOutputs, final Collection>> restResultFutures) throws ExecutionException, InterruptedException { + List result = new LinkedList<>(); + result.addAll(firstOutputs); + for (ListenableFuture> each : restResultFutures) { + result.addAll(each.get()); + } + return result; + } + + +} \ No newline at end of file From 3daeb2bf778debd261ffcfcb20f42597acbbb5cc Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 14:18:57 +0800 Subject: [PATCH 057/198] use Collection --- .../executor/type/memory/MemoryStrictlyExecutorEngine.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java index 4430e4f417e12..26e0a894ca984 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java @@ -50,11 +50,11 @@ public MemoryStrictlyExecutorEngine(final int executorSize) { protected List getExecuteResults(final SQLType sqlType, final Collection baseStatementUnits, final ExecuteCallback executeCallback) throws Exception { Iterator iterator = baseStatementUnits.iterator(); T firstOutput = syncExecute(sqlType, iterator.next(), executeCallback); - List> restFutures = asyncExecute(sqlType, Lists.newArrayList(iterator), executeCallback); + Collection> restFutures = asyncExecute(sqlType, Lists.newArrayList(iterator), executeCallback); return getResultList(firstOutput, restFutures); } - private List> asyncExecute( + private Collection> asyncExecute( final SQLType sqlType, final Collection baseStatementUnits, final ExecuteCallback executeCallback) { List> result = new ArrayList<>(baseStatementUnits.size()); final boolean isExceptionThrown = ExecutorExceptionHandler.isExceptionThrown(); @@ -75,7 +75,7 @@ private T syncExecute(final SQLType sqlType, final BaseStatementUnit baseSta return executeInternal(sqlType, baseStatementUnit, executeCallback, ExecutorExceptionHandler.isExceptionThrown(), ExecutorDataMap.getDataMap()); } - private List getResultList(final T firstOutput, final List> restResultFutures) throws ExecutionException, InterruptedException { + private List getResultList(final T firstOutput, final Collection> restResultFutures) throws ExecutionException, InterruptedException { List result = new LinkedList<>(); result.add(firstOutput); for (ListenableFuture each : restResultFutures) { From 67559ebce2dc482a46842a827f654635fc438e79 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Mon, 6 Aug 2018 14:19:13 +0800 Subject: [PATCH 058/198] for #1099, make backend thread pool infinite by default --- .../core/constant/ShardingPropertiesConstant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java index 21a8c009fce88..1f58d01cb1632 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java @@ -59,7 +59,7 @@ public enum ShardingPropertiesConstant { *

* Execute SQL Statement and PrepareStatement will use this thread pool. * One sharding data source will use a independent thread pool, it does not share thread pool even different data source in same JVM. - * Default: same with CPU cores. + * Default: infinite. *

*/ EXECUTOR_SIZE("executor.size", String.valueOf(0), int.class), From e687843fd12f176d43cc6a7522b8ab23922bc26c Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 14:19:53 +0800 Subject: [PATCH 059/198] for check style --- .../core/executor/type/memory/MemoryStrictlyExecutorEngine.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java index 26e0a894ca984..529ecdbefa9f3 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java @@ -84,3 +84,4 @@ private List getResultList(final T firstOutput, final Collection Date: Mon, 6 Aug 2018 14:20:03 +0800 Subject: [PATCH 060/198] remove blank line --- .../type/connection/ConnectionStrictlyExecutorEngine.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/ConnectionStrictlyExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/ConnectionStrictlyExecutorEngine.java index 9448baeb48997..f3877e5d482d9 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/ConnectionStrictlyExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/ConnectionStrictlyExecutorEngine.java @@ -102,6 +102,4 @@ private List getResultList(final Collection firstOutputs, final Collec } return result; } - - -} \ No newline at end of file +} From cad9727a4c5b1f93ec1cc47c9a069006c8bb114e Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 14:28:50 +0800 Subject: [PATCH 061/198] refactor BackendNettyClient --- .../datasource/ShardingDataSourceMetaData.java | 10 +++++----- .../core/rewrite/SQLBuilder.java | 2 +- .../ShardingDataSourceMetaDataTest.java | 4 ++-- .../netty/client/BackendNettyClient.java | 18 ++++++++++-------- .../netty/client/NettyChannelPoolHandler.java | 3 +-- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/ShardingDataSourceMetaData.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/ShardingDataSourceMetaData.java index 3a1b61b0d55c6..1943c29df0a25 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/ShardingDataSourceMetaData.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/datasource/ShardingDataSourceMetaData.java @@ -98,12 +98,12 @@ private boolean isExisted(final String dataSourceName, final Collection } /** - * Get actual schema name. - * + * Get data source meta data. + * * @param actualDataSourceName actual data source name - * @return actual schema name + * @return actual data source meta data */ - public String getActualSchemaName(final String actualDataSourceName) { - return dataSourceMetaDataMap.get(actualDataSourceName).getSchemeName(); + public DataSourceMetaData getActualDataSourceMetaData(final String actualDataSourceName) { + return dataSourceMetaDataMap.get(actualDataSourceName); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLBuilder.java b/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLBuilder.java index ef1709b8767a7..a2c24c05bb92b 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLBuilder.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/rewrite/SQLBuilder.java @@ -131,7 +131,7 @@ private void appendTablePlaceholder(final TablePlaceholder tablePlaceholder, fin private void appendSchemaPlaceholder(final ShardingRule shardingRule, final ShardingDataSourceMetaData shardingDataSourceMetaData, final String actualTableName, final StringBuilder stringBuilder) { - stringBuilder.append(shardingDataSourceMetaData.getActualSchemaName(shardingRule.getActualDataSourceNameByActualTableName(actualTableName))); + stringBuilder.append(shardingDataSourceMetaData.getActualDataSourceMetaData(shardingRule.getActualDataSourceNameByActualTableName(actualTableName)).getSchemeName()); } private void appendIndexPlaceholder(final IndexPlaceholder indexPlaceholder, final String actualTableName, final StringBuilder stringBuilder) { diff --git a/sharding-core/src/test/java/io/shardingsphere/core/metadata/datasource/ShardingDataSourceMetaDataTest.java b/sharding-core/src/test/java/io/shardingsphere/core/metadata/datasource/ShardingDataSourceMetaDataTest.java index b1258cebf35c2..0cdec1e94084d 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/metadata/datasource/ShardingDataSourceMetaDataTest.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/metadata/datasource/ShardingDataSourceMetaDataTest.java @@ -93,11 +93,11 @@ public void assertGetAllInstanceDataSourceNamesForShardingRule() { @Test public void assertGetActualSchemaNameForMasterSlaveShardingRule() { - assertEquals(masterSlaveShardingDataSourceMetaData.getActualSchemaName("ms_0"), "master_0"); + assertEquals(masterSlaveShardingDataSourceMetaData.getActualDataSourceMetaData("ms_0").getSchemeName(), "master_0"); } @Test public void assertGetActualSchemaNameForShardingRule() { - assertEquals(shardingDataSourceMetaData.getActualSchemaName("ds_0"), "db_0"); + assertEquals(shardingDataSourceMetaData.getActualDataSourceMetaData("ds_0").getSchemeName(), "db_0"); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java index b58a9576cac28..6a7186111a1d1 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java @@ -17,7 +17,6 @@ package io.shardingsphere.proxy.backend.netty.client; -import com.google.common.collect.Maps; import io.netty.bootstrap.Bootstrap; import io.netty.buffer.PooledByteBufAllocator; import io.netty.channel.Channel; @@ -32,6 +31,7 @@ import io.netty.channel.pool.FixedChannelPool; import io.netty.channel.pool.SimpleChannelPool; import io.netty.channel.socket.nio.NioSocketChannel; +import io.shardingsphere.core.metadata.datasource.DataSourceMetaData; import io.shardingsphere.core.rule.DataSourceParameter; import io.shardingsphere.proxy.config.RuleRegistry; import lombok.AccessLevel; @@ -39,8 +39,7 @@ import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import java.net.MalformedURLException; -import java.net.URL; +import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ExecutionException; @@ -67,7 +66,7 @@ public final class BackendNettyClient { private static final int CONNECTION_TIMEOUT_SECONDS = RULE_REGISTRY.getBackendNIOConfig().getConnectionTimeoutSeconds(); - private final Map dataSourceConfigMap = Maps.newHashMap(); + private final Map dataSourceConfigMap = new HashMap<>(); private EventLoopGroup workerGroup; @@ -86,14 +85,16 @@ public static BackendNettyClient getInstance() { /** * Start backend connection client for netty. * - * @throws MalformedURLException URL is illegal * @throws InterruptedException interrupted exception */ - public void start() throws MalformedURLException, InterruptedException { + public void start() throws InterruptedException { Map dataSourceConfigurationMap = RULE_REGISTRY.getDataSourceConfigurationMap(); for (Entry each : dataSourceConfigurationMap.entrySet()) { - URL url = new URL(each.getValue().getUrl().replaceAll("jdbc:mysql:", "http:")); - dataSourceConfigMap.put(each.getKey(), new DataSourceConfig(url.getHost(), url.getPort(), url.getPath().substring(1), each.getValue().getUsername(), each.getValue().getPassword())); + String actualDataSourceName = each.getKey(); + DataSourceParameter dataSourceParameter = each.getValue(); + DataSourceMetaData dataSourceMetaData = RULE_REGISTRY.getMetaData().getDataSource().getActualDataSourceMetaData(actualDataSourceName); + dataSourceConfigMap.put(each.getKey(), new DataSourceConfig( + dataSourceMetaData.getHostName(), dataSourceMetaData.getPort(), dataSourceMetaData.getSchemeName(), dataSourceParameter.getUsername(), dataSourceParameter.getPassword())); } Bootstrap bootstrap = new Bootstrap(); // TODO :jiaqi where to init workerGroup? @@ -137,6 +138,7 @@ private void groupsNio(final Bootstrap bootstrap) { private void initPoolMap(final Bootstrap bootstrap) throws InterruptedException { poolMap = new AbstractChannelPoolMap() { + @Override protected SimpleChannelPool newPool(final String datasourceName) { DataSourceConfig dataSourceConfig = dataSourceConfigMap.get(datasourceName); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java index b4cd1fe3c20de..48ca6e6c34b38 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java @@ -19,8 +19,6 @@ import io.netty.channel.Channel; import io.netty.channel.pool.ChannelPoolHandler; -import io.shardingsphere.proxy.backend.netty.client.BackendNettyClientChannelInitializer; -import io.shardingsphere.proxy.backend.netty.client.DataSourceConfig; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -33,6 +31,7 @@ @RequiredArgsConstructor @Slf4j public class NettyChannelPoolHandler implements ChannelPoolHandler { + private final DataSourceConfig dataSourceConfig; @Override From a7e104458fe73e77ea9e17fbb58dd6c30da555aa Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 14:30:21 +0800 Subject: [PATCH 062/198] modify BatchPreparedStatementUnit --- .../core/jdbc/core/statement/ShardingPreparedStatement.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java index 00fb01076b462..863cd442c57a3 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java @@ -290,8 +290,7 @@ public boolean apply(final BatchPreparedStatementUnit input) { preparedBatchStatement.get().getSqlExecutionUnit().getSqlUnit().getParameterSets().add(sqlExecutionUnit.getSqlUnit().getParameterSets().get(0)); return preparedBatchStatement.get(); } - BatchPreparedStatementUnit result = new BatchPreparedStatementUnit(sqlExecutionUnit, generatePreparedStatement(connection.getConnection(sqlExecutionUnit.getDataSource()), - sqlExecutionUnit.getSqlUnit().getSql())); + BatchPreparedStatementUnit result = new BatchPreparedStatementUnit(sqlExecutionUnit, generatePreparedStatement(connection.getConnection(sqlExecutionUnit.getDataSource()), sqlExecutionUnit.getSqlUnit().getSql())); batchStatementUnits.add(result); return result; } From 43b5a2d742573a4876039a4e68e727400f688e79 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 14:34:27 +0800 Subject: [PATCH 063/198] add getQueryResults --- .../statement/ShardingPreparedStatement.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java index 863cd442c57a3..b50d153bf3cea 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java @@ -24,6 +24,8 @@ import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementExecutor; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementUnit; +import io.shardingsphere.core.executor.type.connection.MemoryQueryResult; +import io.shardingsphere.core.executor.type.memory.StreamQueryResult; import io.shardingsphere.core.executor.type.prepared.PreparedStatementExecutor; import io.shardingsphere.core.executor.type.prepared.PreparedStatementUnit; import io.shardingsphere.core.jdbc.adapter.AbstractShardingPreparedStatementAdapter; @@ -139,12 +141,8 @@ public ResultSet executeQuery() throws SQLException { Collection preparedStatementUnits = route(); List resultSets = new PreparedStatementExecutor( connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), preparedStatementUnits).executeQuery(); - List queryResults = new ArrayList<>(resultSets.size()); - for (ResultSet each : resultSets) { - queryResults.add(new JDBCQueryResult(each)); - } MergeEngine mergeEngine = MergeEngineFactory.newInstance( - connection.getShardingContext().getShardingRule(), queryResults, routeResult.getSqlStatement(), connection.getShardingContext().getMetaData().getTable()); + connection.getShardingContext().getShardingRule(), getQueryResults(resultSets), routeResult.getSqlStatement(), connection.getShardingContext().getMetaData().getTable()); result = new ShardingResultSet(resultSets, merge(mergeEngine), this); } finally { clearBatch(); @@ -153,6 +151,18 @@ public ResultSet executeQuery() throws SQLException { return result; } + private List getQueryResults(final List resultSets) throws SQLException { + List result = new ArrayList<>(resultSets.size()); + for (ResultSet each : resultSets) { + if (ProxyMode.MEMORY_STRICTLY == connection.getShardingContext().getProxyMode()) { + result.add(new StreamQueryResult(each)); + } else { + result.add(new MemoryQueryResult(each)); + } + } + return result; + } + @Override public int executeUpdate() throws SQLException { routedStatements.clear(); From cb0247207872fe0a0fcb5bdba9f16b2a44d27ec3 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 14:37:44 +0800 Subject: [PATCH 064/198] add getQueryResults() --- .../core/statement/ShardingStatement.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java index 99ba311049a9c..2fc104d88e3e4 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java @@ -20,6 +20,8 @@ import com.google.common.base.Optional; import io.shardingsphere.core.constant.ProxyMode; import io.shardingsphere.core.constant.SQLType; +import io.shardingsphere.core.executor.type.connection.MemoryQueryResult; +import io.shardingsphere.core.executor.type.memory.StreamQueryResult; import io.shardingsphere.core.executor.type.statement.StatementExecutor; import io.shardingsphere.core.executor.type.statement.StatementUnit; import io.shardingsphere.core.jdbc.adapter.AbstractStatementAdapter; @@ -112,12 +114,8 @@ public ResultSet executeQuery(final String sql) throws SQLException { ResultSet result; try { List resultSets = generateExecutor(sql).executeQuery(); - List queryResults = new ArrayList<>(resultSets.size()); - for (ResultSet each : resultSets) { - queryResults.add(new JDBCQueryResult(each)); - } MergeEngine mergeEngine = MergeEngineFactory.newInstance( - connection.getShardingContext().getShardingRule(), queryResults, routeResult.getSqlStatement(), connection.getShardingContext().getMetaData().getTable()); + connection.getShardingContext().getShardingRule(), getQueryResults(resultSets), routeResult.getSqlStatement(), connection.getShardingContext().getMetaData().getTable()); result = new ShardingResultSet(resultSets, merge(mergeEngine), this); } finally { currentResultSet = null; @@ -126,6 +124,18 @@ public ResultSet executeQuery(final String sql) throws SQLException { return result; } + private List getQueryResults(final List resultSets) throws SQLException { + List result = new ArrayList<>(resultSets.size()); + for (ResultSet each : resultSets) { + if (ProxyMode.MEMORY_STRICTLY == connection.getShardingContext().getProxyMode()) { + result.add(new StreamQueryResult(each)); + } else { + result.add(new MemoryQueryResult(each)); + } + } + return result; + } + @Override public int executeUpdate(final String sql) throws SQLException { try { From fd849b5038f017340a5498c4d18ee530bd959c22 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 14:38:36 +0800 Subject: [PATCH 065/198] add author --- .../core/jdbc/core/statement/ShardingStatement.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java index 2fc104d88e3e4..c713d24478a01 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java @@ -70,6 +70,7 @@ * @author caohao * @author zhangliang * @author zhaojun + * @author panjuan */ @Getter public class ShardingStatement extends AbstractStatementAdapter { From 38877d0b5e6dc4c5ff2670b787e8bf41e7b8942a Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 14:44:50 +0800 Subject: [PATCH 066/198] remove DataSourceConfig --- .../netty/client/BackendNettyClient.java | 22 ++-------- .../BackendNettyClientChannelInitializer.java | 4 +- .../netty/client/DataSourceConfig.java | 41 ------------------- .../client/NettyBackendHandlerFactory.java | 6 +-- .../netty/client/NettyChannelPoolHandler.java | 4 +- .../client/mysql/MySQLBackendHandler.java | 20 +++++---- 6 files changed, 24 insertions(+), 73 deletions(-) delete mode 100644 sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/DataSourceConfig.java diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java index 6a7186111a1d1..1f3f05799e01f 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java @@ -32,16 +32,12 @@ import io.netty.channel.pool.SimpleChannelPool; import io.netty.channel.socket.nio.NioSocketChannel; import io.shardingsphere.core.metadata.datasource.DataSourceMetaData; -import io.shardingsphere.core.rule.DataSourceParameter; import io.shardingsphere.proxy.config.RuleRegistry; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -66,8 +62,6 @@ public final class BackendNettyClient { private static final int CONNECTION_TIMEOUT_SECONDS = RULE_REGISTRY.getBackendNIOConfig().getConnectionTimeoutSeconds(); - private final Map dataSourceConfigMap = new HashMap<>(); - private EventLoopGroup workerGroup; @Getter @@ -88,14 +82,6 @@ public static BackendNettyClient getInstance() { * @throws InterruptedException interrupted exception */ public void start() throws InterruptedException { - Map dataSourceConfigurationMap = RULE_REGISTRY.getDataSourceConfigurationMap(); - for (Entry each : dataSourceConfigurationMap.entrySet()) { - String actualDataSourceName = each.getKey(); - DataSourceParameter dataSourceParameter = each.getValue(); - DataSourceMetaData dataSourceMetaData = RULE_REGISTRY.getMetaData().getDataSource().getActualDataSourceMetaData(actualDataSourceName); - dataSourceConfigMap.put(each.getKey(), new DataSourceConfig( - dataSourceMetaData.getHostName(), dataSourceMetaData.getPort(), dataSourceMetaData.getSchemeName(), dataSourceParameter.getUsername(), dataSourceParameter.getPassword())); - } Bootstrap bootstrap = new Bootstrap(); // TODO :jiaqi where to init workerGroup? if (workerGroup instanceof EpollEventLoopGroup) { @@ -140,12 +126,12 @@ private void initPoolMap(final Bootstrap bootstrap) throws InterruptedException poolMap = new AbstractChannelPoolMap() { @Override - protected SimpleChannelPool newPool(final String datasourceName) { - DataSourceConfig dataSourceConfig = dataSourceConfigMap.get(datasourceName); - return new FixedChannelPool(bootstrap.remoteAddress(dataSourceConfig.getIp(), dataSourceConfig.getPort()), new NettyChannelPoolHandler(dataSourceConfig), MAX_CONNECTIONS); + protected SimpleChannelPool newPool(final String dataSourceName) { + DataSourceMetaData dataSourceMetaData = RULE_REGISTRY.getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); + return new FixedChannelPool(bootstrap.remoteAddress(dataSourceMetaData.getHostName(), dataSourceMetaData.getPort()), new NettyChannelPoolHandler(dataSourceName), MAX_CONNECTIONS); } }; - for (String each : dataSourceConfigMap.keySet()) { + for (String each : RULE_REGISTRY.getDataSourceConfigurationMap().keySet()) { SimpleChannelPool pool = poolMap.get(each); Channel[] channels = new Channel[MAX_CONNECTIONS]; for (int i = 0; i < MAX_CONNECTIONS; i++) { diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java index 5a52fbb94a3c5..a66a3c4016d4e 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java @@ -33,13 +33,13 @@ @RequiredArgsConstructor public final class BackendNettyClientChannelInitializer extends ChannelInitializer { - private final DataSourceConfig dataSourceConfig; + private final String dataSourceName; @Override protected void initChannel(final Channel channel) { ChannelPipeline pipeline = channel.pipeline(); // TODO load database type from yaml or startup arguments pipeline.addLast(PacketCodecFactory.createPacketCodecInstance(DatabaseType.MySQL)); - pipeline.addLast(NettyBackendHandlerFactory.createBackendHandlerInstance(DatabaseType.MySQL, dataSourceConfig)); + pipeline.addLast(NettyBackendHandlerFactory.createBackendHandlerInstance(DatabaseType.MySQL, dataSourceName)); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/DataSourceConfig.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/DataSourceConfig.java deleted file mode 100644 index c6ec899d55149..0000000000000 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/DataSourceConfig.java +++ /dev/null @@ -1,41 +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.proxy.backend.netty.client; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -/** - * DataSourceConfig. - * - * @author linjiaqi - */ -@RequiredArgsConstructor -@Getter -public final class DataSourceConfig { - - private final String ip; - - private final int port; - - private final String database; - - private final String username; - - private final String password; -} diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java index ecddc38efd6de..c61deccd2e47b 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java @@ -31,13 +31,13 @@ public final class NettyBackendHandlerFactory { * Create backend handler instance. * * @param databaseType database type - * @param dataSourceConfig dataSourceConfig + * @param dataSourceName data source name * @return backend handler instance */ - public static CommandResponsePacketsHandler createBackendHandlerInstance(final DatabaseType databaseType, final DataSourceConfig dataSourceConfig) { + public static CommandResponsePacketsHandler createBackendHandlerInstance(final DatabaseType databaseType, final String dataSourceName) { switch (databaseType) { case MySQL: - return new MySQLBackendHandler(dataSourceConfig); + return new MySQLBackendHandler(dataSourceName); default: throw new UnsupportedOperationException(String.format("Cannot support database type '%s'", databaseType)); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java index 48ca6e6c34b38..8c6021b968a59 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java @@ -32,7 +32,7 @@ @Slf4j public class NettyChannelPoolHandler implements ChannelPoolHandler { - private final DataSourceConfig dataSourceConfig; + private final String dataSourceName; @Override public void channelReleased(final Channel channel) { @@ -47,6 +47,6 @@ public void channelAcquired(final Channel channel) { @Override public void channelCreated(final Channel channel) { log.info("channelCreated. Channel ID: {}" + channel.id().asShortText()); - channel.pipeline().addLast(new BackendNettyClientChannelInitializer(dataSourceConfig)); + channel.pipeline().addLast(new BackendNettyClientChannelInitializer(dataSourceName)); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLBackendHandler.java index 123d48be7dec5..63345e920e660 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLBackendHandler.java @@ -20,9 +20,12 @@ import com.google.common.collect.Maps; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; +import io.shardingsphere.core.metadata.datasource.DataSourceMetaData; +import io.shardingsphere.core.rule.DataSourceParameter; import io.shardingsphere.proxy.backend.constant.AuthType; import io.shardingsphere.proxy.backend.netty.client.CommandResponsePacketsHandler; -import io.shardingsphere.proxy.backend.netty.client.DataSourceConfig; +import io.shardingsphere.proxy.backend.netty.future.FutureRegistry; +import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.runtime.ChannelRegistry; import io.shardingsphere.proxy.transport.mysql.constant.CapabilityFlag; import io.shardingsphere.proxy.transport.mysql.constant.PacketHeader; @@ -35,7 +38,6 @@ import io.shardingsphere.proxy.transport.mysql.packet.generic.OKPacket; import io.shardingsphere.proxy.transport.mysql.packet.handshake.HandshakePacket; import io.shardingsphere.proxy.transport.mysql.packet.handshake.HandshakeResponse41Packet; -import io.shardingsphere.proxy.backend.netty.future.FutureRegistry; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -53,7 +55,9 @@ @RequiredArgsConstructor public class MySQLBackendHandler extends CommandResponsePacketsHandler { - private final DataSourceConfig dataSourceConfig; + private static final RuleRegistry RULE_REGISTRY = RuleRegistry.getInstance(); + + private final String dataSourceName; private final Map resultMap = Maps.newHashMap(); @@ -95,11 +99,13 @@ public void channelRead(final ChannelHandlerContext context, final Object messag @Override protected void auth(final ChannelHandlerContext context, final MySQLPacketPayload payload) { try { + DataSourceParameter dataSourceParameter = RULE_REGISTRY.getDataSourceConfigurationMap().get(dataSourceName); + DataSourceMetaData dataSourceMetaData = RULE_REGISTRY.getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); HandshakePacket handshakePacket = new HandshakePacket(payload); - int capabilityFlags = CapabilityFlag.calculateHandshakeCapabilityFlagsLower(); - byte[] authResponse = securePasswordAuthentication(dataSourceConfig.getPassword().getBytes(), handshakePacket.getAuthPluginData().getAuthPluginData()); - HandshakeResponse41Packet handshakeResponse41Packet = new HandshakeResponse41Packet(handshakePacket.getSequenceId() + 1, capabilityFlags, 16777215, - ServerInfo.CHARSET, dataSourceConfig.getUsername(), authResponse, dataSourceConfig.getDatabase()); + byte[] authResponse = securePasswordAuthentication(dataSourceParameter.getPassword().getBytes(), handshakePacket.getAuthPluginData().getAuthPluginData()); + HandshakeResponse41Packet handshakeResponse41Packet = new HandshakeResponse41Packet( + handshakePacket.getSequenceId() + 1, CapabilityFlag.calculateHandshakeCapabilityFlagsLower(), 16777215, ServerInfo.CHARSET, + dataSourceParameter.getUsername(), authResponse, dataSourceMetaData.getSchemeName()); ChannelRegistry.getInstance().putConnectionId(context.channel().id().asShortText(), handshakePacket.getConnectionId()); context.writeAndFlush(handshakeResponse41Packet); } finally { From 1d48ceb0eaa7a74b3a7314f28c7b9432d7de8db7 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 15:06:31 +0800 Subject: [PATCH 067/198] new executor --- .../core/jdbc/core/connection/ShardingConnectionTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java index 5f8354f98d45c..f5be507e6e006 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java @@ -21,6 +21,7 @@ import io.shardingsphere.core.api.config.ShardingRuleConfiguration; import io.shardingsphere.core.api.config.TableRuleConfiguration; import io.shardingsphere.core.constant.DatabaseType; +import io.shardingsphere.core.constant.ProxyMode; import io.shardingsphere.core.fixture.TestDataSource; import io.shardingsphere.core.jdbc.core.ShardingContext; import io.shardingsphere.core.jdbc.core.datasource.MasterSlaveDataSource; @@ -72,7 +73,7 @@ public void setUp() { Map dataSourceMap = new HashMap<>(1, 1); dataSourceMap.put(DS_NAME, masterSlaveDataSource); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()); - ShardingContext shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.H2, null, new ShardingTableMetaData(Collections.emptyMap()), false); + ShardingContext shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.H2, null, new ShardingTableMetaData(Collections.emptyMap()), false, ProxyMode.MEMORY_STRICTLY); connection = new ShardingConnection(shardingContext); } From 1cbded2e45a96fc7f1fbc534e48f1d1348116252 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 15:06:51 +0800 Subject: [PATCH 068/198] change position for executor. --- .../core/jdbc/core/datasource/ShardingDataSource.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java index 15d0273327e76..b1493055b6956 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java @@ -72,11 +72,11 @@ public ShardingDataSource(final Map dataSourceMap, final Sha } shardingProperties = new ShardingProperties(null == props ? new Properties() : props); int executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); + ProxyMode proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); + executorEngine = ProxyMode.MEMORY_STRICTLY == proxyMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData( new TableMetaDataInitializer(executorEngine.getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule)); boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); - ProxyMode proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); - executorEngine = ProxyMode.MEMORY_STRICTLY == proxyMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL, proxyMode); } From 8edf1d513c380f44fb972b11c79e9b463842be2b Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 15:07:04 +0800 Subject: [PATCH 069/198] add MemoryStrictlyExecutorEngine --- .../core/executor/type/AbstractBaseExecutorTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/AbstractBaseExecutorTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/AbstractBaseExecutorTest.java index f8d51b60f3d9d..ce81d1ca39d06 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/AbstractBaseExecutorTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/AbstractBaseExecutorTest.java @@ -24,6 +24,7 @@ import io.shardingsphere.core.executor.fixture.TestDQLExecutionEventListener; import io.shardingsphere.core.executor.fixture.TestOverallExecutionEventListener; import io.shardingsphere.core.executor.threadlocal.ExecutorExceptionHandler; +import io.shardingsphere.core.executor.type.memory.MemoryStrictlyExecutorEngine; import io.shardingsphere.core.util.EventBusInstance; import lombok.AccessLevel; import lombok.Getter; @@ -50,7 +51,7 @@ public abstract class AbstractBaseExecutorTest { public void setUp() { MockitoAnnotations.initMocks(this); ExecutorExceptionHandler.setExceptionThrown(false); - executorEngine = new ExecutorEngine(Runtime.getRuntime().availableProcessors()); + executorEngine = new MemoryStrictlyExecutorEngine(Runtime.getRuntime().availableProcessors()); overallExecutionEventListener = new TestOverallExecutionEventListener(eventCaller); dqlExecutionEventListener = new TestDQLExecutionEventListener(eventCaller); dmlExecutionEventListener = new TestDMLExecutionEventListener(eventCaller); From 1952584842bff79a73a4d2d2d609b4e80f34a0e9 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 15:20:05 +0800 Subject: [PATCH 070/198] NettyChannelPoolHandler => BackendNettyClientChannelPoolHandler --- .../proxy/backend/netty/client/BackendNettyClient.java | 2 +- ...Handler.java => BackendNettyClientChannelPoolHandler.java} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/{NettyChannelPoolHandler.java => BackendNettyClientChannelPoolHandler.java} (91%) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java index 1f3f05799e01f..beaa25373fc17 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java @@ -128,7 +128,7 @@ private void initPoolMap(final Bootstrap bootstrap) throws InterruptedException @Override protected SimpleChannelPool newPool(final String dataSourceName) { DataSourceMetaData dataSourceMetaData = RULE_REGISTRY.getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); - return new FixedChannelPool(bootstrap.remoteAddress(dataSourceMetaData.getHostName(), dataSourceMetaData.getPort()), new NettyChannelPoolHandler(dataSourceName), MAX_CONNECTIONS); + return new FixedChannelPool(bootstrap.remoteAddress(dataSourceMetaData.getHostName(), dataSourceMetaData.getPort()), new BackendNettyClientChannelPoolHandler(dataSourceName), MAX_CONNECTIONS); } }; for (String each : RULE_REGISTRY.getDataSourceConfigurationMap().keySet()) { diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelPoolHandler.java similarity index 91% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelPoolHandler.java index 8c6021b968a59..f00a9bb06ce4c 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyChannelPoolHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelPoolHandler.java @@ -23,14 +23,14 @@ import lombok.extern.slf4j.Slf4j; /** - * NettyChannelPoolHandler. + * Channel pool handler of backend netty client. * * @author wangkai * @author linjiaqi */ @RequiredArgsConstructor @Slf4j -public class NettyChannelPoolHandler implements ChannelPoolHandler { +public final class BackendNettyClientChannelPoolHandler implements ChannelPoolHandler { private final String dataSourceName; From e998c55e30457e42bfed076423da027de6bb6b65 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 15:23:12 +0800 Subject: [PATCH 071/198] refactor NettyBackendHandlerFactory --- .../netty/client/BackendNettyClientChannelInitializer.java | 2 +- .../backend/netty/client/NettyBackendHandlerFactory.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java index a66a3c4016d4e..f9f7a02f39084 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java @@ -40,6 +40,6 @@ protected void initChannel(final Channel channel) { ChannelPipeline pipeline = channel.pipeline(); // TODO load database type from yaml or startup arguments pipeline.addLast(PacketCodecFactory.createPacketCodecInstance(DatabaseType.MySQL)); - pipeline.addLast(NettyBackendHandlerFactory.createBackendHandlerInstance(DatabaseType.MySQL, dataSourceName)); + pipeline.addLast(NettyBackendHandlerFactory.newInstance(DatabaseType.MySQL, dataSourceName)); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java index c61deccd2e47b..8dd70af78526e 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java @@ -19,6 +19,8 @@ import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.proxy.backend.netty.client.mysql.MySQLBackendHandler; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; /** * Backend handler factory for netty. @@ -26,15 +28,16 @@ * @author wangkai * @author linjiaqi */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class NettyBackendHandlerFactory { /** - * Create backend handler instance. + * Create new instance of netty backend handler. * * @param databaseType database type * @param dataSourceName data source name * @return backend handler instance */ - public static CommandResponsePacketsHandler createBackendHandlerInstance(final DatabaseType databaseType, final String dataSourceName) { + public static CommandResponsePacketsHandler newInstance(final DatabaseType databaseType, final String dataSourceName) { switch (databaseType) { case MySQL: return new MySQLBackendHandler(dataSourceName); From bf6ae8e3eb7b80dea9a06365e7f864b5e1891bab Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 15:32:12 +0800 Subject: [PATCH 072/198] refactor package of backend.netty --- .../proxy/backend/netty/NettyBackendHandler.java | 2 +- .../BackendNettyClientChannelInitializer.java | 3 ++- .../ResponseHandler.java} | 6 +++--- .../ResponseHandlerFactory.java} | 16 ++++++++-------- .../{ => response}/mysql/MySQLQueryResult.java | 2 +- .../mysql/MySQLResponseHandler.java} | 12 ++++++------ 6 files changed, 21 insertions(+), 20 deletions(-) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/{CommandResponsePacketsHandler.java => response/ResponseHandler.java} (88%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/{NettyBackendHandlerFactory.java => response/ResponseHandlerFactory.java} (65%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/{ => response}/mysql/MySQLQueryResult.java (99%) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/{mysql/MySQLBackendHandler.java => response/mysql/MySQLResponseHandler.java} (96%) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java index 08c227b7fb9ab..4d7c5532191e8 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java @@ -37,7 +37,7 @@ import io.shardingsphere.proxy.backend.netty.client.BackendNettyClient; import io.shardingsphere.proxy.backend.netty.future.FutureRegistry; import io.shardingsphere.proxy.backend.netty.future.SynchronizedFuture; -import io.shardingsphere.proxy.backend.netty.client.mysql.MySQLQueryResult; +import io.shardingsphere.proxy.backend.netty.client.response.mysql.MySQLQueryResult; import io.shardingsphere.proxy.config.ProxyTableMetaDataConnectionManager; import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.runtime.ChannelRegistry; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java index f9f7a02f39084..25be3ca2c6df2 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClientChannelInitializer.java @@ -21,6 +21,7 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.shardingsphere.core.constant.DatabaseType; +import io.shardingsphere.proxy.backend.netty.client.response.ResponseHandlerFactory; import io.shardingsphere.proxy.transport.common.codec.PacketCodecFactory; import lombok.RequiredArgsConstructor; @@ -40,6 +41,6 @@ protected void initChannel(final Channel channel) { ChannelPipeline pipeline = channel.pipeline(); // TODO load database type from yaml or startup arguments pipeline.addLast(PacketCodecFactory.createPacketCodecInstance(DatabaseType.MySQL)); - pipeline.addLast(NettyBackendHandlerFactory.newInstance(DatabaseType.MySQL, dataSourceName)); + pipeline.addLast(ResponseHandlerFactory.newInstance(DatabaseType.MySQL, dataSourceName)); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/CommandResponsePacketsHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java similarity index 88% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/CommandResponsePacketsHandler.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java index f892280253ff3..896d7c72985e3 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/CommandResponsePacketsHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java @@ -15,19 +15,19 @@ *

*/ -package io.shardingsphere.proxy.backend.netty.client; +package io.shardingsphere.proxy.backend.netty.client.response; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload; /** - * SQL execute backend handler. + * SQL executed response handler. * * @author wangkai * @author linjiaqi */ -public abstract class CommandResponsePacketsHandler extends ChannelInboundHandlerAdapter { +public abstract class ResponseHandler extends ChannelInboundHandlerAdapter { protected abstract void auth(ChannelHandlerContext context, MySQLPacketPayload payload); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandlerFactory.java similarity index 65% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandlerFactory.java index 8dd70af78526e..4e527bc5cf397 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/NettyBackendHandlerFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandlerFactory.java @@ -15,32 +15,32 @@ *

*/ -package io.shardingsphere.proxy.backend.netty.client; +package io.shardingsphere.proxy.backend.netty.client.response; import io.shardingsphere.core.constant.DatabaseType; -import io.shardingsphere.proxy.backend.netty.client.mysql.MySQLBackendHandler; +import io.shardingsphere.proxy.backend.netty.client.response.mysql.MySQLResponseHandler; import lombok.AccessLevel; import lombok.NoArgsConstructor; /** - * Backend handler factory for netty. + * Response handler factory for using netty connect backend. * * @author wangkai * @author linjiaqi */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class NettyBackendHandlerFactory { +public final class ResponseHandlerFactory { /** - * Create new instance of netty backend handler. + * Create new instance of response handler factory for using netty connect backend. * * @param databaseType database type * @param dataSourceName data source name - * @return backend handler instance + * @return new instance of response handler factory for using netty connect backend */ - public static CommandResponsePacketsHandler newInstance(final DatabaseType databaseType, final String dataSourceName) { + public static ResponseHandler newInstance(final DatabaseType databaseType, final String dataSourceName) { switch (databaseType) { case MySQL: - return new MySQLBackendHandler(dataSourceName); + return new MySQLResponseHandler(dataSourceName); default: throw new UnsupportedOperationException(String.format("Cannot support database type '%s'", databaseType)); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLQueryResult.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLQueryResult.java similarity index 99% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLQueryResult.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLQueryResult.java index 079e040a0f401..4f99f5fce189f 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLQueryResult.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLQueryResult.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.proxy.backend.netty.client.mysql; +package io.shardingsphere.proxy.backend.netty.client.response.mysql; import com.google.common.collect.Lists; import io.shardingsphere.core.merger.QueryResult; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java similarity index 96% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLBackendHandler.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java index 63345e920e660..554d239128560 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/mysql/MySQLBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java @@ -15,15 +15,14 @@ *

*/ -package io.shardingsphere.proxy.backend.netty.client.mysql; +package io.shardingsphere.proxy.backend.netty.client.response.mysql; -import com.google.common.collect.Maps; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.shardingsphere.core.metadata.datasource.DataSourceMetaData; import io.shardingsphere.core.rule.DataSourceParameter; import io.shardingsphere.proxy.backend.constant.AuthType; -import io.shardingsphere.proxy.backend.netty.client.CommandResponsePacketsHandler; +import io.shardingsphere.proxy.backend.netty.client.response.ResponseHandler; import io.shardingsphere.proxy.backend.netty.future.FutureRegistry; import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.runtime.ChannelRegistry; @@ -43,23 +42,24 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.HashMap; import java.util.Map; /** - * Backend handler for MySQL. + * Response handler for MySQL. * * @author wangkai * @author linjiaqi */ @Slf4j @RequiredArgsConstructor -public class MySQLBackendHandler extends CommandResponsePacketsHandler { +public final class MySQLResponseHandler extends ResponseHandler { private static final RuleRegistry RULE_REGISTRY = RuleRegistry.getInstance(); private final String dataSourceName; - private final Map resultMap = Maps.newHashMap(); + private final Map resultMap = new HashMap<>(); private AuthType authType = AuthType.UN_AUTH; From 61073f1bca1dc60b4fe8b9224bc9e858e0a249d1 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Mon, 6 Aug 2018 16:29:29 +0800 Subject: [PATCH 073/198] for #1099, make jdbc thread pool infinite by default --- .../io/shardingsphere/core/executor/ExecutorEngine.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java index 2e066f42257e4..0513fc24ff626 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java @@ -45,6 +45,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -66,8 +67,13 @@ public final class ExecutorEngine implements AutoCloseable { private final ListeningExecutorService executorService; public ExecutorEngine(final int executorSize) { - executorService = MoreExecutors.listeningDecorator(new ThreadPoolExecutor( + if (0 == executorSize) { + executorService = MoreExecutors.listeningDecorator(new ThreadPoolExecutor( + 0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue(), new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Sharding-JDBC-%d").build())); + } else { + executorService = MoreExecutors.listeningDecorator(new ThreadPoolExecutor( executorSize, executorSize, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Sharding-JDBC-%d").build())); + } MoreExecutors.addDelayedShutdownHook(executorService, 60, TimeUnit.SECONDS); } From 03e3c21e839c92eaf08d0cd75f6f1845dad408f7 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 16:33:26 +0800 Subject: [PATCH 074/198] set result.setMaxTotal(50); --- .../io/shardingsphere/core/common/base/AbstractSQLTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java index ceca41f7bc67b..a88e4287312e3 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java @@ -96,7 +96,7 @@ private static BasicDataSource buildDataSource(final String dbName, final Databa result.setUrl(dbEnv.getURL(dbName)); result.setUsername(dbEnv.getUsername()); result.setPassword(dbEnv.getPassword()); - result.setMaxTotal(1); + result.setMaxTotal(50); return result; } From 12b312066763a8ad57b0ab86458b8811613c2301 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 16:33:38 +0800 Subject: [PATCH 075/198] use Collection --- .../jdbc/adapter/ConnectionAdapterTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java index 150f4919c267f..1e216fcd2a20a 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java @@ -26,7 +26,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Map; +import java.util.Collection; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNull; @@ -51,9 +51,9 @@ public void assertSetAutoCommit() throws SQLException { private void assertAutoCommit(final ShardingConnection actual, final boolean autoCommit) throws SQLException { assertThat(actual.getAutoCommit(), is(autoCommit)); - Map cachedConnections = getCachedConnections(actual); + Collection cachedConnections = getCachedConnections(actual); assertThat(cachedConnections.size(), is(2)); - for (Connection each : cachedConnections.values()) { + for (Connection each : cachedConnections) { assertThat(each.getAutoCommit(), is(autoCommit)); } } @@ -90,9 +90,9 @@ public void assertClose() throws SQLException { private void assertClose(final ShardingConnection actual, final boolean closed) throws SQLException { assertThat(actual.isClosed(), is(closed)); - Map cachedConnections = getCachedConnections(actual); + Collection cachedConnections = getCachedConnections(actual); assertThat(cachedConnections.size(), is(2)); - for (Connection each : cachedConnections.values()) { + for (Connection each : cachedConnections) { assertThat(each.isClosed(), is(closed)); } } @@ -111,9 +111,9 @@ public void assertSetReadOnly() throws SQLException { private void assertReadOnly(final ShardingConnection actual, final boolean readOnly) throws SQLException { assertThat(actual.isReadOnly(), is(readOnly)); - Map cachedConnections = getCachedConnections(actual); + Collection cachedConnections = getCachedConnections(actual); assertThat(cachedConnections.size(), is(2)); - for (Connection each : cachedConnections.values()) { + for (Connection each : cachedConnections) { assertThat(each.isReadOnly(), is(readOnly)); } } @@ -140,9 +140,9 @@ public void assertSetTransactionIsolation() throws SQLException { private void assertTransactionIsolation(final ShardingConnection actual, final int transactionIsolation) throws SQLException { assertThat(actual.getTransactionIsolation(), is(transactionIsolation)); - Map cachedConnections = getCachedConnections(actual); + Collection cachedConnections = getCachedConnections(actual); assertThat(cachedConnections.size(), is(2)); - for (Connection each : cachedConnections.values()) { + for (Connection each : cachedConnections) { assertThat(each.getTransactionIsolation(), is(transactionIsolation)); } } @@ -177,11 +177,11 @@ public void assertSetHoldability() throws SQLException { } @SuppressWarnings("unchecked") - private Map getCachedConnections(final AbstractConnectionAdapter connectionAdapter) { + private Collection getCachedConnections(final AbstractConnectionAdapter connectionAdapter) { try { Field field = AbstractConnectionAdapter.class.getDeclaredField("cachedConnections"); field.setAccessible(true); - return (Map) field.get(connectionAdapter); + return (Collection) field.get(connectionAdapter); } catch (final ReflectiveOperationException ex) { throw new RuntimeException(ex); } From 4d73473e20a2808f8ab13801184cc7ddff396880 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 16:52:50 +0800 Subject: [PATCH 076/198] add result.setMaxTotal(50); --- .../core/jdbc/adapter/ConnectionAdapterTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java index 1e216fcd2a20a..f51f18af0ea7f 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java @@ -52,7 +52,7 @@ public void assertSetAutoCommit() throws SQLException { private void assertAutoCommit(final ShardingConnection actual, final boolean autoCommit) throws SQLException { assertThat(actual.getAutoCommit(), is(autoCommit)); Collection cachedConnections = getCachedConnections(actual); - assertThat(cachedConnections.size(), is(2)); + assertThat(cachedConnections.size(), is(4)); for (Connection each : cachedConnections) { assertThat(each.getAutoCommit(), is(autoCommit)); } @@ -91,7 +91,7 @@ public void assertClose() throws SQLException { private void assertClose(final ShardingConnection actual, final boolean closed) throws SQLException { assertThat(actual.isClosed(), is(closed)); Collection cachedConnections = getCachedConnections(actual); - assertThat(cachedConnections.size(), is(2)); + assertThat(cachedConnections.size(), is(4)); for (Connection each : cachedConnections) { assertThat(each.isClosed(), is(closed)); } @@ -112,7 +112,7 @@ public void assertSetReadOnly() throws SQLException { private void assertReadOnly(final ShardingConnection actual, final boolean readOnly) throws SQLException { assertThat(actual.isReadOnly(), is(readOnly)); Collection cachedConnections = getCachedConnections(actual); - assertThat(cachedConnections.size(), is(2)); + assertThat(cachedConnections.size(), is(4)); for (Connection each : cachedConnections) { assertThat(each.isReadOnly(), is(readOnly)); } @@ -141,7 +141,7 @@ public void assertSetTransactionIsolation() throws SQLException { private void assertTransactionIsolation(final ShardingConnection actual, final int transactionIsolation) throws SQLException { assertThat(actual.getTransactionIsolation(), is(transactionIsolation)); Collection cachedConnections = getCachedConnections(actual); - assertThat(cachedConnections.size(), is(2)); + assertThat(cachedConnections.size(), is(4)); for (Connection each : cachedConnections) { assertThat(each.getTransactionIsolation(), is(transactionIsolation)); } From 648e986eade1b1b5f125fd7c839b3dfeb2e73b56 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 16:53:07 +0800 Subject: [PATCH 077/198] delete file --- .../core/executor/ExecutorEngineFactory.java | 44 ------------------- 1 file changed, 44 deletions(-) delete mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java deleted file mode 100644 index 96f6f3c81933c..0000000000000 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngineFactory.java +++ /dev/null @@ -1,44 +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.core.executor; - -import io.shardingsphere.core.constant.ProxyMode; -import io.shardingsphere.core.executor.type.connection.ConnectionStrictlyExecutorEngine; -import io.shardingsphere.core.executor.type.memory.MemoryStrictlyExecutorEngine; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -/** - * JDBC execute engine factory. - * - * @author panjuan - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ExecutorEngineFactory { - - /** - * Create instance for execute engine. - * - * @param proxyMode proxy mode - * @param executorSize executor size - * @return instance for text protocol - */ - public static ExecutorEngine createTextProtocolInstance(final ProxyMode proxyMode, final int executorSize) { - return ProxyMode.MEMORY_STRICTLY == proxyMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); - } -} From d5dca11b93cf9c5ecb9342ed6c10b238a6db0162 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 16:57:32 +0800 Subject: [PATCH 078/198] use assertNotSame --- .../core/jdbc/core/connection/ShardingConnectionTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java index f5be507e6e006..61c7b508153e3 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java @@ -42,7 +42,6 @@ import java.util.Properties; import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; public final class ShardingConnectionTest { @@ -87,7 +86,7 @@ public void clear() { @Test public void assertGetConnectionFromCache() throws SQLException { - assertSame(connection.getConnection(DS_NAME), connection.getConnection(DS_NAME)); + assertNotSame(connection.getConnection(DS_NAME), connection.getConnection(DS_NAME)); } @Test(expected = IllegalStateException.class) From cdddc4d730053e4c3d358a7615d3ac31709ad64f Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 16:58:09 +0800 Subject: [PATCH 079/198] use setMaxTotal(50) --- .../shardingsphere/dbtest/env/datasource/DataSourceUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/env/datasource/DataSourceUtil.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/env/datasource/DataSourceUtil.java index 835dbe2a8acb8..26f22d0150241 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/env/datasource/DataSourceUtil.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/env/datasource/DataSourceUtil.java @@ -78,7 +78,7 @@ private static DataSource createDBCP(final DatabaseType databaseType, final Stri result.setUrl(null == dataSourceName ? databaseEnvironment.getURL() : databaseEnvironment.getURL(dataSourceName)); result.setUsername(databaseEnvironment.getUsername()); result.setPassword(databaseEnvironment.getPassword()); - result.setMaxTotal(1); + result.setMaxTotal(50); result.setValidationQuery("SELECT 1"); if (DatabaseType.Oracle == databaseType) { result.setConnectionInitSqls(Collections.singleton("ALTER SESSION SET CURRENT_SCHEMA = " + dataSourceName)); @@ -93,7 +93,7 @@ private static DataSource createHikariCP(final DatabaseType databaseType, final result.setJdbcUrl(null == dataSourceName ? databaseEnvironment.getURL() : databaseEnvironment.getURL(dataSourceName)); result.setUsername(databaseEnvironment.getUsername()); result.setPassword(databaseEnvironment.getPassword()); - result.setMaximumPoolSize(1); + result.setMaximumPoolSize(50); result.setTransactionIsolation("TRANSACTION_READ_COMMITTED"); result.setConnectionTestQuery("SELECT 1"); if (DatabaseType.Oracle == databaseType) { From c15b2283e9423a42fb99e684d9a4b198f797caa0 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 16:59:48 +0800 Subject: [PATCH 080/198] remove useless exception --- .../io/shardingsphere/proxy/frontend/ShardingProxy.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java index cd2b165c7fe9d..976a4c652d52c 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java @@ -30,12 +30,10 @@ import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; +import io.shardingsphere.proxy.backend.BackendExecutorContext; import io.shardingsphere.proxy.backend.netty.client.BackendNettyClient; import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.frontend.common.netty.ServerHandlerInitializer; -import io.shardingsphere.proxy.backend.BackendExecutorContext; - -import java.net.MalformedURLException; /** * Sharding-Proxy. @@ -65,9 +63,8 @@ public ShardingProxy() { * * @param port port * @throws InterruptedException interrupted exception - * @throws MalformedURLException URL exception */ - public void start(final int port) throws InterruptedException, MalformedURLException { + public void start(final int port) throws InterruptedException { try { if (RULE_REGISTRY.getBackendNIOConfig().isUseNIO()) { BackendNettyClient.getInstance().start(); From b4dfd8570d8a2348677701d1ecb7c128b8250db2 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Mon, 6 Aug 2018 17:19:11 +0800 Subject: [PATCH 081/198] revise writeIntLenenc in MySQLPacketPayload to resolve auto-generated key can't exceed 65530. --- .../proxy/transport/mysql/packet/MySQLPacketPayload.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/MySQLPacketPayload.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/MySQLPacketPayload.java index a058571c26818..3e5eab08aa034 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/MySQLPacketPayload.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/MySQLPacketPayload.java @@ -220,7 +220,7 @@ public void writeIntLenenc(final long value) { } if (value < Math.pow(2, 24)) { byteBuf.writeByte(0xfd); - byteBuf.writeInt((int) value); + byteBuf.writeMediumLE((int) value); return; } byteBuf.writeByte(0xfe); From 8dadd1f87a99d5696dbcfba076fded322e93dc53 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Mon, 6 Aug 2018 17:35:46 +0800 Subject: [PATCH 082/198] for #1099, for comments --- .../proxy/frontend/ShardingProxy.java | 12 ++--- .../proxy/frontend/UserGroupContext.java | 45 ------------------- .../common/FrontendHandlerFactory.java | 6 ++- .../common/executor/ExecutorGroup.java | 7 +-- .../netty/ServerHandlerInitializer.java | 5 ++- .../frontend/mysql/MySQLFrontendHandler.java | 5 ++- 6 files changed, 22 insertions(+), 58 deletions(-) delete mode 100644 sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/UserGroupContext.java diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java index 88553689c9a70..fc9c21ae91cab 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/ShardingProxy.java @@ -54,7 +54,7 @@ public final class ShardingProxy { private EventLoopGroup workerGroup; - private final UserGroupContext userGroupContext = UserGroupContext.getInstance(); + private EventLoopGroup userGroup; public ShardingProxy() { RULE_REGISTRY.initShardingMetaData(backendExecutorContext.getExecutorService()); @@ -82,9 +82,9 @@ public void start(final int port) throws InterruptedException, MalformedURLExcep ChannelFuture future = bootstrap.bind(port).sync(); future.channel().closeFuture().sync(); } finally { + userGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); bossGroup.shutdownGracefully(); - userGroupContext.getUserGroup().shutdownGracefully(); backendExecutorContext.getExecutorService().shutdown(); if (RULE_REGISTRY.getBackendNIOConfig().isUseNIO()) { ShardingProxyClient.getInstance().stop(); @@ -102,7 +102,7 @@ private EventLoopGroup createEventLoopGroup() { private void groupsEpoll(final ServerBootstrap bootstrap) { workerGroup = new EpollEventLoopGroup(RULE_REGISTRY.getAcceptorSize()); - userGroupContext.setUserGroup(new EpollEventLoopGroup(RULE_REGISTRY.getAcceptorSize())); + userGroup = new EpollEventLoopGroup(RULE_REGISTRY.getAcceptorSize()); bootstrap.group(bossGroup, workerGroup) .channel(EpollServerSocketChannel.class) .option(EpollChannelOption.SO_BACKLOG, 128) @@ -110,12 +110,12 @@ private void groupsEpoll(final ServerBootstrap bootstrap) { .option(EpollChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(EpollChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .handler(new LoggingHandler(LogLevel.INFO)) - .childHandler(new ServerHandlerInitializer()); + .childHandler(new ServerHandlerInitializer(userGroup)); } private void groupsNio(final ServerBootstrap bootstrap) { workerGroup = new NioEventLoopGroup(RULE_REGISTRY.getAcceptorSize()); - userGroupContext.setUserGroup(new NioEventLoopGroup(RULE_REGISTRY.getAcceptorSize())); + userGroup = new NioEventLoopGroup(RULE_REGISTRY.getAcceptorSize()); bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 128) @@ -124,6 +124,6 @@ private void groupsNio(final ServerBootstrap bootstrap) { .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .handler(new LoggingHandler(LogLevel.INFO)) - .childHandler(new ServerHandlerInitializer()); + .childHandler(new ServerHandlerInitializer(userGroup)); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/UserGroupContext.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/UserGroupContext.java deleted file mode 100644 index 9557d9272c63c..0000000000000 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/UserGroupContext.java +++ /dev/null @@ -1,45 +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.proxy.frontend; - -import io.netty.channel.EventLoopGroup; -import lombok.Getter; -import lombok.Setter; - -/** - * User group context. - * - * @author zhangyonglun - */ -public final class UserGroupContext { - - private static final UserGroupContext INSTANCE = new UserGroupContext(); - - @Getter - @Setter - private EventLoopGroup userGroup; - - /** - * Get user group context instance. - * - * @return instance of user group context - */ - public static UserGroupContext getInstance() { - return INSTANCE; - } -} diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/FrontendHandlerFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/FrontendHandlerFactory.java index 56f85faf03e11..b2dbcfc397aa5 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/FrontendHandlerFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/FrontendHandlerFactory.java @@ -17,6 +17,7 @@ package io.shardingsphere.proxy.frontend.common; +import io.netty.channel.EventLoopGroup; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.proxy.frontend.mysql.MySQLFrontendHandler; import lombok.AccessLevel; @@ -35,12 +36,13 @@ public final class FrontendHandlerFactory { * Create frontend handler instance. * * @param databaseType database type + * @param userGroup user group * @return frontend handler instance */ - public static FrontendHandler createFrontendHandlerInstance(final DatabaseType databaseType) { + public static FrontendHandler createFrontendHandlerInstance(final DatabaseType databaseType, final EventLoopGroup userGroup) { switch (databaseType) { case MySQL: - return new MySQLFrontendHandler(); + return new MySQLFrontendHandler(userGroup); default: throw new UnsupportedOperationException(String.format("Cannot support database type '%s'", databaseType)); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java index 8d02443af3682..943092ed76432 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/executor/ExecutorGroup.java @@ -18,9 +18,9 @@ package io.shardingsphere.proxy.frontend.common.executor; import io.netty.channel.ChannelId; +import io.netty.channel.EventLoopGroup; import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.proxy.config.RuleRegistry; -import io.shardingsphere.proxy.frontend.UserGroupContext; import lombok.RequiredArgsConstructor; import java.util.concurrent.ExecutorService; @@ -35,6 +35,8 @@ public final class ExecutorGroup { private static final RuleRegistry RULE_REGISTRY = RuleRegistry.getInstance(); + private final EventLoopGroup eventLoopGroup; + private final ChannelId channelId; /** @@ -43,7 +45,6 @@ public final class ExecutorGroup { * @return executor service */ public ExecutorService getExecutorService() { - return TransactionType.XA.equals(RULE_REGISTRY.getTransactionType()) ? ChannelThreadExecutorGroup.getInstance().get(channelId) - : UserGroupContext.getInstance().getUserGroup(); + return TransactionType.XA.equals(RULE_REGISTRY.getTransactionType()) ? ChannelThreadExecutorGroup.getInstance().get(channelId) : eventLoopGroup; } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/netty/ServerHandlerInitializer.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/netty/ServerHandlerInitializer.java index e1afa5055a5c6..3b9825885d709 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/netty/ServerHandlerInitializer.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/netty/ServerHandlerInitializer.java @@ -19,6 +19,7 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.proxy.frontend.common.FrontendHandlerFactory; @@ -33,11 +34,13 @@ @RequiredArgsConstructor public final class ServerHandlerInitializer extends ChannelInitializer { + private final EventLoopGroup userGroup; + @Override protected void initChannel(final SocketChannel socketChannel) { ChannelPipeline pipeline = socketChannel.pipeline(); // TODO load database type from yaml or startup arguments pipeline.addLast(PacketCodecFactory.createPacketCodecInstance(DatabaseType.MySQL)); - pipeline.addLast(FrontendHandlerFactory.createFrontendHandlerInstance(DatabaseType.MySQL)); + pipeline.addLast(FrontendHandlerFactory.createFrontendHandlerInstance(DatabaseType.MySQL, userGroup)); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/mysql/MySQLFrontendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/mysql/MySQLFrontendHandler.java index 513e38bb35138..39edfa9c4ea9d 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/mysql/MySQLFrontendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/mysql/MySQLFrontendHandler.java @@ -20,6 +20,7 @@ import com.google.common.base.Optional; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.EventLoopGroup; import io.shardingsphere.proxy.backend.jdbc.connection.BackendConnection; import io.shardingsphere.proxy.frontend.common.FrontendHandler; import io.shardingsphere.proxy.frontend.common.executor.ExecutorGroup; @@ -52,6 +53,8 @@ @RequiredArgsConstructor public final class MySQLFrontendHandler extends FrontendHandler { + private final EventLoopGroup eventLoopGroup; + private final AuthorityHandler authorityHandler = new AuthorityHandler(); @Override @@ -77,7 +80,7 @@ protected void auth(final ChannelHandlerContext context, final ByteBuf message) @Override protected void executeCommand(final ChannelHandlerContext context, final ByteBuf message) { - new ExecutorGroup(context.channel().id()).getExecutorService().execute(new CommandExecutor(context, message)); + new ExecutorGroup(eventLoopGroup, context.channel().id()).getExecutorService().execute(new CommandExecutor(context, message)); } @Override From d52ff59533b6bc2c174d064d135c8547f90af984 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 18:55:30 +0800 Subject: [PATCH 083/198] add --- .../META-INF/rdb/datasource/masterSlaveDataSource.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/resources/META-INF/rdb/datasource/masterSlaveDataSource.xml b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/resources/META-INF/rdb/datasource/masterSlaveDataSource.xml index 409aa1090e599..4766f2002c65e 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/resources/META-INF/rdb/datasource/masterSlaveDataSource.xml +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/resources/META-INF/rdb/datasource/masterSlaveDataSource.xml @@ -14,6 +14,7 @@ + @@ -21,6 +22,7 @@ + @@ -28,6 +30,7 @@ + @@ -36,6 +39,7 @@ + @@ -43,6 +47,7 @@ + @@ -50,5 +55,6 @@ + From 4c8b2fd5dd59156707d4cf7f0c3b6da93dac48f3 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 18:55:37 +0800 Subject: [PATCH 084/198] add --- .../src/test/resources/META-INF/rdb/datasource/dataSource.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/resources/META-INF/rdb/datasource/dataSource.xml b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/resources/META-INF/rdb/datasource/dataSource.xml index 26f417882c2d2..141d074d3719a 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/resources/META-INF/rdb/datasource/dataSource.xml +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/resources/META-INF/rdb/datasource/dataSource.xml @@ -14,6 +14,7 @@ + @@ -21,5 +22,6 @@ + From 22ba1f79b9edcd63354226ec880f772be9d60452 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 19:00:44 +0800 Subject: [PATCH 085/198] change to connection mode --- .../constant/ShardingPropertiesConstant.java | 4 ++-- .../core/jdbc/core/ShardingContext.java | 8 ++++---- .../core/datasource/ShardingDataSource.java | 18 +++++++++--------- .../statement/ShardingPreparedStatement.java | 6 +++--- .../jdbc/core/statement/ShardingStatement.java | 6 +++--- .../connection/ShardingConnectionTest.java | 4 ++-- .../proxy/config/RuleRegistry.java | 6 +++--- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java index eb466c7af9002..67a90af07d659 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java @@ -54,7 +54,7 @@ public enum ShardingPropertiesConstant { EXECUTOR_SIZE("executor.size", String.valueOf(Runtime.getRuntime().availableProcessors()), int.class), /** - * Proxy mode. + * Connection mode. * *

* MEMORY_STRICTLY: @@ -65,7 +65,7 @@ public enum ShardingPropertiesConstant { * Meanwhile, the cost of the memory will be increased. *

*/ - PROXY_MODE("proxy.mode", "MEMORY_STRICTLY", String.class), + CONNECTION_MODE("connection.mode", "MEMORY_STRICTLY", String.class), PROXY_TRANSACTION_MODE("proxy.transaction.mode", "NONE", String.class), diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java index 1ec523da155f1..461771161e7e9 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java @@ -18,7 +18,7 @@ package io.shardingsphere.core.jdbc.core; import io.shardingsphere.core.constant.DatabaseType; -import io.shardingsphere.core.constant.ProxyMode; +import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.executor.ExecutorEngine; import io.shardingsphere.core.metadata.ShardingMetaData; @@ -55,18 +55,18 @@ public final class ShardingContext { private final boolean showSQL; - private final ProxyMode proxyMode; + private final ConnectionMode connectionMode; private final ShardingMetaData metaData; public ShardingContext(final Map dataSourceMap, final ShardingRule shardingRule, - final DatabaseType databaseType, final ExecutorEngine executorEngine, final ShardingTableMetaData shardingTableMetaData, final boolean showSQL, final ProxyMode proxyMode) { + final DatabaseType databaseType, final ExecutorEngine executorEngine, final ShardingTableMetaData shardingTableMetaData, final boolean showSQL, final ConnectionMode connectionMode) { this.dataSourceMap = dataSourceMap; this.shardingRule = shardingRule; this.databaseType = databaseType; this.executorEngine = executorEngine; this.showSQL = showSQL; - this.proxyMode = proxyMode; + this.connectionMode = connectionMode; metaData = new ShardingMetaData(new ShardingDataSourceMetaData(getDataSourceURLs(dataSourceMap), shardingRule, databaseType), shardingTableMetaData); } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java index b1493055b6956..890bdd44cc9c9 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java @@ -20,7 +20,7 @@ import io.shardingsphere.core.api.ConfigMapContext; import io.shardingsphere.core.api.config.MasterSlaveRuleConfiguration; import io.shardingsphere.core.api.config.ShardingRuleConfiguration; -import io.shardingsphere.core.constant.ProxyMode; +import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.ShardingProperties; import io.shardingsphere.core.constant.ShardingPropertiesConstant; import io.shardingsphere.core.executor.ExecutorEngine; @@ -72,12 +72,12 @@ public ShardingDataSource(final Map dataSourceMap, final Sha } shardingProperties = new ShardingProperties(null == props ? new Properties() : props); int executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); - ProxyMode proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); - executorEngine = ProxyMode.MEMORY_STRICTLY == proxyMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); + ConnectionMode connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); + executorEngine = ConnectionMode.MEMORY_STRICTLY == connectionMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData( new TableMetaDataInitializer(executorEngine.getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule)); boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); - shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL, proxyMode); + shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL, connectionMode); } /** @@ -91,18 +91,18 @@ public void renew(final Map newDataSourceMap, final Sharding ShardingProperties newShardingProperties = new ShardingProperties(null == newProps ? new Properties() : newProps); int originalExecutorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); int newExecutorSize = newShardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); - ProxyMode originalProxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); - ProxyMode newProxyMode = ProxyMode.valueOf(newShardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); - if (originalExecutorSize != newExecutorSize || originalProxyMode != newProxyMode) { + ConnectionMode originalConnectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); + ConnectionMode newConnectionMode = ConnectionMode.valueOf(newShardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); + if (originalExecutorSize != newExecutorSize || originalConnectionMode != newConnectionMode) { ExecutorEngine originalExecutorEngine = executorEngine; - executorEngine = ProxyMode.MEMORY_STRICTLY == newProxyMode ? new MemoryStrictlyExecutorEngine(newExecutorSize) : new ConnectionStrictlyExecutorEngine(newExecutorSize); + executorEngine = ConnectionMode.MEMORY_STRICTLY == newConnectionMode ? new MemoryStrictlyExecutorEngine(newExecutorSize) : new ConnectionStrictlyExecutorEngine(newExecutorSize); originalExecutorEngine.close(); } boolean newShowSQL = newShardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); ShardingTableMetaData shardingMetaData = new ShardingTableMetaData( new TableMetaDataInitializer(executorEngine.getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(newDataSourceMap)).load(newShardingRule)); shardingProperties = newShardingProperties; - shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, shardingMetaData, newShowSQL, newProxyMode); + shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, shardingMetaData, newShowSQL, newConnectionMode); } @Override diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java index b50d153bf3cea..35f84cdb40bce 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java @@ -20,7 +20,7 @@ import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.Iterators; -import io.shardingsphere.core.constant.ProxyMode; +import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementExecutor; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementUnit; @@ -154,7 +154,7 @@ public ResultSet executeQuery() throws SQLException { private List getQueryResults(final List resultSets) throws SQLException { List result = new ArrayList<>(resultSets.size()); for (ResultSet each : resultSets) { - if (ProxyMode.MEMORY_STRICTLY == connection.getShardingContext().getProxyMode()) { + if (ConnectionMode.MEMORY_STRICTLY == connection.getShardingContext().getConnectionMode()) { result.add(new StreamQueryResult(each)); } else { result.add(new MemoryQueryResult(each)); @@ -191,7 +191,7 @@ public boolean execute() throws SQLException { private Collection route() throws SQLException { sqlRoute(); - if (ProxyMode.MEMORY_STRICTLY == connection.getShardingContext().getProxyMode()) { + if (ConnectionMode.MEMORY_STRICTLY == connection.getShardingContext().getConnectionMode()) { return getPreparedStatementUnitsForMemoryStrictly(); } return getPreparedStatementUnitsForConnectionStrictly(); diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java index c713d24478a01..65b1c169bf5e0 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java @@ -18,7 +18,7 @@ package io.shardingsphere.core.jdbc.core.statement; import com.google.common.base.Optional; -import io.shardingsphere.core.constant.ProxyMode; +import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.SQLType; import io.shardingsphere.core.executor.type.connection.MemoryQueryResult; import io.shardingsphere.core.executor.type.memory.StreamQueryResult; @@ -128,7 +128,7 @@ public ResultSet executeQuery(final String sql) throws SQLException { private List getQueryResults(final List resultSets) throws SQLException { List result = new ArrayList<>(resultSets.size()); for (ResultSet each : resultSets) { - if (ProxyMode.MEMORY_STRICTLY == connection.getShardingContext().getProxyMode()) { + if (ConnectionMode.MEMORY_STRICTLY == connection.getShardingContext().getConnectionMode()) { result.add(new StreamQueryResult(each)); } else { result.add(new MemoryQueryResult(each)); @@ -224,7 +224,7 @@ public boolean execute(final String sql, final String[] columnNames) throws SQLE private StatementExecutor generateExecutor(final String sql) throws SQLException { clearPrevious(); sqlRoute(sql); - if (ProxyMode.MEMORY_STRICTLY == connection.getShardingContext().getProxyMode()) { + if (ConnectionMode.MEMORY_STRICTLY == connection.getShardingContext().getConnectionMode()) { return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), getStatementUnitsForMemoryStrictly()); } return new StatementExecutor(connection.getShardingContext().getExecutorEngine(), routeResult.getSqlStatement().getType(), getStatementUnitsForConnectionStrictly()); diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java index 61c7b508153e3..4b916b1b9032e 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java @@ -21,7 +21,7 @@ import io.shardingsphere.core.api.config.ShardingRuleConfiguration; import io.shardingsphere.core.api.config.TableRuleConfiguration; import io.shardingsphere.core.constant.DatabaseType; -import io.shardingsphere.core.constant.ProxyMode; +import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.fixture.TestDataSource; import io.shardingsphere.core.jdbc.core.ShardingContext; import io.shardingsphere.core.jdbc.core.datasource.MasterSlaveDataSource; @@ -72,7 +72,7 @@ public void setUp() { Map dataSourceMap = new HashMap<>(1, 1); dataSourceMap.put(DS_NAME, masterSlaveDataSource); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()); - ShardingContext shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.H2, null, new ShardingTableMetaData(Collections.emptyMap()), false, ProxyMode.MEMORY_STRICTLY); + ShardingContext shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.H2, null, new ShardingTableMetaData(Collections.emptyMap()), false, ConnectionMode.MEMORY_STRICTLY); connection = new ShardingConnection(shardingContext); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 6b2b41c1eb28b..d9d0e8eb9539e 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -35,7 +35,7 @@ import io.shardingsphere.core.transaction.spi.TransactionManager; import io.shardingsphere.jdbc.orchestration.internal.OrchestrationProxyConfiguration; import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent; -import io.shardingsphere.core.constant.ProxyMode; +import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource; import io.shardingsphere.proxy.util.ProxyTransactionLoader; import lombok.AccessLevel; @@ -73,7 +73,7 @@ public final class RuleRegistry { private boolean showSQL; - private ProxyMode proxyMode; + private ConnectionMode connectionMode; private TransactionType transactionType; @@ -109,7 +109,7 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { Properties properties = null == config.getShardingRule() ? config.getMasterSlaveRule().getProps() : config.getShardingRule().getProps(); ShardingProperties shardingProperties = new ShardingProperties(null == properties ? new Properties() : properties); showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); - proxyMode = ProxyMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MODE)); + connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE)); transactionManager = ProxyTransactionLoader.load(transactionType); maxWorkingThreads = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_MAX_WORKING_THREADS); From 1b51a16006bc7d6ec38137b58386f435750cbf81 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 19:00:57 +0800 Subject: [PATCH 086/198] change to connection mode --- .../core/constant/ProxyMode.java | 33 ------------------- .../execute/JDBCExecuteEngineFactory.java | 6 ++-- 2 files changed, 3 insertions(+), 36 deletions(-) delete mode 100644 sharding-core/src/main/java/io/shardingsphere/core/constant/ProxyMode.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/constant/ProxyMode.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ProxyMode.java deleted file mode 100644 index b09a4797acd90..0000000000000 --- a/sharding-core/src/main/java/io/shardingsphere/core/constant/ProxyMode.java +++ /dev/null @@ -1,33 +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.core.constant; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -/** - * Proxy Mode. - * - * @author zhangyonglun - */ -@RequiredArgsConstructor -@Getter -public enum ProxyMode { - - MEMORY_STRICTLY, CONNECTION_STRICTLY -} diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java index b99fe86658050..a961adfec14cd 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/JDBCExecuteEngineFactory.java @@ -17,7 +17,7 @@ package io.shardingsphere.proxy.backend.jdbc.execute; -import io.shardingsphere.core.constant.ProxyMode; +import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.proxy.backend.jdbc.connection.BackendConnection; import io.shardingsphere.proxy.backend.jdbc.execute.memory.ConnectionStrictlyExecuteEngine; import io.shardingsphere.proxy.backend.jdbc.execute.stream.MemoryStrictlyExecuteEngine; @@ -48,7 +48,7 @@ public final class JDBCExecuteEngineFactory { */ public static JDBCExecuteEngine createTextProtocolInstance(final BackendConnection backendConnection) { JDBCExecutorWrapper jdbcExecutorWrapper = new StatementExecutorWrapper(); - return ProxyMode.MEMORY_STRICTLY == RULE_REGISTRY.getProxyMode() + return ConnectionMode.MEMORY_STRICTLY == RULE_REGISTRY.getConnectionMode() ? new MemoryStrictlyExecuteEngine(backendConnection, jdbcExecutorWrapper) : new ConnectionStrictlyExecuteEngine(backendConnection, jdbcExecutorWrapper); } @@ -61,7 +61,7 @@ public static JDBCExecuteEngine createTextProtocolInstance(final BackendConnecti */ public static JDBCExecuteEngine createBinaryProtocolInstance(final List parameters, final BackendConnection backendConnection) { JDBCExecutorWrapper jdbcExecutorWrapper = new PreparedStatementExecutorWrapper(parameters); - return ProxyMode.MEMORY_STRICTLY == RULE_REGISTRY.getProxyMode() + return ConnectionMode.MEMORY_STRICTLY == RULE_REGISTRY.getConnectionMode() ? new MemoryStrictlyExecuteEngine(backendConnection, jdbcExecutorWrapper) : new ConnectionStrictlyExecuteEngine(backendConnection, jdbcExecutorWrapper); } } From df5eb433426874677c8ceb1688507cbf49407473 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Mon, 6 Aug 2018 19:06:22 +0800 Subject: [PATCH 087/198] add connection mode --- .../core/constant/ConnectionMode.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/constant/ConnectionMode.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/constant/ConnectionMode.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ConnectionMode.java new file mode 100644 index 0000000000000..7af1254aece47 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/ConnectionMode.java @@ -0,0 +1,34 @@ +/* + * 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.core.constant; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +/** + * Proxy Mode. + * + * @author zhangyonglun + * @author panjuan + */ +@RequiredArgsConstructor +@Getter +public enum ConnectionMode { + + MEMORY_STRICTLY, CONNECTION_STRICTLY +} From 7875d4633c78ec7790b80dc44edaeab3a37147ea Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 21:43:51 +0800 Subject: [PATCH 088/198] remove PacketHeader --- .../response/mysql/MySQLResponseHandler.java | 34 +++++++++------- .../mysql/constant/PacketHeader.java | 39 ------------------- .../mysql/packet/generic/EofPacket.java | 5 ++- .../mysql/packet/generic/ErrPacket.java | 5 ++- .../mysql/packet/generic/OKPacket.java | 5 ++- 5 files changed, 31 insertions(+), 57 deletions(-) delete mode 100644 sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/PacketHeader.java diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java index 554d239128560..c15de6d9c9ecd 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java @@ -27,7 +27,6 @@ import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.runtime.ChannelRegistry; import io.shardingsphere.proxy.transport.mysql.constant.CapabilityFlag; -import io.shardingsphere.proxy.transport.mysql.constant.PacketHeader; import io.shardingsphere.proxy.transport.mysql.constant.ServerInfo; import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload; import io.shardingsphere.proxy.transport.mysql.packet.command.query.ColumnDefinition41Packet; @@ -66,15 +65,12 @@ public final class MySQLResponseHandler extends ResponseHandler { @Override public void channelRead(final ChannelHandlerContext context, final Object message) { MySQLPacketPayload payload = new MySQLPacketPayload((ByteBuf) message); - payload.getByteBuf().markReaderIndex(); - payload.readInt1(); - int header = payload.readInt1(); - payload.getByteBuf().resetReaderIndex(); + int header = getHeader(payload); if (AuthType.UN_AUTH == authType) { auth(context, payload); authType = AuthType.AUTHING; } else if (AuthType.AUTHING == authType) { - if (PacketHeader.OK.getValue() == header) { + if (OKPacket.HEADER == header) { okPacket(context, payload); authType = AuthType.AUTH_SUCCESS; } else { @@ -84,11 +80,11 @@ public void channelRead(final ChannelHandlerContext context, final Object messag } else if (AuthType.AUTH_FAILED == authType) { log.error("mysql auth failed, cannot handle channel read message"); } else { - if (PacketHeader.EOF.getValue() == header) { + if (EofPacket.HEADER == header) { eofPacket(context, payload); - } else if (PacketHeader.OK.getValue() == header) { + } else if (OKPacket.HEADER == header) { okPacket(context, payload); - } else if (PacketHeader.ERR.getValue() == header) { + } else if (ErrPacket.HEADER == header) { errPacket(context, payload); } else { commonPacket(context, payload); @@ -96,6 +92,14 @@ public void channelRead(final ChannelHandlerContext context, final Object messag } } + private int getHeader(final MySQLPacketPayload payload) { + payload.getByteBuf().markReaderIndex(); + payload.readInt1(); + int result = payload.readInt1(); + payload.getByteBuf().resetReaderIndex(); + return result; + } + @Override protected void auth(final ChannelHandlerContext context, final MySQLPacketPayload payload) { try { @@ -169,12 +173,6 @@ protected void commonPacket(final ChannelHandlerContext context, final MySQLPack } } - @Override - public void channelInactive(final ChannelHandlerContext ctx) throws Exception { - //TODO delete connection map. - super.channelInactive(ctx); - } - private byte[] securePasswordAuthentication(final byte[] password, final byte[] authPluginData) { try { MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); @@ -200,4 +198,10 @@ private void setResponse(final ChannelHandlerContext context) { FutureRegistry.getInstance().get(connectionId).setResponse(resultMap.get(connectionId)); } } + + @Override + public void channelInactive(final ChannelHandlerContext ctx) throws Exception { + //TODO delete connection map. + super.channelInactive(ctx); + } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/PacketHeader.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/PacketHeader.java deleted file mode 100644 index e59b7f11e12c6..0000000000000 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/PacketHeader.java +++ /dev/null @@ -1,39 +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.proxy.transport.mysql.constant; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -/** - * Generic Packet Header. - * - * @author linjiaqi - */ -@RequiredArgsConstructor -@Getter -public enum PacketHeader { - - OK(0x00), - - EOF(0xfe), - - ERR(0xff); - - private final int value; -} diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/EofPacket.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/EofPacket.java index 64607842147e6..e69f201fd8f02 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/EofPacket.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/EofPacket.java @@ -36,7 +36,10 @@ @Getter public final class EofPacket implements MySQLPacket { - private static final int HEADER = 0xfe; + /** + * Header of EOF packet. + */ + public static final int HEADER = 0xfe; private final int sequenceId; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/ErrPacket.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/ErrPacket.java index dfb181c03d02a..87c0f7031b21b 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/ErrPacket.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/ErrPacket.java @@ -38,7 +38,10 @@ @Getter public final class ErrPacket implements MySQLPacket { - private static final int HEADER = 0xff; + /** + * Header of ERR packet. + */ + public static final int HEADER = 0xff; private static final String SQL_STATE_MARKER = "#"; diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/OKPacket.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/OKPacket.java index 0d595d3c081ad..70d0c8c5873c7 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/OKPacket.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/generic/OKPacket.java @@ -36,7 +36,10 @@ @Getter public final class OKPacket implements MySQLPacket { - private static final int HEADER = 0x00; + /** + * Header of OK packet. + */ + public static final int HEADER = 0x00; private static final int STATUS_FLAG = StatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue(); From 28b18d9d0e3428dec7c3b071527bf8cffd3ffe68 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 21:49:46 +0800 Subject: [PATCH 089/198] refactor MySQLResponseHandler.channelRead --- .../response/mysql/MySQLResponseHandler.java | 61 ++++++++++++------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java index c15de6d9c9ecd..6c41cb09d7914 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java @@ -66,29 +66,21 @@ public final class MySQLResponseHandler extends ResponseHandler { public void channelRead(final ChannelHandlerContext context, final Object message) { MySQLPacketPayload payload = new MySQLPacketPayload((ByteBuf) message); int header = getHeader(payload); - if (AuthType.UN_AUTH == authType) { - auth(context, payload); - authType = AuthType.AUTHING; - } else if (AuthType.AUTHING == authType) { - if (OKPacket.HEADER == header) { - okPacket(context, payload); - authType = AuthType.AUTH_SUCCESS; - } else { - errPacket(context, payload); - authType = AuthType.AUTH_FAILED; - } - } else if (AuthType.AUTH_FAILED == authType) { - log.error("mysql auth failed, cannot handle channel read message"); - } else { - if (EofPacket.HEADER == header) { - eofPacket(context, payload); - } else if (OKPacket.HEADER == header) { - okPacket(context, payload); - } else if (ErrPacket.HEADER == header) { - errPacket(context, payload); - } else { - commonPacket(context, payload); - } + switch (authType) { + case UN_AUTH: + auth(context, payload); + return; + case AUTHING: + authing(context, payload, header); + return; + case AUTH_SUCCESS: + authSuccess(context, payload, header); + return; + case AUTH_FAILED: + log.error("mysql auth failed, cannot handle channel read message"); + return; + default: + throw new UnsupportedOperationException(authType.name()); } } @@ -115,6 +107,29 @@ protected void auth(final ChannelHandlerContext context, final MySQLPacketPayloa } finally { payload.close(); } + authType = AuthType.AUTHING; + } + + private void authing(final ChannelHandlerContext context, final MySQLPacketPayload payload, final int header) { + if (OKPacket.HEADER == header) { + okPacket(context, payload); + authType = AuthType.AUTH_SUCCESS; + } else { + errPacket(context, payload); + authType = AuthType.AUTH_FAILED; + } + } + + private void authSuccess(final ChannelHandlerContext context, final MySQLPacketPayload payload, final int header) { + if (EofPacket.HEADER == header) { + eofPacket(context, payload); + } else if (OKPacket.HEADER == header) { + okPacket(context, payload); + } else if (ErrPacket.HEADER == header) { + errPacket(context, payload); + } else { + commonPacket(context, payload); + } } @Override From 19f2a681eca3f257f3eae684cf839ab2a398bc72 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 21:59:45 +0800 Subject: [PATCH 090/198] refactor MySQLResponseHandler --- .../response/mysql/MySQLResponseHandler.java | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java index 6c41cb09d7914..7fb8b9cbec246 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java @@ -19,6 +19,7 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; +import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.metadata.datasource.DataSourceMetaData; import io.shardingsphere.core.rule.DataSourceParameter; import io.shardingsphere.proxy.backend.constant.AuthType; @@ -69,16 +70,16 @@ public void channelRead(final ChannelHandlerContext context, final Object messag switch (authType) { case UN_AUTH: auth(context, payload); - return; + break; case AUTHING: authing(context, payload, header); - return; + break; case AUTH_SUCCESS: authSuccess(context, payload, header); - return; + break; case AUTH_FAILED: log.error("mysql auth failed, cannot handle channel read message"); - return; + break; default: throw new UnsupportedOperationException(authType.name()); } @@ -110,6 +111,24 @@ protected void auth(final ChannelHandlerContext context, final MySQLPacketPayloa authType = AuthType.AUTHING; } + private byte[] securePasswordAuthentication(final byte[] password, final byte[] authPluginData) { + try { + MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); + byte[] part1 = messageDigest.digest(password); + messageDigest.reset(); + byte[] part2 = messageDigest.digest(part1); + messageDigest.reset(); + messageDigest.update(authPluginData); + byte[] result = messageDigest.digest(part2); + for (int i = 0; i < result.length; i++) { + result[i] = (byte) (result[i] ^ part1[i]); + } + return result; + } catch (final NoSuchAlgorithmException ex) { + throw new ShardingException(ex); + } + } + private void authing(final ChannelHandlerContext context, final MySQLPacketPayload payload, final int header) { if (OKPacket.HEADER == header) { okPacket(context, payload); @@ -121,14 +140,18 @@ private void authing(final ChannelHandlerContext context, final MySQLPacketPaylo } private void authSuccess(final ChannelHandlerContext context, final MySQLPacketPayload payload, final int header) { - if (EofPacket.HEADER == header) { - eofPacket(context, payload); - } else if (OKPacket.HEADER == header) { - okPacket(context, payload); - } else if (ErrPacket.HEADER == header) { - errPacket(context, payload); - } else { - commonPacket(context, payload); + switch (header) { + case EofPacket.HEADER: + eofPacket(context, payload); + break; + case OKPacket.HEADER: + okPacket(context, payload); + break; + case ErrPacket.HEADER: + errPacket(context, payload); + break; + default: + commonPacket(context, payload); } } @@ -174,11 +197,18 @@ protected void eofPacket(final ChannelHandlerContext context, final MySQLPacketP } } + private void setResponse(final ChannelHandlerContext context) { + int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); + if (null != FutureRegistry.getInstance().get(connectionId)) { + FutureRegistry.getInstance().get(connectionId).setResponse(resultMap.get(connectionId)); + } + } + @Override protected void commonPacket(final ChannelHandlerContext context, final MySQLPacketPayload payload) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); MySQLQueryResult mysqlQueryResult = resultMap.get(connectionId); - if (mysqlQueryResult == null) { + if (null == mysqlQueryResult) { mysqlQueryResult = new MySQLQueryResult(payload); resultMap.put(connectionId, mysqlQueryResult); } else if (mysqlQueryResult.needColumnDefinition()) { @@ -188,35 +218,9 @@ protected void commonPacket(final ChannelHandlerContext context, final MySQLPack } } - private byte[] securePasswordAuthentication(final byte[] password, final byte[] authPluginData) { - try { - MessageDigest messageDigest = MessageDigest.getInstance("SHA-1"); - byte[] part1 = messageDigest.digest(password); - messageDigest.reset(); - byte[] part2 = messageDigest.digest(part1); - messageDigest.reset(); - messageDigest.update(authPluginData); - byte[] result = messageDigest.digest(part2); - for (int i = 0; i < result.length; i++) { - result[i] = (byte) (result[i] ^ part1[i]); - } - return result; - } catch (final NoSuchAlgorithmException ex) { - log.error(ex.getMessage(), ex); - } - return null; - } - - private void setResponse(final ChannelHandlerContext context) { - int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); - if (FutureRegistry.getInstance().get(connectionId) != null) { - FutureRegistry.getInstance().get(connectionId).setResponse(resultMap.get(connectionId)); - } - } - @Override public void channelInactive(final ChannelHandlerContext ctx) throws Exception { - //TODO delete connection map. + //TODO delete connection map super.channelInactive(ctx); } } From c0fd00bc9a453c6bdf1729dc9b7451d31769fdd0 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 22:13:11 +0800 Subject: [PATCH 091/198] refactor ResponseHandler --- .../client/response}/AuthType.java | 2 +- .../client/response/ResponseHandler.java | 12 ++-- .../response/mysql/MySQLResponseHandler.java | 70 ++++++++++--------- 3 files changed, 44 insertions(+), 40 deletions(-) rename sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/{constant => netty/client/response}/AuthType.java (93%) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/AuthType.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/AuthType.java similarity index 93% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/AuthType.java rename to sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/AuthType.java index 3d64dbe50c6f0..14672f6d69713 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/AuthType.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/AuthType.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.proxy.backend.constant; +package io.shardingsphere.proxy.backend.netty.client.response; /** * Auth Type. diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java index 896d7c72985e3..974838faf0f53 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java @@ -17,9 +17,9 @@ package io.shardingsphere.proxy.backend.netty.client.response; +import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; -import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload; /** * SQL executed response handler. @@ -29,13 +29,13 @@ */ public abstract class ResponseHandler extends ChannelInboundHandlerAdapter { - protected abstract void auth(ChannelHandlerContext context, MySQLPacketPayload payload); + protected abstract void auth(ChannelHandlerContext context, ByteBuf byteBuf); - protected abstract void eofPacket(ChannelHandlerContext context, MySQLPacketPayload payload); + protected abstract void eofPacket(ChannelHandlerContext context, ByteBuf byteBuf); - protected abstract void okPacket(ChannelHandlerContext context, MySQLPacketPayload payload); + protected abstract void okPacket(ChannelHandlerContext context, ByteBuf byteBuf); - protected abstract void errPacket(ChannelHandlerContext context, MySQLPacketPayload payload); + protected abstract void errPacket(ChannelHandlerContext context, ByteBuf byteBuf); - protected abstract void commonPacket(ChannelHandlerContext context, MySQLPacketPayload payload); + protected abstract void commonPacket(ChannelHandlerContext context, ByteBuf byteBuf); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java index 7fb8b9cbec246..e71b86c96bf37 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java @@ -22,7 +22,7 @@ import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.metadata.datasource.DataSourceMetaData; import io.shardingsphere.core.rule.DataSourceParameter; -import io.shardingsphere.proxy.backend.constant.AuthType; +import io.shardingsphere.proxy.backend.netty.client.response.AuthType; import io.shardingsphere.proxy.backend.netty.client.response.ResponseHandler; import io.shardingsphere.proxy.backend.netty.future.FutureRegistry; import io.shardingsphere.proxy.config.RuleRegistry; @@ -55,27 +55,34 @@ @RequiredArgsConstructor public final class MySQLResponseHandler extends ResponseHandler { - private static final RuleRegistry RULE_REGISTRY = RuleRegistry.getInstance(); + private final DataSourceParameter dataSourceParameter; - private final String dataSourceName; + private final DataSourceMetaData dataSourceMetaData; - private final Map resultMap = new HashMap<>(); + private final Map resultMap; - private AuthType authType = AuthType.UN_AUTH; + private AuthType authType; + + public MySQLResponseHandler(final String dataSourceName) { + dataSourceParameter = RuleRegistry.getInstance().getDataSourceConfigurationMap().get(dataSourceName); + dataSourceMetaData = RuleRegistry.getInstance().getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); + resultMap = new HashMap<>(); + authType = AuthType.UN_AUTH; + } @Override public void channelRead(final ChannelHandlerContext context, final Object message) { - MySQLPacketPayload payload = new MySQLPacketPayload((ByteBuf) message); - int header = getHeader(payload); + ByteBuf byteBuf = (ByteBuf) message; + int header = getHeader(byteBuf); switch (authType) { case UN_AUTH: - auth(context, payload); + auth(context, byteBuf); break; case AUTHING: - authing(context, payload, header); + authing(context, byteBuf, header); break; case AUTH_SUCCESS: - authSuccess(context, payload, header); + authSuccess(context, byteBuf, header); break; case AUTH_FAILED: log.error("mysql auth failed, cannot handle channel read message"); @@ -85,7 +92,8 @@ public void channelRead(final ChannelHandlerContext context, final Object messag } } - private int getHeader(final MySQLPacketPayload payload) { + private int getHeader(final ByteBuf byteBuf) { + MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf); payload.getByteBuf().markReaderIndex(); payload.readInt1(); int result = payload.readInt1(); @@ -94,10 +102,8 @@ private int getHeader(final MySQLPacketPayload payload) { } @Override - protected void auth(final ChannelHandlerContext context, final MySQLPacketPayload payload) { - try { - DataSourceParameter dataSourceParameter = RULE_REGISTRY.getDataSourceConfigurationMap().get(dataSourceName); - DataSourceMetaData dataSourceMetaData = RULE_REGISTRY.getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); + protected void auth(final ChannelHandlerContext context, final ByteBuf byteBuf) { + try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { HandshakePacket handshakePacket = new HandshakePacket(payload); byte[] authResponse = securePasswordAuthentication(dataSourceParameter.getPassword().getBytes(), handshakePacket.getAuthPluginData().getAuthPluginData()); HandshakeResponse41Packet handshakeResponse41Packet = new HandshakeResponse41Packet( @@ -105,8 +111,6 @@ protected void auth(final ChannelHandlerContext context, final MySQLPacketPayloa dataSourceParameter.getUsername(), authResponse, dataSourceMetaData.getSchemeName()); ChannelRegistry.getInstance().putConnectionId(context.channel().id().asShortText(), handshakePacket.getConnectionId()); context.writeAndFlush(handshakeResponse41Packet); - } finally { - payload.close(); } authType = AuthType.AUTHING; } @@ -129,64 +133,63 @@ private byte[] securePasswordAuthentication(final byte[] password, final byte[] } } - private void authing(final ChannelHandlerContext context, final MySQLPacketPayload payload, final int header) { + private void authing(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { if (OKPacket.HEADER == header) { - okPacket(context, payload); + okPacket(context, byteBuf); authType = AuthType.AUTH_SUCCESS; } else { - errPacket(context, payload); + errPacket(context, byteBuf); authType = AuthType.AUTH_FAILED; } } - private void authSuccess(final ChannelHandlerContext context, final MySQLPacketPayload payload, final int header) { + private void authSuccess(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { switch (header) { case EofPacket.HEADER: - eofPacket(context, payload); + eofPacket(context, byteBuf); break; case OKPacket.HEADER: - okPacket(context, payload); + okPacket(context, byteBuf); break; case ErrPacket.HEADER: - errPacket(context, payload); + errPacket(context, byteBuf); break; default: - commonPacket(context, payload); + commonPacket(context, byteBuf); } } @Override - protected void okPacket(final ChannelHandlerContext context, final MySQLPacketPayload payload) { + protected void okPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); - try { + try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { MySQLQueryResult mysqlQueryResult = new MySQLQueryResult(); mysqlQueryResult.setGenericResponse(new OKPacket(payload)); resultMap.put(connectionId, mysqlQueryResult); setResponse(context); } finally { resultMap.remove(connectionId); - payload.close(); } } @Override - protected void errPacket(final ChannelHandlerContext context, final MySQLPacketPayload payload) { + protected void errPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); - try { + try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { MySQLQueryResult mysqlQueryResult = new MySQLQueryResult(); mysqlQueryResult.setGenericResponse(new ErrPacket(payload)); resultMap.put(connectionId, mysqlQueryResult); setResponse(context); } finally { resultMap.remove(connectionId); - payload.close(); } } @Override - protected void eofPacket(final ChannelHandlerContext context, final MySQLPacketPayload payload) { + protected void eofPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); MySQLQueryResult mysqlQueryResult = resultMap.get(connectionId); + MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf); if (mysqlQueryResult.isColumnFinished()) { mysqlQueryResult.setRowFinished(new EofPacket(payload)); resultMap.remove(connectionId); @@ -205,9 +208,10 @@ private void setResponse(final ChannelHandlerContext context) { } @Override - protected void commonPacket(final ChannelHandlerContext context, final MySQLPacketPayload payload) { + protected void commonPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); MySQLQueryResult mysqlQueryResult = resultMap.get(connectionId); + MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf); if (null == mysqlQueryResult) { mysqlQueryResult = new MySQLQueryResult(payload); resultMap.put(connectionId, mysqlQueryResult); From d054acce4c1e218a77dc5a11da19e42b28a11d6e Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 22:23:22 +0800 Subject: [PATCH 092/198] pull up channelRead & channelInactive to ResponseHandler --- .../netty/client/response/AuthType.java | 24 +---------- .../client/response/ResponseHandler.java | 35 ++++++++++++++++ .../response/mysql/MySQLResponseHandler.java | 42 +++---------------- 3 files changed, 41 insertions(+), 60 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/AuthType.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/AuthType.java index 14672f6d69713..fd6fa9e391158 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/AuthType.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/AuthType.java @@ -24,27 +24,5 @@ */ public enum AuthType { - /** - * Database UN_AUTH. - * - */ - UN_AUTH, - - /** - * Database AUTHING. - * - */ - AUTHING, - - /** - * Database AUTH_SUCCESS. - * - */ - AUTH_SUCCESS, - - /** - * Database AUTH_FAILED. - * - */ - AUTH_FAILED + UN_AUTH, AUTHING, AUTH_FIN } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java index 974838faf0f53..c8bc14ed09ae3 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java @@ -29,8 +29,37 @@ */ public abstract class ResponseHandler extends ChannelInboundHandlerAdapter { + private AuthType authType; + + @Override + public void channelRead(final ChannelHandlerContext context, final Object message) { + ByteBuf byteBuf = (ByteBuf) message; + int header = getHeader(byteBuf); + switch (authType) { + case UN_AUTH: + auth(context, byteBuf); + authType = AuthType.AUTHING; + break; + case AUTHING: + authing(context, byteBuf, header); + authType = AuthType.AUTH_FIN; + break; + case AUTH_FIN: + authSuccess(context, byteBuf, header); + break; + default: + throw new UnsupportedOperationException(authType.name()); + } + } + + protected abstract int getHeader(ByteBuf byteBuf); + protected abstract void auth(ChannelHandlerContext context, ByteBuf byteBuf); + protected abstract void authing(ChannelHandlerContext context, ByteBuf byteBuf, int header); + + protected abstract void authSuccess(ChannelHandlerContext context, ByteBuf byteBuf, int header); + protected abstract void eofPacket(ChannelHandlerContext context, ByteBuf byteBuf); protected abstract void okPacket(ChannelHandlerContext context, ByteBuf byteBuf); @@ -38,4 +67,10 @@ public abstract class ResponseHandler extends ChannelInboundHandlerAdapter { protected abstract void errPacket(ChannelHandlerContext context, ByteBuf byteBuf); protected abstract void commonPacket(ChannelHandlerContext context, ByteBuf byteBuf); + + @Override + public void channelInactive(final ChannelHandlerContext ctx) throws Exception { + //TODO delete connection map + super.channelInactive(ctx); + } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java index e71b86c96bf37..3f18c863dfab0 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java @@ -22,7 +22,6 @@ import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.metadata.datasource.DataSourceMetaData; import io.shardingsphere.core.rule.DataSourceParameter; -import io.shardingsphere.proxy.backend.netty.client.response.AuthType; import io.shardingsphere.proxy.backend.netty.client.response.ResponseHandler; import io.shardingsphere.proxy.backend.netty.future.FutureRegistry; import io.shardingsphere.proxy.config.RuleRegistry; @@ -61,38 +60,14 @@ public final class MySQLResponseHandler extends ResponseHandler { private final Map resultMap; - private AuthType authType; - public MySQLResponseHandler(final String dataSourceName) { dataSourceParameter = RuleRegistry.getInstance().getDataSourceConfigurationMap().get(dataSourceName); dataSourceMetaData = RuleRegistry.getInstance().getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); resultMap = new HashMap<>(); - authType = AuthType.UN_AUTH; } @Override - public void channelRead(final ChannelHandlerContext context, final Object message) { - ByteBuf byteBuf = (ByteBuf) message; - int header = getHeader(byteBuf); - switch (authType) { - case UN_AUTH: - auth(context, byteBuf); - break; - case AUTHING: - authing(context, byteBuf, header); - break; - case AUTH_SUCCESS: - authSuccess(context, byteBuf, header); - break; - case AUTH_FAILED: - log.error("mysql auth failed, cannot handle channel read message"); - break; - default: - throw new UnsupportedOperationException(authType.name()); - } - } - - private int getHeader(final ByteBuf byteBuf) { + protected int getHeader(final ByteBuf byteBuf) { MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf); payload.getByteBuf().markReaderIndex(); payload.readInt1(); @@ -112,7 +87,6 @@ protected void auth(final ChannelHandlerContext context, final ByteBuf byteBuf) ChannelRegistry.getInstance().putConnectionId(context.channel().id().asShortText(), handshakePacket.getConnectionId()); context.writeAndFlush(handshakeResponse41Packet); } - authType = AuthType.AUTHING; } private byte[] securePasswordAuthentication(final byte[] password, final byte[] authPluginData) { @@ -133,17 +107,17 @@ private byte[] securePasswordAuthentication(final byte[] password, final byte[] } } - private void authing(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { + @Override + protected void authing(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { if (OKPacket.HEADER == header) { okPacket(context, byteBuf); - authType = AuthType.AUTH_SUCCESS; } else { errPacket(context, byteBuf); - authType = AuthType.AUTH_FAILED; } } - private void authSuccess(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { + @Override + protected void authSuccess(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { switch (header) { case EofPacket.HEADER: eofPacket(context, byteBuf); @@ -221,10 +195,4 @@ protected void commonPacket(final ChannelHandlerContext context, final ByteBuf b mysqlQueryResult.addTextResultSetRow(new TextResultSetRowPacket(payload, mysqlQueryResult.getColumnCount())); } } - - @Override - public void channelInactive(final ChannelHandlerContext ctx) throws Exception { - //TODO delete connection map - super.channelInactive(ctx); - } } From 8d310830715fb85001e3c675fe2c4edbaeb472a7 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 22:39:41 +0800 Subject: [PATCH 093/198] refactor MySQLResponseHandler --- .../proxy/backend/netty/client/response/ResponseHandler.java | 2 +- .../netty/client/response/mysql/MySQLResponseHandler.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java index c8bc14ed09ae3..a12468e476ab3 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java @@ -29,7 +29,7 @@ */ public abstract class ResponseHandler extends ChannelInboundHandlerAdapter { - private AuthType authType; + private AuthType authType = AuthType.UN_AUTH; @Override public void channelRead(final ChannelHandlerContext context, final Object message) { diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java index 3f18c863dfab0..4286b4e61bcc8 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java @@ -80,7 +80,8 @@ protected int getHeader(final ByteBuf byteBuf) { protected void auth(final ChannelHandlerContext context, final ByteBuf byteBuf) { try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { HandshakePacket handshakePacket = new HandshakePacket(payload); - byte[] authResponse = securePasswordAuthentication(dataSourceParameter.getPassword().getBytes(), handshakePacket.getAuthPluginData().getAuthPluginData()); + byte[] authResponse = securePasswordAuthentication( + (null == dataSourceParameter.getPassword() ? "" : dataSourceParameter.getPassword()).getBytes(), handshakePacket.getAuthPluginData().getAuthPluginData()); HandshakeResponse41Packet handshakeResponse41Packet = new HandshakeResponse41Packet( handshakePacket.getSequenceId() + 1, CapabilityFlag.calculateHandshakeCapabilityFlagsLower(), 16777215, ServerInfo.CHARSET, dataSourceParameter.getUsername(), authResponse, dataSourceMetaData.getSchemeName()); From 6482843f8e14e8de2f5807b8cca089f95472178f Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 6 Aug 2018 23:04:50 +0800 Subject: [PATCH 094/198] refactor ResponseHandler --- .../netty/client/response/ResponseHandler.java | 12 ++---------- .../response/mysql/MySQLResponseHandler.java | 16 ++++++---------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java index a12468e476ab3..30d35bd3d6dd7 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java @@ -45,7 +45,7 @@ public void channelRead(final ChannelHandlerContext context, final Object messag authType = AuthType.AUTH_FIN; break; case AUTH_FIN: - authSuccess(context, byteBuf, header); + executeCommand(context, byteBuf, header); break; default: throw new UnsupportedOperationException(authType.name()); @@ -58,15 +58,7 @@ public void channelRead(final ChannelHandlerContext context, final Object messag protected abstract void authing(ChannelHandlerContext context, ByteBuf byteBuf, int header); - protected abstract void authSuccess(ChannelHandlerContext context, ByteBuf byteBuf, int header); - - protected abstract void eofPacket(ChannelHandlerContext context, ByteBuf byteBuf); - - protected abstract void okPacket(ChannelHandlerContext context, ByteBuf byteBuf); - - protected abstract void errPacket(ChannelHandlerContext context, ByteBuf byteBuf); - - protected abstract void commonPacket(ChannelHandlerContext context, ByteBuf byteBuf); + protected abstract void executeCommand(ChannelHandlerContext context, ByteBuf byteBuf, int header); @Override public void channelInactive(final ChannelHandlerContext ctx) throws Exception { diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java index 4286b4e61bcc8..9ef68812dd633 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java @@ -118,7 +118,7 @@ protected void authing(final ChannelHandlerContext context, final ByteBuf byteBu } @Override - protected void authSuccess(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { + protected void executeCommand(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { switch (header) { case EofPacket.HEADER: eofPacket(context, byteBuf); @@ -130,12 +130,11 @@ protected void authSuccess(final ChannelHandlerContext context, final ByteBuf by errPacket(context, byteBuf); break; default: - commonPacket(context, byteBuf); + commandPacket(context, byteBuf); } } - @Override - protected void okPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { + private void okPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { MySQLQueryResult mysqlQueryResult = new MySQLQueryResult(); @@ -147,8 +146,7 @@ protected void okPacket(final ChannelHandlerContext context, final ByteBuf byteB } } - @Override - protected void errPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { + private void errPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { MySQLQueryResult mysqlQueryResult = new MySQLQueryResult(); @@ -160,8 +158,7 @@ protected void errPacket(final ChannelHandlerContext context, final ByteBuf byte } } - @Override - protected void eofPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { + private void eofPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); MySQLQueryResult mysqlQueryResult = resultMap.get(connectionId); MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf); @@ -182,8 +179,7 @@ private void setResponse(final ChannelHandlerContext context) { } } - @Override - protected void commonPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { + private void commandPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); MySQLQueryResult mysqlQueryResult = resultMap.get(connectionId); MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf); From 44e37fb24b2299c4c303ef3c6721780366551340 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 10:01:45 +0800 Subject: [PATCH 095/198] USE max-total=100 --- .../src/test/resources/application-masterslave.properties | 6 +++--- .../src/test/resources/application-sharding.properties | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-masterslave.properties b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-masterslave.properties index ddaba089af31a..baca2af0b0e0b 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-masterslave.properties +++ b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-masterslave.properties @@ -5,21 +5,21 @@ sharding.jdbc.datasource.ds_master.driver-class-name=org.h2.Driver sharding.jdbc.datasource.ds_master.url=jdbc:h2:mem:ds_master;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL sharding.jdbc.datasource.ds_master.username=root sharding.jdbc.datasource.ds_master.password= -sharding.jdbc.datasource.ds_master.max-total=16 +sharding.jdbc.datasource.ds_master.max-total=100 sharding.jdbc.datasource.ds_slave_0.type=org.apache.commons.dbcp2.BasicDataSource sharding.jdbc.datasource.ds_slave_0.driver-class-name=org.h2.Driver sharding.jdbc.datasource.ds_slave_0.url=jdbc:h2:mem:demo_ds_slave_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL sharding.jdbc.datasource.ds_slave_0.username=${sharding.jdbc.config.masterslave.config-map.username} sharding.jdbc.datasource.ds_slave_0.password= -sharding.jdbc.datasource.ds_slave_0.max-total=16 +sharding.jdbc.datasource.ds_slave_0.max-total=100 sharding.jdbc.datasource.ds_slave_1.type=org.apache.commons.dbcp2.BasicDataSource sharding.jdbc.datasource.ds_slave_1.driver-class-name=org.h2.Driver sharding.jdbc.datasource.ds_slave_1.url=jdbc:h2:mem:demo_ds_slave_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL sharding.jdbc.datasource.ds_slave_1.username=root sharding.jdbc.datasource.ds_slave_1.password= -sharding.jdbc.datasource.ds_slave_1.max-total=16 +sharding.jdbc.datasource.ds_slave_1.max-total=100 sharding.jdbc.config.masterslave.name=ds_ms sharding.jdbc.config.masterslave.master-data-source-name=ds_master diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-sharding.properties b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-sharding.properties index dffdb83506cfc..7c45fb034f5a2 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-sharding.properties +++ b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/resources/application-sharding.properties @@ -4,21 +4,21 @@ sharding.jdbc.datasource.ds.driver-class-name=org.h2.Driver sharding.jdbc.datasource.ds.url=jdbc:h2:mem:ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL sharding.jdbc.datasource.ds.username=sa sharding.jdbc.datasource.ds.password= -sharding.jdbc.datasource.ds.max-total=16 +sharding.jdbc.datasource.ds.max-total=100 sharding.jdbc.datasource.ds_0.type=org.apache.commons.dbcp2.BasicDataSource sharding.jdbc.datasource.ds_0.driver-class-name=org.h2.Driver sharding.jdbc.datasource.ds_0.url=jdbc:h2:mem:ds_0;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL sharding.jdbc.datasource.ds_0.username=sa sharding.jdbc.datasource.ds_0.password= -sharding.jdbc.datasource.ds_0.max-total=16 +sharding.jdbc.datasource.ds_0.max-total=100 sharding.jdbc.datasource.ds_1.type=org.apache.commons.dbcp2.BasicDataSource sharding.jdbc.datasource.ds_1.driver-class-name=org.h2.Driver sharding.jdbc.datasource.ds_1.url=jdbc:h2:mem:ds_1;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL sharding.jdbc.datasource.ds_1.username=sa sharding.jdbc.datasource.ds_1.password= -sharding.jdbc.datasource.ds_1.max-total=16 +sharding.jdbc.datasource.ds_1.max-total=100 sharding.jdbc.config.sharding.default-data-source-name=ds sharding.jdbc.config.sharding.default-database-strategy.inline.sharding-column=user_id From f39424238b01a9342790189cc430649d8fb9da53 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 10:01:59 +0800 Subject: [PATCH 096/198] MODIFY assert --- .../shardingsphere/opentracing/ExecuteEventListenerTest.java | 3 ++- .../io/shardingsphere/opentracing/MergeEventListenerTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/ExecuteEventListenerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/ExecuteEventListenerTest.java index 08518c92932d2..94a9c99879852 100644 --- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/ExecuteEventListenerTest.java +++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/ExecuteEventListenerTest.java @@ -28,6 +28,7 @@ import io.shardingsphere.core.executor.ExecuteCallback; import io.shardingsphere.core.executor.ExecutorEngine; import io.shardingsphere.core.executor.type.batch.BatchPreparedStatementUnit; +import io.shardingsphere.core.executor.type.memory.MemoryStrictlyExecutorEngine; import io.shardingsphere.core.executor.type.statement.StatementUnit; import io.shardingsphere.core.routing.SQLExecutionUnit; import io.shardingsphere.core.routing.SQLUnit; @@ -56,7 +57,7 @@ public final class ExecuteEventListenerTest { private static final MockTracer TRACER = new MockTracer(new ThreadLocalActiveSpanSource(), MockTracer.Propagator.TEXT_MAP); - private final ExecutorEngine executorEngine = new ExecutorEngine(5); + private final ExecutorEngine executorEngine = new MemoryStrictlyExecutorEngine(5); @BeforeClass public static void init() { diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java index 02b6730358bb1..1a484b72bee6b 100644 --- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java +++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java @@ -26,6 +26,7 @@ import io.opentracing.util.ThreadLocalActiveSpanSource; import io.shardingsphere.core.api.config.ShardingRuleConfiguration; import io.shardingsphere.core.api.config.TableRuleConfiguration; +import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.jdbc.core.ShardingContext; import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; @@ -87,7 +88,7 @@ public void setUp() throws SQLException { dataSourceMap.put("ds_0", mockDataSource()); dataSourceMap.put("ds_1", mockDataSource()); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()); - shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, null, true); + shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, null, true, ConnectionMode.MEMORY_STRICTLY); mergeEngine = new DALMergeEngine(null, null, new ShowDatabasesStatement(), null); } From d495598a1a9168e4e6f84b6073bd9948c6f732ba Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 10:02:16 +0800 Subject: [PATCH 097/198] add connection mode --- .../jdbc/spring/boot/type/SpringBootMasterSlaveTest.java | 2 +- .../jdbc/spring/boot/type/SpringBootShardingTest.java | 2 +- .../opentracing/SqlRoutingEventListenerTest.java | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/type/SpringBootMasterSlaveTest.java b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/type/SpringBootMasterSlaveTest.java index 69b0b8a513a6e..fd6871647ee3e 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/type/SpringBootMasterSlaveTest.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/type/SpringBootMasterSlaveTest.java @@ -49,7 +49,7 @@ public class SpringBootMasterSlaveTest { public void assertWithMasterSlaveDataSource() { assertTrue(dataSource instanceof MasterSlaveDataSource); for (DataSource each : ((MasterSlaveDataSource) dataSource).getAllDataSources().values()) { - assertThat(((BasicDataSource) each).getMaxTotal(), is(16)); + assertThat(((BasicDataSource) each).getMaxTotal(), is(100)); } Map configMap = new ConcurrentHashMap<>(); configMap.put("key1", "value1"); diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/type/SpringBootShardingTest.java b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/type/SpringBootShardingTest.java index bd07561ec5061..ad9ed895a1f9e 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/type/SpringBootShardingTest.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/type/SpringBootShardingTest.java @@ -56,7 +56,7 @@ public void assertWithShardingDataSource() throws NoSuchFieldException, IllegalA field.setAccessible(true); ShardingContext shardingContext = (ShardingContext) field.get(dataSource); for (DataSource each : shardingContext.getDataSourceMap().values()) { - assertThat(((BasicDataSource) each).getMaxTotal(), is(16)); + assertThat(((BasicDataSource) each).getMaxTotal(), is(100)); } assertTrue(shardingContext.isShowSQL()); Map configMap = new ConcurrentHashMap<>(); diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java index 23ed731edbf55..23ea9e5015aca 100644 --- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java +++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java @@ -26,6 +26,7 @@ import io.opentracing.util.ThreadLocalActiveSpanSource; import io.shardingsphere.core.api.config.ShardingRuleConfiguration; import io.shardingsphere.core.api.config.TableRuleConfiguration; +import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.jdbc.core.ShardingContext; import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; @@ -81,7 +82,7 @@ public void setUp() throws SQLException { dataSourceMap.put("ds_0", mockDataSource()); dataSourceMap.put("ds_1", mockDataSource()); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()); - shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, null, true); + shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, null, true, ConnectionMode.MEMORY_STRICTLY); } private DataSource mockDataSource() throws SQLException { From 068e1c7895759cd3bcdd61b18aee741dd954a3d0 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Tue, 7 Aug 2018 11:15:24 +0800 Subject: [PATCH 098/198] remove xa property files temporary for M2 publish. --- .../src/main/resources/assembly/assembly.xml | 1 - .../src/main/resources/jta.properties | 20 ------------------- 2 files changed, 21 deletions(-) delete mode 100644 sharding-proxy/src/main/resources/jta.properties diff --git a/sharding-proxy/src/main/resources/assembly/assembly.xml b/sharding-proxy/src/main/resources/assembly/assembly.xml index 465ab3d14b3db..b4ae99b4dce79 100644 --- a/sharding-proxy/src/main/resources/assembly/assembly.xml +++ b/sharding-proxy/src/main/resources/assembly/assembly.xml @@ -21,7 +21,6 @@ src/main/resources logback.xml - jta.properties conf 0644 diff --git a/sharding-proxy/src/main/resources/jta.properties b/sharding-proxy/src/main/resources/jta.properties deleted file mode 100644 index 826de48a7843d..0000000000000 --- a/sharding-proxy/src/main/resources/jta.properties +++ /dev/null @@ -1,20 +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. -#

-# - -com.atomikos.icatch.serial_jta_transactions=false -com.atomikos.icatch.default_jta_timeout = 1000000 -com.atomikos.icatch.max_actives = 10000 From 138711320d1864966a686a59f0f8a11f0f89fbf5 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Tue, 7 Aug 2018 12:40:22 +0800 Subject: [PATCH 099/198] update AbstractBackendHandler.findSQLException --- .../shardingsphere/proxy/backend/AbstractBackendHandler.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/AbstractBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/AbstractBackendHandler.java index 3f4f967287d74..1448b4a59d905 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/AbstractBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/AbstractBackendHandler.java @@ -47,6 +47,9 @@ public final CommandResponsePackets execute() { protected abstract CommandResponsePackets execute0() throws Exception; private Optional findSQLException(final Exception exception) { + if (exception instanceof SQLException) { + return Optional.of((SQLException) exception); + } if (null == exception.getCause()) { return Optional.absent(); } @@ -57,7 +60,7 @@ private Optional findSQLException(final Exception exception) { return Optional.absent(); } if (exception.getCause().getCause() instanceof SQLException) { - return Optional.of((SQLException) exception.getCause()); + return Optional.of((SQLException) exception.getCause().getCause()); } return Optional.absent(); } From 15d023f2a4c44acf5c113c2a6f74df6d0f9871df Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 14:22:27 +0800 Subject: [PATCH 100/198] use MemoryQueryResult --- .../core/jdbc/core/statement/ShardingPreparedStatement.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java index 35f84cdb40bce..3f7c2d9a4c98d 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java @@ -34,7 +34,6 @@ import io.shardingsphere.core.jdbc.core.resultset.GeneratedKeysResultSet; import io.shardingsphere.core.jdbc.core.resultset.ShardingResultSet; import io.shardingsphere.core.jdbc.metadata.ShardingConnectionTableMetaDataConnectionManager; -import io.shardingsphere.core.merger.JDBCQueryResult; import io.shardingsphere.core.merger.MergeEngine; import io.shardingsphere.core.merger.MergeEngineFactory; import io.shardingsphere.core.merger.MergedResult; @@ -348,7 +347,7 @@ public ResultSet getResultSet() throws SQLException { for (PreparedStatement each : routedStatements) { ResultSet resultSet = each.getResultSet(); resultSets.add(resultSet); - queryResults.add(new JDBCQueryResult(resultSet)); + queryResults.add(new MemoryQueryResult(resultSet)); } if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) { MergeEngine mergeEngine = MergeEngineFactory.newInstance( From 74adaf56b53ee44558a54a6167a49df379979a67 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 14:22:52 +0800 Subject: [PATCH 101/198] instead of jdbc query result --- .../core/jdbc/core/statement/ShardingStatement.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java index 65b1c169bf5e0..919374b7b9a96 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java @@ -30,7 +30,6 @@ import io.shardingsphere.core.jdbc.core.resultset.GeneratedKeysResultSet; import io.shardingsphere.core.jdbc.core.resultset.ShardingResultSet; import io.shardingsphere.core.jdbc.metadata.ShardingConnectionTableMetaDataConnectionManager; -import io.shardingsphere.core.merger.JDBCQueryResult; import io.shardingsphere.core.merger.MergeEngine; import io.shardingsphere.core.merger.MergeEngineFactory; import io.shardingsphere.core.merger.MergedResult; @@ -326,7 +325,7 @@ public ResultSet getResultSet() throws SQLException { for (Statement each : routedStatements) { ResultSet resultSet = each.getResultSet(); resultSets.add(resultSet); - queryResults.add(new JDBCQueryResult(resultSet)); + queryResults.add(new MemoryQueryResult(resultSet)); } if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) { MergeEngine mergeEngine = MergeEngineFactory.newInstance( From 78c3aa7c6f54785862551452d070d371964cf9ea Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 14:23:02 +0800 Subject: [PATCH 102/198] delete this file --- .../core/merger/JDBCQueryResult.java | 215 ------------------ 1 file changed, 215 deletions(-) delete mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/merger/JDBCQueryResult.java diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/merger/JDBCQueryResult.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/merger/JDBCQueryResult.java deleted file mode 100644 index 2685b19079c2e..0000000000000 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/merger/JDBCQueryResult.java +++ /dev/null @@ -1,215 +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.core.merger; - -import lombok.RequiredArgsConstructor; - -import java.io.InputStream; -import java.io.Reader; -import java.math.BigDecimal; -import java.net.URL; -import java.sql.Blob; -import java.sql.Clob; -import java.sql.Date; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.SQLXML; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.Calendar; - -/** - * Query result form database for JDBC. - * - * @author zhangliang - */ -@RequiredArgsConstructor -public final class JDBCQueryResult implements QueryResult { - - private final ResultSet resultSet; - - @Override - public boolean next() throws SQLException { - return resultSet.next(); - } - - @Override - public Object getValue(final int columnIndex, final Class type) throws SQLException { - Object result; - if (Object.class == type) { - result = resultSet.getObject(columnIndex); - } else if (boolean.class == type) { - result = resultSet.getBoolean(columnIndex); - } else if (byte.class == type) { - result = resultSet.getByte(columnIndex); - } else if (short.class == type) { - result = resultSet.getShort(columnIndex); - } else if (int.class == type) { - result = resultSet.getInt(columnIndex); - } else if (long.class == type) { - result = resultSet.getLong(columnIndex); - } else if (float.class == type) { - result = resultSet.getFloat(columnIndex); - } else if (double.class == type) { - result = resultSet.getDouble(columnIndex); - } else if (String.class == type) { - result = resultSet.getString(columnIndex); - } else if (BigDecimal.class == type) { - result = resultSet.getBigDecimal(columnIndex); - } else if (byte[].class == type) { - result = resultSet.getBytes(columnIndex); - } else if (Date.class == type) { - result = resultSet.getDate(columnIndex); - } else if (Time.class == type) { - result = resultSet.getTime(columnIndex); - } else if (Timestamp.class == type) { - result = resultSet.getTimestamp(columnIndex); - } else if (URL.class == type) { - result = resultSet.getURL(columnIndex); - } else if (Blob.class == type) { - result = resultSet.getBlob(columnIndex); - } else if (Clob.class == type) { - result = resultSet.getClob(columnIndex); - } else if (SQLXML.class == type) { - result = resultSet.getSQLXML(columnIndex); - } else if (Reader.class == type) { - result = resultSet.getCharacterStream(columnIndex); - } else { - result = resultSet.getObject(columnIndex); - } - return result; - } - - @Override - public Object getValue(final String columnLabel, final Class type) throws SQLException { - Object result; - if (Object.class == type) { - result = resultSet.getObject(columnLabel); - } else if (boolean.class == type) { - result = resultSet.getBoolean(columnLabel); - } else if (byte.class == type) { - result = resultSet.getByte(columnLabel); - } else if (short.class == type) { - result = resultSet.getShort(columnLabel); - } else if (int.class == type) { - result = resultSet.getInt(columnLabel); - } else if (long.class == type) { - result = resultSet.getLong(columnLabel); - } else if (float.class == type) { - result = resultSet.getFloat(columnLabel); - } else if (double.class == type) { - result = resultSet.getDouble(columnLabel); - } else if (String.class == type) { - result = resultSet.getString(columnLabel); - } else if (BigDecimal.class == type) { - result = resultSet.getBigDecimal(columnLabel); - } else if (byte[].class == type) { - result = resultSet.getBytes(columnLabel); - } else if (Date.class == type) { - result = resultSet.getDate(columnLabel); - } else if (Time.class == type) { - result = resultSet.getTime(columnLabel); - } else if (Timestamp.class == type) { - result = resultSet.getTimestamp(columnLabel); - } else if (URL.class == type) { - result = resultSet.getURL(columnLabel); - } else if (Blob.class == type) { - result = resultSet.getBlob(columnLabel); - } else if (Clob.class == type) { - result = resultSet.getClob(columnLabel); - } else if (SQLXML.class == type) { - result = resultSet.getSQLXML(columnLabel); - } else if (Reader.class == type) { - result = resultSet.getCharacterStream(columnLabel); - } else { - result = resultSet.getObject(columnLabel); - } - return result; - } - - @Override - public Object getCalendarValue(final int columnIndex, final Class type, final Calendar calendar) throws SQLException { - if (Date.class == type) { - return resultSet.getDate(columnIndex, calendar); - } - if (Time.class == type) { - return resultSet.getTime(columnIndex, calendar); - } - if (Timestamp.class == type) { - return resultSet.getTimestamp(columnIndex, calendar); - } - throw new SQLException(String.format("Unsupported type: %s", type)); - } - - @Override - public Object getCalendarValue(final String columnLabel, final Class type, final Calendar calendar) throws SQLException { - if (Date.class == type) { - return resultSet.getDate(columnLabel, calendar); - } - if (Time.class == type) { - return resultSet.getTime(columnLabel, calendar); - } - if (Timestamp.class == type) { - return resultSet.getTimestamp(columnLabel, calendar); - } - throw new SQLException(String.format("Unsupported type: %s", type)); - } - - @Override - public InputStream getInputStream(final int columnIndex, final String type) throws SQLException { - switch (type) { - case "Ascii": - return resultSet.getAsciiStream(columnIndex); - case "Unicode": - return resultSet.getUnicodeStream(columnIndex); - case "Binary": - return resultSet.getBinaryStream(columnIndex); - default: - throw new SQLException(String.format("Unsupported type: %s", type)); - } - } - - @Override - public InputStream getInputStream(final String columnLabel, final String type) throws SQLException { - switch (type) { - case "Ascii": - return resultSet.getAsciiStream(columnLabel); - case "Unicode": - return resultSet.getUnicodeStream(columnLabel); - case "Binary": - return resultSet.getBinaryStream(columnLabel); - default: - throw new SQLException(String.format("Unsupported type: %s", type)); - } - } - - @Override - public boolean wasNull() throws SQLException { - return resultSet.wasNull(); - } - - @Override - public int getColumnCount() throws SQLException { - return resultSet.getMetaData().getColumnCount(); - } - - @Override - public String getColumnLabel(final int columnIndex) throws SQLException { - return resultSet.getMetaData().getColumnLabel(columnIndex); - } -} From 3b9e507316633879ef14892912ede9483aab5791 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Tue, 7 Aug 2018 16:26:43 +0800 Subject: [PATCH 103/198] remove AuthType --- .../netty/client/response/AuthType.java | 28 ------------------- .../client/response/ResponseHandler.java | 24 +++++----------- .../response/mysql/MySQLResponseHandler.java | 9 ------ 3 files changed, 7 insertions(+), 54 deletions(-) delete mode 100644 sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/AuthType.java diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/AuthType.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/AuthType.java deleted file mode 100644 index fd6fa9e391158..0000000000000 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/AuthType.java +++ /dev/null @@ -1,28 +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.proxy.backend.netty.client.response; - -/** - * Auth Type. - * - * @author linjiaqi - */ -public enum AuthType { - - UN_AUTH, AUTHING, AUTH_FIN -} diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java index 30d35bd3d6dd7..da260e854603a 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java @@ -29,26 +29,18 @@ */ public abstract class ResponseHandler extends ChannelInboundHandlerAdapter { - private AuthType authType = AuthType.UN_AUTH; + private boolean authorized; @Override public void channelRead(final ChannelHandlerContext context, final Object message) { ByteBuf byteBuf = (ByteBuf) message; int header = getHeader(byteBuf); - switch (authType) { - case UN_AUTH: - auth(context, byteBuf); - authType = AuthType.AUTHING; - break; - case AUTHING: - authing(context, byteBuf, header); - authType = AuthType.AUTH_FIN; - break; - case AUTH_FIN: - executeCommand(context, byteBuf, header); - break; - default: - throw new UnsupportedOperationException(authType.name()); + + if (!authorized) { + auth(context, byteBuf); + authorized = true; + } else { + executeCommand(context, byteBuf, header); } } @@ -56,8 +48,6 @@ public void channelRead(final ChannelHandlerContext context, final Object messag protected abstract void auth(ChannelHandlerContext context, ByteBuf byteBuf); - protected abstract void authing(ChannelHandlerContext context, ByteBuf byteBuf, int header); - protected abstract void executeCommand(ChannelHandlerContext context, ByteBuf byteBuf, int header); @Override diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java index 9ef68812dd633..b4448faa63cbe 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLResponseHandler.java @@ -108,15 +108,6 @@ private byte[] securePasswordAuthentication(final byte[] password, final byte[] } } - @Override - protected void authing(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { - if (OKPacket.HEADER == header) { - okPacket(context, byteBuf); - } else { - errPacket(context, byteBuf); - } - } - @Override protected void executeCommand(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { switch (header) { From 050861f6c13067cd1868fd3606e2609f12922b95 Mon Sep 17 00:00:00 2001 From: saaav Date: Tue, 7 Aug 2018 16:30:08 +0800 Subject: [PATCH 104/198] use lombok --- .../reg/newzk/client/cache/PathNode.java | 24 ++++--------------- .../reg/newzk/client/cache/PathTree.java | 8 +++---- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathNode.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathNode.java index e13fc41f7df23..d46a4651ab3e8 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathNode.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathNode.java @@ -34,8 +34,10 @@ @Slf4j public final class PathNode { + @Getter private final Map children = new ConcurrentHashMap<>(); + @Getter private final String nodeKey; @Getter(value = AccessLevel.PACKAGE) @@ -56,32 +58,14 @@ public final class PathNode { this.path = key; } - /** - * Get children. - * - * @return children - */ - public Map getChildren() { - return children; - } - - /** - * Get key. - * - * @return node key - */ - public String getKey() { - return this.nodeKey; - } - /** * Attach child node. * * @param node node */ - public void attachChild(final PathNode node) { + void attachChild(final PathNode node) { this.children.put(node.nodeKey, node); - node.setPath(PathUtil.getRealPath(path, node.getKey())); + node.setPath(PathUtil.getRealPath(path, node.getNodeKey())); } PathNode set(final PathResolve pathResolve, final String value) { diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java index 10f54af0627c0..31d81ce77ef5e 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java @@ -92,8 +92,8 @@ public void load() throws KeeperException, InterruptedException { log.debug("loading status:{}", status); status = PathStatus.CHANGING; - final PathNode newRoot = new PathNode(rootNode.get().getKey()); - final List children = provider.getChildren(PathUtil.checkPath(rootNode.get().getKey())); + final PathNode newRoot = new PathNode(rootNode.get().getNodeKey()); + final List children = provider.getChildren(PathUtil.checkPath(rootNode.get().getNodeKey())); children.remove(ZookeeperConstants.CHANGING_KEY); attachIntoNode(children, newRoot); rootNode.set(newRoot); @@ -190,7 +190,7 @@ public void stopRefresh() { * Watch data change. */ public void watch() { - watch(new ZookeeperEventListener(rootNode.get().getKey()) { + watch(new ZookeeperEventListener(rootNode.get().getNodeKey()) { @Override public void process(final WatchedEvent event) { String path = event.getPath(); @@ -222,7 +222,7 @@ public void watch(final ZookeeperEventListener zookeeperEventListener) { } final String key = zookeeperEventListener.getKey(); log.debug("PathTree Watch:{}", key); - client.registerWatch(rootNode.get().getKey(), zookeeperEventListener); + client.registerWatch(rootNode.get().getNodeKey(), zookeeperEventListener); watcherKeys.add(key); } From a55c1e47429d825938f634e8a73202c6e7c2a103 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Tue, 7 Aug 2018 16:31:16 +0800 Subject: [PATCH 105/198] refactor MySQLQueryResult --- .../response/mysql/MySQLQueryResult.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLQueryResult.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLQueryResult.java index 4f99f5fce189f..3812034623d5a 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLQueryResult.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLQueryResult.java @@ -88,24 +88,27 @@ public MySQLQueryResult(final MySQLPacketPayload payload) { } /** - * Set GenericResponse to the CommandResponsePackets. - * @param mysqlPacket mysqlPacket + * Set generic response to command response packets. + * + * @param mysqlPacket MySQL packet */ public void setGenericResponse(final MySQLPacket mysqlPacket) { commandResponsePackets.getPackets().add(mysqlPacket); } /** - * Whether the QueryResult is needed to add ColumnDefinition. - * @return whether the columnCount is larger than columnDefinitions's size + * Whether query result is needed to add column definition. + * + * @return whether the column count is larger than column definitions's size */ public boolean needColumnDefinition() { return columnCount > columnDefinitions.size(); } /** - * Add ColumnDefinition to the QueryResult. - * @param columnDefinition columnDefinition + * Add column definition. + * + * @param columnDefinition column definition */ public void addColumnDefinition(final ColumnDefinition41Packet columnDefinition) { commandResponsePackets.getPackets().add(columnDefinition); @@ -116,16 +119,17 @@ public void addColumnDefinition(final ColumnDefinition41Packet columnDefinition) } /** - * Add TextResultSetRow to the QueryResult. - * @param textResultSetRow textResultSetRow + * Add text result set row. + * + * @param textResultSetRow text result set row */ public void addTextResultSetRow(final TextResultSetRowPacket textResultSetRow) { put(textResultSetRow); } /** - * Set Column Finished. - * @param eofPacket eofPacket + * Set column finished. + * @param eofPacket eof packet */ public void setColumnFinished(final EofPacket eofPacket) { commandResponsePackets.getPackets().add(eofPacket); @@ -134,8 +138,8 @@ public void setColumnFinished(final EofPacket eofPacket) { } /** - * Set Row Finished. - * @param eofPacket eofPacket + * Set row finished. + * @param eofPacket eof packet */ public void setRowFinished(final EofPacket eofPacket) { put(eofPacket); From 9b3fa4dd0b2e9a66d42484068c8bbee49eaa1690 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Tue, 7 Aug 2018 16:39:13 +0800 Subject: [PATCH 106/198] upgrade to 3.0.0.M2 --- pom.xml | 2 +- sharding-core/pom.xml | 2 +- sharding-jdbc-orchestration-spring/pom.xml | 2 +- .../sharding-jdbc-orchestration-spring-boot-starter/pom.xml | 2 +- .../sharding-jdbc-orchestration-spring-namespace/pom.xml | 2 +- sharding-jdbc-orchestration/pom.xml | 4 ++-- sharding-jdbc-plugin/pom.xml | 4 ++-- sharding-jdbc-spring/pom.xml | 2 +- .../sharding-jdbc-spring-boot-starter/pom.xml | 2 +- sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml | 2 +- sharding-jdbc-transaction-parent/pom.xml | 2 +- .../sharding-jdbc-transaction-async-job/pom.xml | 2 +- .../sharding-jdbc-transaction-storage/pom.xml | 2 +- .../sharding-jdbc-transaction/pom.xml | 2 +- sharding-jdbc/pom.xml | 2 +- sharding-opentracing/pom.xml | 2 +- sharding-proxy/pom.xml | 4 ++-- sharding-sql-test/pom.xml | 2 +- 18 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index f003acfabb4e5..a38d6910c243d 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.shardingsphere sharding-sphere - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 pom ${project.artifactId} diff --git a/sharding-core/pom.xml b/sharding-core/pom.xml index be5b84acfbd10..bb229bf4c13f7 100644 --- a/sharding-core/pom.xml +++ b/sharding-core/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-core ${project.artifactId} diff --git a/sharding-jdbc-orchestration-spring/pom.xml b/sharding-jdbc-orchestration-spring/pom.xml index 6f16c4d089108..dc291a946efaa 100644 --- a/sharding-jdbc-orchestration-spring/pom.xml +++ b/sharding-jdbc-orchestration-spring/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-jdbc-orchestration-spring pom diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/pom.xml b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/pom.xml index b22894a9bdea4..6a5038ec83e83 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/pom.xml +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-orchestration-spring - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-jdbc-orchestration-spring-boot-starter diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/pom.xml b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/pom.xml index 25265aef3aa6e..45655cd774ffb 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/pom.xml +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-orchestration-spring - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-jdbc-orchestration-spring-namespace diff --git a/sharding-jdbc-orchestration/pom.xml b/sharding-jdbc-orchestration/pom.xml index 5067a4d7ffe04..cecebf91938f8 100644 --- a/sharding-jdbc-orchestration/pom.xml +++ b/sharding-jdbc-orchestration/pom.xml @@ -5,14 +5,14 @@ io.shardingsphere sharding-sphere - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 4.0.0 sharding-jdbc-orchestration ${project.artifactId} - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 diff --git a/sharding-jdbc-plugin/pom.xml b/sharding-jdbc-plugin/pom.xml index ad19ebcbbe870..42237b18a5e71 100644 --- a/sharding-jdbc-plugin/pom.xml +++ b/sharding-jdbc-plugin/pom.xml @@ -5,11 +5,11 @@ 4.0.0 io.shardingsphere sharding-jdbc-plugin - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 pom - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 4.12 1.6.6 1.7 diff --git a/sharding-jdbc-spring/pom.xml b/sharding-jdbc-spring/pom.xml index 233cb061c502c..16e8372b3c215 100644 --- a/sharding-jdbc-spring/pom.xml +++ b/sharding-jdbc-spring/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-jdbc-spring pom diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/pom.xml b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/pom.xml index c34c7a7053db6..3636755edf6d1 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/pom.xml +++ b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-spring - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-jdbc-spring-boot-starter diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml index ceccaabeceabc..2c82d6fd7ef83 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-spring - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-jdbc-spring-namespace diff --git a/sharding-jdbc-transaction-parent/pom.xml b/sharding-jdbc-transaction-parent/pom.xml index 0af233cee31df..f59cac0f3c22b 100644 --- a/sharding-jdbc-transaction-parent/pom.xml +++ b/sharding-jdbc-transaction-parent/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-jdbc-transaction-parent pom diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/pom.xml b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/pom.xml index 55d0d0568efaa..32edf84eaf51c 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/pom.xml +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-transaction-parent - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-jdbc-transaction-async-job ${project.artifactId} diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/pom.xml b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/pom.xml index 9bc391997ea8a..b61943f8fd0a3 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/pom.xml +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-transaction-parent - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-jdbc-transaction-storage ${project.artifactId} diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/pom.xml b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/pom.xml index b604b82c937a3..942a848aa6b84 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/pom.xml +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-transaction-parent - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-jdbc-transaction ${project.artifactId} diff --git a/sharding-jdbc/pom.xml b/sharding-jdbc/pom.xml index faa93cefd5368..0a42961cb6611 100644 --- a/sharding-jdbc/pom.xml +++ b/sharding-jdbc/pom.xml @@ -4,7 +4,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-jdbc ${project.artifactId} diff --git a/sharding-opentracing/pom.xml b/sharding-opentracing/pom.xml index 6ea46b144ff41..0bdec56b84378 100644 --- a/sharding-opentracing/pom.xml +++ b/sharding-opentracing/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-opentracing ${project.artifactId} diff --git a/sharding-proxy/pom.xml b/sharding-proxy/pom.xml index 40e7e9ec6a9a4..c8628d8a982a8 100644 --- a/sharding-proxy/pom.xml +++ b/sharding-proxy/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-proxy ${project.artifactId} @@ -102,7 +102,7 @@ com.spotify docker-maven-plugin - shardingsphere/sharding-proxy:3.0.0.M2-SNAPSHOT + shardingsphere/sharding-proxy:3.0.0.M2 ${project.basedir}/src/main/docker diff --git a/sharding-sql-test/pom.xml b/sharding-sql-test/pom.xml index 3e6fd308a3d30..773f553b833ba 100644 --- a/sharding-sql-test/pom.xml +++ b/sharding-sql-test/pom.xml @@ -6,7 +6,7 @@ sharding-sphere io.shardingsphere - 3.0.0.M2-SNAPSHOT + 3.0.0.M2 sharding-sql-test ${project.artifactId} From 1df12740780e1b36961f8df2adedd372007fee54 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Tue, 7 Aug 2018 17:22:48 +0800 Subject: [PATCH 107/198] recovery xa properties file. --- .../src/main/resources/assembly/assembly.xml | 1 + .../src/main/resources/conf/jta.properties | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 sharding-proxy/src/main/resources/conf/jta.properties diff --git a/sharding-proxy/src/main/resources/assembly/assembly.xml b/sharding-proxy/src/main/resources/assembly/assembly.xml index b4ae99b4dce79..465ab3d14b3db 100644 --- a/sharding-proxy/src/main/resources/assembly/assembly.xml +++ b/sharding-proxy/src/main/resources/assembly/assembly.xml @@ -21,6 +21,7 @@ src/main/resources logback.xml + jta.properties conf 0644 diff --git a/sharding-proxy/src/main/resources/conf/jta.properties b/sharding-proxy/src/main/resources/conf/jta.properties new file mode 100644 index 0000000000000..826de48a7843d --- /dev/null +++ b/sharding-proxy/src/main/resources/conf/jta.properties @@ -0,0 +1,20 @@ +# +# 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. +#

+# + +com.atomikos.icatch.serial_jta_transactions=false +com.atomikos.icatch.default_jta_timeout = 1000000 +com.atomikos.icatch.max_actives = 10000 From c9728c8411a6ebd0191842be843d7216389507c6 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 19:28:03 +0800 Subject: [PATCH 108/198] remove synchronize. --- .../core/executor/ExecutorEngine.java | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java index d4cf086f8e5fe..0ad22f5d5936b 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java @@ -110,34 +110,32 @@ public List execute( protected T executeInternal(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final ExecuteCallback executeCallback, final boolean isExceptionThrown, final Map dataMap) throws Exception { - synchronized (baseStatementUnit.getStatement().getConnection()) { - T result; - ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown); - ExecutorDataMap.setDataMap(dataMap); - List events = new LinkedList<>(); - for (List each : baseStatementUnit.getSqlExecutionUnit().getSqlUnit().getParameterSets()) { - events.add(getExecutionEvent(sqlType, baseStatementUnit, each)); - } - for (AbstractExecutionEvent event : events) { - EventBusInstance.getInstance().post(event); - } - try { - result = executeCallback.execute(baseStatementUnit); - } catch (final SQLException ex) { - for (AbstractExecutionEvent each : events) { - each.setEventExecutionType(EventExecutionType.EXECUTE_FAILURE); - each.setException(ex); - EventBusInstance.getInstance().post(each); - ExecutorExceptionHandler.handleException(ex); - } - return null; - } + T result; + ExecutorExceptionHandler.setExceptionThrown(isExceptionThrown); + ExecutorDataMap.setDataMap(dataMap); + List events = new LinkedList<>(); + for (List each : baseStatementUnit.getSqlExecutionUnit().getSqlUnit().getParameterSets()) { + events.add(getExecutionEvent(sqlType, baseStatementUnit, each)); + } + for (AbstractExecutionEvent event : events) { + EventBusInstance.getInstance().post(event); + } + try { + result = executeCallback.execute(baseStatementUnit); + } catch (final SQLException ex) { for (AbstractExecutionEvent each : events) { - each.setEventExecutionType(EventExecutionType.EXECUTE_SUCCESS); + each.setEventExecutionType(EventExecutionType.EXECUTE_FAILURE); + each.setException(ex); EventBusInstance.getInstance().post(each); + ExecutorExceptionHandler.handleException(ex); } - return result; + return null; + } + for (AbstractExecutionEvent each : events) { + each.setEventExecutionType(EventExecutionType.EXECUTE_SUCCESS); + EventBusInstance.getInstance().post(each); } + return result; } private AbstractExecutionEvent getExecutionEvent(final SQLType sqlType, final BaseStatementUnit baseStatementUnit, final List parameters) { From 86fd450ee8bb2a8dea3caf2e3b6277ecefe08503 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 19:33:45 +0800 Subject: [PATCH 109/198] remove Iterator --- .../java/io/shardingsphere/core/executor/ExecutorEngine.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java index 0ad22f5d5936b..3f826e6ba68f6 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java @@ -89,7 +89,6 @@ public List execute( } OverallExecutionEvent event = new OverallExecutionEvent(sqlType, baseStatementUnits.size()); EventBusInstance.getInstance().post(event); - Iterator iterator = baseStatementUnits.iterator(); try { List result = getExecuteResults(sqlType, baseStatementUnits, executeCallback); event.setEventExecutionType(EventExecutionType.EXECUTE_SUCCESS); From d68a4414908396cd9855b451eb1fd009913e7b28 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 19:34:04 +0800 Subject: [PATCH 110/198] delete import java.util.Iterator; --- .../java/io/shardingsphere/core/executor/ExecutorEngine.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java index 3f826e6ba68f6..caa7c06872c57 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java @@ -35,7 +35,6 @@ import java.sql.SQLException; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; From aed7c462a3eeb9de2f1275d96544eafc69694ecc Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 19:46:59 +0800 Subject: [PATCH 111/198] add author --- .../core/executor/type/connection/MemoryQueryResult.java | 1 + .../core/executor/type/memory/StreamQueryResult.java | 1 + 2 files changed, 2 insertions(+) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java index 8ca08596fe603..61587bd65df56 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java @@ -37,6 +37,7 @@ * Query result for memory loading. * * @author zhangliang + * @author panjuan */ public final class MemoryQueryResult implements QueryResult { diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java index 56ec8ef4df0cb..43332c85e1d89 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java @@ -38,6 +38,7 @@ * Query result for stream loading. * * @author zhangliang + * @author panjuan */ @RequiredArgsConstructor public final class StreamQueryResult implements QueryResult { From 1e7b72aafb02211a6e6946b12c9f928e9809b328 Mon Sep 17 00:00:00 2001 From: chidaodezhongsheng Date: Tue, 7 Aug 2018 20:28:31 +0800 Subject: [PATCH 112/198] fix bug, when run the TCL sql, the channel of netty will release back to the channel pool --- .../backend/netty/NettyBackendHandler.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java index 4d7c5532191e8..8f4c7bd76ebd5 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java @@ -166,6 +166,9 @@ private CommandResponsePackets merge(final SQLStatement sqlStatement, final List return new CommandResponsePackets(each); } } + if (SQLType.TCL == sqlStatement.getType()) { + channelRelease(); + } if (SQLType.DML == sqlStatement.getType()) { return mergeDML(headPackets); } @@ -207,11 +210,7 @@ private void refreshTableMetaData(final String logicTableName) { @Override public boolean next() throws SQLException { if (null == mergedResult || !mergedResult.next()) { - for (Entry> entry : channelMap.entrySet()) { - for (Channel each : entry.getValue()) { - BackendNettyClient.getInstance().getPoolMap().get(entry.getKey()).release(each); - } - } + channelRelease(); return false; } return true; @@ -225,4 +224,12 @@ public ResultPacket getResultValue() throws SQLException { } return new ResultPacket(++currentSequenceId, data, columnCount, Collections.emptyList()); } + + private void channelRelease() { + for (Entry> entry : channelMap.entrySet()) { + for (Channel each : entry.getValue()) { + BackendNettyClient.getInstance().getPoolMap().get(entry.getKey()).release(each); + } + } + } } From 79b2263813974f69df115280817e9d86d51463db Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 20:38:18 +0800 Subject: [PATCH 113/198] use StreamQueryResult --- .../core/jdbc/core/statement/ShardingPreparedStatement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java index 3f7c2d9a4c98d..2429937b4579f 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java @@ -347,7 +347,7 @@ public ResultSet getResultSet() throws SQLException { for (PreparedStatement each : routedStatements) { ResultSet resultSet = each.getResultSet(); resultSets.add(resultSet); - queryResults.add(new MemoryQueryResult(resultSet)); + queryResults.add(new StreamQueryResult(resultSet)); } if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) { MergeEngine mergeEngine = MergeEngineFactory.newInstance( From 638bc3a209bd2b78539cb7001d344d5cdb1fb163 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Tue, 7 Aug 2018 20:38:31 +0800 Subject: [PATCH 114/198] use StreamQueryResult --- .../core/jdbc/core/statement/ShardingStatement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java index 919374b7b9a96..028a1525c4e75 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java @@ -325,7 +325,7 @@ public ResultSet getResultSet() throws SQLException { for (Statement each : routedStatements) { ResultSet resultSet = each.getResultSet(); resultSets.add(resultSet); - queryResults.add(new MemoryQueryResult(resultSet)); + queryResults.add(new StreamQueryResult(resultSet)); } if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) { MergeEngine mergeEngine = MergeEngineFactory.newInstance( From a7b94cfe3d80baed72886d6ddd75ed5cf4691274 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Tue, 7 Aug 2018 23:55:30 +0800 Subject: [PATCH 115/198] checkstyle for newzk --- .../reg/newzk/NewZookeeperRegistryCenter.java | 72 +++++----- .../client/action/ContentionCallback.java | 6 +- .../reg/newzk/client/action/IAction.java | 50 +++---- .../reg/newzk/client/action/IClient.java | 46 +++---- .../newzk/client/action/IExecStrategy.java | 8 +- .../reg/newzk/client/action/IGroupAction.java | 16 +-- .../reg/newzk/client/action/IProvider.java | 54 ++++---- .../client/action/ITransactionProvider.java | 6 +- .../reg/newzk/client/cache/CacheStrategy.java | 6 +- .../reg/newzk/client/cache/PathNode.java | 29 ++-- .../reg/newzk/client/cache/PathResolve.java | 4 +- .../reg/newzk/client/cache/PathStatus.java | 5 +- .../reg/newzk/client/cache/PathTree.java | 128 ++++++++---------- .../newzk/client/election/LeaderElection.java | 57 ++++---- .../newzk/client/retry/AsyncRetryCenter.java | 14 +- .../client/retry/DelayPolicyExecutor.java | 24 ++-- .../newzk/client/retry/DelayRetryPolicy.java | 23 +--- .../reg/newzk/client/retry/RetryCallable.java | 23 ++-- .../client/retry/RetryResultCallable.java | 12 +- .../reg/newzk/client/retry/RetryThread.java | 23 ++-- .../reg/newzk/client/utility/PathUtil.java | 8 +- .../client/utility/ZookeeperConstants.java | 6 +- .../newzk/client/zookeeper/CacheClient.java | 26 ++-- .../newzk/client/zookeeper/ClientFactory.java | 18 +-- .../newzk/client/zookeeper/UsualClient.java | 12 +- .../client/zookeeper/base/BaseClient.java | 19 +-- .../zookeeper/base/BaseClientFactory.java | 20 +-- .../client/zookeeper/base/BaseContext.java | 9 +- .../client/zookeeper/base/BaseOperation.java | 21 ++- .../newzk/client/zookeeper/base/Holder.java | 52 ++++--- .../operation/CreateAllNeedOperation.java | 8 +- .../operation/CreateCurrentOperation.java | 8 +- .../operation/DeleteAllChildrenOperation.java | 8 +- .../DeleteCurrentBranchOperation.java | 8 +- .../operation/DeleteCurrentOperation.java | 6 +- .../zookeeper/operation/UpdateOperation.java | 6 +- .../zookeeper/provider/BaseProvider.java | 32 ++--- .../provider/TransactionProvider.java | 8 +- .../zookeeper/section/ClientContext.java | 23 ++-- .../client/zookeeper/section/ClientTask.java | 6 +- .../client/zookeeper/section/Connection.java | 4 +- .../zookeeper/section/StrategyType.java | 2 +- .../zookeeper/section/WatcherCreator.java | 4 +- .../section/ZookeeperEventListener.java | 4 +- .../strategy/AsyncRetryStrategy.java | 2 +- .../zookeeper/strategy/BaseStrategy.java | 10 +- .../strategy/ContentionStrategy.java | 46 ++++--- .../zookeeper/strategy/SyncRetryStrategy.java | 6 +- .../strategy/TransactionContendStrategy.java | 36 ++--- .../zookeeper/strategy/UsualStrategy.java | 52 +++---- .../transaction/BaseTransaction.java | 36 ++--- ...saction.java => ZooKeeperTransaction.java} | 38 +++--- .../client/zookeeper/base/TestClient.java | 4 +- 53 files changed, 550 insertions(+), 604 deletions(-) rename sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/transaction/{ZKTransaction.java => ZooKeeperTransaction.java} (67%) diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/NewZookeeperRegistryCenter.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/NewZookeeperRegistryCenter.java index 2c7167513db96..0e18f5e568f7b 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/NewZookeeperRegistryCenter.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/NewZookeeperRegistryCenter.java @@ -18,6 +18,7 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk; import com.google.common.base.Charsets; +import com.google.common.base.Optional; import com.google.common.base.Strings; import io.shardingsphere.jdbc.orchestration.reg.api.RegistryCenter; import io.shardingsphere.jdbc.orchestration.reg.exception.RegExceptionHandler; @@ -31,6 +32,11 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.StrategyType; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.ZookeeperEventListener; import io.shardingsphere.jdbc.orchestration.reg.zookeeper.ZookeeperConfiguration; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; +import org.apache.zookeeper.ZooDefs; + import java.io.IOException; import java.util.Collections; import java.util.Comparator; @@ -39,10 +45,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; -import org.apache.zookeeper.CreateMode; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.WatchedEvent; -import org.apache.zookeeper.ZooDefs; /** * Zookeeper native based registry center. @@ -53,62 +55,60 @@ public final class NewZookeeperRegistryCenter implements RegistryCenter { private final IClient client; - private final Map caches = new HashMap<>(); + private final Map caches; public NewZookeeperRegistryCenter(final ZookeeperConfiguration zkConfig) { - final ClientFactory creator = buildCreator(zkConfig); - client = initClient(creator, zkConfig); + client = initClient(buildClientFactory(zkConfig), zkConfig); + caches = new HashMap<>(); } - private ClientFactory buildCreator(final ZookeeperConfiguration zkConfig) { - final ClientFactory creator = new ClientFactory(); - creator.setClientNamespace(zkConfig.getNamespace()) - .newClient(zkConfig.getServerLists(), zkConfig.getSessionTimeoutMilliseconds()) + private ClientFactory buildClientFactory(final ZookeeperConfiguration zkConfig) { + ClientFactory result = new ClientFactory(); + result.setClientNamespace(zkConfig.getNamespace()).newClient(zkConfig.getServerLists(), zkConfig.getSessionTimeoutMilliseconds()) .setRetryPolicy(new DelayRetryPolicy(zkConfig.getBaseSleepTimeMilliseconds(), zkConfig.getMaxRetries(), zkConfig.getMaxSleepTimeMilliseconds())); if (!Strings.isNullOrEmpty(zkConfig.getDigest())) { - creator.authorization("digest", zkConfig.getDigest().getBytes(Charsets.UTF_8), ZooDefs.Ids.CREATOR_ALL_ACL); + result.authorization("digest", zkConfig.getDigest().getBytes(Charsets.UTF_8), ZooDefs.Ids.CREATOR_ALL_ACL); } - return creator; + return result; } - private IClient initClient(final ClientFactory creator, final ZookeeperConfiguration zkConfig) { - IClient newClient = null; + private IClient initClient(final ClientFactory clientFactory, final ZookeeperConfiguration zkConfig) { + IClient result = null; try { - // todo There is a bug when the start time is very short, and I haven't found the reason yet - // newClient = creator.start(zkConfig.getMaxSleepTimeMilliseconds() * zkConfig.getMaxRetries(), TimeUnit.MILLISECONDS); - newClient = creator.start(); - if (!newClient.blockUntilConnected(zkConfig.getMaxSleepTimeMilliseconds() * zkConfig.getMaxRetries(), TimeUnit.MILLISECONDS)) { - newClient.close(); + // TODO There is a bug when the start time is very short, and I haven't found the reason yet + // result = clientFactory.start(zkConfig.getMaxSleepTimeMilliseconds() * zkConfig.getMaxRetries(), TimeUnit.MILLISECONDS); + result = clientFactory.start(); + if (!result.blockUntilConnected(zkConfig.getMaxSleepTimeMilliseconds() * zkConfig.getMaxRetries(), TimeUnit.MILLISECONDS)) { + result.close(); throw new KeeperException.OperationTimeoutException(); } - - newClient.useExecStrategy(StrategyType.SYNC_RETRY); + result.useExecStrategy(StrategyType.SYNC_RETRY); } catch (final KeeperException.OperationTimeoutException | IOException | InterruptedException ex) { RegExceptionHandler.handleException(ex); } - return newClient; + return result; } @Override public String get(final String key) { - final PathTree cache = findTreeCache(key); - if (null == cache) { + Optional cache = findTreeCache(key); + if (!cache.isPresent()) { return getDirectly(key); } - byte[] resultInCache = cache.getValue(key); + byte[] resultInCache = cache.get().getValue(key); if (null != resultInCache) { - return null == resultInCache ? null : new String(resultInCache, Charsets.UTF_8); + return new String(resultInCache, Charsets.UTF_8); } return getDirectly(key); } - private PathTree findTreeCache(final String key) { + private Optional findTreeCache(final String key) { for (Entry entry : caches.entrySet()) { if (key.startsWith(entry.getKey())) { - return entry.getValue(); + return Optional.of(entry.getValue()); } } - return null; + return Optional.absent(); } @Override @@ -185,23 +185,19 @@ public void persistEphemeral(final String key, final String value) { @Override public void watch(final String key, final EventListener eventListener) { - final String path = key + "/"; + String path = key + "/"; if (!caches.containsKey(path)) { addCacheData(key); } - final PathTree cache = caches.get(path); + PathTree cache = caches.get(path); cache.watch(new ZookeeperEventListener() { @Override public void process(final WatchedEvent event) { if (!Strings.isNullOrEmpty(event.getPath())) { - eventListener.onChange(new DataChangedEvent(getEventType(event), event.getPath(), getWithoutCache(event.getPath()))); + eventListener.onChange(new DataChangedEvent(extractEventType(event), event.getPath(), getWithoutCache(event.getPath()))); } } - - private DataChangedEvent.Type getEventType(final WatchedEvent event) { - return extractEventType(event); - } }); } @@ -230,7 +226,7 @@ private synchronized String getWithoutCache(final String key) { } private void addCacheData(final String cachePath) { - final PathTree cache = new PathTree(cachePath, client); + PathTree cache = new PathTree(cachePath, client); try { cache.load(); cache.watch(); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/ContentionCallback.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/ContentionCallback.java index 105941acaf45d..23d942b2a0d02 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/ContentionCallback.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/ContentionCallback.java @@ -17,7 +17,7 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk.client.action; -/* +/** * Callback on contention has not reached. * * @author lidongbo @@ -25,7 +25,7 @@ public interface ContentionCallback { /** - * Process callback result. - */ + * Process callback result. + */ void processResult(); } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IAction.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IAction.java index 905961e92bd13..a20d3433f632c 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IAction.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IAction.java @@ -24,7 +24,7 @@ import java.util.List; -/* +/** * The basic actions of the client. * * @author lidongbo @@ -36,8 +36,8 @@ public interface IAction { * * @param key key * @return data String - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ String getDataString(String key) throws KeeperException, InterruptedException; @@ -46,8 +46,8 @@ public interface IAction { * * @param key key * @return data - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ byte[] getData(String key) throws KeeperException, InterruptedException; @@ -56,9 +56,9 @@ public interface IAction { * * @param key key * @param callback callback - * @param ctx ctx - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @param ctx context + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void getData(String key, AsyncCallback.DataCallback callback, Object ctx) throws KeeperException, InterruptedException; @@ -66,9 +66,9 @@ public interface IAction { * Check exist. * * @param key key - * @return exist - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @return exist or not + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ boolean checkExists(String key) throws KeeperException, InterruptedException; @@ -77,9 +77,9 @@ public interface IAction { * * @param key key * @param watcher watcher - * @return exist - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @return exist or not + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ boolean checkExists(String key, Watcher watcher) throws KeeperException, InterruptedException; @@ -88,8 +88,8 @@ public interface IAction { * * @param key key * @return children keys - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ List getChildren(String key) throws KeeperException, InterruptedException; @@ -99,8 +99,8 @@ public interface IAction { * @param key key * @param value value * @param createMode createMode - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void createCurrentOnly(String key, String value, CreateMode createMode) throws KeeperException, InterruptedException; @@ -109,8 +109,8 @@ public interface IAction { * * @param key key * @param value value - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void update(String key, String value) throws KeeperException, InterruptedException; @@ -118,8 +118,8 @@ public interface IAction { * Only delete target node.. * * @param key key - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void deleteOnlyCurrent(String key) throws KeeperException, InterruptedException; @@ -128,9 +128,9 @@ public interface IAction { * * @param key key * @param callback callback - * @param ctx ctx - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @param ctx context + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void deleteOnlyCurrent(String key, AsyncCallback.VoidCallback callback, Object ctx) throws KeeperException, InterruptedException; } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java index 9706f14bb5725..5d2d2c0f6914f 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java @@ -24,8 +24,8 @@ import java.io.IOException; import java.util.concurrent.TimeUnit; -/* - * Client api. +/** + * Client API. * * @author lidongbo */ @@ -34,42 +34,37 @@ public interface IClient extends IAction, IGroupAction { /** * Start. * - * @throws IOException IO Exception - * @throws InterruptedException InterruptedException + * @throws IOException IO exception + * @throws InterruptedException interrupted exception */ void start() throws IOException, InterruptedException; /** * Start until out. * - * @param wait wait - * @param units units - * @return connected - * @throws IOException IO Exception - * @throws InterruptedException InterruptedException + * @param waitingTime waiting time + * @param timeUnit time unit + * @return connected or not + * @throws IOException IO exception + * @throws InterruptedException interrupted exception */ - boolean start(int wait, TimeUnit units) throws IOException, InterruptedException; + boolean start(int waitingTime, TimeUnit timeUnit) throws IOException, InterruptedException; /** * Block until connected. * - * @param wait wait - * @param units units - * @return connected - * @throws InterruptedException InterruptedException - */ - boolean blockUntilConnected(int wait, TimeUnit units) throws InterruptedException; - - /** - * Close. + * @param waitingTime waiting time + * @param timeUnit time unit + * @return connected or not + * @throws InterruptedException interrupted exception */ - void close(); + boolean blockUntilConnected(int waitingTime, TimeUnit timeUnit) throws InterruptedException; /** * Register watcher. * * @param key key - * @param zookeeperEventListener listener + * @param zookeeperEventListener zookeeper event listener */ void registerWatch(String key, ZookeeperEventListener zookeeperEventListener); @@ -88,9 +83,14 @@ public interface IClient extends IAction, IGroupAction { void useExecStrategy(StrategyType strategyType); /** - * Create transaction. + * Create zookeeper transaction. * - * @return ZKTransaction + * @return zookeeper transaction */ BaseTransaction transaction(); + + /** + * Close. + */ + void close(); } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IExecStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IExecStrategy.java index 012172bcfdc45..d7f587ad9efe8 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IExecStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IExecStrategy.java @@ -19,7 +19,7 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.transaction.BaseTransaction; -/* +/** * Client 's execution strategy. * * @author lidongbo @@ -29,14 +29,14 @@ public interface IExecStrategy extends IAction, IGroupAction { /** * Get provider. * - * @return IProvider + * @return provider */ IProvider getProvider(); /** - * Create transaction. + * Create zookeeper transaction. * - * @return BaseTransaction + * @return zookeeper transaction */ BaseTransaction transaction(); } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IGroupAction.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IGroupAction.java index 75e2b1aaf1bc3..03a79e49a2f64 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IGroupAction.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IGroupAction.java @@ -20,7 +20,7 @@ import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -/* +/** * One action contains a group operation. * * @author lidongbo @@ -32,9 +32,9 @@ public interface IGroupAction { * * @param key key * @param value value - * @param createMode createMode - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @param createMode create mode + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void createAllNeedPath(String key, String value, CreateMode createMode) throws KeeperException, InterruptedException; @@ -42,8 +42,8 @@ public interface IGroupAction { * Delete target node and children nodes. * * @param key key - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void deleteAllChildren(String key) throws KeeperException, InterruptedException; @@ -51,8 +51,8 @@ public interface IGroupAction { * 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 InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void deleteCurrentBranch(String key) throws KeeperException, InterruptedException; } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IProvider.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IProvider.java index 845603eab686e..c2414251b0da2 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IProvider.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IProvider.java @@ -27,8 +27,8 @@ import java.util.List; import java.util.Stack; -/* - * Provider api. +/** + * Provider API. * * @author lidongbo */ @@ -39,8 +39,8 @@ public interface IProvider { * * @param key key * @return data String - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ String getDataString(String key) throws KeeperException, InterruptedException; @@ -49,8 +49,8 @@ public interface IProvider { * * @param key key * @return data - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ byte[] getData(String key) throws KeeperException, InterruptedException; @@ -60,8 +60,8 @@ public interface IProvider { * @param key key * @param callback callback * @param ctx ctx - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void getData(String key, AsyncCallback.DataCallback callback, Object ctx) throws KeeperException, InterruptedException; @@ -70,8 +70,8 @@ public interface IProvider { * * @param key key * @return exist - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ boolean exists(String key) throws KeeperException, InterruptedException; @@ -81,8 +81,8 @@ public interface IProvider { * @param key key * @param watcher watcher * @return exist - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ boolean exists(String key, Watcher watcher) throws KeeperException, InterruptedException; @@ -91,8 +91,8 @@ public interface IProvider { * * @param key key * @return exist - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ List getChildren(String key) throws KeeperException, InterruptedException; @@ -101,9 +101,9 @@ public interface IProvider { * * @param key key * @param value value - * @param createMode createMode - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @param createMode create mode + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void create(String key, String value, CreateMode createMode) throws KeeperException, InterruptedException; @@ -113,8 +113,8 @@ public interface IProvider { * @param key key * @param value value * @return is success - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ boolean update(String key, String value) throws KeeperException, InterruptedException; @@ -122,19 +122,19 @@ public interface IProvider { * Only delete target node.. * * @param key key - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void delete(String key) throws KeeperException, InterruptedException; /** - * Only delete target node.. + * Only delete target node. * * @param key key * @param callback callback * @param ctx ctx - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ void delete(String key, AsyncCallback.VoidCallback callback, Object ctx) throws KeeperException, InterruptedException; @@ -166,7 +166,7 @@ public interface IProvider { * Contention exec. * * @param election election - * @throws KeeperException Zookeeper Exception + * @throws KeeperException zookeeper exception * @throws InterruptedException InterruptedException */ void executeContention(LeaderElection election) throws KeeperException, InterruptedException; @@ -177,9 +177,9 @@ public interface IProvider { void resetConnection(); /** - * Create transaction. + * Create zookeeper transaction. * - * @return BaseTransaction + * @return zookeeper transaction */ BaseTransaction transaction(); } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/ITransactionProvider.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/ITransactionProvider.java index 6acb30d5c1716..fe53483e4becb 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/ITransactionProvider.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/ITransactionProvider.java @@ -20,7 +20,7 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.transaction.BaseTransaction; import org.apache.zookeeper.CreateMode; -/* +/** * Provider with transaction. * * @author lidongbo @@ -32,8 +32,8 @@ public interface ITransactionProvider extends IProvider { * * @param key key * @param value value - * @param createMode createMode - * @param transaction transaction + * @param createMode create mode + * @param transaction zookeeper transaction */ void createInTransaction(String key, String value, CreateMode createMode, BaseTransaction transaction); } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/CacheStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/CacheStrategy.java index 9a43f0790b651..2e3260d6f2f90 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/CacheStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/CacheStrategy.java @@ -17,14 +17,12 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk.client.cache; -/* +/** * Cache strategy. * * @author lidongbo */ public enum CacheStrategy { - NONE, - WATCH, - ALL + NONE, WATCH, ALL } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathNode.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathNode.java index d46a4651ab3e8..22ecbbc5376a2 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathNode.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathNode.java @@ -19,33 +19,29 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.PathUtil; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.ZookeeperConstants; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; -/* +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** * Zookeeper node cache. * * @author lidongbo */ +@Getter +@Setter @Slf4j public final class PathNode { - @Getter private final Map children = new ConcurrentHashMap<>(); - - @Getter + private final String nodeKey; - @Getter(value = AccessLevel.PACKAGE) - @Setter(value = AccessLevel.PACKAGE) private String path; - - @Getter(value = AccessLevel.PACKAGE) - @Setter(value = AccessLevel.PACKAGE) + private byte[] value; PathNode(final String key) { @@ -58,13 +54,8 @@ public final class PathNode { this.path = key; } - /** - * Attach child node. - * - * @param node node - */ void attachChild(final PathNode node) { - this.children.put(node.nodeKey, node); + children.put(node.nodeKey, node); node.setPath(PathUtil.getRealPath(path, node.getNodeKey())); } @@ -74,7 +65,7 @@ PathNode set(final PathResolve pathResolve, final String value) { return this; } pathResolve.next(); - log.debug("PathNode set:{},value:{}", pathResolve.getCurrent(), value); + log.debug("PathNode set: {}, value: {}", pathResolve.getCurrent(), value); if (children.containsKey(pathResolve.getCurrent())) { return children.get(pathResolve.getCurrent()).set(pathResolve, value); } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathResolve.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathResolve.java index 322f971ae6c96..1f04fde02ccf2 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathResolve.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathResolve.java @@ -21,14 +21,14 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -/* +/** * Path hierarchy resolve. * * @author lidongbo */ @Slf4j @RequiredArgsConstructor -class PathResolve { +final class PathResolve { @Getter private final String path; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathStatus.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathStatus.java index 029d0db8d8eda..5768454450c24 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathStatus.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathStatus.java @@ -17,13 +17,12 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk.client.cache; -/* +/** * Path status. * * @author lidongbo */ public enum PathStatus { - CHANGING, - RELEASE + CHANGING, RELEASE } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java index 31d81ce77ef5e..025cfa6ff2bf1 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java @@ -25,42 +25,42 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.ZookeeperConstants; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.UsualClient; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.ZookeeperEventListener; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; + import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.ReentrantLock; -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.WatchedEvent; -/* +/** * Zookeeper cache tree. * * @author lidongbo */ @Slf4j -public final class PathTree { +public final class PathTree implements AutoCloseable { - private final transient ReentrantLock lock = new ReentrantLock(); + private final IClient client; + + private final IProvider provider; private final AtomicReference rootNode = new AtomicReference<>(); private final List watcherKeys = new ArrayList<>(); + private final transient ReentrantLock lock = new ReentrantLock(); + private boolean executorStart; private ScheduledExecutorService cacheService; - private final IClient client; - - private final IProvider provider; - @Getter @Setter private PathStatus status; @@ -68,11 +68,11 @@ public final class PathTree { private boolean closed; public PathTree(final String root, final IClient client) { - this.rootNode.set(new PathNode(root)); - this.status = PathStatus.RELEASE; + rootNode.set(new PathNode(root)); + status = PathStatus.RELEASE; this.client = client; - // todo It looks unpleasant - this.provider = ((UsualClient) client).getStrategy().getProvider(); + // TODO It looks unpleasant + provider = ((UsualClient) client).getStrategy().getProvider(); } /** @@ -82,30 +82,28 @@ public PathTree(final String root, final IClient client) { * @throws InterruptedException InterruptedException */ public void load() throws KeeperException, InterruptedException { - final ReentrantLock lock = this.lock; + ReentrantLock lock = this.lock; lock.lockInterruptibly(); if (closed) { return; } try { if (status == PathStatus.RELEASE) { - log.debug("loading status:{}", status); + log.debug("loading status: {}", status); status = PathStatus.CHANGING; - - final PathNode newRoot = new PathNode(rootNode.get().getNodeKey()); - final List children = provider.getChildren(PathUtil.checkPath(rootNode.get().getNodeKey())); + PathNode newRoot = new PathNode(rootNode.get().getNodeKey()); + List children = provider.getChildren(PathUtil.checkPath(rootNode.get().getNodeKey())); children.remove(ZookeeperConstants.CHANGING_KEY); attachIntoNode(children, newRoot); rootNode.set(newRoot); - status = PathStatus.RELEASE; - log.debug("loading release:{}", status); + log.debug("loading release: {}", status); } else { log.info("loading but cache status not release"); try { Thread.sleep(10L); } catch (final InterruptedException ex) { - log.error("loading sleep error:{}", ex.getMessage(), ex); + log.error("loading sleep error: {}", ex.getMessage(), ex); } load(); } @@ -118,16 +116,16 @@ private void attachIntoNode(final List children, final PathNode pathNode if (closed) { return; } - log.debug("attechIntoNode children:{}", children); + log.debug("attachIntoNode children: {}", children); if (children.isEmpty()) { - log.info("attechIntoNode there are no children"); + log.info("attachIntoNode there are no children"); return; } for (String each : children) { - final String childPath = PathUtil.getRealPath(pathNode.getPath(), each); - final PathNode current = new PathNode(each, provider.getData(childPath)); + String childPath = PathUtil.getRealPath(pathNode.getPath(), each); + PathNode current = new PathNode(each, provider.getData(childPath)); pathNode.attachChild(current); - final List subs = provider.getChildren(childPath); + List subs = provider.getChildren(childPath); attachIntoNode(subs, current); } } @@ -138,7 +136,7 @@ private void attachIntoNode(final List children, final PathNode pathNode * @param period period */ public void refreshPeriodic(final long period) { - final ReentrantLock lock = this.lock; + ReentrantLock lock = this.lock; lock.lock(); if (closed) { return; @@ -149,12 +147,13 @@ public void refreshPeriodic(final long period) { if (threadPeriod < 1) { threadPeriod = ZookeeperConstants.THREAD_PERIOD; } - log.debug("refreshPeriodic:{}", period); + log.debug("refreshPeriodic: {}", period); cacheService = Executors.newSingleThreadScheduledExecutor(); cacheService.scheduleAtFixedRate(new Runnable() { + @Override public void run() { - log.debug("cacheService run:{}", getStatus()); + log.debug("cacheService run: {}", getStatus()); if (PathStatus.RELEASE == getStatus()) { try { load(); @@ -166,6 +165,7 @@ public void run() { }, ZookeeperConstants.THREAD_INITIAL_DELAY, threadPeriod, TimeUnit.MILLISECONDS); executorStart = true; Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + @Override public void run() { log.debug("cacheService stop"); @@ -183,7 +183,7 @@ public void run() { public void stopRefresh() { cacheService.shutdown(); executorStart = false; - log.debug("stopRefresh"); + log.debug("stop refresh"); } /** @@ -191,10 +191,11 @@ public void stopRefresh() { */ public void watch() { watch(new ZookeeperEventListener(rootNode.get().getNodeKey()) { + @Override public void process(final WatchedEvent event) { String path = event.getPath(); - log.debug("PathTree Watch event:{}", event.toString()); + log.debug("PathTree Watch event: {}", event.toString()); switch (event.getType()) { case NodeCreated: case NodeDataChanged: @@ -220,15 +221,15 @@ public void watch(final ZookeeperEventListener zookeeperEventListener) { if (closed) { return; } - final String key = zookeeperEventListener.getKey(); - log.debug("PathTree Watch:{}", key); + String key = zookeeperEventListener.getKey(); + log.debug("PathTree Watch: {}", key); client.registerWatch(rootNode.get().getNodeKey(), zookeeperEventListener); watcherKeys.add(key); } private void processNodeChange(final String path) { try { - final String value = provider.getDataString(path); + String value = provider.getDataString(path); put(path, value); } catch (final KeeperException | InterruptedException ex) { if (ex instanceof KeeperException.NoNodeException || ex instanceof KeeperException.ConnectionLossException) { @@ -239,15 +240,6 @@ private void processNodeChange(final String path) { } } - /** - * Get root node. - * - * @return root node - */ - public PathNode getRootNode() { - return rootNode.get(); - } - /** * Get node value. * @@ -258,7 +250,7 @@ public byte[] getValue(final String path) { if (closed) { return null; } - final PathNode node = get(path); + PathNode node = get(path); return null == node ? null : node.getValue(); } @@ -272,8 +264,8 @@ public List getChildren(final String path) { if (closed) { return null; } - final PathNode node = get(path); - final List result = new ArrayList<>(); + PathNode node = get(path); + List result = new ArrayList<>(); if (node == null) { log.info("getChildren null"); return result; @@ -282,20 +274,19 @@ public List getChildren(final String path) { log.info("getChildren no child"); return result; } - final Iterator children = node.getChildren().values().iterator(); - while (children.hasNext()) { - result.add(new String(children.next().getValue())); + for (final PathNode pathNode : node.getChildren().values()) { + result.add(new String(pathNode.getValue())); } return result; } private PathNode get(final String path) { - log.debug("PathTree get:{}", path); + log.debug("PathTree get: {}", path); if (Strings.isNullOrEmpty(path) || path.equals(ZookeeperConstants.PATH_SEPARATOR)) { return rootNode.get(); } - final String realPath = provider.getRealPath(path); - final PathResolve pathResolve = new PathResolve(realPath); + String realPath = provider.getRealPath(path); + PathResolve pathResolve = new PathResolve(realPath); pathResolve.next(); if (pathResolve.isEnd()) { log.info("path node get() hit root!"); @@ -311,7 +302,7 @@ private PathNode get(final String path) { * @param value value */ public void put(final String path, final String value) { - final ReentrantLock lock = this.lock; + ReentrantLock lock = this.lock; lock.lock(); if (closed) { return; @@ -319,12 +310,12 @@ public void put(final String path, final String value) { try { log.debug("cache put:{},value:{},status:{}", path, value, status); if (status == PathStatus.RELEASE) { - this.setStatus(PathStatus.CHANGING); - final String realPath = provider.getRealPath(path); - final PathResolve pathResolve = new PathResolve(realPath); + setStatus(PathStatus.CHANGING); + String realPath = provider.getRealPath(path); + PathResolve pathResolve = new PathResolve(realPath); pathResolve.next(); rootNode.get().set(pathResolve, value); - this.setStatus(PathStatus.RELEASE); + setStatus(PathStatus.RELEASE); } else { try { log.debug("put but cache status not release"); @@ -346,19 +337,18 @@ public void put(final String path, final String value) { */ public void delete(final String path) { log.debug("PathTree begin delete:{}", path); - final ReentrantLock lock = this.lock; + ReentrantLock lock = this.lock; lock.lock(); if (closed) { return; } - try { if (rootNode.get().getChildren().containsKey(path)) { rootNode.get().getChildren().remove(path); return; } - final String realPath = provider.getRealPath(path); - final PathResolve pathResolve = new PathResolve(realPath); + String realPath = provider.getRealPath(path); + PathResolve pathResolve = new PathResolve(realPath); pathResolve.next(); rootNode.get().delete(pathResolve); log.debug("PathTree end delete:{}", path); @@ -367,13 +357,11 @@ public void delete(final String path) { } } - /** - * Close. - */ + @Override public void close() { - final ReentrantLock lock = this.lock; + ReentrantLock lock = this.lock; lock.lock(); - this.closed = true; + closed = true; try { if (executorStart) { stopRefresh(); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/election/LeaderElection.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/election/LeaderElection.java index 1702e54226fa2..598d89b588c12 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/election/LeaderElection.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/election/LeaderElection.java @@ -27,7 +27,7 @@ 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. * @@ -36,41 +36,24 @@ @Slf4j public abstract class LeaderElection { - private boolean done; - - private int retryCount; + private int retryCount = ZookeeperConstants.NODE_ELECTION_RETRY; - public LeaderElection() { - retryCount = ZookeeperConstants.NODE_ELECTION_RETRY; - } - - private boolean contend(final String node, final IProvider provider, final ZookeeperEventListener zookeeperEventListener) throws KeeperException, InterruptedException { - boolean success = false; - try { - // todo EPHEMERAL_SEQUENTIAL check index value - provider.create(node, ZookeeperConstants.CLIENT_ID, CreateMode.EPHEMERAL); - success = true; - } catch (final KeeperException.NodeExistsException ex) { - log.info("contend not success"); - // TODO or changing_key node value == current client id - provider.exists(node, WatcherCreator.deleteWatcher(zookeeperEventListener)); - } - return success; - } + private boolean done; /** * Listener will be register when the contention of the path is unsuccessful. * - * @param nodeBeContend nodeBeContend + * @param nodeBeContend node be contend * @param provider provider - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @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); - final String contendNode = PathUtil.getRealPath(realNode, ZookeeperConstants.CHANGING_KEY); - canBegin = this.contend(contendNode, provider, new ZookeeperEventListener(contendNode) { + String contendNode = PathUtil.getRealPath(realNode, ZookeeperConstants.CHANGING_KEY); + canBegin = contend(contendNode, provider, new ZookeeperEventListener(contendNode) { + @Override public void process(final WatchedEvent event) { try { @@ -85,7 +68,6 @@ public void process(final WatchedEvent event) { } } }); - if (canBegin) { try { action(); @@ -98,6 +80,20 @@ public void process(final WatchedEvent event) { } } + 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. */ @@ -112,10 +108,10 @@ public void waitDone() { } /** - * Contend exec. + * Contend execute. * - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ public abstract void action() throws KeeperException, InterruptedException; @@ -123,6 +119,5 @@ public void waitDone() { * Callback. */ public void callback() { - } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/AsyncRetryCenter.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/AsyncRetryCenter.java index 2276006edd6b4..d6e9afe619d2e 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/AsyncRetryCenter.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/AsyncRetryCenter.java @@ -22,7 +22,7 @@ import java.util.concurrent.DelayQueue; -/* +/** * Async retry center. * * @author lidongbo @@ -41,13 +41,13 @@ public enum AsyncRetryCenter { private DelayRetryPolicy delayRetryPolicy; /** - * init. + * Initialize. * - * @param delayRetryPolicy delayRetryPolicy + * @param delayRetryPolicy delay retry policy */ public void init(final DelayRetryPolicy delayRetryPolicy) { log.debug("delayRetryPolicy init"); - if (delayRetryPolicy == null) { + if (null == delayRetryPolicy) { log.warn("delayRetryPolicy is null and auto init with DelayRetryPolicy.defaultDelayPolicy"); this.delayRetryPolicy = DelayRetryPolicy.defaultDelayPolicy(); return; @@ -64,7 +64,7 @@ public synchronized void start() { } retryThread.setName("retry-thread"); retryThread.start(); - this.started = true; + started = true; } /** @@ -73,12 +73,12 @@ public synchronized void start() { * @param operation operation */ public void add(final BaseOperation operation) { - if (delayRetryPolicy == null) { + if (null == delayRetryPolicy) { log.warn("delayRetryPolicy no init and auto init with DelayRetryPolicy.defaultDelayPolicy"); delayRetryPolicy = DelayRetryPolicy.defaultDelayPolicy(); } operation.setDelayPolicyExecutor(new DelayPolicyExecutor(delayRetryPolicy)); queue.offer(operation); - log.debug("enqueue operation:{}", operation.toString()); + log.debug("enqueue operation: {}", operation.toString()); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/DelayPolicyExecutor.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/DelayPolicyExecutor.java index 481c58ddfafba..a254a9a202f1a 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/DelayPolicyExecutor.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/DelayPolicyExecutor.java @@ -17,35 +17,27 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk.client.retry; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import java.util.Random; -/* +/** * Delay policy executor. * * @author lidongbo */ +@RequiredArgsConstructor @Slf4j -public class DelayPolicyExecutor { +public final class DelayPolicyExecutor { private final DelayRetryPolicy delayRetryPolicy; - private final Random random; + private final Random random = new Random(); private int executeCount; - private long executeTick; - - public DelayPolicyExecutor() { - this(DelayRetryPolicy.defaultDelayPolicy()); - } - - public DelayPolicyExecutor(final DelayRetryPolicy delayRetryPolicy) { - this.delayRetryPolicy = delayRetryPolicy; - this.executeTick = System.currentTimeMillis(); - this.random = new Random(); - } + private long executeTick = System.currentTimeMillis(); /** * Has next. @@ -57,9 +49,9 @@ public boolean hasNext() { } /** - * Next exec tick. + * Next execute tick. * - * @return next exec tick + * @return next execute tick */ public long getNextTick() { return executeTick; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/DelayRetryPolicy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/DelayRetryPolicy.java index 05d245387a50e..1297501fc8e80 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/DelayRetryPolicy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/DelayRetryPolicy.java @@ -18,12 +18,15 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk.client.retry; import lombok.Getter; +import lombok.RequiredArgsConstructor; -/* - * Delay policy +/** + * Delay policy. * * @author lidongbo */ +@RequiredArgsConstructor +@Getter public class DelayRetryPolicy { private static final long BASE_DELAY = 10; @@ -32,32 +35,20 @@ public class DelayRetryPolicy { private static final int RETRY_COUNT_BOUND = 29; - @Getter private final int retryCount; - @Getter private final long baseDelay; - @Getter private final long delayUpperBound; - /* - * Millis - */ public DelayRetryPolicy(final long baseDelay) { this(RETRY_COUNT_BOUND, baseDelay, Integer.MAX_VALUE); } - public DelayRetryPolicy(final int retryCount, final long baseDelay, final long delayUpperBound) { - this.retryCount = retryCount; - this.baseDelay = baseDelay; - this.delayUpperBound = delayUpperBound; - } - /** - * Default DelayPolicy. + * Default delay policy. * - * @return DelayPolicy + * @return delay policy */ public static DelayRetryPolicy defaultDelayPolicy() { return new DelayRetryPolicy(BASE_COUNT, BASE_DELAY, Integer.MAX_VALUE); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryCallable.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryCallable.java index 32f9ac79c9337..39170dd4ff5bb 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryCallable.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryCallable.java @@ -24,44 +24,43 @@ import lombok.extern.slf4j.Slf4j; import org.apache.zookeeper.KeeperException; -/* +/** * Sync retry call. * * @author lidongbo */ @Slf4j +@Getter(value = AccessLevel.PROTECTED) public abstract class RetryCallable { - @Getter(value = AccessLevel.PROTECTED) - private final DelayPolicyExecutor delayPolicyExecutor; - - @Getter(value = AccessLevel.PROTECTED) private final IProvider provider; + private final DelayPolicyExecutor delayPolicyExecutor; + public RetryCallable(final IProvider provider, final DelayRetryPolicy delayRetryPolicy) { - this.delayPolicyExecutor = new DelayPolicyExecutor(delayRetryPolicy); this.provider = provider; + delayPolicyExecutor = new DelayPolicyExecutor(delayRetryPolicy); } /** * Call the action. * - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ public abstract void call() throws KeeperException, InterruptedException; /** * Call without result. * - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ public void exec() throws KeeperException, InterruptedException { try { call(); } catch (final KeeperException ex) { - log.warn("exec KeeperException:{}", ex.getMessage()); + log.warn("exec KeeperException: {}", ex.getMessage()); delayPolicyExecutor.next(); if (Connection.needReset(ex)) { provider.resetConnection(); @@ -74,7 +73,7 @@ private void execDelay() throws KeeperException, InterruptedException { for (;;) { long delay = delayPolicyExecutor.getNextTick() - System.currentTimeMillis(); if (delay > 0) { - log.debug("exec delay:{}", delay); + log.debug("exec delay: {}", delay); Thread.sleep(delay); } else { if (delayPolicyExecutor.hasNext()) { diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryResultCallable.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryResultCallable.java index 8cc889d8d1f78..ca06dc8507426 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryResultCallable.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryResultCallable.java @@ -22,8 +22,8 @@ import lombok.extern.slf4j.Slf4j; import org.apache.zookeeper.KeeperException; -/* - * Sync retry call with Result. +/** + * Sync retry call with result. * * @author lidongbo */ @@ -41,14 +41,14 @@ public RetryResultCallable(final IProvider provider, final DelayRetryPolicy dela * Get result. * * @return result - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ public T getResult() throws KeeperException, InterruptedException { - if (result == null) { + if (null == result) { exec(); } - log.debug("result:{}", result); + log.debug("result: {}", result); return result; } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryThread.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryThread.java index ac8209ef90eff..e84a5e8a7c0c9 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryThread.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/RetryThread.java @@ -19,6 +19,7 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.base.BaseOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.zookeeper.KeeperException; import java.util.concurrent.DelayQueue; import java.util.concurrent.ExecutorService; @@ -27,9 +28,8 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.zookeeper.KeeperException; -/* +/** * Async retry. * * @author lidongbo @@ -39,8 +39,6 @@ public final class RetryThread extends Thread { private final int corePoolSize = Runtime.getRuntime().availableProcessors(); - private final ThreadPoolExecutor retryExecutor; - private final int maximumPoolSize = corePoolSize; private final long keepAliveTime = 0; @@ -49,6 +47,8 @@ public final class RetryThread extends Thread { private final DelayQueue queue; + private final ThreadPoolExecutor retryExecutor; + public RetryThread(final DelayQueue queue) { this.queue = queue; retryExecutor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(10), new ThreadFactory() { @@ -56,11 +56,11 @@ public RetryThread(final DelayQueue queue) { private final AtomicInteger threadIndex = new AtomicInteger(0); @Override - public Thread newThread(final Runnable r) { - Thread thread = new Thread(r); + public Thread newThread(final Runnable runnable) { + Thread thread = new Thread(runnable); thread.setDaemon(true); thread.setName("zk-retry-" + threadIndex.incrementAndGet()); - log.debug("new thread:{}", thread.getName()); + log.debug("new thread: {}", thread.getName()); return thread; } }); @@ -74,9 +74,9 @@ public void run() { final BaseOperation operation; try { operation = queue.take(); - log.debug("take operation:{}", operation.toString()); + log.debug("take operation: {}", operation.toString()); } catch (final InterruptedException ex) { - log.error("retry interrupt ex:{}", ex.getMessage()); + log.error("retry interrupt ex: {}", ex.getMessage()); continue; } retryExecutor.submit(new Runnable() { @@ -88,11 +88,11 @@ public void run() { result = operation.executeOperation(); } catch (final KeeperException | InterruptedException ex) { result = false; - log.error("retry disrupt operation:{}, ex:{}", operation.toString(), ex.getMessage()); + log.error("retry disrupt operation: {}, ex: {}", operation.toString(), ex.getMessage()); } if (result) { queue.offer(operation); - log.debug("enqueue again operation:{}", operation.toString()); + log.debug("enqueue again operation: {}", operation.toString()); } } }); @@ -110,7 +110,6 @@ public void run() { service.shutdown(); service.awaitTermination(terminationTimeout, timeUnit); } catch (final InterruptedException ignored) { - // shutting down anyway, just ignore. } } }); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/utility/PathUtil.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/utility/PathUtil.java index 9ea8be75d0534..34f41978b31c1 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/utility/PathUtil.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/utility/PathUtil.java @@ -19,16 +19,20 @@ 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 */ -public class PathUtil { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class PathUtil { /** * Get real path. diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/utility/ZookeeperConstants.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/utility/ZookeeperConstants.java index bbd21297766b1..775bf50a4c702 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/utility/ZookeeperConstants.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/utility/ZookeeperConstants.java @@ -17,13 +17,17 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk.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; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/CacheClient.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/CacheClient.java index 2e02745c61e5b..f6f3d580570ed 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/CacheClient.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/CacheClient.java @@ -30,12 +30,12 @@ import java.io.IOException; import java.util.List; -/* +/** * Cache Client. * - * // todo Partially prepared product * @author lidongbo */ +// TODO Partially prepared product @Slf4j public final class CacheClient extends UsualClient { @@ -58,7 +58,7 @@ public void start() throws IOException, InterruptedException { @Override public void close() { super.close(); - this.pathTree.close(); + pathTree.close(); } //todo put it here? @@ -83,11 +83,11 @@ private PathTree loadPathTree() throws KeeperException, InterruptedException { } private PathTree loadPathTree(final String treeRoot) throws KeeperException, InterruptedException { - PathTree tree = new PathTree(treeRoot, this); - log.debug("load path tree:{}", treeRoot); - tree.load(); - tree.watch(); - return tree; + PathTree result = new PathTree(treeRoot, this); + log.debug("load path result: {}", treeRoot); + result.load(); + result.watch(); + return result; } @Override @@ -112,11 +112,11 @@ public void deleteOnlyCurrent(final String key, final AsyncCallback.VoidCallback public byte[] getData(final String key) throws KeeperException, InterruptedException { String path = PathUtil.getRealPath(getRootNode(), key); byte[] data = pathTree.getValue(path); - if (data != null) { - log.debug("getData cache hit:{}", data); + if (null != data) { + log.debug("getData cache hit: {}", key); return data; } - log.debug("getData cache not hit:{}", data); + log.debug("getData cache not hit: {}", key); return getStrategy().getData(key); } @@ -125,10 +125,10 @@ public List getChildren(final String key) throws KeeperException, Interr String path = PathUtil.getRealPath(getRootNode(), key); List keys = pathTree.getChildren(path); if (!keys.isEmpty()) { - log.debug("getChildren cache hit:{}", keys); + log.debug("getChildren cache hit: {}", keys); return keys; } - log.debug("getChildren cache not hit:{}", keys); + log.debug("getChildren cache not hit: {}", keys); return getStrategy().getChildren(PathUtil.getRealPath(getRootNode(), key)); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/ClientFactory.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/ClientFactory.java index 8abef6e2bc48e..62c0728b2daba 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/ClientFactory.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/ClientFactory.java @@ -30,13 +30,13 @@ import java.io.IOException; import java.util.List; -/* +/** * Client factory. * * @author lidongbo */ @Slf4j -public class ClientFactory extends BaseClientFactory { +public final class ClientFactory extends BaseClientFactory { private DelayRetryPolicy delayRetryPolicy; @@ -44,7 +44,7 @@ public class ClientFactory extends BaseClientFactory { * Create a new client. * * @param servers servers - * @param sessionTimeoutMilliseconds sessionTimeoutMilliseconds + * @param sessionTimeoutMilliseconds session timeout milliseconds * @return ClientFactory this */ public ClientFactory newClient(final String servers, final int sessionTimeoutMilliseconds) { @@ -82,8 +82,8 @@ ClientFactory newCacheClient(final String servers, final int sessionTimeoutMilli /** * Wait to register global listener. * - * @param globalZookeeperEventListener globalListener - * @return ClientFactory this + * @param globalZookeeperEventListener global listener + * @return client factory */ public ClientFactory watch(final ZookeeperEventListener globalZookeeperEventListener) { setGlobalZookeeperEventListener(globalZookeeperEventListener); @@ -94,7 +94,7 @@ public ClientFactory watch(final ZookeeperEventListener globalZookeeperEventList * Set client namespace. * * @param namespace namespace - * @return ClientFactory this + * @return client factory */ public ClientFactory setClientNamespace(final String namespace) { setNamespace(PathUtil.checkPath(namespace)); @@ -107,7 +107,7 @@ public ClientFactory setClientNamespace(final String namespace) { * @param scheme scheme * @param auth auth * @param authorities authorities - * @return ClientFactory this + * @return client factory */ public ClientFactory authorization(final String scheme, final byte[] auth, final List authorities) { setScheme(scheme); @@ -119,8 +119,8 @@ public ClientFactory authorization(final String scheme, final byte[] auth, final /** * Set delay retry policy. * - * @param delayRetryPolicy delayRetryPolicy - * @return ClientFactory this + * @param delayRetryPolicy delay retry policy + * @return client factory */ public ClientFactory setRetryPolicy(final DelayRetryPolicy delayRetryPolicy) { this.delayRetryPolicy = delayRetryPolicy; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/UsualClient.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/UsualClient.java index ea4415f245e04..650b1ce85463e 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/UsualClient.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/UsualClient.java @@ -42,7 +42,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -/* +/** * Usually use client. * * @author lidongbo @@ -61,7 +61,7 @@ protected UsualClient(final BaseContext context) { @Override public void close() { - this.strategies.clear(); + strategies.clear(); super.close(); } @@ -130,7 +130,7 @@ public List getChildren(final String key) throws KeeperException, Interr @Override public void createCurrentOnly(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException { - this.createNamespace(); + createNamespace(); if (getRootNode().equals(key)) { return; } @@ -139,7 +139,7 @@ public void createCurrentOnly(final String key, final String value, final Create @Override public void createAllNeedPath(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException { - this.createNamespace(); + createNamespace(); if (getRootNode().equals(key)) { return; } @@ -174,7 +174,7 @@ public void deleteAllChildren(final String key) throws KeeperException, Interrup strategy.deleteAllChildren(key); if (getRootNode().equals(key)) { setRootExist(false); - log.debug("deleteAllChildren delete root:{}", getRootNode()); + log.debug("deleteAllChildren delete root: {}", getRootNode()); } } @@ -183,7 +183,7 @@ public void deleteCurrentBranch(final String key) throws KeeperException, Interr strategy.deleteCurrentBranch(key); if (!strategy.checkExists(getRootNode())) { setRootExist(false); - log.debug("deleteCurrentBranch delete root:{}", getRootNode()); + log.debug("deleteCurrentBranch delete root: {}", getRootNode()); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClient.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClient.java index 94e1498ce942e..368f24c408f44 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClient.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClient.java @@ -24,9 +24,6 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.StrategyType; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.WatcherCreator; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.ZookeeperEventListener; -import java.io.IOException; -import java.util.List; -import java.util.concurrent.TimeUnit; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; @@ -36,7 +33,11 @@ import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.data.ACL; -/* +import java.io.IOException; +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** * Base client. * * @author lidongbo @@ -75,10 +76,10 @@ public void start() throws IOException, InterruptedException { } @Override - public synchronized boolean start(final int wait, final TimeUnit units) throws InterruptedException, IOException { - log.debug("start wait:{}, units:{}", wait, units); + public synchronized boolean start(final int waitingTime, final TimeUnit timeUnit) throws InterruptedException, IOException { + log.debug("start wait:{}, units:{}", waitingTime, timeUnit); prepareStart(); - holder.start(wait, units); + holder.start(waitingTime, timeUnit); return holder.isConnected(); } @@ -88,8 +89,8 @@ private void prepareStart() { } @Override - public synchronized boolean blockUntilConnected(final int wait, final TimeUnit units) throws InterruptedException { - long maxWait = units != null ? TimeUnit.MILLISECONDS.convert(wait, units) : 0; + public synchronized boolean blockUntilConnected(final int waitingTime, final TimeUnit timeUnit) throws InterruptedException { + long maxWait = timeUnit != null ? TimeUnit.MILLISECONDS.convert(waitingTime, timeUnit) : 0; while (!holder.isConnected()) { long waitTime = maxWait - CIRCLE_WAIT; if (waitTime <= 0) { diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClientFactory.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClientFactory.java index daf1256c8cdc1..0f6393d17cf07 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClientFactory.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClientFactory.java @@ -30,7 +30,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; -/* +/** * Base client factory. * * @author lidongbo @@ -69,16 +69,16 @@ public IClient start() throws IOException, InterruptedException { /** * Start until Timeout. * - * @param wait wait - * @param units units - * @return connected + * @param waitingTime waiting time + * @param timeUnit time unit + * @return connected or not * @throws IOException IO Exception - * @throws InterruptedException InterruptedException - * @throws KeeperException OperationTimeoutException + * @throws InterruptedException interrupted exception + * @throws KeeperException operation timeout exception */ - public IClient start(final int wait, final TimeUnit units) throws IOException, InterruptedException, KeeperException { + public IClient start(final int waitingTime, final TimeUnit timeUnit) throws IOException, InterruptedException, KeeperException { prepareClient(); - if (!client.start(wait, units)) { + if (!client.start(waitingTime, timeUnit)) { client.close(); throw new KeeperException.OperationTimeoutException(); } @@ -87,11 +87,11 @@ public IClient start(final int wait, final TimeUnit units) throws IOException, I private void prepareClient() { client.setRootNode(namespace); - if (scheme == null) { + if (null == scheme) { authorities = ZooDefs.Ids.OPEN_ACL_UNSAFE; } client.setAuthorities(scheme, auth, authorities); - if (globalZookeeperEventListener != null) { + if (null != globalZookeeperEventListener) { client.registerWatch(globalZookeeperEventListener); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseContext.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseContext.java index c66d0536d1135..c5b7cde3d40ce 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseContext.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseContext.java @@ -18,13 +18,14 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.base; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.ZookeeperEventListener; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; -/* +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** * Base context. * * @author lidongbo @@ -49,6 +50,6 @@ public abstract class BaseContext { * Close. */ public void close() { - this.watchers.clear(); + watchers.clear(); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseOperation.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseOperation.java index 3cb6f72631b86..fbbef2f0c98d9 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseOperation.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseOperation.java @@ -21,6 +21,7 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.retry.DelayPolicyExecutor; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.Connection; import lombok.Getter; +import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.zookeeper.KeeperException; @@ -28,11 +29,12 @@ import java.util.concurrent.Delayed; import java.util.concurrent.TimeUnit; -/* +/** * Base async retry operation. * * @author lidongbo */ +@RequiredArgsConstructor @Slf4j public abstract class BaseOperation implements Delayed { @@ -42,20 +44,13 @@ public abstract class BaseOperation implements Delayed { @Setter private DelayPolicyExecutor delayPolicyExecutor; - protected BaseOperation(final IProvider provider) { - this.provider = provider; - } - @Override - public long getDelay(final TimeUnit unit) { + public long getDelay(final TimeUnit timeUnit) { long absoluteBlock = this.delayPolicyExecutor.getNextTick() - System.currentTimeMillis(); - log.debug("queue getDelay block:{}", absoluteBlock); - return unit.convert(absoluteBlock, TimeUnit.MILLISECONDS); + log.debug("queue getDelay block: {}", absoluteBlock); + return timeUnit.convert(absoluteBlock, TimeUnit.MILLISECONDS); } - /** - * Queue precedence. - */ @Override public int compareTo(final Delayed delayed) { return (int) (this.getDelay(TimeUnit.MILLISECONDS) - delayed.getDelay(TimeUnit.MILLISECONDS)); @@ -67,8 +62,8 @@ public int compareTo(final Delayed delayed) { * Queue precedence. * * @return whether or not continue enqueue - * @throws KeeperException Keeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException keeper exception + * @throws InterruptedException interrupted exception */ public boolean executeOperation() throws KeeperException, InterruptedException { boolean result; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/Holder.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/Holder.java index bda6177be91fe..90fac561e8e47 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/Holder.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/Holder.java @@ -20,11 +20,9 @@ import com.google.common.base.Strings; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.ZookeeperConstants; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.ZookeeperEventListener; -import java.io.IOException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import lombok.AccessLevel; import lombok.Getter; +import lombok.RequiredArgsConstructor; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.zookeeper.KeeperException; @@ -32,11 +30,17 @@ import org.apache.zookeeper.Watcher; import org.apache.zookeeper.ZooKeeper; -/* +import java.io.IOException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +/** * Zookeeper connection holder. * * @author lidongbo */ +@RequiredArgsConstructor +@Getter @Slf4j public class Holder { @@ -45,22 +49,16 @@ public class Holder { @Getter(value = AccessLevel.PROTECTED) private final BaseContext context; - @Getter private ZooKeeper zooKeeper; - @Getter @Setter(value = AccessLevel.PROTECTED) private boolean connected; - Holder(final BaseContext context) { - this.context = context; - } - /** * Start. * - * @throws IOException IO Exception - * @throws InterruptedException InterruptedException + * @throws IOException IO exception + * @throws InterruptedException interrupted exception */ public void start() throws IOException, InterruptedException { initZookeeper(); @@ -73,25 +71,25 @@ protected void start(final int wait, final TimeUnit units) throws IOException, I } protected void initZookeeper() throws IOException { - log.debug("Holder servers:{},sessionTimeOut:{}", context.getServers(), context.getSessionTimeOut()); + log.debug("Holder servers: {}, sessionTimeOut: {}", context.getServers(), context.getSessionTimeOut()); zooKeeper = new ZooKeeper(context.getServers(), context.getSessionTimeOut(), startWatcher()); if (!Strings.isNullOrEmpty(context.getScheme())) { zooKeeper.addAuthInfo(context.getScheme(), context.getAuth()); - log.debug("Holder scheme:{},auth:{}", context.getScheme(), context.getAuth()); + log.debug("Holder scheme: {}, auth: {}", context.getScheme(), context.getAuth()); } } private Watcher startWatcher() { return new Watcher() { + @Override public void process(final WatchedEvent event) { - log.debug("event-----------:" + event.toString()); processConnection(event); if (!isConnected()) { return; } processGlobalListener(event); - // todo filter event type or path + // TODO filter event type or path if (event.getType() == Event.EventType.None) { return; } @@ -103,7 +101,7 @@ public void process(final WatchedEvent event) { } protected void processConnection(final WatchedEvent event) { - log.debug("BaseClient process event:{}", event.toString()); + log.debug("BaseClient process event: {}", event.toString()); if (Watcher.Event.EventType.None == event.getType()) { if (Watcher.Event.KeeperState.SyncConnected == event.getState()) { connectLatch.countDown(); @@ -115,7 +113,7 @@ protected void processConnection(final WatchedEvent event) { log.warn("startWatcher Event.KeeperState.Expired"); reset(); } catch (final IOException | InterruptedException ex) { - log.error("event state Expired:{}", ex.getMessage(), ex); + log.error("event state Expired: {}", ex.getMessage(), ex); } } else if (Watcher.Event.KeeperState.Disconnected == event.getState()) { connected = false; @@ -124,7 +122,7 @@ protected void processConnection(final WatchedEvent event) { } private void processGlobalListener(final WatchedEvent event) { - if (context.getGlobalZookeeperEventListener() != null) { + if (null != context.getGlobalZookeeperEventListener()) { context.getGlobalZookeeperEventListener().process(event); log.debug("Holder {} process", ZookeeperConstants.GLOBAL_LISTENER_KEY); } @@ -133,8 +131,8 @@ private void processGlobalListener(final WatchedEvent event) { private void processUsualListener(final WatchedEvent event) { if (!context.getWatchers().isEmpty()) { for (ZookeeperEventListener zookeeperEventListener : context.getWatchers().values()) { - if (zookeeperEventListener.getPath() == null || event.getPath().startsWith(zookeeperEventListener.getPath())) { - log.debug("listener process:{}, listener:{}", zookeeperEventListener.getPath(), zookeeperEventListener.getKey()); + if (null == zookeeperEventListener.getPath() || event.getPath().startsWith(zookeeperEventListener.getPath())) { + log.debug("listener process: {}, listener: {}", zookeeperEventListener.getPath(), zookeeperEventListener.getKey()); zookeeperEventListener.process(event); } } @@ -143,23 +141,21 @@ private void processUsualListener(final WatchedEvent event) { private boolean checkPath(final String path) { try { - return zooKeeper.exists(path, true) != null; + return null != zooKeeper.exists(path, true); } catch (final KeeperException | InterruptedException ignore) { + return false; } - return false; } /** * Reset connection. * - * @throws IOException IO Exception - * @throws InterruptedException InterruptedException + * @throws IOException IO exception + * @throws InterruptedException interrupted exception */ public void reset() throws IOException, InterruptedException { - log.debug("zk reset...................................."); close(); start(); - log.debug("....................................zk reset"); } /** @@ -177,7 +173,7 @@ public void process(final WatchedEvent watchedEvent) { zooKeeper.close(); connected = false; log.debug("zk closed"); - this.context.close(); + context.close(); } catch (final InterruptedException ex) { log.warn("Holder close:{}", ex.getMessage()); } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/CreateAllNeedOperation.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/CreateAllNeedOperation.java index 20b83352e61df..85d36f8b35824 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/CreateAllNeedOperation.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/CreateAllNeedOperation.java @@ -23,12 +23,12 @@ import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -/* - * Async retry operation which CreateAllNeed action. +/** + * Async retry operation which create all need action. * * @author lidongbo */ -public class CreateAllNeedOperation extends BaseOperation { +public final class CreateAllNeedOperation extends BaseOperation { private final String key; @@ -50,6 +50,6 @@ protected void execute() throws KeeperException, InterruptedException { @Override public String toString() { - return String.format("CreateAllNeedOperation key:%s,value:%s,createMode:%s", key, value, createMode.name()); + return String.format("CreateAllNeedOperation key: %s,value: %s, createMode: %s", key, value, createMode.name()); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/CreateCurrentOperation.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/CreateCurrentOperation.java index dff46ade9dac8..d41a400d0d5ea 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/CreateCurrentOperation.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/CreateCurrentOperation.java @@ -22,12 +22,12 @@ import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -/* - * Async retry operation which CreateCurrent action. +/** + * Async retry operation which create current action. * * @author lidongbo */ -public class CreateCurrentOperation extends BaseOperation { +public final class CreateCurrentOperation extends BaseOperation { private final String key; @@ -49,6 +49,6 @@ public void execute() throws KeeperException, InterruptedException { @Override public String toString() { - return String.format("CreateCurrentOperation key:%s,value:%s,createMode:%s", key, value, createMode.name()); + return String.format("CreateCurrentOperation key: %s, value: %s, createMode: %s", key, value, createMode.name()); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteAllChildrenOperation.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteAllChildrenOperation.java index bb718c6aeb926..d323b7b8683bb 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteAllChildrenOperation.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteAllChildrenOperation.java @@ -22,12 +22,12 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.strategy.UsualStrategy; import org.apache.zookeeper.KeeperException; -/* - * Async retry operation which DeleteAllChildren action. +/** + * Async retry operation which delete all children action. * * @author lidongbo */ -public class DeleteAllChildrenOperation extends BaseOperation { +public final class DeleteAllChildrenOperation extends BaseOperation { private final String key; @@ -43,6 +43,6 @@ protected void execute() throws KeeperException, InterruptedException { @Override public String toString() { - return String.format("DeleteAllChildrenOperation key:%s", key); + return String.format("DeleteAllChildrenOperation key: %s", key); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentBranchOperation.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentBranchOperation.java index bfa2d9aa032f4..1a13533d39124 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentBranchOperation.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentBranchOperation.java @@ -22,12 +22,12 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.strategy.UsualStrategy; import org.apache.zookeeper.KeeperException; -/* - * Async retry operation which DeleteCurrentBranch action. +/** + * Async retry operation which delete current branch action. * * @author lidongbo */ -public class DeleteCurrentBranchOperation extends BaseOperation { +public final class DeleteCurrentBranchOperation extends BaseOperation { private final String key; @@ -43,6 +43,6 @@ protected void execute() throws KeeperException, InterruptedException { @Override public String toString() { - return String.format("DeleteCurrentBranchOperation key:%s", key); + return String.format("DeleteCurrentBranchOperation key: %s", key); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentOperation.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentOperation.java index bdf59b4e413e2..fabdd081e464a 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentOperation.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentOperation.java @@ -21,8 +21,8 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.base.BaseOperation; import org.apache.zookeeper.KeeperException; -/* - * Async retry operation which DeleteCurrent action. +/** + * Async retry operation which delete current action. * * @author lidongbo */ @@ -42,6 +42,6 @@ protected void execute() throws KeeperException, InterruptedException { @Override public String toString() { - return String.format("DeleteCurrentOperation key:%s", key); + return String.format("DeleteCurrentOperation key: %s", key); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/UpdateOperation.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/UpdateOperation.java index c46ec5fc1fb61..56f646a730304 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/UpdateOperation.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/UpdateOperation.java @@ -21,8 +21,8 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.base.BaseOperation; import org.apache.zookeeper.KeeperException; -/* - * Async retry operation which Update action. +/** + * Async retry operation which update action. * * @author lidongbo */ @@ -45,6 +45,6 @@ protected void execute() throws KeeperException, InterruptedException { @Override public String toString() { - return String.format("UpdateOperation key:%s,value:%s", key, value); + return String.format("UpdateOperation key: %s, value: %s", key, value); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/BaseProvider.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/BaseProvider.java index 89c8a4ce5f39f..162b811b6877f 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/BaseProvider.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/BaseProvider.java @@ -23,11 +23,9 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.ZookeeperConstants; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.base.Holder; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.transaction.BaseTransaction; -import java.io.IOException; -import java.util.List; -import java.util.Stack; import lombok.AccessLevel; import lombok.Getter; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.zookeeper.AsyncCallback; import org.apache.zookeeper.CreateMode; @@ -35,19 +33,24 @@ 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 Holder holder; + private final String rootNode; @Getter - private final String rootNode; + private final Holder holder; @Getter(value = AccessLevel.PROTECTED) private final boolean watched; @@ -55,13 +58,6 @@ public class BaseProvider implements IProvider { @Getter(value = AccessLevel.PROTECTED) private final List authorities; - public BaseProvider(final String rootNode, final Holder holder, final boolean watched, final List authorities) { - this.rootNode = rootNode; - this.holder = holder; - this.watched = watched; - this.authorities = authorities; - } - @Override public String getDataString(final String key) throws KeeperException, InterruptedException { return new String(getData(key)); @@ -95,11 +91,11 @@ public List getChildren(final String key) throws KeeperException, Interr @Override public void create(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException { if (exists(key)) { - log.debug("node exist:{}", key); + log.debug("node exist: {}", key); return; } holder.getZooKeeper().create(key, value.getBytes(ZookeeperConstants.UTF_8), authorities, createMode); - log.debug("BaseProvider createCurrentOnly:{}", key); + log.debug("BaseProvider createCurrentOnly: {}", key); } @Override @@ -114,13 +110,13 @@ public boolean update(final String key, final String value) throws KeeperExcepti @Override public void delete(final String key) throws KeeperException, InterruptedException { holder.getZooKeeper().delete(key, ZookeeperConstants.VERSION); - log.debug("BaseProvider deleteOnlyCurrent:{}", key); + log.debug("BaseProvider deleteOnlyCurrent: {}", key); } @Override public void delete(final String key, final AsyncCallback.VoidCallback callback, final Object ctx) { holder.getZooKeeper().delete(key, ZookeeperConstants.VERSION, callback, ctx); - log.debug("BaseProvider deleteOnlyCurrent:{},ctx:{}", key, ctx); + log.debug("BaseProvider deleteOnlyCurrent: {}, ctx: {}", key, ctx); } @Override @@ -154,7 +150,7 @@ public void resetConnection() { try { holder.reset(); } catch (final InterruptedException | IOException ex) { - log.error("resetConnection Exception:{}", ex.getMessage(), ex); + log.error("resetConnection Exception: {}", ex.getMessage(), ex); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/TransactionProvider.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/TransactionProvider.java index 591e8180a5ccd..89a2d679ed04b 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/TransactionProvider.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/TransactionProvider.java @@ -21,18 +21,18 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.ZookeeperConstants; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.base.Holder; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.transaction.BaseTransaction; -import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.transaction.ZKTransaction; +import io.shardingsphere.jdbc.orchestration.reg.newzk.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 class TransactionProvider extends BaseProvider implements ITransactionProvider { +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); @@ -45,6 +45,6 @@ public void createInTransaction(final String key, final String value, final Crea @Override public BaseTransaction transaction() { - return new ZKTransaction(getRootNode(), getHolder()); + return new ZooKeeperTransaction(getRootNode(), getHolder()); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientContext.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientContext.java index 58aaf274c7700..5e190b45a21ed 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientContext.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientContext.java @@ -23,7 +23,7 @@ import lombok.Getter; import lombok.Setter; -/* +/** * Client context. * * @author lidongbo @@ -37,29 +37,26 @@ public final class ClientContext extends BaseContext { private BaseClientFactory clientFactory; public ClientContext(final String servers, final int sessionTimeoutMilliseconds) { - super(); setServers(servers); setSessionTimeOut(sessionTimeoutMilliseconds); } - /** - * Close. - */ - public void close() { - super.close(); - this.delayRetryPolicy = null; - this.clientFactory = null; - } - /** * Update context. * * @param context context */ public void updateContext(final ClientContext context) { - this.delayRetryPolicy = context.getDelayRetryPolicy(); - this.clientFactory = context.clientFactory; + delayRetryPolicy = context.getDelayRetryPolicy(); + clientFactory = context.clientFactory; getWatchers().clear(); getWatchers().putAll(context.getWatchers()); } + + @Override + public void close() { + super.close(); + delayRetryPolicy = null; + clientFactory = null; + } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientTask.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientTask.java index b42bca471806b..f23604aac656a 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientTask.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientTask.java @@ -22,7 +22,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.zookeeper.KeeperException; -/* +/** * Client task. * * @author lidongbo @@ -37,8 +37,8 @@ public abstract class ClientTask implements Runnable { * Run. * * @param provider provider - * @throws KeeperException Zookeeper Exception - * @throws InterruptedException InterruptedException + * @throws KeeperException zookeeper exception + * @throws InterruptedException interrupted exception */ public abstract void run(IProvider provider) throws KeeperException, InterruptedException; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/Connection.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/Connection.java index 896a563d8c959..c384f5b6fc0b7 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/Connection.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/Connection.java @@ -22,12 +22,12 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -/* +/** * Zookeeper connection check. * * @author lidongbo */ -public class Connection { +public final class Connection { //is need reset private static final Map EXCEPTION_RESETS = new ConcurrentHashMap<>(); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/StrategyType.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/StrategyType.java index ddec170caf048..f0e7573b0501c 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/StrategyType.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/StrategyType.java @@ -17,7 +17,7 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section; -/* +/** * Exec strategy type. * * @author lidongbo diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/WatcherCreator.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/WatcherCreator.java index dd96d2c3e7e12..7cb165b873e41 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/WatcherCreator.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/WatcherCreator.java @@ -21,7 +21,7 @@ import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; -/* +/** * Build public watcher. * * @author lidongbo @@ -42,7 +42,7 @@ public static Watcher deleteWatcher(final ZookeeperEventListener zookeeperEventL public void process(final WatchedEvent event) { if (zookeeperEventListener.getPath().equals(event.getPath()) && Event.EventType.NodeDeleted.equals(event.getType())) { zookeeperEventListener.process(event); - log.debug("delete node event:{}", event.toString()); + log.debug("delete node event: {}", event.toString()); } } }; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ZookeeperEventListener.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ZookeeperEventListener.java index 80629a6776d81..a57a7816a328d 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ZookeeperEventListener.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ZookeeperEventListener.java @@ -21,7 +21,7 @@ import lombok.Setter; import org.apache.zookeeper.WatchedEvent; -/* +/** * Watch event listener. * * @author lidongbo @@ -39,8 +39,8 @@ public ZookeeperEventListener() { } public ZookeeperEventListener(final String path) { - this.path = path; this.key = path + System.currentTimeMillis(); + this.path = path; } /** diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/AsyncRetryStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/AsyncRetryStrategy.java index 57a9793b09ced..90c7f2a964319 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/AsyncRetryStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/AsyncRetryStrategy.java @@ -31,7 +31,7 @@ import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -/* +/** * Async retry strategy. * * @author lidongbo diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/BaseStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/BaseStrategy.java index 6963b9baf1ad1..a6b85959eaa80 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/BaseStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/BaseStrategy.java @@ -21,22 +21,20 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.action.IProvider; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.transaction.BaseTransaction; import lombok.Getter; +import lombok.RequiredArgsConstructor; import org.apache.zookeeper.KeeperException; -/* - * Base exec strategy. +/** + * Base execute strategy. * * @author lidongbo */ +@RequiredArgsConstructor public abstract class BaseStrategy implements IExecStrategy { @Getter private final IProvider provider; - public BaseStrategy(final IProvider provider) { - this.provider = provider; - } - @Override public String getDataString(final String key) throws KeeperException, InterruptedException { return new String(getData(key)); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java index 8f39f50d7cd2d..a4fd3d410c8cf 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java @@ -30,8 +30,8 @@ import java.util.List; import java.util.Stack; -/* - * The ContentionStrategy is effective only when all the clients of the node which be competitive are using ContentionStrategy. +/** + * The contention strategy is effective only when all the clients of the node which be competitive are using contention strategy. * * @author lidongbo */ @@ -51,7 +51,7 @@ public void getData(final String key, final AsyncCallback.DataCallback callback, @Override public void action() throws KeeperException, InterruptedException { getProvider().getData(getProvider().getRealPath(key), callback, ctx); - log.debug("ContentionStrategy getData action:{}", key); + log.debug("ContentionStrategy getData action: {}", key); } }; getProvider().executeContention(election); @@ -68,6 +68,7 @@ public void createCurrentOnly(final String key, final String value, final Create 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); @@ -75,7 +76,7 @@ public void action() throws KeeperException, InterruptedException { @Override public void callback() { - if (contentionCallback != null) { + if (null != contentionCallback) { contentionCallback.processResult(); } } @@ -95,12 +96,12 @@ private LeaderElection buildUpdateElection(final String key, final String value, @Override public void action() throws KeeperException, InterruptedException { getProvider().update(getProvider().getRealPath(key), value); - log.debug("ContentionStrategy update action:{},value:{}", key, value); + log.debug("ContentionStrategy update action: {}, value: {}", key, value); } @Override public void callback() { - if (contentionCallback != null) { + if (null != contentionCallback) { contentionCallback.processResult(); } } @@ -118,16 +119,18 @@ public void deleteOnlyCurrent(final String key) throws KeeperException, Interrup @Override public 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); - log.debug("ContentionStrategy deleteOnlyCurrent action:{},ctx:{}", key, ctx); + log.debug("ContentionStrategy deleteOnlyCurrent action: {}, ctx: {}", key, 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)); @@ -135,7 +138,7 @@ public void action() throws KeeperException, InterruptedException { @Override public void callback() { - if (contentionCallback != null) { + if (null != contentionCallback) { contentionCallback.processResult(); } } @@ -152,15 +155,16 @@ public void createAllNeedPath(final String key, final String value, final Create 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 { - log.debug("ContentionStrategy createAllNeedPath action:{}", key); + log.debug("ContentionStrategy createAllNeedPath action: {}", key); createBegin(getProvider().getRealPath(key), value, createMode); } @Override public void callback() { - if (contentionCallback != null) { + if (null != contentionCallback) { contentionCallback.processResult(); } } @@ -168,7 +172,7 @@ public void callback() { } private void createBegin(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException { - // todo start with / + // TODO start with / if (!key.contains(ZookeeperConstants.PATH_SEPARATOR)) { getProvider().create(key, value, createMode); return; @@ -176,10 +180,10 @@ private void createBegin(final String key, final String value, final CreateMode List nodes = getProvider().getNecessaryPaths(key); for (int i = 0; i < nodes.size(); i++) { if (getProvider().exists(nodes.get(i))) { - log.info("create node exist:{}", nodes.get(i)); + log.info("create node exist: {}", nodes.get(i)); continue; } - log.debug("create node not exist:", nodes.get(i)); + log.debug("create node not exist: {}", nodes.get(i)); if (i == nodes.size() - 1) { getProvider().create(nodes.get(i), value, createMode); } else { @@ -191,6 +195,7 @@ private void createBegin(final String key, final String value, final 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); @@ -202,13 +207,13 @@ public void action() throws KeeperException, InterruptedException { private void deleteChildren(final String key, final boolean deleteCurrentNode) throws KeeperException, InterruptedException { List children = getProvider().getChildren(key); log.debug("deleteChildren:{}", children); - for (int i = 0; i < children.size(); i++) { - String child = PathUtil.getRealPath(key, children.get(i)); + for (String aChildren : children) { + String child = PathUtil.getRealPath(key, aChildren); if (!getProvider().exists(child)) { - log.info("delete not exist:{}", child); + log.info("delete not exist: {}", child); continue; } - log.debug("deleteChildren:{}", child); + log.debug("deleteChildren: {}", child); deleteChildren(child, true); } if (deleteCurrentNode) { @@ -219,6 +224,7 @@ private void deleteChildren(final String key, final boolean deleteCurrentNode) t @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)); @@ -237,16 +243,16 @@ private void deleteBranch(final String key) throws KeeperException, InterruptedE try { getProvider().delete(node); } catch (KeeperException.NotEmptyException e) { - log.warn("deleteBranch {} exist other children:{}", node, this.getChildren(node)); + log.warn("deleteBranch {} exist other children: {}", node, this.getChildren(node)); log.debug(e.getMessage()); return; } } - log.info("deleteBranch node not exist:{}", node); + log.info("deleteBranch node not exist: {}", node); } } - //todo Use arbitrary competitive nodes + //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)); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/SyncRetryStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/SyncRetryStrategy.java index 07def3bbbc677..9781ad0ded5e5 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/SyncRetryStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/SyncRetryStrategy.java @@ -30,20 +30,20 @@ import java.util.List; -/* +/** * Sync retry strategy. * * @author lidongbo */ +@Getter(value = AccessLevel.PROTECTED) @Slf4j public class SyncRetryStrategy extends UsualStrategy { - @Getter(value = AccessLevel.PROTECTED) private final DelayRetryPolicy delayRetryPolicy; public SyncRetryStrategy(final IProvider provider, final DelayRetryPolicy delayRetryPolicy) { super(provider); - if (delayRetryPolicy == null) { + if (null == delayRetryPolicy) { log.info("RetryCallable constructor context's delayRetryPolicy is null"); this.delayRetryPolicy = DelayRetryPolicy.defaultDelayPolicy(); } else { diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/TransactionContendStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/TransactionContendStrategy.java index e4734edd0297a..ba832f67c19ec 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/TransactionContendStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/TransactionContendStrategy.java @@ -23,7 +23,7 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.PathUtil; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.ZookeeperConstants; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.provider.BaseProvider; -import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.transaction.ZKTransaction; +import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.transaction.ZooKeeperTransaction; import lombok.extern.slf4j.Slf4j; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; @@ -31,14 +31,14 @@ import java.util.List; import java.util.Stack; -/* +/** * ContentionStrategy with transaction. * * @author lidongbo * @since zookeeper 3.4.0 */ @Slf4j -public class TransactionContendStrategy extends ContentionStrategy { +public final class TransactionContendStrategy extends ContentionStrategy { public TransactionContendStrategy(final ITransactionProvider provider) { super(provider); @@ -57,8 +57,8 @@ private LeaderElection buildCreateAllNeedElection(final String key, final String @Override public void action() throws KeeperException, InterruptedException { - log.debug("ContentionStrategy createAllNeedPath action:{}", key); - ZKTransaction transaction = new ZKTransaction(((BaseProvider) getProvider()).getRootNode(), ((BaseProvider) getProvider()).getHolder()); + log.debug("ContentionStrategy createAllNeedPath action: {}", key); + ZooKeeperTransaction transaction = new ZooKeeperTransaction(((BaseProvider) getProvider()).getRootNode(), ((BaseProvider) getProvider()).getHolder()); createBegin(key, value, createMode, transaction); transaction.commit(); } @@ -72,7 +72,7 @@ public void callback() { }; } - private void createBegin(final String key, final String value, final CreateMode createMode, final ZKTransaction transaction) throws KeeperException, InterruptedException { + private void createBegin(final String key, final String value, final CreateMode createMode, final ZooKeeperTransaction transaction) throws KeeperException, InterruptedException { if (!key.contains(ZookeeperConstants.PATH_SEPARATOR)) { ((ITransactionProvider) getProvider()).createInTransaction(key, value, createMode, transaction); return; @@ -80,10 +80,10 @@ private void createBegin(final String key, final String value, final CreateMode List nodes = getProvider().getNecessaryPaths(key); for (int i = 0; i < nodes.size(); i++) { if (getProvider().exists(nodes.get(i))) { - log.info("create node exist:{}", nodes.get(i)); + log.info("create node exist: {}", nodes.get(i)); continue; } - log.debug("node not exist and create:", nodes.get(i)); + log.debug("node not exist and create: {}", nodes.get(i)); if (i == nodes.size() - 1) { ((ITransactionProvider) getProvider()).createInTransaction(nodes.get(i), value, createMode, transaction); } else { @@ -98,7 +98,7 @@ public void deleteAllChildren(final String key) throws KeeperException, Interrup @Override public void action() throws KeeperException, InterruptedException { - ZKTransaction transaction = new ZKTransaction(((BaseProvider) getProvider()).getRootNode(), ((BaseProvider) getProvider()).getHolder()); + ZooKeeperTransaction transaction = new ZooKeeperTransaction(((BaseProvider) getProvider()).getRootNode(), ((BaseProvider) getProvider()).getHolder()); deleteChildren(getProvider().getRealPath(key), true, transaction); transaction.commit(); } @@ -106,15 +106,15 @@ public void action() throws KeeperException, InterruptedException { log.debug("ContentionStrategy deleteAllChildren executeContention"); } - private void deleteChildren(final String key, final boolean deleteCurrentNode, final ZKTransaction transaction) throws KeeperException, InterruptedException { + private void deleteChildren(final String key, final boolean deleteCurrentNode, final ZooKeeperTransaction transaction) throws KeeperException, InterruptedException { List children = getProvider().getChildren(key); - for (int i = 0; i < children.size(); i++) { - String child = PathUtil.getRealPath(key, children.get(i)); + for (String each : children) { + String child = PathUtil.getRealPath(key, each); if (!getProvider().exists(child)) { - log.info("delete not exist:{}", child); + log.info("delete not exist: {}", child); continue; } - log.debug("deleteChildren:{}", child); + log.debug("deleteChildren: {}", child); deleteChildren(child, true, transaction); } if (deleteCurrentNode) { @@ -128,7 +128,7 @@ public void deleteCurrentBranch(final String key) throws KeeperException, Interr @Override public void action() throws KeeperException, InterruptedException { - ZKTransaction transaction = new ZKTransaction(((BaseProvider) getProvider()).getRootNode(), ((BaseProvider) getProvider()).getHolder()); + ZooKeeperTransaction transaction = new ZooKeeperTransaction(((BaseProvider) getProvider()).getRootNode(), ((BaseProvider) getProvider()).getHolder()); deleteBranch(getProvider().getRealPath(key), transaction); transaction.commit(); } @@ -136,7 +136,7 @@ public void action() throws KeeperException, InterruptedException { log.debug("ContentionStrategy deleteCurrentBranch executeContention"); } - private void deleteBranch(final String key, final ZKTransaction transaction) throws KeeperException, InterruptedException { + private void deleteBranch(final String key, final ZooKeeperTransaction transaction) throws KeeperException, InterruptedException { deleteChildren(key, false, transaction); Stack pathStack = getProvider().getDeletingPaths(key); String prePath = key; @@ -145,8 +145,8 @@ private void deleteBranch(final String key, final ZKTransaction transaction) thr // contrast cache // Performance needs testing List children = getProvider().getChildren(node); - boolean canDelete = children.size() == 0 || children.size() == 1; - if (children.size() == 1) { + boolean canDelete = children.isEmpty() || 1 == children.size(); + if (1 == children.size()) { if (!PathUtil.getRealPath(node, children.get(0)).equals(prePath)) { canDelete = false; } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/UsualStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/UsualStrategy.java index 27677a6911135..ae1654fa94c18 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/UsualStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/UsualStrategy.java @@ -28,7 +28,7 @@ import java.util.List; -/* +/** * Usual strategy. * * @author lidongbo @@ -88,37 +88,37 @@ public void deleteOnlyCurrent(final String key, final AsyncCallback.VoidCallback @Override public void createAllNeedPath(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException { if (!key.contains(ZookeeperConstants.PATH_SEPARATOR)) { - this.createCurrentOnly(key, value, createMode); + createCurrentOnly(key, value, createMode); return; } List nodes = getProvider().getNecessaryPaths(key); for (int i = 0; i < nodes.size(); i++) { try { if (i == nodes.size() - 1) { - this.createCurrentOnly(nodes.get(i), value, createMode); + createCurrentOnly(nodes.get(i), value, createMode); } else { - this.createCurrentOnly(nodes.get(i), ZookeeperConstants.NOTHING_VALUE, CreateMode.PERSISTENT); + createCurrentOnly(nodes.get(i), ZookeeperConstants.NOTHING_VALUE, CreateMode.PERSISTENT); } - log.debug("node not exist and create:", nodes.get(i)); + log.debug("node not exist and create: {}", nodes.get(i)); } catch (final KeeperException.NodeExistsException ex) { - log.debug("create node exist:{}", nodes.get(i)); + log.debug("create node exist: {}", nodes.get(i)); } } } @Override public void deleteAllChildren(final String key) throws KeeperException, InterruptedException { - log.debug("deleteAllChildren:{}", key); - this.deleteChildren(getProvider().getRealPath(key), true); + log.debug("deleteAllChildren: {}", key); + deleteChildren(getProvider().getRealPath(key), true); } private void deleteChildren(final String path, final boolean deleteCurrentNode) throws KeeperException, InterruptedException { - log.debug("deleteChildren:{}", path); + log.debug("deleteChildren: {}", path); List children; try { children = getProvider().getChildren(path); } catch (final KeeperException.NoNodeException ex) { - log.warn("deleteChildren node not exist:{},ex:{}", path, ex.getMessage()); + log.warn("deleteChildren node not exist: {}, ex: {}", path, ex.getMessage()); return; } for (String each : children) { @@ -126,12 +126,12 @@ private void deleteChildren(final String path, final boolean deleteCurrentNode) } if (deleteCurrentNode) { try { - this.deleteOnlyCurrent(path); + deleteOnlyCurrent(path); } catch (final KeeperException.NotEmptyException ex) { - log.warn("deleteCurrentNode exist children:{},ex:{}", path, ex.getMessage()); + log.warn("deleteCurrentNode exist children: {}, ex: {}", path, ex.getMessage()); deleteChildren(path, true); } catch (final KeeperException.NoNodeException ex) { - log.warn("deleteCurrentNode node not exist:{},ex:{}", path, ex.getMessage()); + log.warn("deleteCurrentNode node not exist: {}, ex: {}", path, ex.getMessage()); } } } @@ -141,43 +141,43 @@ private void deleteChildren(final String path, final boolean deleteCurrentNode) */ @Override public void deleteCurrentBranch(final String key) throws KeeperException, InterruptedException { - log.debug("deleteCurrentBranch:{}", key); + log.debug("deleteCurrentBranch: {}", key); String path = getProvider().getRealPath(key); try { - this.deleteOnlyCurrent(path); + deleteOnlyCurrent(path); } catch (final KeeperException | InterruptedException ex) { if (ex instanceof KeeperException.NotEmptyException) { - this.deleteChildren(path, true); + deleteChildren(path, true); } else if (ex instanceof KeeperException.NoNodeException) { - log.debug("path:{},ex:{}", path, ex.getMessage()); + log.debug("path: {}, ex: {}", path, ex.getMessage()); } else { throw ex; } } String superPath = path.substring(0, path.lastIndexOf(ZookeeperConstants.PATH_SEPARATOR)); try { - this.deleteRecursively(superPath); + deleteRecursively(superPath); } catch (final KeeperException.NotEmptyException ex) { - log.warn("deleteCurrentBranch exist children:{},ex:{}", path, ex.getMessage()); + log.warn("deleteCurrentBranch exist children: {}, ex: {}", path, ex.getMessage()); } catch (final KeeperException.NoNodeException ex) { - log.debug("deleteCurrentBranch:{},ex:{}", superPath, ex.getMessage()); + log.debug("deleteCurrentBranch: {}, ex: {}", superPath, ex.getMessage()); } } private void deleteRecursively(final String path) throws KeeperException, InterruptedException { - log.debug("deleteRecursively:{}", path); + log.debug("deleteRecursively: {}", path); int index = path.lastIndexOf(ZookeeperConstants.PATH_SEPARATOR); if (index == 0) { - this.deleteOnlyCurrent(path); + deleteOnlyCurrent(path); return; } String superPath = path.substring(0, index); try { - this.deleteOnlyCurrent(path); - this.deleteRecursively(superPath); + deleteOnlyCurrent(path); + deleteRecursively(superPath); } catch (final KeeperException.NotEmptyException ex) { - log.info("deleteRecursively exist children:{},ex:{}", path, ex.getMessage()); - log.debug("deleteRecursively {} exist other children:{}", path, this.getChildren(path)); + log.info("deleteRecursively exist children: {}, ex: {}", path, ex.getMessage()); + log.debug("deleteRecursively {} exist other children: {}", path, getChildren(path)); } } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/transaction/BaseTransaction.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/transaction/BaseTransaction.java index ee57474f6a729..facbf6e8f1b28 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/transaction/BaseTransaction.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/transaction/BaseTransaction.java @@ -24,7 +24,7 @@ import java.util.List; -/* +/** * Base transaction. * * @author lidongbo @@ -37,10 +37,10 @@ public class BaseTransaction { * @param path key * @param data value * @param acl acl - * @param createMode createMode - * @return ZKTransaction + * @param createMode create mode + * @return zookeeper transaction */ - public ZKTransaction create(final String path, final byte[] data, final List acl, final CreateMode createMode) { + public ZooKeeperTransaction create(final String path, final byte[] data, final List acl, final CreateMode createMode) { throw new UnsupportedOperationException("check zk version!"); } @@ -48,9 +48,9 @@ public ZKTransaction create(final String path, final byte[] data, final List commit() throws InterruptedException, KeeperException { throw new UnsupportedOperationException("check zk version!"); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/transaction/ZKTransaction.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/transaction/ZooKeeperTransaction.java similarity index 67% rename from sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/transaction/ZKTransaction.java rename to sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/transaction/ZooKeeperTransaction.java index c0a6eaadd6544..c453a7a0ab189 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/transaction/ZKTransaction.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/transaction/ZooKeeperTransaction.java @@ -29,64 +29,64 @@ import java.util.List; -/* +/** * Zookeeper transaction support. * * @author lidongbo * @since zookeeper 3.4.0 */ @Slf4j -public class ZKTransaction extends BaseTransaction { - - private final Transaction transaction; +public final class ZooKeeperTransaction extends BaseTransaction { private final String rootNode; + + private final Transaction transaction; - public ZKTransaction(final String root, final Holder holder) { - transaction = holder.getZooKeeper().transaction(); + public ZooKeeperTransaction(final String root, final Holder holder) { rootNode = root; - log.debug("ZKTransaction root:{}", rootNode); + transaction = holder.getZooKeeper().transaction(); + log.debug("ZKTransaction root: {}", rootNode); } @Override - public ZKTransaction create(final String path, final byte[] data, final List acl, final CreateMode createMode) { - this.transaction.create(PathUtil.getRealPath(rootNode, path), data, acl, createMode); + public ZooKeeperTransaction create(final String path, final byte[] data, final List acl, final CreateMode createMode) { + transaction.create(PathUtil.getRealPath(rootNode, path), data, acl, createMode); log.debug("wait create:{},data:{},acl:{},createMode:{}", path, data, acl, createMode); return this; } @Override - public ZKTransaction delete(final String path) { + public ZooKeeperTransaction delete(final String path) { return delete(path, ZookeeperConstants.VERSION); } @Override - public ZKTransaction delete(final String path, final int version) { - this.transaction.delete(PathUtil.getRealPath(rootNode, path), version); + public ZooKeeperTransaction delete(final String path, final int version) { + transaction.delete(PathUtil.getRealPath(rootNode, path), version); log.debug("wait delete:{}", path); return this; } @Override - public ZKTransaction check(final String path) { + public ZooKeeperTransaction check(final String path) { return check(path, ZookeeperConstants.VERSION); } @Override - public ZKTransaction check(final String path, final int version) { - this.transaction.check(PathUtil.getRealPath(rootNode, path), version); + public ZooKeeperTransaction check(final String path, final int version) { + transaction.check(PathUtil.getRealPath(rootNode, path), version); log.debug("wait check:{}", path); return this; } @Override - public ZKTransaction setData(final String path, final byte[] data) { + public ZooKeeperTransaction setData(final String path, final byte[] data) { return setData(path, data, ZookeeperConstants.VERSION); } @Override - public ZKTransaction setData(final String path, final byte[] data, final int version) { - this.transaction.setData(PathUtil.getRealPath(rootNode, path), data, version); + public ZooKeeperTransaction setData(final String path, final byte[] data, final int version) { + transaction.setData(PathUtil.getRealPath(rootNode, path), data, version); log.debug("wait setData:{},data:{}", path, data); return this; } @@ -94,6 +94,6 @@ public ZKTransaction setData(final String path, final byte[] data, final int ver @Override public List commit() throws InterruptedException, KeeperException { log.debug("ZKTransaction commit"); - return this.transaction.commit(); + return transaction.commit(); } } diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestClient.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestClient.java index 1a9f13df60129..a06c494e0fdb1 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestClient.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestClient.java @@ -30,9 +30,9 @@ public class TestClient extends UsualClient { } @Override - public synchronized boolean start(final int wait, final TimeUnit units) throws InterruptedException, IOException { + public synchronized boolean start(final int waitingTime, final TimeUnit timeUnit) throws InterruptedException, IOException { setHolder(new TestHolder(getContext())); - getHolder().start(wait, units); + getHolder().start(waitingTime, timeUnit); return getHolder().isConnected(); } From 9cdcf5a0aeafedd0d0adf78532d9204b42ddbf1d Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 00:04:30 +0800 Subject: [PATCH 116/198] refactor TableMetaData --- .../table/executor/TableMetaDataInitializer.java | 10 +++++----- .../metadata/table/executor/TableMetaDataLoader.java | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataInitializer.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataInitializer.java index 7b2099ff354d5..2a1b4b9f3ef48 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataInitializer.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataInitializer.java @@ -39,13 +39,13 @@ */ public final class TableMetaDataInitializer { - private final TableMetaDataConnectionManager executorAdapter; + private final TableMetaDataConnectionManager connectionManager; private final TableMetaDataLoader tableMetaDataLoader; - public TableMetaDataInitializer(final ListeningExecutorService executorService, final TableMetaDataConnectionManager executorAdapter) { - this.executorAdapter = executorAdapter; - tableMetaDataLoader = new TableMetaDataLoader(executorService, executorAdapter); + public TableMetaDataInitializer(final ListeningExecutorService executorService, final TableMetaDataConnectionManager connectionManager) { + this.connectionManager = connectionManager; + tableMetaDataLoader = new TableMetaDataLoader(executorService, connectionManager); } /** @@ -86,7 +86,7 @@ private Map loadDefaultTables(final ShardingRule sharding private Collection getAllTableNames(final String dataSourceName) throws SQLException { Collection result = new LinkedList<>(); - try (Connection connection = executorAdapter.getConnection(dataSourceName); + try (Connection connection = connectionManager.getConnection(dataSourceName); ResultSet resultSet = connection.getMetaData().getTables(null, null, null, null)) { while (resultSet.next()) { result.add(resultSet.getString("TABLE_NAME")); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java index 55529d3ee60f0..a783f7f8ec3f2 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java @@ -50,7 +50,7 @@ public final class TableMetaDataLoader { private final ListeningExecutorService executorService; - private final TableMetaDataConnectionManager executorAdapter; + private final TableMetaDataConnectionManager connectionManager; /** * Load table meta data. @@ -70,12 +70,12 @@ private TableMetaData load(final TableRule tableRule, final ShardingDataSourceNa } private TableMetaData load(final DataNode dataNode) throws SQLException { - if (executorAdapter.isAutoClose()) { - try (Connection connection = executorAdapter.getConnection(dataNode.getDataSourceName())) { + if (connectionManager.isAutoClose()) { + try (Connection connection = connectionManager.getConnection(dataNode.getDataSourceName())) { return load(connection, dataNode); } } - return load(executorAdapter.getConnection(dataNode.getDataSourceName()), dataNode); + return load(connectionManager.getConnection(dataNode.getDataSourceName()), dataNode); } private TableMetaData load(final Connection connection, final DataNode dataNode) throws SQLException { From 7679da5e5fe3f52655f206ce8f9529039dcc7b76 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 00:52:53 +0800 Subject: [PATCH 117/198] upgrade all for 3.0.0.M2 --- README.md | 2 +- README_ZH.md | 2 +- sharding-proxy/src/main/docker/Dockerfile | 4 ++-- .../proxy/transport/mysql/constant/ServerInfo.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0922a5f7cc837..da0a1dc54011b 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ It directly connects to databases to provide services in the form of jar, with n ### Sharding-Proxy -[![Download](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/sharding-sphere/sharding-sphere-doc/raw/master/dist/sharding-proxy-3.0.0.M1.tar.gz) +[![Download](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/sharding-sphere/sharding-sphere-doc/raw/master/dist/sharding-proxy-3.0.0.M2.tar.gz) [![Docker Pulls](https://img.shields.io/docker/pulls/shardingsphere/sharding-proxy.svg)](https://store.docker.com/community/images/shardingsphere/sharding-proxy) Sharding-Proxy is positioned as a transparent database proxy, providing a database server that encapsulates database binary protocol to support heterogeneous languages. diff --git a/README_ZH.md b/README_ZH.md index d9c55d2b09782..aa09eeaf3fd0d 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -38,7 +38,7 @@ Sharding-Sphere定位为关系型数据库中间件,旨在充分合理地在 ### Sharding-Proxy -[![Download](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/sharding-sphere/sharding-sphere-doc/raw/master/dist/sharding-proxy-3.0.0.M1.tar.gz) +[![Download](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/sharding-sphere/sharding-sphere-doc/raw/master/dist/sharding-proxy-3.0.0.M2.tar.gz) [![Docker Pulls](https://img.shields.io/docker/pulls/shardingsphere/sharding-proxy.svg)](https://store.docker.com/community/images/shardingsphere/sharding-proxy) 定位为透明化的数据库代理端,提供封装了数据库二进制协议的服务端版本,用于完成对异构语言的支持。 diff --git a/sharding-proxy/src/main/docker/Dockerfile b/sharding-proxy/src/main/docker/Dockerfile index fceed07920c33..01df57a4f6e82 100644 --- a/sharding-proxy/src/main/docker/Dockerfile +++ b/sharding-proxy/src/main/docker/Dockerfile @@ -1,6 +1,6 @@ FROM java:7 MAINTAINER caohao "caohaoch@gmail.com" -ADD sharding-proxy-3.0.0.M1.tar.gz / -RUN mv /sharding-proxy-3.0.0.M1 /opt/sharding-proxy +ADD sharding-proxy-3.0.0.M2.tar.gz / +RUN mv /sharding-proxy-3.0.0.M2 /opt/sharding-proxy ENTRYPOINT /opt/sharding-proxy/bin/start.sh $PORT && tail -f /opt/sharding-proxy/logs/stdout.log diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java index 205111c421d46..a5793c745c758 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java @@ -32,7 +32,7 @@ public interface ServerInfo { /** * Server version. */ - String SERVER_VERSION = "5.6.0-Sharding-Proxy 3.0.0.M1"; + String SERVER_VERSION = "5.6.0-Sharding-Proxy 3.0.0.M2"; /** * Charset code 0x21 is utf8_general_ci. From 1664bdbf4fdfeb037ecc9a3a986ac3b902824f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E4=BA=AE?= Date: Wed, 8 Aug 2018 01:03:54 +0800 Subject: [PATCH 118/198] Create CONTRIBUTING.md --- CONTRIBUTING.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000000..8b33e89c67670 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,34 @@ +You can report a bug, submit a new feature enhancement recommendation, or commit codes by a pull request. + +## Reporting Bugs + + - Before report a bug, please search from google to confirm you cannot find any hint on it. + - Look [issues List](https://github.com/sharding-sphere/sharding-sphere/issues) to confirm this issue is not a duplicated one. + - [Create](https://github.com/sharding-sphere/sharding-sphere/issues/new) a new issue. + - Define a clear and descriptive title for the issue. + - If bug reported, please provide information below: + - Details for reproduce bug step by step. Include SQL, configuration, expected results, actual results and tracing log. + - Sharding and Operation System version. + - Source code to reproduce bug on github cna copy the link here. + - Stack trace if exception thrown. + - Screenshot and animated gif to help bug reproduce if necessary. + - Screenshot for CPU, Memory, Network and IO stat if performance issue. + - If enhancement recommendation reported, please provide information below: + - Details for enhancement behaviour. + - Explain why this enhancement is general feature for most developers. + - List similar features which already available in other product if possible. Both open source and commercial software are available. + - Assign label after create issue. Label should be bug, enhancement, discussion and so on. + - Please pay attention on the issue and provide more information during discuss. + - Please close issue when it is resolved. If you don't close it, we will close it after 3 days。 + - If this issue has new information, please reopen it again. Please note, issue can reopen which only closed by yourself. If the issue is closed by us, you have no permission to reopen any more. + +## Commit pull request + + - Please choose a interested issue, or create a new issue and then settle a correct label. + - Reply a deadline message to pickup this issue. + - Find a mentor in [Core developers list](/en/organization/), he will give you feedback for design and implements. + - Fork to your github repo and begin to work. + - Please follow Sharding's [Development conventions](/en/contribute/convention/), and complete check before pull request submit. + - Submit a pull request to dev branch when finished, please do not submit pull request to master. + - Mentor will do code review and discuss some details, include design, implement, performance and code style. Code will be merged until mentor accepted. + - Finally, congratulations that you have become the official contributor for Sharding! From 5c4d8e41c5599dca3e485ba330bdf81c9fb2add7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E4=BA=AE?= Date: Wed, 8 Aug 2018 01:05:45 +0800 Subject: [PATCH 119/198] Create CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000000..e20541ac1d7e8 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,43 @@ +# Contributor Covenant Code of Conduct + +## Development idea + + - Write extremely clean, simplify and graceful code. Fully agree with <Refactoring: Improving the Design of Existing Code> and <Clean Code: A Handbook of Agile Software Craftsma>. + +## Code push conventions + + - Make sure all test cases passed. + - Make sure test coverage not lower than dev branch. + - Use checkstyle to check code style, provide special reason if rule violated. Find checkstyle template from `sharding-sphere/src/resources/sharding_checks.xml`, please use checkstyle 8.8 to run the rule. + - Make sure `mvn clean install` can be success. + - Delete unused code in time. + +## Code Conventions + + - Use linux line seperator. + - Indent (including blank lines) is consistent with the previous line. + - No unnecessary blank line. + - All logs and java docs are in English. + - Commit allow javadoc, todo and fixme only. + - Give a meaningful variable name. The name of return value is result; The name of unit value is each in for each sentence, instead of entry for map iterator. + - Name of properties file is camel-case, first letter is lowercase. + - Constant on left and variable on right in conditional expression. + - The nested loop should extract to a new private method. + - Replace Nested Conditional with Guard Clauses. + - Access permissions for classes and methods should minimal as possible. + - Parameters and return value are not allowed to be null. + - If use comment to explain the code, try to split several small methods, and use method name to explain it. + - Use lombok instead of the constructor, getter, setter methods and log variable. + - keep style consistent with existed code. + - No duplicate code and configuration. + +## Unit Test Conventions + + - Test code and production code equality, should follow the same code conventions. + - Test cases should fully covered if no special reason. + - Separate environment preparation codes and test codes. + - Only junit Assert, hamcrest CoreMatchers, Mockito related can use static import. + - For single parameter assert, should use `assertTrue`, `assertFalse`, `assertNull` and `assertNotNull`. + - For multiple parameters assert, should use `assertThat`. + - Assert accurately, do not use `not`, `containsString` and so on. + - Use actualXXX and expectedXXX to name related variable. From 3a1454874386cb21671e6bd32ce84cd1fb4796c2 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 01:12:40 +0800 Subject: [PATCH 120/198] upgrade to 3.0.0.M3-SNAPSHOT --- pom.xml | 2 +- sharding-core/pom.xml | 2 +- sharding-jdbc-orchestration-spring/pom.xml | 2 +- .../sharding-jdbc-orchestration-spring-boot-starter/pom.xml | 2 +- .../sharding-jdbc-orchestration-spring-namespace/pom.xml | 2 +- sharding-jdbc-orchestration/pom.xml | 4 ++-- sharding-jdbc-plugin/pom.xml | 4 ++-- sharding-jdbc-spring/pom.xml | 2 +- .../sharding-jdbc-spring-boot-starter/pom.xml | 2 +- sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml | 2 +- sharding-jdbc-transaction-parent/pom.xml | 2 +- .../sharding-jdbc-transaction-async-job/pom.xml | 2 +- .../sharding-jdbc-transaction-storage/pom.xml | 2 +- .../sharding-jdbc-transaction/pom.xml | 2 +- sharding-jdbc/pom.xml | 2 +- sharding-opentracing/pom.xml | 2 +- sharding-proxy/pom.xml | 4 ++-- sharding-proxy/src/main/docker/Dockerfile | 4 ++-- .../proxy/transport/mysql/constant/ServerInfo.java | 2 +- sharding-sql-test/pom.xml | 2 +- 20 files changed, 24 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index a38d6910c243d..f120c573075d2 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.shardingsphere sharding-sphere - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT pom ${project.artifactId} diff --git a/sharding-core/pom.xml b/sharding-core/pom.xml index bb229bf4c13f7..806cd04176731 100644 --- a/sharding-core/pom.xml +++ b/sharding-core/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-core ${project.artifactId} diff --git a/sharding-jdbc-orchestration-spring/pom.xml b/sharding-jdbc-orchestration-spring/pom.xml index dc291a946efaa..7ef3b7b555fb8 100644 --- a/sharding-jdbc-orchestration-spring/pom.xml +++ b/sharding-jdbc-orchestration-spring/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-jdbc-orchestration-spring pom diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/pom.xml b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/pom.xml index 6a5038ec83e83..9caa30775e111 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/pom.xml +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-orchestration-spring - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-jdbc-orchestration-spring-boot-starter diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/pom.xml b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/pom.xml index 45655cd774ffb..d56e3ba8de08d 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/pom.xml +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-orchestration-spring - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-jdbc-orchestration-spring-namespace diff --git a/sharding-jdbc-orchestration/pom.xml b/sharding-jdbc-orchestration/pom.xml index cecebf91938f8..bf58bf8835eb8 100644 --- a/sharding-jdbc-orchestration/pom.xml +++ b/sharding-jdbc-orchestration/pom.xml @@ -5,14 +5,14 @@ io.shardingsphere sharding-sphere - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT 4.0.0 sharding-jdbc-orchestration ${project.artifactId} - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT diff --git a/sharding-jdbc-plugin/pom.xml b/sharding-jdbc-plugin/pom.xml index 42237b18a5e71..7fbc8c4efa02a 100644 --- a/sharding-jdbc-plugin/pom.xml +++ b/sharding-jdbc-plugin/pom.xml @@ -5,11 +5,11 @@ 4.0.0 io.shardingsphere sharding-jdbc-plugin - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT pom - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT 4.12 1.6.6 1.7 diff --git a/sharding-jdbc-spring/pom.xml b/sharding-jdbc-spring/pom.xml index 16e8372b3c215..4c99a74254c3e 100644 --- a/sharding-jdbc-spring/pom.xml +++ b/sharding-jdbc-spring/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-jdbc-spring pom diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/pom.xml b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/pom.xml index 3636755edf6d1..1d7f853ef3eb2 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/pom.xml +++ b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-spring - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-jdbc-spring-boot-starter diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml index 2c82d6fd7ef83..103ae461000b1 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-spring - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-jdbc-spring-namespace diff --git a/sharding-jdbc-transaction-parent/pom.xml b/sharding-jdbc-transaction-parent/pom.xml index f59cac0f3c22b..c93b37da4430e 100644 --- a/sharding-jdbc-transaction-parent/pom.xml +++ b/sharding-jdbc-transaction-parent/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-jdbc-transaction-parent pom diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/pom.xml b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/pom.xml index 32edf84eaf51c..52fd0cd92ec3a 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/pom.xml +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-transaction-parent - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-jdbc-transaction-async-job ${project.artifactId} diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/pom.xml b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/pom.xml index b61943f8fd0a3..83c6493c45621 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/pom.xml +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-transaction-parent - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-jdbc-transaction-storage ${project.artifactId} diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/pom.xml b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/pom.xml index 942a848aa6b84..63ece54f29a77 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/pom.xml +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/pom.xml @@ -3,7 +3,7 @@ io.shardingsphere sharding-jdbc-transaction-parent - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-jdbc-transaction ${project.artifactId} diff --git a/sharding-jdbc/pom.xml b/sharding-jdbc/pom.xml index 0a42961cb6611..f17c114fa43d1 100644 --- a/sharding-jdbc/pom.xml +++ b/sharding-jdbc/pom.xml @@ -4,7 +4,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-jdbc ${project.artifactId} diff --git a/sharding-opentracing/pom.xml b/sharding-opentracing/pom.xml index 0bdec56b84378..711dfb61232e5 100644 --- a/sharding-opentracing/pom.xml +++ b/sharding-opentracing/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-opentracing ${project.artifactId} diff --git a/sharding-proxy/pom.xml b/sharding-proxy/pom.xml index c8628d8a982a8..207bc03ac7d2b 100644 --- a/sharding-proxy/pom.xml +++ b/sharding-proxy/pom.xml @@ -6,7 +6,7 @@ io.shardingsphere sharding-sphere - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-proxy ${project.artifactId} @@ -102,7 +102,7 @@ com.spotify docker-maven-plugin - shardingsphere/sharding-proxy:3.0.0.M2 + shardingsphere/sharding-proxy:3.0.0.M3-SNAPSHOT ${project.basedir}/src/main/docker diff --git a/sharding-proxy/src/main/docker/Dockerfile b/sharding-proxy/src/main/docker/Dockerfile index 01df57a4f6e82..9b51d402387f6 100644 --- a/sharding-proxy/src/main/docker/Dockerfile +++ b/sharding-proxy/src/main/docker/Dockerfile @@ -1,6 +1,6 @@ FROM java:7 MAINTAINER caohao "caohaoch@gmail.com" -ADD sharding-proxy-3.0.0.M2.tar.gz / -RUN mv /sharding-proxy-3.0.0.M2 /opt/sharding-proxy +ADD sharding-proxy-3.0.0.M3.tar.gz / +RUN mv /sharding-proxy-3.0.0.M3 /opt/sharding-proxy ENTRYPOINT /opt/sharding-proxy/bin/start.sh $PORT && tail -f /opt/sharding-proxy/logs/stdout.log diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java index a5793c745c758..bad3e8af0fe1c 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java @@ -32,7 +32,7 @@ public interface ServerInfo { /** * Server version. */ - String SERVER_VERSION = "5.6.0-Sharding-Proxy 3.0.0.M2"; + String SERVER_VERSION = "5.6.0-Sharding-Proxy 3.0.0.M3"; /** * Charset code 0x21 is utf8_general_ci. diff --git a/sharding-sql-test/pom.xml b/sharding-sql-test/pom.xml index 773f553b833ba..843e06e49d1b8 100644 --- a/sharding-sql-test/pom.xml +++ b/sharding-sql-test/pom.xml @@ -6,7 +6,7 @@ sharding-sphere io.shardingsphere - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-sql-test ${project.artifactId} From 269fc5a45a9965aa6fda8d68f6e09b183aaa0460 Mon Sep 17 00:00:00 2001 From: saaav Date: Wed, 8 Aug 2018 12:02:21 +0800 Subject: [PATCH 121/198] checkstyle blank line --- .../client/zookeeper/strategy/ContentionStrategy.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java index a4fd3d410c8cf..a86e6631ab003 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java @@ -47,14 +47,14 @@ public ContentionStrategy(final IProvider provider) { */ @Override public void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) throws KeeperException, InterruptedException { - LeaderElection election = new LeaderElection() { + getProvider().executeContention(new LeaderElection() { + @Override public void action() throws KeeperException, InterruptedException { getProvider().getData(getProvider().getRealPath(key), callback, ctx); log.debug("ContentionStrategy getData action: {}", key); } - }; - getProvider().executeContention(election); + }); log.debug("ContentionStrategy getData executeContention"); } @@ -93,6 +93,7 @@ public void update(final String key, final String value) throws KeeperException, 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); From 9bc3ba612d2595c71c7a210900930f790f3d8656 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 13:01:55 +0800 Subject: [PATCH 122/198] update release notes --- RELEASE-NOTES.md | 5 ++--- RELEASE-NOTES_ZH.md | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index bc1e861db43da..bcd8dfa0bbe17 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -8,9 +8,9 @@ 1. [ISSUE #290](https://github.com/sharding-sphere/sharding-sphere/issues/290) Support batch INSERT statements 1. [ISSUE #501](https://github.com/sharding-sphere/sharding-sphere/issues/501) Support OR statement -1. [ISSUE #862](https://github.com/sharding-sphere/sharding-sphere/issues/862) Support data orchestration in cloud side +1. [ISSUE #916](https://github.com/sharding-sphere/sharding-sphere/issues/916) Support authorization for Sharding-Proxy +1. [ISSUE #936](https://github.com/sharding-sphere/sharding-sphere/issues/936) Support the registry center for Sharding-Proxy 1. [ISSUE #980](https://github.com/sharding-sphere/sharding-sphere/issues/980) Support DCL statement -1. [ISSUE #936](https://github.com/sharding-sphere/sharding-sphere/issues/936) Support the registry center for Proxy ### Enhancements @@ -24,7 +24,6 @@ 1. [ISSUE #719](https://github.com/sharding-sphere/sharding-sphere/issues/719) Support Spring bean namespace to inject key generator objects 1. [ISSUE #720](https://github.com/sharding-sphere/sharding-sphere/issues/720) Support Spring bean namespace to inject sharding algorithm objects 1. [ISSUE #773](https://github.com/sharding-sphere/sharding-sphere/issues/773) Support sharding and autoincrement primary key of INSERT statements without column names -1. [ISSUE #916](https://github.com/sharding-sphere/sharding-sphere/issues/916) Support authorization for Sharding Proxy 1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) Support to store configuration by using Yaml instead of JSON in registry center. 1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) Support props configuration for MasterSlave rule. diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index 2a77985a1fed3..a65b8df274d6e 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -8,9 +8,9 @@ 1. [ISSUE #290](https://github.com/sharding-sphere/sharding-sphere/issues/290) 支持批量INSERT语句 1. [ISSUE #501](https://github.com/sharding-sphere/sharding-sphere/issues/501) 支持OR语句 -1. [ISSUE #862](https://github.com/sharding-sphere/sharding-sphere/issues/862) 支持在Cloud端进行数据治理 +1. [ISSUE #916](https://github.com/sharding-sphere/sharding-sphere/issues/916) 支持Sharding-Proxy登录认证 +1. [ISSUE #936](https://github.com/sharding-sphere/sharding-sphere/issues/936) 支持Sharding Proxy使用注册中心进行治理 1. [ISSUE #980](https://github.com/sharding-sphere/sharding-sphere/issues/980) 支持DCL语句 -1. [ISSUE #936](https://github.com/sharding-sphere/sharding-sphere/issues/936) 支持Proxy使用注册中心 ### 功能提升 @@ -24,7 +24,6 @@ 1. [ISSUE #719](https://github.com/sharding-sphere/sharding-sphere/issues/719) 支持Spring bean的方式在命名空间中注入自增序列生成器对象 1. [ISSUE #720](https://github.com/sharding-sphere/sharding-sphere/issues/720) 支持Spring bean的方式在命名空间中注入分片算法对象 1. [ISSUE #773](https://github.com/sharding-sphere/sharding-sphere/issues/773) 支持不包含列名的INSERT语句的分片与自增主键 -1. [ISSUE #916](https://github.com/sharding-sphere/sharding-sphere/issues/916) 支持Sharding Proxy的登录权限认证 1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) 取代JSON格式,而将Yaml格式的配置文件存储在注册中心 1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) 支持在使用读写分离规则时,配置props属性 From 84c43450544ca5c9c950b15fc8695e661d621f28 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 14:03:21 +0800 Subject: [PATCH 123/198] update issue template --- .github/ISSUE_TEMPLATE | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE index b3da04059cc08..7fc62f0c5aac6 100644 --- a/.github/ISSUE_TEMPLATE +++ b/.github/ISSUE_TEMPLATE @@ -4,6 +4,8 @@ Please answer these questions before submitting your issue. Thanks! ### Which version of Sharding-Sphere do you using? +### Which project do you using? Sharding-JDBC or Sharding-Proxy? + ### Expected behavior ### Actual behavior From c38a79aef7348a373d99e67acb2945bc858ce527 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 14:31:18 +0800 Subject: [PATCH 124/198] update release notes --- RELEASE-NOTES.md | 49 +++++++++++++++++++++++++++++---------------- RELEASE-NOTES_ZH.md | 42 +++++++++++++++++++++++++------------- 2 files changed, 60 insertions(+), 31 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index bcd8dfa0bbe17..14baa20e50afd 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -6,41 +6,56 @@ ### New Features -1. [ISSUE #290](https://github.com/sharding-sphere/sharding-sphere/issues/290) Support batch INSERT statements -1. [ISSUE #501](https://github.com/sharding-sphere/sharding-sphere/issues/501) Support OR statement -1. [ISSUE #916](https://github.com/sharding-sphere/sharding-sphere/issues/916) Support authorization for Sharding-Proxy -1. [ISSUE #936](https://github.com/sharding-sphere/sharding-sphere/issues/936) Support the registry center for Sharding-Proxy -1. [ISSUE #980](https://github.com/sharding-sphere/sharding-sphere/issues/980) Support DCL statement +#### Core + +1. [ISSUE #290](https://github.com/sharding-sphere/sharding-sphere/issues/290) Support batch INSERT +1. [ISSUE #501](https://github.com/sharding-sphere/sharding-sphere/issues/501) Support OR +1. [ISSUE #980](https://github.com/sharding-sphere/sharding-sphere/issues/980) Support DCL +1. [ISSUE #1111](https://github.com/sharding-sphere/sharding-sphere/issues/1111) SupportMySQL DAL + +#### Sharding-Proxy + +1. [ISSUE #916](https://github.com/sharding-sphere/sharding-sphere/issues/916) Support authorization +1. [ISSUE #936](https://github.com/sharding-sphere/sharding-sphere/issues/936) Support registry center + ### Enhancements -1. [ISSUE #608](https://github.com/sharding-sphere/sharding-sphere/issues/608) Support the USE statement of MySQL -1. [ISSUE #609](https://github.com/sharding-sphere/sharding-sphere/issues/609) Support the SHOW statement of MySQL -1. [ISSUE #610](https://github.com/sharding-sphere/sharding-sphere/issues/610) Optimize the DQL that does not contain a table name -1. [ISSUE #611](https://github.com/sharding-sphere/sharding-sphere/issues/611) Support the DESC statement of MySQL -1. [ISSUE #652](https://github.com/sharding-sphere/sharding-sphere/issues/652) Support Spring Boot Starter 2.x +#### Core + +1. [ISSUE #610](https://github.com/sharding-sphere/sharding-sphere/issues/610) Route unicast for DQL without table 1. [ISSUE #701](https://github.com/sharding-sphere/sharding-sphere/issues/701) Support caching parsing results of SQL to improve performance +1. [ISSUE #773](https://github.com/sharding-sphere/sharding-sphere/issues/773) Support sharding and autoincrement primary key of INSERT statements without column names +1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) Support to store configuration by using Yaml instead of JSON in registry center +1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) Support props configuration for MasterSlave rule + +#### Sharding-JDBC + +1. [ISSUE #652](https://github.com/sharding-sphere/sharding-sphere/issues/652) Support Spring Boot Starter 2.x 1. [ISSUE #702](https://github.com/sharding-sphere/sharding-sphere/issues/702) Support $->{..} as mark for inline expression 1. [ISSUE #719](https://github.com/sharding-sphere/sharding-sphere/issues/719) Support Spring bean namespace to inject key generator objects 1. [ISSUE #720](https://github.com/sharding-sphere/sharding-sphere/issues/720) Support Spring bean namespace to inject sharding algorithm objects -1. [ISSUE #773](https://github.com/sharding-sphere/sharding-sphere/issues/773) Support sharding and autoincrement primary key of INSERT statements without column names -1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) Support to store configuration by using Yaml instead of JSON in registry center. -1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) Support props configuration for MasterSlave rule. + ### Bug Fixes -1. [ISSUE #372](https://github.com/sharding-sphere/sharding-sphere/issues/372) Reuse PreparedStatement cause cache of route result do not clean +#### Core + 1. [ISSUE #628](https://github.com/sharding-sphere/sharding-sphere/issues/628) Support data type jsonb for PostgreSQL -1. [ISSUE #629](https://github.com/sharding-sphere/sharding-sphere/issues/629) Support transaction isolation on JDBC 1. [ISSUE #646](https://github.com/sharding-sphere/sharding-sphere/issues/646) When aliases in SELECT ITEMS correspond to the real column names of GROUP BY or ORDER BY, there is no need to add columns -1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) Unexpected slave datasource routing result when using Round-robin load-balance algorithm in Mybatis 1. [ISSUE #806](https://github.com/sharding-sphere/sharding-sphere/issues/806) SQL parse error with `NOT IN` 1. [ISSUE #827](https://github.com/sharding-sphere/sharding-sphere/issues/827) Fix endless loop for bad SQL like `SELECT * FROM table WHERE id IN ()` 1. [ISSUE #919](https://github.com/sharding-sphere/sharding-sphere/issues/919) Use groovy to parse inline expression may cause memory leak 1. [ISSUE #993](https://github.com/sharding-sphere/sharding-sphere/issues/993) Fail to parsing PostgreSQL due to the quotation -1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) Can't resolve placeholder in spring boot configuration yaml 1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) Support the statement of `SELECT id, COUNT(*) FROM table GROUP BY 1,2` +#### Sharding-JDBC + +1. [ISSUE #372](https://github.com/sharding-sphere/sharding-sphere/issues/372) Reuse PreparedStatement cause cache of route result do not clean +1. [ISSUE #629](https://github.com/sharding-sphere/sharding-sphere/issues/629) Support transaction isolation on JDBC +1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) Unexpected slave datasource routing result when using Round-robin load-balance algorithm in Mybatis +1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) Can't resolve placeholder in spring boot configuration yaml + ## 2.0.3 ### Enhancements diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index a65b8df274d6e..8ffd8eed95572 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -6,41 +6,55 @@ ### 新功能 +#### 内核 + 1. [ISSUE #290](https://github.com/sharding-sphere/sharding-sphere/issues/290) 支持批量INSERT语句 1. [ISSUE #501](https://github.com/sharding-sphere/sharding-sphere/issues/501) 支持OR语句 -1. [ISSUE #916](https://github.com/sharding-sphere/sharding-sphere/issues/916) 支持Sharding-Proxy登录认证 -1. [ISSUE #936](https://github.com/sharding-sphere/sharding-sphere/issues/936) 支持Sharding Proxy使用注册中心进行治理 1. [ISSUE #980](https://github.com/sharding-sphere/sharding-sphere/issues/980) 支持DCL语句 +1. [ISSUE #1111](https://github.com/sharding-sphere/sharding-sphere/issues/1111) 支持MySQL DAL语句 + +#### Sharding-Proxy + +1. [ISSUE #916](https://github.com/sharding-sphere/sharding-sphere/issues/916) 支持登录认证 +1. [ISSUE #936](https://github.com/sharding-sphere/sharding-sphere/issues/936) 支持注册中心进行治理 + ### 功能提升 -1. [ISSUE #608](https://github.com/sharding-sphere/sharding-sphere/issues/608) 支持MySQL的USE语句 -1. [ISSUE #609](https://github.com/sharding-sphere/sharding-sphere/issues/609) 支持MySQL的SHOW语句 -1. [ISSUE #610](https://github.com/sharding-sphere/sharding-sphere/issues/610) 优化不包含表的DQL -1. [ISSUE #611](https://github.com/sharding-sphere/sharding-sphere/issues/611) 支持MySQL的DESC语句 +#### 内核 + +1. [ISSUE #610](https://github.com/sharding-sphere/sharding-sphere/issues/610) 无表名称的DQL采用单播路由 +1. [ISSUE #701](https://github.com/sharding-sphere/sharding-sphere/issues/701) 缓存SQL解析结果以提升性能 +1. [ISSUE #773](https://github.com/sharding-sphere/sharding-sphere/issues/773) 支持不包含列名的INSERT语句的分片与自增主键 +1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) 取代JSON格式,而将Yaml格式的配置文件存储在注册中心 +1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) 支持在使用读写分离规则时,配置props属性 + +#### Sharding-JDBC + 1. [ISSUE #652](https://github.com/sharding-sphere/sharding-sphere/issues/652) Spring Boot Starter 2.x支持 -1. [ISSUE #701](https://github.com/sharding-sphere/sharding-sphere/issues/701) 支持缓存SQL解析结果以提升性能 1. [ISSUE #702](https://github.com/sharding-sphere/sharding-sphere/issues/702) 支持以 $->{..} 作为inline表达式的标记 1. [ISSUE #719](https://github.com/sharding-sphere/sharding-sphere/issues/719) 支持Spring bean的方式在命名空间中注入自增序列生成器对象 1. [ISSUE #720](https://github.com/sharding-sphere/sharding-sphere/issues/720) 支持Spring bean的方式在命名空间中注入分片算法对象 -1. [ISSUE #773](https://github.com/sharding-sphere/sharding-sphere/issues/773) 支持不包含列名的INSERT语句的分片与自增主键 -1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) 取代JSON格式,而将Yaml格式的配置文件存储在注册中心 -1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) 支持在使用读写分离规则时,配置props属性 ### 缺陷修正 -1. [ISSUE #372](https://github.com/sharding-sphere/sharding-sphere/issues/372) 同一PreparedStatement反复使用导致路由缓存未清理 +#### 内核 + 1. [ISSUE #628](https://github.com/sharding-sphere/sharding-sphere/issues/628) 支持PostgreSQL的数据类型jsonb -1. [ISSUE #629](https://github.com/sharding-sphere/sharding-sphere/issues/629) 支持JDBC中设置事务隔离级别 1. [ISSUE #646](https://github.com/sharding-sphere/sharding-sphere/issues/646) 当SELECT ITEMS中的别名与GROUP BY或ORDER BY的真实列名对应时,无需补列 -1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) 在Mybatis中使用RoundRobinMasterSlaveLoadBalanceAlgorithm算法路由存在问题 1. [ISSUE #806](https://github.com/sharding-sphere/sharding-sphere/issues/806) `NOT IN`解析异常 1. [ISSUE #827](https://github.com/sharding-sphere/sharding-sphere/issues/827) 将`SELECT * FROM table WHERE id IN ()`这种SQL跳出死循环 1. [ISSUE #919](https://github.com/sharding-sphere/sharding-sphere/issues/919) 使用Groovy解析行表达式可能导致内存泄漏 1. [ISSUE #993](https://github.com/sharding-sphere/sharding-sphere/issues/993) 无法解析PostgreSQL的双引号占位符 -1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) 无法在Spring Boot的yaml中处理占位符 1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) 支持使用`SELECT id, COUNT(*) FROM table GROUP BY 1,2` +#### Sharding-JDBC + +1. [ISSUE #372](https://github.com/sharding-sphere/sharding-sphere/issues/372) 同一PreparedStatement反复使用导致路由缓存未清理 +1. [ISSUE #629](https://github.com/sharding-sphere/sharding-sphere/issues/629) 支持JDBC中设置事务隔离级别 +1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) 在Mybatis中使用RoundRobinMasterSlaveLoadBalanceAlgorithm算法路由存在问题 +1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) 无法在Spring Boot的yaml中处理占位符 + ## 2.0.3 ### 功能提升 From 2dc02a24cf94f315f3c58270095ee886ff644761 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Wed, 8 Aug 2018 15:23:01 +0800 Subject: [PATCH 125/198] remove get connection --- .../executor/type/BatchPreparedStatementExecutorTest.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/BatchPreparedStatementExecutorTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/BatchPreparedStatementExecutorTest.java index 161a4146ce937..a440c7c5686cd 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/BatchPreparedStatementExecutorTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/BatchPreparedStatementExecutorTest.java @@ -84,8 +84,6 @@ public void assertExecuteBatchForMultiplePreparedStatementsSuccess() throws SQLE assertThat(actual.executeBatch(), is(new int[] {30, 60})); verify(preparedStatement1).executeBatch(); verify(preparedStatement2).executeBatch(); - verify(preparedStatement1).getConnection(); - verify(preparedStatement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML); verify(getEventCaller(), times(4)).verifyDataSource("ds_0"); verify(getEventCaller(), times(4)).verifyDataSource("ds_1"); @@ -131,8 +129,6 @@ public void assertExecuteBatchForMultiplePreparedStatementsFailure() throws SQLE assertThat(actual.executeBatch(), is(new int[] {0, 0})); verify(preparedStatement1).executeBatch(); verify(preparedStatement2).executeBatch(); - verify(preparedStatement1).getConnection(); - verify(preparedStatement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML); verify(getEventCaller(), times(4)).verifyDataSource("ds_0"); verify(getEventCaller(), times(4)).verifyDataSource("ds_1"); From 9d13a5857a6a86ff2abadde4b3985f80f8e25ee7 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Wed, 8 Aug 2018 15:23:10 +0800 Subject: [PATCH 126/198] remove get connection check --- .../type/PreparedStatementExecutorTest.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/PreparedStatementExecutorTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/PreparedStatementExecutorTest.java index f96012daf518b..51e2e266e86f5 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/PreparedStatementExecutorTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/PreparedStatementExecutorTest.java @@ -96,8 +96,6 @@ public void assertExecuteQueryForMultiplePreparedStatementsSuccess() throws SQLE assertThat(actualResultSets, hasItem(resultSet2)); verify(preparedStatement1).executeQuery(); verify(preparedStatement2).executeQuery(); - verify(preparedStatement1).getConnection(); - verify(preparedStatement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DQL); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -142,8 +140,6 @@ public void assertExecuteQueryForMultiplePreparedStatementsFailure() throws SQLE assertThat(actualResultSets, is(Arrays.asList((ResultSet) null, null))); verify(preparedStatement1).executeQuery(); verify(preparedStatement2).executeQuery(); - verify(preparedStatement1).getConnection(); - verify(preparedStatement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DQL); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -185,8 +181,6 @@ public void assertExecuteUpdateForMultiplePreparedStatementsSuccess() throws SQL assertThat(actual.executeUpdate(), is(30)); verify(preparedStatement1).executeUpdate(); verify(preparedStatement2).executeUpdate(); - verify(preparedStatement1).getConnection(); - verify(preparedStatement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -230,8 +224,6 @@ public void assertExecuteUpdateForMultiplePreparedStatementsFailure() throws SQL assertThat(actual.executeUpdate(), is(0)); verify(preparedStatement1).executeUpdate(); verify(preparedStatement2).executeUpdate(); - verify(preparedStatement1).getConnection(); - verify(preparedStatement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -273,8 +265,6 @@ public void assertExecuteForMultiplePreparedStatementsSuccessWithDML() throws SQ assertFalse(actual.execute()); verify(preparedStatement1).execute(); verify(preparedStatement2).execute(); - verify(preparedStatement1).getConnection(); - verify(preparedStatement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -317,9 +307,7 @@ public void assertExecuteForMultiplePreparedStatementsFailureWithDML() throws SQ getExecutorEngine(), SQLType.DML, createPreparedStatementUnits(DML_SQL, preparedStatement1, "ds_0", preparedStatement2, "ds_1")); assertFalse(actual.execute()); verify(preparedStatement1).execute(); - verify(preparedStatement2).execute(); - verify(preparedStatement1).getConnection(); - verify(preparedStatement2).getConnection(); + verify(preparedStatement2).execute();; verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -361,8 +349,6 @@ public void assertExecuteForMultiplePreparedStatements() throws SQLException { assertTrue(actual.execute()); verify(preparedStatement1).execute(); verify(preparedStatement2).execute(); - verify(preparedStatement1).getConnection(); - verify(preparedStatement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DQL); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); From 1e168e822201ff85b7ee7fc10a319e278c11279e Mon Sep 17 00:00:00 2001 From: tristaZero Date: Wed, 8 Aug 2018 15:23:21 +0800 Subject: [PATCH 127/198] remove get connection checking --- .../core/executor/type/StatementExecutorTest.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/StatementExecutorTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/StatementExecutorTest.java index f4937b390188e..1a63acf4d85bd 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/StatementExecutorTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/StatementExecutorTest.java @@ -93,9 +93,7 @@ public void assertExecuteQueryForMultipleStatementsSuccess() throws SQLException assertThat(actualResultSets, hasItem(resultSet1)); assertThat(actualResultSets, hasItem(resultSet2)); verify(statement1).executeQuery(DQL_SQL); - verify(statement1).getConnection(); verify(statement2).executeQuery(DQL_SQL); - verify(statement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DQL); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -138,8 +136,6 @@ public void assertExecuteQueryForMultipleStatementsFailure() throws SQLException assertThat(actualResultSets, is(Arrays.asList((ResultSet) null, null))); verify(statement1).executeQuery(DQL_SQL); verify(statement2).executeQuery(DQL_SQL); - verify(statement1).getConnection(); - verify(statement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DQL); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -179,8 +175,6 @@ public void assertExecuteUpdateForMultipleStatementsSuccess() throws SQLExceptio assertThat(actual.executeUpdate(), is(30)); verify(statement1).executeUpdate(DML_SQL); verify(statement2).executeUpdate(DML_SQL); - verify(statement1).getConnection(); - verify(statement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -222,8 +216,6 @@ public void assertExecuteUpdateForMultipleStatementsFailure() throws SQLExceptio assertThat(actual.executeUpdate(), is(0)); verify(statement1).executeUpdate(DML_SQL); verify(statement2).executeUpdate(DML_SQL); - verify(statement1).getConnection(); - verify(statement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -314,8 +306,6 @@ public void assertExecuteForMultipleStatementsSuccessWithDML() throws SQLExcepti assertFalse(actual.execute()); verify(statement1).execute(DML_SQL); verify(statement2).execute(DML_SQL); - verify(statement1).getConnection(); - verify(statement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -357,8 +347,6 @@ public void assertExecuteForMultipleStatementsFailureWithDML() throws SQLExcepti assertFalse(actual.execute()); verify(statement1).execute(DML_SQL); verify(statement2).execute(DML_SQL); - verify(statement1).getConnection(); - verify(statement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); @@ -398,8 +386,6 @@ public void assertExecuteForMultipleStatements() throws SQLException { assertTrue(actual.execute()); verify(statement1).execute(DQL_SQL); verify(statement2).execute(DQL_SQL); - verify(statement1).getConnection(); - verify(statement2).getConnection(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DQL); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); From 195537f922cee55e3a918eefc704ba15a2043470 Mon Sep 17 00:00:00 2001 From: tristaZero Date: Wed, 8 Aug 2018 15:24:26 +0800 Subject: [PATCH 128/198] delete ; --- .../core/executor/type/PreparedStatementExecutorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/PreparedStatementExecutorTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/PreparedStatementExecutorTest.java index 51e2e266e86f5..f5175f16e8b8e 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/PreparedStatementExecutorTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/type/PreparedStatementExecutorTest.java @@ -307,7 +307,7 @@ public void assertExecuteForMultiplePreparedStatementsFailureWithDML() throws SQ getExecutorEngine(), SQLType.DML, createPreparedStatementUnits(DML_SQL, preparedStatement1, "ds_0", preparedStatement2, "ds_1")); assertFalse(actual.execute()); verify(preparedStatement1).execute(); - verify(preparedStatement2).execute();; + verify(preparedStatement2).execute(); verify(getEventCaller(), times(2)).verifySQLType(SQLType.DML); verify(getEventCaller(), times(2)).verifyDataSource("ds_0"); verify(getEventCaller(), times(2)).verifyDataSource("ds_1"); From 2507497f000619cb07045ffbcbe40adeda449b38 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 15:32:34 +0800 Subject: [PATCH 129/198] update release notes for 3.0.0 --- RELEASE-NOTES.md | 32 +++++++++++++++----------------- RELEASE-NOTES_ZH.md | 14 +++++++------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 14baa20e50afd..2a5c170a50390 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -18,43 +18,41 @@ 1. [ISSUE #916](https://github.com/sharding-sphere/sharding-sphere/issues/916) Support authorization 1. [ISSUE #936](https://github.com/sharding-sphere/sharding-sphere/issues/936) Support registry center - ### Enhancements #### Core 1. [ISSUE #610](https://github.com/sharding-sphere/sharding-sphere/issues/610) Route unicast for DQL without table -1. [ISSUE #701](https://github.com/sharding-sphere/sharding-sphere/issues/701) Support caching parsing results of SQL to improve performance -1. [ISSUE #773](https://github.com/sharding-sphere/sharding-sphere/issues/773) Support sharding and autoincrement primary key of INSERT statements without column names -1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) Support to store configuration by using Yaml instead of JSON in registry center -1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) Support props configuration for MasterSlave rule +1. [ISSUE #701](https://github.com/sharding-sphere/sharding-sphere/issues/701) Caching parsed results to improve performance +1. [ISSUE #773](https://github.com/sharding-sphere/sharding-sphere/issues/773) Support sharding and autoincrement key of INSERT without column names +1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) Use YAML instead of JSON to store configurations in registry center +1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) Properties can configure for Sharding and Master-slave independent #### Sharding-JDBC -1. [ISSUE #652](https://github.com/sharding-sphere/sharding-sphere/issues/652) Support Spring Boot Starter 2.x -1. [ISSUE #702](https://github.com/sharding-sphere/sharding-sphere/issues/702) Support $->{..} as mark for inline expression -1. [ISSUE #719](https://github.com/sharding-sphere/sharding-sphere/issues/719) Support Spring bean namespace to inject key generator objects -1. [ISSUE #720](https://github.com/sharding-sphere/sharding-sphere/issues/720) Support Spring bean namespace to inject sharding algorithm objects - +1. [ISSUE #652](https://github.com/sharding-sphere/sharding-sphere/issues/652) Support `Spring Boot Starter` 2.X +1. [ISSUE #702](https://github.com/sharding-sphere/sharding-sphere/issues/702) Support `$->{..}` for inline expression +1. [ISSUE #719](https://github.com/sharding-sphere/sharding-sphere/issues/719) Support inject key generator objects by spring namespace +1. [ISSUE #720](https://github.com/sharding-sphere/sharding-sphere/issues/720) Support inject sharding algorithm objects by spring namespace ### Bug Fixes #### Core 1. [ISSUE #628](https://github.com/sharding-sphere/sharding-sphere/issues/628) Support data type jsonb for PostgreSQL -1. [ISSUE #646](https://github.com/sharding-sphere/sharding-sphere/issues/646) When aliases in SELECT ITEMS correspond to the real column names of GROUP BY or ORDER BY, there is no need to add columns -1. [ISSUE #806](https://github.com/sharding-sphere/sharding-sphere/issues/806) SQL parse error with `NOT IN` -1. [ISSUE #827](https://github.com/sharding-sphere/sharding-sphere/issues/827) Fix endless loop for bad SQL like `SELECT * FROM table WHERE id IN ()` -1. [ISSUE #919](https://github.com/sharding-sphere/sharding-sphere/issues/919) Use groovy to parse inline expression may cause memory leak +1. [ISSUE #646](https://github.com/sharding-sphere/sharding-sphere/issues/646) When aliases in `SELECT ITEMS` correspond to the real column names of `GROUP BY` or `ORDER BY`, there is no need to generate derived columns +1. [ISSUE #806](https://github.com/sharding-sphere/sharding-sphere/issues/806) `NOT IN` parse exception +1. [ISSUE #827](https://github.com/sharding-sphere/sharding-sphere/issues/827) Endless loop for bad SQL like `SELECT * FROM table WHERE id IN ()` +1. [ISSUE #919](https://github.com/sharding-sphere/sharding-sphere/issues/919) Inline expression with groovy may cause memory leak 1. [ISSUE #993](https://github.com/sharding-sphere/sharding-sphere/issues/993) Fail to parsing PostgreSQL due to the quotation -1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) Support the statement of `SELECT id, COUNT(*) FROM table GROUP BY 1,2` +1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) Support SQL like `SELECT id, COUNT(*) FROM table GROUP BY 1,2` #### Sharding-JDBC 1. [ISSUE #372](https://github.com/sharding-sphere/sharding-sphere/issues/372) Reuse PreparedStatement cause cache of route result do not clean 1. [ISSUE #629](https://github.com/sharding-sphere/sharding-sphere/issues/629) Support transaction isolation on JDBC -1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) Unexpected slave datasource routing result when using Round-robin load-balance algorithm in Mybatis -1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) Can't resolve placeholder in spring boot configuration yaml +1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) Unexpected slave datasource routing result when using `Round-robin` load-balance algorithm in Mybatis +1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) Can't resolve placeholder in `Spring Boot YAML` configuration ## 2.0.3 diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index 8ffd8eed95572..5e7c40b23dc7b 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -27,12 +27,12 @@ 1. [ISSUE #701](https://github.com/sharding-sphere/sharding-sphere/issues/701) 缓存SQL解析结果以提升性能 1. [ISSUE #773](https://github.com/sharding-sphere/sharding-sphere/issues/773) 支持不包含列名的INSERT语句的分片与自增主键 1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) 取代JSON格式,而将Yaml格式的配置文件存储在注册中心 -1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) 支持在使用读写分离规则时,配置props属性 +1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) props属性可在分片和读写分离规则配置时独立使用 #### Sharding-JDBC -1. [ISSUE #652](https://github.com/sharding-sphere/sharding-sphere/issues/652) Spring Boot Starter 2.x支持 -1. [ISSUE #702](https://github.com/sharding-sphere/sharding-sphere/issues/702) 支持以 $->{..} 作为inline表达式的标记 +1. [ISSUE #652](https://github.com/sharding-sphere/sharding-sphere/issues/652) `Spring Boot Starter` 2.X支持 +1. [ISSUE #702](https://github.com/sharding-sphere/sharding-sphere/issues/702) 支持以 `$->{..}` 作为行表达式的标记 1. [ISSUE #719](https://github.com/sharding-sphere/sharding-sphere/issues/719) 支持Spring bean的方式在命名空间中注入自增序列生成器对象 1. [ISSUE #720](https://github.com/sharding-sphere/sharding-sphere/issues/720) 支持Spring bean的方式在命名空间中注入分片算法对象 @@ -41,19 +41,19 @@ #### 内核 1. [ISSUE #628](https://github.com/sharding-sphere/sharding-sphere/issues/628) 支持PostgreSQL的数据类型jsonb -1. [ISSUE #646](https://github.com/sharding-sphere/sharding-sphere/issues/646) 当SELECT ITEMS中的别名与GROUP BY或ORDER BY的真实列名对应时,无需补列 +1. [ISSUE #646](https://github.com/sharding-sphere/sharding-sphere/issues/646) 当SELECT ITEMS中的别名与GROUP BY或ORDER BY的真实列名对应时无需补列 1. [ISSUE #806](https://github.com/sharding-sphere/sharding-sphere/issues/806) `NOT IN`解析异常 1. [ISSUE #827](https://github.com/sharding-sphere/sharding-sphere/issues/827) 将`SELECT * FROM table WHERE id IN ()`这种SQL跳出死循环 1. [ISSUE #919](https://github.com/sharding-sphere/sharding-sphere/issues/919) 使用Groovy解析行表达式可能导致内存泄漏 1. [ISSUE #993](https://github.com/sharding-sphere/sharding-sphere/issues/993) 无法解析PostgreSQL的双引号占位符 -1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) 支持使用`SELECT id, COUNT(*) FROM table GROUP BY 1,2` +1. [ISSUE #1015](https://github.com/sharding-sphere/sharding-sphere/issues/1015) 支持SQL `SELECT id, COUNT(*) FROM table GROUP BY 1,2` #### Sharding-JDBC 1. [ISSUE #372](https://github.com/sharding-sphere/sharding-sphere/issues/372) 同一PreparedStatement反复使用导致路由缓存未清理 1. [ISSUE #629](https://github.com/sharding-sphere/sharding-sphere/issues/629) 支持JDBC中设置事务隔离级别 -1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) 在Mybatis中使用RoundRobinMasterSlaveLoadBalanceAlgorithm算法路由存在问题 -1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) 无法在Spring Boot的yaml中处理占位符 +1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) 在Mybatis中使用`Round-robin`的读写分离算法路由存在问题 +1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) 无法在`Spring Boot`的`YAML`中处理占位符 ## 2.0.3 From f12058342ae1f913e96d96f088238b9843d123e1 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 15:50:59 +0800 Subject: [PATCH 130/198] update release notes for 2.0.3 --- RELEASE-NOTES.md | 17 ++++++++++++----- RELEASE-NOTES_ZH.md | 15 +++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 2a5c170a50390..377481af104c4 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -25,7 +25,7 @@ 1. [ISSUE #610](https://github.com/sharding-sphere/sharding-sphere/issues/610) Route unicast for DQL without table 1. [ISSUE #701](https://github.com/sharding-sphere/sharding-sphere/issues/701) Caching parsed results to improve performance 1. [ISSUE #773](https://github.com/sharding-sphere/sharding-sphere/issues/773) Support sharding and autoincrement key of INSERT without column names -1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) Use YAML instead of JSON to store configurations in registry center +1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) Use `YAML` instead of `JSON` to store configurations in registry center 1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) Properties can configure for Sharding and Master-slave independent #### Sharding-JDBC @@ -56,15 +56,22 @@ ## 2.0.3 -### Enhancements +### New Features + +#### Core 1. [ISSUE #600](https://github.com/sharding-sphere/sharding-sphere/issues/600) Support TCL ### Bug Fixes -1. [ISSUE #522](https://github.com/sharding-sphere/sharding-sphere/issues/522) The slave database does not need to execute the DDL statement for read-write separation -1. [ISSUE #540](https://github.com/sharding-sphere/sharding-sphere/issues/540) Support SQLs that the alias is the keyword -1. [ISSUE #577](https://github.com/sharding-sphere/sharding-sphere/issues/577) Support newline for YAML configuration +#### Core + +1. [ISSUE #540](https://github.com/sharding-sphere/sharding-sphere/issues/540) Support SQL that alias is the keyword +1. [ISSUE #577](https://github.com/sharding-sphere/sharding-sphere/issues/577) Support new line for `YAML` configuration + +#### Sharding-JDBC + +1. [ISSUE #522](https://github.com/sharding-sphere/sharding-sphere/issues/522) Slave database does not need to execute the DDL for read-write splitting ## 2.0.2 diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index 5e7c40b23dc7b..5d44b436458fb 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -26,7 +26,7 @@ 1. [ISSUE #610](https://github.com/sharding-sphere/sharding-sphere/issues/610) 无表名称的DQL采用单播路由 1. [ISSUE #701](https://github.com/sharding-sphere/sharding-sphere/issues/701) 缓存SQL解析结果以提升性能 1. [ISSUE #773](https://github.com/sharding-sphere/sharding-sphere/issues/773) 支持不包含列名的INSERT语句的分片与自增主键 -1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) 取代JSON格式,而将Yaml格式的配置文件存储在注册中心 +1. [ISSUE #935](https://github.com/sharding-sphere/sharding-sphere/issues/935) 取代`JSON`格式,而将`YAML`格式的配置文件存储在注册中心 1. [ISSUE #1004](https://github.com/sharding-sphere/sharding-sphere/issues/1004) props属性可在分片和读写分离规则配置时独立使用 #### Sharding-JDBC @@ -57,15 +57,22 @@ ## 2.0.3 -### 功能提升 +### 新功能 + +#### 内核 1. [ISSUE #600](https://github.com/sharding-sphere/sharding-sphere/issues/600) 支持TCL ### 缺陷修正 -1. [ISSUE #522](https://github.com/sharding-sphere/sharding-sphere/issues/522) 读写分离Slave库不需要执行DDL语句 +#### 内核 + 1. [ISSUE #540](https://github.com/sharding-sphere/sharding-sphere/issues/540) 梳理并支持别名为关键字SQL -1. [ISSUE #577](https://github.com/sharding-sphere/sharding-sphere/issues/577) 支持YAML配置换行 +1. [ISSUE #577](https://github.com/sharding-sphere/sharding-sphere/issues/577) 支持`YAML`配置换行 + +#### Sharding-JDBC + +1. [ISSUE #522](https://github.com/sharding-sphere/sharding-sphere/issues/522) 读写分离的从库不需要执行DDL语句 ## 2.0.2 From bf9eb3ab04bafb8e35f2230ded7a0d18e88b6d71 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 16:07:47 +0800 Subject: [PATCH 131/198] update release notes for 2.0.2 --- RELEASE-NOTES.md | 27 +++++++++++++++++++-------- RELEASE-NOTES_ZH.md | 23 ++++++++++++++++------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 377481af104c4..ca97c7cbfd576 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -54,6 +54,7 @@ 1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) Unexpected slave datasource routing result when using `Round-robin` load-balance algorithm in Mybatis 1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) Can't resolve placeholder in `Spring Boot YAML` configuration + ## 2.0.3 ### New Features @@ -73,22 +74,31 @@ 1. [ISSUE #522](https://github.com/sharding-sphere/sharding-sphere/issues/522) Slave database does not need to execute the DDL for read-write splitting + ## 2.0.2 ### Enhancements -1. [ISSUE #475](https://github.com/sharding-sphere/sharding-sphere/issues/475) Support CREATE INDEX -1. [ISSUE #525](https://github.com/sharding-sphere/sharding-sphere/issues/525) Support DROP INDEX +#### Core + +1. [ISSUE #475](https://github.com/sharding-sphere/sharding-sphere/issues/475) Support `CREATE INDEX` +1. [ISSUE #525](https://github.com/sharding-sphere/sharding-sphere/issues/525) Support `DROP INDEX` ### Bug Fixes -1. [ISSUE #520](https://github.com/sharding-sphere/sharding-sphere/issues/520) When the partition table is introduced, the exception type is no longer DuplicateKeyException when the unique key conflict occurs -1. [ISSUE #521](https://github.com/sharding-sphere/sharding-sphere/issues/521) ShardingProperties is invalid in YAML configuration +#### Core + +1. [ISSUE #521](https://github.com/sharding-sphere/sharding-sphere/issues/521) `ShardingProperties` is invalid in `YAML` configuration 1. [ISSUE #529](https://github.com/sharding-sphere/sharding-sphere/issues/529) Table name capitalization cannot be queried -1. [ISSUE #541](https://github.com/sharding-sphere/sharding-sphere/issues/541) Can't parse IS NOT NULL -1. [ISSUE #557](https://github.com/sharding-sphere/sharding-sphere/issues/557) When GroupBy and OrderBy aliases are inconsistent, stream merging should be used -1. [ISSUE #559](https://github.com/sharding-sphere/sharding-sphere/issues/559) Support parsing numbers beginning with minus and decimal (e.g. -.12). -1. [ISSUE #567](https://github.com/sharding-sphere/sharding-sphere/issues/567) MySQL adds an escape character when columns are added to prevent errors caused by using keywords as column names or aliases +1. [ISSUE #541](https://github.com/sharding-sphere/sharding-sphere/issues/541) `IS NOT NULL` parse error +1. [ISSUE #557](https://github.com/sharding-sphere/sharding-sphere/issues/557) When `GROUP BY` and `ORDER BY` aliases are inconsistent, stream merging should be used +1. [ISSUE #559](https://github.com/sharding-sphere/sharding-sphere/issues/559) Support parsing numbers beginning with minus and decimal (e.g. `-.12`) +1. [ISSUE #567](https://github.com/sharding-sphere/sharding-sphere/issues/567) Add escape char for derived columns or alias when using MySQL + +#### Sharding-JDBC + +1. [ISSUE #520](https://github.com/sharding-sphere/sharding-sphere/issues/520) Exception is no longer `DuplicateKeyException` when the unique key conflict + ## 2.0.1 @@ -103,6 +113,7 @@ 1. [ISSUE #490](https://github.com/sharding-sphere/sharding-sphere/issues/490) Oracle using rownum greater than or equal to or less than or equal to the result of paging is incorrect 1. [ISSUE #491](https://github.com/sharding-sphere/sharding-sphere/issues/491) Can't close connection by ResultSet.getStatement().getConnection().close() + ## 2.0.0 ### Milestones diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index 5d44b436458fb..11b73d2dd71a6 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -55,6 +55,7 @@ 1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) 在Mybatis中使用`Round-robin`的读写分离算法路由存在问题 1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) 无法在`Spring Boot`的`YAML`中处理占位符 + ## 2.0.3 ### 新功能 @@ -74,23 +75,31 @@ 1. [ISSUE #522](https://github.com/sharding-sphere/sharding-sphere/issues/522) 读写分离的从库不需要执行DDL语句 + ## 2.0.2 ### 功能提升 -1. [ISSUE #475](https://github.com/sharding-sphere/sharding-sphere/issues/475) 支持CREATE INDEX -1. [ISSUE #525](https://github.com/sharding-sphere/sharding-sphere/issues/525) 支持DROP INDEX +#### 内核 +1. [ISSUE #475](https://github.com/sharding-sphere/sharding-sphere/issues/475) 支持`CREATE INDEX` +1. [ISSUE #525](https://github.com/sharding-sphere/sharding-sphere/issues/525) 支持`DROP INDEX` ### 缺陷修正 -1. [ISSUE #520](https://github.com/sharding-sphere/sharding-sphere/issues/520) 引入分表后,唯一键冲突时异常类型不再是DuplicateKeyException -1. [ISSUE #521](https://github.com/sharding-sphere/sharding-sphere/issues/521) YAML文件中ShardingProperties设置无效 +#### 内核 + +1. [ISSUE #521](https://github.com/sharding-sphere/sharding-sphere/issues/521) `YAML`文件中`ShardingProperties`设置无效 1. [ISSUE #529](https://github.com/sharding-sphere/sharding-sphere/issues/529) 表名大写无法查询 -1. [ISSUE #541](https://github.com/sharding-sphere/sharding-sphere/issues/541) 无法解析IS NOT NULL -1. [ISSUE #557](https://github.com/sharding-sphere/sharding-sphere/issues/557) GroupBy和OrderBy仅别名不一致问题应使用流式归并 -1. [ISSUE #559](https://github.com/sharding-sphere/sharding-sphere/issues/559) 支持解析以负号和小数点开头的数字(如:-.12) +1. [ISSUE #541](https://github.com/sharding-sphere/sharding-sphere/issues/541) 无法解析`IS NOT NULL` +1. [ISSUE #557](https://github.com/sharding-sphere/sharding-sphere/issues/557) `GROUP BY`和`ORDER BY`仅别名不一致问题应使用流式归并 +1. [ISSUE #559](https://github.com/sharding-sphere/sharding-sphere/issues/559) 支持解析以负号和小数点开头的数字(如: `-.12`) 1. [ISSUE #567](https://github.com/sharding-sphere/sharding-sphere/issues/567) MySQL补列时增加转义符以防止使用关键字作为列名或别名导致错误 +#### Sharding-JDBC + +1. [ISSUE #520](https://github.com/sharding-sphere/sharding-sphere/issues/520) 唯一键冲突时异常类型不是`DuplicateKeyException` + + ## 2.0.1 ### 功能提升 From b5abe8d637dbfc40e16867ab40276561bafd240f Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 16:20:04 +0800 Subject: [PATCH 132/198] update release notes for 2.0.1 --- RELEASE-NOTES.md | 12 ++++++++---- RELEASE-NOTES_ZH.md | 10 +++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index ca97c7cbfd576..98566d11ec8ee 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -104,14 +104,18 @@ ### Enhancements -1. [ISSUE #489](https://github.com/sharding-sphere/sharding-sphere/issues/489) SpringName uses RuntimeBeanReference to prevent the creation of InnerBean +#### Core + +1. [ISSUE #490](https://github.com/sharding-sphere/sharding-sphere/issues/490) Using `rownum` greater than or equal to or less than or equal to the result of paging is incorrect in Oracle 1. [ISSUE #496](https://github.com/sharding-sphere/sharding-sphere/issues/496) Logical table names in sharding configuration can be case sensitive -1. [ISSUE #497](https://github.com/sharding-sphere/sharding-sphere/issues/497) The registry center closes gracefully +1. [ISSUE #497](https://github.com/sharding-sphere/sharding-sphere/issues/497) Close registry center gracefully ### Bug Fixes -1. [ISSUE #490](https://github.com/sharding-sphere/sharding-sphere/issues/490) Oracle using rownum greater than or equal to or less than or equal to the result of paging is incorrect -1. [ISSUE #491](https://github.com/sharding-sphere/sharding-sphere/issues/491) Can't close connection by ResultSet.getStatement().getConnection().close() +#### Sharding-JDBC + +1. [ISSUE #489](https://github.com/sharding-sphere/sharding-sphere/issues/489) Uses `RuntimeBeanReference` to prevent the creation of `InnerBean` on spring namespace +1. [ISSUE #491](https://github.com/sharding-sphere/sharding-sphere/issues/491) Can't close connection by `ResultSet.getStatement().getConnection().close()` ## 2.0.0 diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index 11b73d2dd71a6..6526a94a2678c 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -104,14 +104,18 @@ ### 功能提升 -1. [ISSUE #489](https://github.com/sharding-sphere/sharding-sphere/issues/489) SpringName使用RuntimeBeanReference防止创建InnerBean +#### Core + +1. [ISSUE #490](https://github.com/sharding-sphere/sharding-sphere/issues/490) Oracle使用`rownum`大于等于或小于等于分页结果不正确 1. [ISSUE #496](https://github.com/sharding-sphere/sharding-sphere/issues/496) 分片配置中逻辑表名可以大小写不敏感 1. [ISSUE #497](https://github.com/sharding-sphere/sharding-sphere/issues/497) 注册中心优雅关闭 ### 缺陷修正 -1. [ISSUE #490](https://github.com/sharding-sphere/sharding-sphere/issues/490) Oracle使用rownum大于等于或小于等于分页结果不正确 -1. [ISSUE #491](https://github.com/sharding-sphere/sharding-sphere/issues/491) 通过ResultSet.getStatement().getConnection().close()无法释放连接 +#### Sharding-JDBC + +1. [ISSUE #489](https://github.com/sharding-sphere/sharding-sphere/issues/489) 在Spring namespace中使用`RuntimeBeanReference`防止创建`InnerBean` +1. [ISSUE #491](https://github.com/sharding-sphere/sharding-sphere/issues/491) 通过`ResultSet.getStatement().getConnection().close()`无法释放连接 ## 2.0.0 From 9b85c8e8cf69b2df29f637be702636dd41eb6b4a Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 16:39:26 +0800 Subject: [PATCH 133/198] update release notes for 2.0.0 --- RELEASE-NOTES.md | 31 ++++++++++++++++++++----------- RELEASE-NOTES_ZH.md | 31 ++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 98566d11ec8ee..77b8f581ef3b1 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -122,30 +122,39 @@ ### Milestones -1. API adjust. Brand new Maven coordinate name, package name and spring namespace name. Simplify and enhance API configuration, inline expression full configuration support -1. Support spring-boot-starter of sharding-jdbc -1. Dynamic configuration. Zookeeper and etcd can be used as registry to dynamically modify data sources and sharding configurations -1. Data governance. Fusing database access procedures to access databases and disable access to slave databases +1. API adjust. Brand new groupId and artifactId for `Maven`, package name and spring namespace name. Simplify and enhance API configuration, inline expression fully configuration support +1. Support `spring-boot-starter` of `Sharding-JDBC` +1. Dynamic configuration. `ZooKeeper` and `etcd` can be used as registry to dynamically modify data sources and sharding configurations +1. Database orchestration. Fusing database access procedures to access databases and disable access to slave databases 1. ConfigMap support. Predefined metadata can be obtained in the sharding and read-write separation strategy -1. Tracking system support. You can view the invocation chain of sharding-jdbc through sky-walking and other Opentracing based APM systems +1. Tracking system support. You can view the invocation chain of `Sharding-JDBC` through `sky-walking` and other `Opentracing` based APM systems ### Enhancements -1. [ISSUE #386](https://github.com/sharding-sphere/sharding-sphere/issues/386) Support for SELECT 1, a SQL that does not contain table names -1. [ISSUE #407](https://github.com/sharding-sphere/sharding-sphere/issues/407) Sharding-jdbc's spring-boot-starter compatibility uses two ways of attribute configuration: minus sign and hump +#### Core + +1. [ISSUE #386](https://github.com/sharding-sphere/sharding-sphere/issues/386) Support SQL that does not contain table names, such as `SELECT 1` + +#### Sharding-JDBC + +1. [ISSUE #407](https://github.com/sharding-sphere/sharding-sphere/issues/407) Support Hyphen properties for `sharding-jdbc-spring-boot-starter` 1. [ISSUE #424](https://github.com/sharding-sphere/sharding-sphere/issues/424) Providing SQL overall execution events ### Bug Fixes +#### Core + 1. [ISSUE #387](https://github.com/sharding-sphere/sharding-sphere/issues/387) Prevent errors from keywords process when '`' exists in function + column name +1. [ISSUE #419](https://github.com/sharding-sphere/sharding-sphere/issues/419) When SQL is rewritten, it does not determine whether alias is a keyword without the escape character, which results in SQL exception +1. [ISSUE #464](https://github.com/sharding-sphere/sharding-sphere/issues/464) SQL if the varchar type is not closed due to the absence of matching single quotes, and the next varchar in SQL is the wrong SQL of Chinese characters, it will lead to higher use of CPU + +#### Sharding-JDBC + 1. [ISSUE #394](https://github.com/sharding-sphere/sharding-sphere/issues/394) Can't only close statement 1. [ISSUE #398](https://github.com/sharding-sphere/sharding-sphere/issues/398) Use Hint routing to shield case sensitivity 1. [ISSUE #404](https://github.com/sharding-sphere/sharding-sphere/issues/404) Sharding-jdbc's spring-boot-starter does not support HikariDataSource -1. [ISSUE #419](https://github.com/sharding-sphere/sharding-sphere/issues/419) When SQL is rewritten, it does not determine whether alias is a keyword without the escape character, which results in SQL exception -1. [ISSUE #436](https://github.com/sharding-sphere/sharding-sphere/issues/436) Read-write separation, when the RoundRobin algorithm is configured from the database and MyBatis is used, it can only be routed to the same slave library +1. [ISSUE #436](https://github.com/sharding-sphere/sharding-sphere/issues/436) Read-write splitting, when the RoundRobin algorithm is configured from the database and MyBatis is used, it can only be routed to the same slave library 1. [ISSUE #452](https://github.com/sharding-sphere/sharding-sphere/issues/452) Sharding of DDL statements to more than one table causes a connection leak -1. [ISSUE #453](https://github.com/sharding-sphere/sharding-sphere/issues/453) Orchestration datasource name is conflict with Druid datasource name -1. [ISSUE #464](https://github.com/sharding-sphere/sharding-sphere/issues/464) SQL if the varchar type is not closed due to the absence of matching single quotes, and the next varchar in SQL is the wrong SQL of Chinese characters, it will lead to higher use of CPU 1. [ISSUE #472](https://github.com/sharding-sphere/sharding-sphere/issues/472) Before Connection executes createStatement, it calls getMetaData first and then setAutoCommit can not take effective connection to the database that was created later ## 1.5.4.1 diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index 6526a94a2678c..7c2345f64e34c 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -104,7 +104,7 @@ ### 功能提升 -#### Core +#### 内核 1. [ISSUE #490](https://github.com/sharding-sphere/sharding-sphere/issues/490) Oracle使用`rownum`大于等于或小于等于分页结果不正确 1. [ISSUE #496](https://github.com/sharding-sphere/sharding-sphere/issues/496) 分片配置中逻辑表名可以大小写不敏感 @@ -121,30 +121,39 @@ ### 里程碑 -1. API调整. 全新的Maven坐标名称, 包名称和spring命名空间名称. 简化和提升API配置, inline表达式全配置支持 -1. 提供sharding-jdbc的spring-boot-starter -1. 配置动态化. 可以通过zookeeper和etcd作为注册中心动态修改数据源以及分片配置 -1. 数据治理. 熔断数据库访问程序对数据库的访问和禁用从库的访问 +1. API调整. 全新的`Maven`坐标名称, 包名称和spring命名空间名称. 简化和提升API配置, 行表达式全配置支持 +1. 提供`Sharding-JDBC`的`spring-boot-starter` +1. 配置动态化. 可以通过`ZooKeeper`和`etcd`作为注册中心动态修改数据源以及分片配置 +1. 数据库治理. 熔断数据库访问程序对数据库的访问和禁用从库的访问 1. ConfigMap支持. 可以在分片和读写分离策略中获取预定义的元数据 -1. 跟踪系统支持. 可以通过sky-walking等基于Opentracing协议的APM系统中查看sharding-jdbc的调用链 +1. 追踪系统支持. 可以通过`sky-walking`等基于`Opentracing`协议的APM系统中查看`Sharding-JDBC`的调用链 ### 功能提升 -1. [ISSUE #386](https://github.com/sharding-sphere/sharding-sphere/issues/386) 支持SELECT 1这种不包含表名称的SQL -1. [ISSUE #407](https://github.com/sharding-sphere/sharding-sphere/issues/407) sharding-jdbc的spring-boot-starter兼容使用减号和驼峰两种方式进行属性配置 +#### 内核 + +1. [ISSUE #386](https://github.com/sharding-sphere/sharding-sphere/issues/386) 支持不包含表名称的SQL, 例如: `SELECT 1` + +#### Sharding-JDBC + +1. [ISSUE #407](https://github.com/sharding-sphere/sharding-sphere/issues/407) `sharding-jdbc-spring-boot-starter`兼容使用减号和驼峰两种方式进行属性配置 1. [ISSUE #424](https://github.com/sharding-sphere/sharding-sphere/issues/424) 提供SQL总体执行情况事件 ### 缺陷修正 +#### 内核 + 1. [ISSUE #387](https://github.com/sharding-sphere/sharding-sphere/issues/387) 当函数 + 列名中存在'`'防止关键字时处理出错 +1. [ISSUE #419](https://github.com/sharding-sphere/sharding-sphere/issues/419) SQL改写时, 未判断别名是否为关键字未加转义符导致了SQL异常 +1. [ISSUE #464](https://github.com/sharding-sphere/sharding-sphere/issues/464) SQL如果varchar类型由于没有匹配单引号并未关闭, 而恰好sql中的下一个varchar又是汉字的错误SQL, 将导致CPU使用增高 + +#### Sharding-JDBC + 1. [ISSUE #394](https://github.com/sharding-sphere/sharding-sphere/issues/394) 无法单独close statement 1. [ISSUE #398](https://github.com/sharding-sphere/sharding-sphere/issues/398) 使用Hint路由屏蔽表和列名称的大小写区别 1. [ISSUE #404](https://github.com/sharding-sphere/sharding-sphere/issues/404) sharding-jdbc的spring-boot-starter不支持HikariDataSource -1. [ISSUE #419](https://github.com/sharding-sphere/sharding-sphere/issues/419) SQL改写时, 未判断别名是否为关键字未加转义符导致了SQL异常 1. [ISSUE #436](https://github.com/sharding-sphere/sharding-sphere/issues/436) 读写分离当从库配置RoundRobin算法并使用MyBatis时,只能路由到同一从库 1. [ISSUE #452](https://github.com/sharding-sphere/sharding-sphere/issues/452) DDL语句分片至多个表会造成连接泄漏的问题 -1. [ISSUE #453](https://github.com/sharding-sphere/sharding-sphere/issues/453) 编排治理数据源配置name与Druid数据源name冲突 -1. [ISSUE #464](https://github.com/sharding-sphere/sharding-sphere/issues/464) SQL如果varchar类型由于没有匹配单引号并未关闭, 而恰好sql中的下一个varchar又是汉字的错误SQL, 将导致CPU使用增高 1. [ISSUE #472](https://github.com/sharding-sphere/sharding-sphere/issues/472) Connection执行createStatement之前, 先调用getMetaData再setAutoCommit无法对之后创建的数据库真实连接生效 ## 1.5.4.1 From e31e815a4cafe1435b85339465f475d977fd9e43 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Wed, 8 Aug 2018 17:19:13 +0800 Subject: [PATCH 134/198] #1113, set netTimeoutForStreamingResults=0 --- .../jdbc/datasource/JDBCRawBackendDataSourceFactory.java | 1 + .../jdbc/datasource/JDBCXABackendDataSourceFactory.java | 3 +++ 2 files changed, 4 insertions(+) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCRawBackendDataSourceFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCRawBackendDataSourceFactory.java index 90d21b9f04cc4..c3b3c1f53ce7c 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCRawBackendDataSourceFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCRawBackendDataSourceFactory.java @@ -45,6 +45,7 @@ public DataSource build(final String dataSourceName, final DataSourceParameter d config.setMaximumPoolSize(dataSourceParameter.getMaximumPoolSize()); config.addDataSourceProperty("useServerPrepStmts", "true"); config.addDataSourceProperty("cachePrepStmts", "true"); + config.addDataSourceProperty("netTimeoutForStreamingResults", 0); return new HikariDataSource(config); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCXABackendDataSourceFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCXABackendDataSourceFactory.java index 659c3605b87a6..4566948ea5041 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCXABackendDataSourceFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCXABackendDataSourceFactory.java @@ -50,6 +50,9 @@ private Properties getProperties(final DataSourceParameter dataSourceParameter) result.setProperty("URL", dataSourceParameter.getUrl()); result.setProperty("pinGlobalTxToPhysicalConnection", Boolean.TRUE.toString()); result.setProperty("autoReconnect", Boolean.TRUE.toString()); + result.setProperty("useServerPrepStmts", Boolean.TRUE.toString()); + result.setProperty("cachePrepStmts", Boolean.TRUE.toString()); + result.setProperty("netTimeoutForStreamingResults", "0"); return result; } } From 2f8f00208ea9db8a7247dfb9d95decae603abdb7 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Wed, 8 Aug 2018 20:14:20 +0800 Subject: [PATCH 135/198] #1117, improve MySQL configuration --- .../jdbc/datasource/JDBCRawBackendDataSourceFactory.java | 8 ++++++++ .../jdbc/datasource/JDBCXABackendDataSourceFactory.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCRawBackendDataSourceFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCRawBackendDataSourceFactory.java index c3b3c1f53ce7c..f7d081a24438a 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCRawBackendDataSourceFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCRawBackendDataSourceFactory.java @@ -45,6 +45,14 @@ public DataSource build(final String dataSourceName, final DataSourceParameter d config.setMaximumPoolSize(dataSourceParameter.getMaximumPoolSize()); config.addDataSourceProperty("useServerPrepStmts", "true"); config.addDataSourceProperty("cachePrepStmts", "true"); + config.addDataSourceProperty("prepStmtCacheSize", 250); + config.addDataSourceProperty("prepStmtCacheSqlLimit", 2048); + config.addDataSourceProperty("useLocalSessionState", "true"); + config.addDataSourceProperty("rewriteBatchedStatements", "true"); + config.addDataSourceProperty("cacheResultSetMetadata", "true"); + config.addDataSourceProperty("cacheServerConfiguration", "true"); + config.addDataSourceProperty("elideSetAutoCommits", "true"); + config.addDataSourceProperty("maintainTimeStats", "false"); config.addDataSourceProperty("netTimeoutForStreamingResults", 0); return new HikariDataSource(config); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCXABackendDataSourceFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCXABackendDataSourceFactory.java index 4566948ea5041..df8d3fb75c6ab 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCXABackendDataSourceFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/datasource/JDBCXABackendDataSourceFactory.java @@ -52,6 +52,14 @@ private Properties getProperties(final DataSourceParameter dataSourceParameter) result.setProperty("autoReconnect", Boolean.TRUE.toString()); result.setProperty("useServerPrepStmts", Boolean.TRUE.toString()); result.setProperty("cachePrepStmts", Boolean.TRUE.toString()); + result.setProperty("prepStmtCacheSize", "250"); + result.setProperty("prepStmtCacheSqlLimit", "2048"); + result.setProperty("useLocalSessionState", Boolean.TRUE.toString()); + result.setProperty("rewriteBatchedStatements", Boolean.TRUE.toString()); + result.setProperty("cacheResultSetMetadata", Boolean.TRUE.toString()); + result.setProperty("cacheServerConfiguration", Boolean.TRUE.toString()); + result.setProperty("elideSetAutoCommits", Boolean.TRUE.toString()); + result.setProperty("maintainTimeStats", Boolean.FALSE.toString()); result.setProperty("netTimeoutForStreamingResults", "0"); return result; } From 459b338e25872ce3b3d64390e0fe87fd21c88b07 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Wed, 8 Aug 2018 22:43:20 +0800 Subject: [PATCH 136/198] ignore transaction type --- .../java/io/shardingsphere/proxy/config/RuleRegistry.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index cd64f2e14ae7f..06cc91d133404 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -108,7 +108,9 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { ShardingProperties shardingProperties = new ShardingProperties(null == properties ? new Properties() : properties); showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); - transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE)); + // TODO :zhaojun add distribute transaction for 3.1.x + transactionType = TransactionType.NONE; +// transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE)); transactionManager = ProxyTransactionLoader.load(transactionType); acceptorSize = shardingProperties.getValue(ShardingPropertiesConstant.ACCEPTOR_SIZE); executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); From 8ad0208e45a1f491f3ad7906a53cf24b3e7863b9 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 10:54:28 +0800 Subject: [PATCH 137/198] for #1119, parse show table status sql --- .../lexer/dialect/mysql/MySQLKeyword.java | 3 +- .../dialect/mysql/sql/MySQLShowParser.java | 4 + .../statement/ShowTableStatusStatement.java | 28 ++++ .../src/main/resources/conf/config.yaml | 132 +++++++++--------- 4 files changed, 100 insertions(+), 67 deletions(-) create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/statement/ShowTableStatusStatement.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/mysql/MySQLKeyword.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/mysql/MySQLKeyword.java index fa4a73189fa58..3f61d9f22030f 100755 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/mysql/MySQLKeyword.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/mysql/MySQLKeyword.java @@ -98,5 +98,6 @@ public enum MySQLKeyword implements Keyword { STRAIGHT_JOIN, REGEXP, INDEXES, - KEYS + KEYS, + STATUS } 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 fb5e3fa7a8b1e..5b4473adbcecc 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 @@ -26,6 +26,7 @@ import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement; import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowIndexStatement; import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowOtherStatement; +import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowTableStatusStatement; import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement; import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement; import io.shardingsphere.core.parsing.parser.sql.dal.show.AbstractShowParser; @@ -58,6 +59,9 @@ public DALStatement parse() { if (lexerEngine.equalAny(MySQLKeyword.DATABASES)) { return new ShowDatabasesStatement(); } + if (lexerEngine.skipIfEqual(DefaultKeyword.TABLE, MySQLKeyword.STATUS)) { + return new ShowTableStatusStatement(); + } if (lexerEngine.skipIfEqual(MySQLKeyword.TABLES)) { DALStatement result = new ShowTablesStatement(); if (lexerEngine.equalAny(DefaultKeyword.FROM, DefaultKeyword.IN)) { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/statement/ShowTableStatusStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/statement/ShowTableStatusStatement.java new file mode 100644 index 0000000000000..98f6a021fbf90 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/statement/ShowTableStatusStatement.java @@ -0,0 +1,28 @@ +/* + * 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.core.parsing.parser.dialect.mysql.statement; + +import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement; + +/** + * Show table status statement. + * + * @author zhangliang + */ +public final class ShowTableStatusStatement extends DALStatement { +} diff --git a/sharding-proxy/src/main/resources/conf/config.yaml b/sharding-proxy/src/main/resources/conf/config.yaml index a8f824c6f5b0c..6b3f056c3c0f3 100644 --- a/sharding-proxy/src/main/resources/conf/config.yaml +++ b/sharding-proxy/src/main/resources/conf/config.yaml @@ -9,70 +9,70 @@ # The example of Sharding rule. -#dataSources: -# ds_0: -# url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false -# username: root -# password: -# autoCommit: true -# connectionTimeout: 30000 -# idleTimeout: 60000 -# maxLifetime: 1800000 -# maximumPoolSize: 65 -# ds_1: -# url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false -# username: root -# password: -# autoCommit: true -# connectionTimeout: 30000 -# idleTimeout: 60000 -# maxLifetime: 1800000 -# maximumPoolSize: 65 -# -#shardingRule: -# tables: -# t_order: -# actualDataNodes: ds_${0..1}.t_order_${0..1} -# tableStrategy: -# inline: -# shardingColumn: order_id -# algorithmExpression: t_order_${order_id % 2} -# keyGeneratorColumnName: order_id -# t_order_item: -# actualDataNodes: ds_${0..1}.t_order_item_${0..1} -# tableStrategy: -# inline: -# shardingColumn: order_id -# algorithmExpression: t_order_item_${order_id % 2} -# bindingTables: -# - t_order,t_order_item -# defaultDatabaseStrategy: -# inline: -# shardingColumn: user_id -# algorithmExpression: ds_${user_id % 2} -# defaultTableStrategy: -# none: -# defaultKeyGeneratorClassName: io.shardingsphere.core.keygen.DefaultKeyGenerator -# -# props: -# # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database. -# # The benefit of this approach is saving memory for Proxy by Stream ResultSet. +dataSources: + ds_0: + url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false + username: root + password: + autoCommit: true + connectionTimeout: 30000 + idleTimeout: 60000 + maxLifetime: 1800000 + maximumPoolSize: 65 + ds_1: + url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false + username: root + password: + autoCommit: true + connectionTimeout: 30000 + idleTimeout: 60000 + maxLifetime: 1800000 + maximumPoolSize: 65 -# # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. -# # Meanwhile, the cost of the memory will be increased. -# connection.mode: MEMORY_STRICTLY -# acceptor.size: 16 # The default value is available processors count * 2. -# executor.size: 16 # Infinite by default. -# sql.show: false -# -#orchestration: -# name: orchestration_ds -# type: SHARDING -# overwrite: true -# zookeeper: -# namespace: orchestration -# serverLists: localhost:2181 -# -#proxyAuthority: -# username: root -# password: root +shardingRule: + tables: + t_order: + actualDataNodes: ds_${0..1}.t_order_${0..1} + tableStrategy: + inline: + shardingColumn: order_id + algorithmExpression: t_order_${order_id % 2} + keyGeneratorColumnName: order_id + t_order_item: + actualDataNodes: ds_${0..1}.t_order_item_${0..1} + tableStrategy: + inline: + shardingColumn: order_id + algorithmExpression: t_order_item_${order_id % 2} + bindingTables: + - t_order,t_order_item + defaultDatabaseStrategy: + inline: + shardingColumn: user_id + algorithmExpression: ds_${user_id % 2} + defaultTableStrategy: + none: + defaultKeyGeneratorClassName: io.shardingsphere.core.keygen.DefaultKeyGenerator + + props: + # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database. + # The benefit of this approach is saving memory for Proxy by Stream ResultSet. + + # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. + # Meanwhile, the cost of the memory will be increased. + connection.mode: MEMORY_STRICTLY + acceptor.size: 16 # The default value is available processors count * 2. + executor.size: 16 # Infinite by default. + sql.show: false + +orchestration: + name: orchestration_ds + type: SHARDING + overwrite: true + zookeeper: + namespace: orchestration + serverLists: localhost:2181 + +proxyAuthority: + username: root + password: root From 02106c7d009446fb619314d6bb81043ab1848a5c Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 10:55:08 +0800 Subject: [PATCH 138/198] for #1119, add test case for parse show table status sql --- .../src/test/resources/parser/show.xml | 4 +- .../src/main/resources/conf/config.yaml | 132 +++++++++--------- .../resources/sql/dal/show_table_status.xml | 4 + 3 files changed, 72 insertions(+), 68 deletions(-) create mode 100644 sharding-sql-test/src/main/resources/sql/dal/show_table_status.xml diff --git a/sharding-core/src/test/resources/parser/show.xml b/sharding-core/src/test/resources/parser/show.xml index aa16008ebabc2..82c529ac6a80d 100644 --- a/sharding-core/src/test/resources/parser/show.xml +++ b/sharding-core/src/test/resources/parser/show.xml @@ -1,6 +1,5 @@ - @@ -66,5 +65,6 @@ - + + diff --git a/sharding-proxy/src/main/resources/conf/config.yaml b/sharding-proxy/src/main/resources/conf/config.yaml index 6b3f056c3c0f3..a8f824c6f5b0c 100644 --- a/sharding-proxy/src/main/resources/conf/config.yaml +++ b/sharding-proxy/src/main/resources/conf/config.yaml @@ -9,70 +9,70 @@ # The example of Sharding rule. -dataSources: - ds_0: - url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 - ds_1: - url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false - username: root - password: - autoCommit: true - connectionTimeout: 30000 - idleTimeout: 60000 - maxLifetime: 1800000 - maximumPoolSize: 65 - -shardingRule: - tables: - t_order: - actualDataNodes: ds_${0..1}.t_order_${0..1} - tableStrategy: - inline: - shardingColumn: order_id - algorithmExpression: t_order_${order_id % 2} - keyGeneratorColumnName: order_id - t_order_item: - actualDataNodes: ds_${0..1}.t_order_item_${0..1} - tableStrategy: - inline: - shardingColumn: order_id - algorithmExpression: t_order_item_${order_id % 2} - bindingTables: - - t_order,t_order_item - defaultDatabaseStrategy: - inline: - shardingColumn: user_id - algorithmExpression: ds_${user_id % 2} - defaultTableStrategy: - none: - defaultKeyGeneratorClassName: io.shardingsphere.core.keygen.DefaultKeyGenerator - - props: - # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database. - # The benefit of this approach is saving memory for Proxy by Stream ResultSet. - - # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. - # Meanwhile, the cost of the memory will be increased. - connection.mode: MEMORY_STRICTLY - acceptor.size: 16 # The default value is available processors count * 2. - executor.size: 16 # Infinite by default. - sql.show: false - -orchestration: - name: orchestration_ds - type: SHARDING - overwrite: true - zookeeper: - namespace: orchestration - serverLists: localhost:2181 +#dataSources: +# ds_0: +# url: jdbc:mysql://127.0.0.1:3306/ds_0?serverTimezone=UTC&useSSL=false +# username: root +# password: +# autoCommit: true +# connectionTimeout: 30000 +# idleTimeout: 60000 +# maxLifetime: 1800000 +# maximumPoolSize: 65 +# ds_1: +# url: jdbc:mysql://127.0.0.1:3306/ds_1?serverTimezone=UTC&useSSL=false +# username: root +# password: +# autoCommit: true +# connectionTimeout: 30000 +# idleTimeout: 60000 +# maxLifetime: 1800000 +# maximumPoolSize: 65 +# +#shardingRule: +# tables: +# t_order: +# actualDataNodes: ds_${0..1}.t_order_${0..1} +# tableStrategy: +# inline: +# shardingColumn: order_id +# algorithmExpression: t_order_${order_id % 2} +# keyGeneratorColumnName: order_id +# t_order_item: +# actualDataNodes: ds_${0..1}.t_order_item_${0..1} +# tableStrategy: +# inline: +# shardingColumn: order_id +# algorithmExpression: t_order_item_${order_id % 2} +# bindingTables: +# - t_order,t_order_item +# defaultDatabaseStrategy: +# inline: +# shardingColumn: user_id +# algorithmExpression: ds_${user_id % 2} +# defaultTableStrategy: +# none: +# defaultKeyGeneratorClassName: io.shardingsphere.core.keygen.DefaultKeyGenerator +# +# props: +# # MEMORY_STRICTLY: Proxy holds as many connections as the count of actual tables routed in a database. +# # The benefit of this approach is saving memory for Proxy by Stream ResultSet. -proxyAuthority: - username: root - password: root +# # CONNECTION_STRICTLY: Proxy will release connections after get the overall rows from the ResultSet. +# # Meanwhile, the cost of the memory will be increased. +# connection.mode: MEMORY_STRICTLY +# acceptor.size: 16 # The default value is available processors count * 2. +# executor.size: 16 # Infinite by default. +# sql.show: false +# +#orchestration: +# name: orchestration_ds +# type: SHARDING +# overwrite: true +# zookeeper: +# namespace: orchestration +# serverLists: localhost:2181 +# +#proxyAuthority: +# username: root +# password: root diff --git a/sharding-sql-test/src/main/resources/sql/dal/show_table_status.xml b/sharding-sql-test/src/main/resources/sql/dal/show_table_status.xml new file mode 100644 index 0000000000000..e059672153ac3 --- /dev/null +++ b/sharding-sql-test/src/main/resources/sql/dal/show_table_status.xml @@ -0,0 +1,4 @@ + + + + From 583aaa3909999357bab732d358a1f5664478a355 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 11:04:16 +0800 Subject: [PATCH 139/198] for #1119, add merge for show table status --- .../core/merger/dal/DALMergeEngine.java | 5 + .../dal/show/ShowTableStatusMergedResult.java | 112 ++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTableStatusMergedResult.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java index dc6acaaca78ee..7b83523da785a 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java @@ -23,10 +23,12 @@ import io.shardingsphere.core.merger.dal.show.ShowCreateTableMergedResult; import io.shardingsphere.core.merger.dal.show.ShowDatabasesMergedResult; import io.shardingsphere.core.merger.dal.show.ShowOtherMergedResult; +import io.shardingsphere.core.merger.dal.show.ShowTableStatusMergedResult; import io.shardingsphere.core.merger.dal.show.ShowTablesMergedResult; import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowCreateTableStatement; import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement; +import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowTableStatusStatement; import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement; import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement; import io.shardingsphere.core.rule.ShardingRule; @@ -57,6 +59,9 @@ public MergedResult merge() throws SQLException { if (dalStatement instanceof ShowDatabasesStatement) { return new ShowDatabasesMergedResult(); } + if (dalStatement instanceof ShowTableStatusStatement) { + return new ShowTableStatusMergedResult(shardingRule, queryResults, shardingTableMetaData); + } if (dalStatement instanceof ShowTablesStatement) { return new ShowTablesMergedResult(shardingRule, queryResults, shardingTableMetaData); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTableStatusMergedResult.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTableStatusMergedResult.java new file mode 100644 index 0000000000000..dfa98657ff11a --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTableStatusMergedResult.java @@ -0,0 +1,112 @@ +/* + * 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.core.merger.dal.show; + +import com.google.common.base.Optional; +import io.shardingsphere.core.merger.QueryResult; +import io.shardingsphere.core.merger.dql.common.MemoryMergedResult; +import io.shardingsphere.core.merger.dql.common.MemoryQueryResultRow; +import io.shardingsphere.core.metadata.table.ShardingTableMetaData; +import io.shardingsphere.core.rule.ShardingRule; +import io.shardingsphere.core.rule.TableRule; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Merged result for show table status. + * + * @author zhangliang + */ +public final class ShowTableStatusMergedResult extends MemoryMergedResult { + + private static final Map LABEL_AND_INDEX_MAP = new HashMap<>(1, 1); + + private final ShardingRule shardingRule; + + private final Iterator memoryResultSetRows; + + private final Set tableNames = new HashSet<>(); + + private final ShardingTableMetaData shardingTableMetaData; + + static { + LABEL_AND_INDEX_MAP.put("Name", 1); + LABEL_AND_INDEX_MAP.put("Engine", 2); + LABEL_AND_INDEX_MAP.put("Version", 3); + LABEL_AND_INDEX_MAP.put("Row_format", 4); + LABEL_AND_INDEX_MAP.put("Rows", 5); + LABEL_AND_INDEX_MAP.put("Avg_row_length", 6); + LABEL_AND_INDEX_MAP.put("Data_length", 7); + LABEL_AND_INDEX_MAP.put("Max_data_length", 8); + LABEL_AND_INDEX_MAP.put("Data_free", 9); + LABEL_AND_INDEX_MAP.put("Auto_increment", 10); + LABEL_AND_INDEX_MAP.put("Create_time", 11); + LABEL_AND_INDEX_MAP.put("Update_time", 12); + LABEL_AND_INDEX_MAP.put("Check_time", 13); + LABEL_AND_INDEX_MAP.put("Collation", 14); + LABEL_AND_INDEX_MAP.put("Checksum", 15); + LABEL_AND_INDEX_MAP.put("Create_options", 16); + LABEL_AND_INDEX_MAP.put("Comment", 17); + } + + public ShowTableStatusMergedResult(final ShardingRule shardingRule, final List queryResults, final ShardingTableMetaData shardingTableMetaData) throws SQLException { + super(LABEL_AND_INDEX_MAP); + this.shardingRule = shardingRule; + this.shardingTableMetaData = shardingTableMetaData; + memoryResultSetRows = init(queryResults); + } + + private Iterator init(final List queryResults) throws SQLException { + List result = new LinkedList<>(); + for (QueryResult each : queryResults) { + while (each.next()) { + MemoryQueryResultRow memoryResultSetRow = new MemoryQueryResultRow(each); + String actualTableName = memoryResultSetRow.getCell(1).toString(); + Optional tableRule = shardingRule.tryFindTableRuleByActualTable(actualTableName); + if (!tableRule.isPresent()) { + if (shardingRule.getTableRules().isEmpty() || shardingTableMetaData.containsTable(actualTableName) && tableNames.add(actualTableName)) { + result.add(memoryResultSetRow); + } + } else if (tableNames.add(tableRule.get().getLogicTable())) { + memoryResultSetRow.setCell(1, tableRule.get().getLogicTable()); + result.add(memoryResultSetRow); + } + } + } + if (!result.isEmpty()) { + setCurrentResultSetRow(result.get(0)); + } + return result.iterator(); + } + + @Override + public boolean next() { + if (memoryResultSetRows.hasNext()) { + setCurrentResultSetRow(memoryResultSetRows.next()); + return true; + } + return false; + } +} From 44bd27d8c2fb674361e0b9212a1d1389718e64a7 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 11:08:03 +0800 Subject: [PATCH 140/198] for #1119, refactor MySQLShowParser --- .../dialect/mysql/sql/MySQLShowParser.java | 82 ++++++++++++------- 1 file changed, 53 insertions(+), 29 deletions(-) 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 5b4473adbcecc..35a820556e726 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 @@ -57,46 +57,70 @@ public DALStatement parse() { lexerEngine.nextToken(); lexerEngine.skipIfEqual(DefaultKeyword.FULL); if (lexerEngine.equalAny(MySQLKeyword.DATABASES)) { - return new ShowDatabasesStatement(); + return showDatabases(); } if (lexerEngine.skipIfEqual(DefaultKeyword.TABLE, MySQLKeyword.STATUS)) { - return new ShowTableStatusStatement(); + return parseShowTableStatus(); } if (lexerEngine.skipIfEqual(MySQLKeyword.TABLES)) { - DALStatement result = new ShowTablesStatement(); - if (lexerEngine.equalAny(DefaultKeyword.FROM, DefaultKeyword.IN)) { - int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length(); - lexerEngine.nextToken(); - lexerEngine.nextToken(); - result.getSqlTokens().add(new RemoveToken(beginPosition, lexerEngine.getCurrentToken().getEndPosition())); - } - return result; + return parseShowTables(); } if (lexerEngine.skipIfEqual(MySQLKeyword.COLUMNS, MySQLKeyword.FIELDS)) { - DALStatement result = new ShowColumnsStatement(); - lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN); - 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())); - } - return result; + return parseShowColumnsFields(); } if (lexerEngine.skipIfEqual(DefaultKeyword.CREATE) && lexerEngine.skipIfEqual(DefaultKeyword.TABLE)) { - DALStatement result = new ShowCreateTableStatement(); - tableReferencesClauseParser.parseSingleTableWithoutAlias(result); - return result; + return parseShowCreateTable(); } if (lexerEngine.skipIfEqual(DefaultKeyword.INDEX, MySQLKeyword.INDEXES, MySQLKeyword.KEYS)) { - DALStatement result = new ShowIndexStatement(); - lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN); - 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())); - } - return result; + return parseShowIndex(); } return new ShowOtherStatement(); } + + private DALStatement showDatabases() { + return new ShowDatabasesStatement(); + } + + private DALStatement parseShowTableStatus() { + return new ShowTableStatusStatement(); + } + + private DALStatement parseShowTables() { + DALStatement result = new ShowTablesStatement(); + if (lexerEngine.equalAny(DefaultKeyword.FROM, DefaultKeyword.IN)) { + int beginPosition = lexerEngine.getCurrentToken().getEndPosition() - lexerEngine.getCurrentToken().getLiterals().length(); + lexerEngine.nextToken(); + lexerEngine.nextToken(); + result.getSqlTokens().add(new RemoveToken(beginPosition, lexerEngine.getCurrentToken().getEndPosition())); + } + return result; + } + + private DALStatement parseShowColumnsFields() { + DALStatement result = new ShowColumnsStatement(); + lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN); + 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())); + } + return result; + } + + private DALStatement parseShowCreateTable() { + DALStatement result = new ShowCreateTableStatement(); + tableReferencesClauseParser.parseSingleTableWithoutAlias(result); + return result; + } + + private DALStatement parseShowIndex() { + DALStatement result = new ShowIndexStatement(); + lexerEngine.skipIfEqual(DefaultKeyword.FROM, DefaultKeyword.IN); + 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())); + } + return result; + } } From 47a1d3ff2e29aee98f13f20007cac429b48531ec Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 11:28:02 +0800 Subject: [PATCH 141/198] for #1119, add LogicTablesMergedResult --- .../dal/show/LogicTablesMergedResult.java | 94 +++++++++++++++++++ .../dal/show/ShowTableStatusMergedResult.java | 57 +---------- .../dal/show/ShowTablesMergedResult.java | 55 +---------- 3 files changed, 99 insertions(+), 107 deletions(-) create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/LogicTablesMergedResult.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/LogicTablesMergedResult.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/LogicTablesMergedResult.java new file mode 100644 index 0000000000000..da3aa34eb520d --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/LogicTablesMergedResult.java @@ -0,0 +1,94 @@ +/* + * 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.core.merger.dal.show; + +import com.google.common.base.Optional; +import io.shardingsphere.core.merger.QueryResult; +import io.shardingsphere.core.merger.dql.common.MemoryMergedResult; +import io.shardingsphere.core.merger.dql.common.MemoryQueryResultRow; +import io.shardingsphere.core.metadata.table.ShardingTableMetaData; +import io.shardingsphere.core.rule.ShardingRule; +import io.shardingsphere.core.rule.TableRule; + +import java.sql.SQLException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Logic tables merged result. + * + * @author zhangliang + */ +public abstract class LogicTablesMergedResult extends MemoryMergedResult { + + private final ShardingRule shardingRule; + + private final Iterator memoryResultSetRows; + + private final Set tableNames = new HashSet<>(); + + private final ShardingTableMetaData shardingTableMetaData; + + public LogicTablesMergedResult(final Map labelAndIndexMap, + final ShardingRule shardingRule, final List queryResults, final ShardingTableMetaData shardingTableMetaData) throws SQLException { + super(labelAndIndexMap); + this.shardingRule = shardingRule; + this.shardingTableMetaData = shardingTableMetaData; + memoryResultSetRows = init(queryResults); + } + + private Iterator init(final List queryResults) throws SQLException { + List result = new LinkedList<>(); + for (QueryResult each : queryResults) { + while (each.next()) { + MemoryQueryResultRow memoryResultSetRow = new MemoryQueryResultRow(each); + String actualTableName = memoryResultSetRow.getCell(1).toString(); + Optional tableRule = shardingRule.tryFindTableRuleByActualTable(actualTableName); + if (!tableRule.isPresent()) { + if (shardingRule.getTableRules().isEmpty() || shardingTableMetaData.containsTable(actualTableName) && tableNames.add(actualTableName)) { + result.add(memoryResultSetRow); + } + } else if (tableNames.add(tableRule.get().getLogicTable())) { + memoryResultSetRow.setCell(1, tableRule.get().getLogicTable()); + setCellValue(memoryResultSetRow, tableRule.get().getLogicTable(), actualTableName); + result.add(memoryResultSetRow); + } + } + } + if (!result.isEmpty()) { + setCurrentResultSetRow(result.get(0)); + } + return result.iterator(); + } + + protected void setCellValue(final MemoryQueryResultRow memoryResultSetRow, final String logicTableName, final String actualTableName) { + } + + @Override + public boolean next() { + if (memoryResultSetRows.hasNext()) { + setCurrentResultSetRow(memoryResultSetRows.next()); + return true; + } + return false; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTableStatusMergedResult.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTableStatusMergedResult.java index dfa98657ff11a..3f326a0470be2 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTableStatusMergedResult.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTableStatusMergedResult.java @@ -17,39 +17,23 @@ package io.shardingsphere.core.merger.dal.show; -import com.google.common.base.Optional; import io.shardingsphere.core.merger.QueryResult; -import io.shardingsphere.core.merger.dql.common.MemoryMergedResult; -import io.shardingsphere.core.merger.dql.common.MemoryQueryResultRow; import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.rule.ShardingRule; -import io.shardingsphere.core.rule.TableRule; import java.sql.SQLException; import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; /** * Merged result for show table status. * * @author zhangliang */ -public final class ShowTableStatusMergedResult extends MemoryMergedResult { +public final class ShowTableStatusMergedResult extends LogicTablesMergedResult { - private static final Map LABEL_AND_INDEX_MAP = new HashMap<>(1, 1); - - private final ShardingRule shardingRule; - - private final Iterator memoryResultSetRows; - - private final Set tableNames = new HashSet<>(); - - private final ShardingTableMetaData shardingTableMetaData; + private static final Map LABEL_AND_INDEX_MAP = new HashMap<>(17, 1); static { LABEL_AND_INDEX_MAP.put("Name", 1); @@ -72,41 +56,6 @@ public final class ShowTableStatusMergedResult extends MemoryMergedResult { } public ShowTableStatusMergedResult(final ShardingRule shardingRule, final List queryResults, final ShardingTableMetaData shardingTableMetaData) throws SQLException { - super(LABEL_AND_INDEX_MAP); - this.shardingRule = shardingRule; - this.shardingTableMetaData = shardingTableMetaData; - memoryResultSetRows = init(queryResults); - } - - private Iterator init(final List queryResults) throws SQLException { - List result = new LinkedList<>(); - for (QueryResult each : queryResults) { - while (each.next()) { - MemoryQueryResultRow memoryResultSetRow = new MemoryQueryResultRow(each); - String actualTableName = memoryResultSetRow.getCell(1).toString(); - Optional tableRule = shardingRule.tryFindTableRuleByActualTable(actualTableName); - if (!tableRule.isPresent()) { - if (shardingRule.getTableRules().isEmpty() || shardingTableMetaData.containsTable(actualTableName) && tableNames.add(actualTableName)) { - result.add(memoryResultSetRow); - } - } else if (tableNames.add(tableRule.get().getLogicTable())) { - memoryResultSetRow.setCell(1, tableRule.get().getLogicTable()); - result.add(memoryResultSetRow); - } - } - } - if (!result.isEmpty()) { - setCurrentResultSetRow(result.get(0)); - } - return result.iterator(); - } - - @Override - public boolean next() { - if (memoryResultSetRows.hasNext()) { - setCurrentResultSetRow(memoryResultSetRows.next()); - return true; - } - return false; + super(LABEL_AND_INDEX_MAP, shardingRule, queryResults, shardingTableMetaData); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResult.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResult.java index 41d8ed32fddb6..64f6b8862a171 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResult.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResult.java @@ -17,23 +17,15 @@ package io.shardingsphere.core.merger.dal.show; -import com.google.common.base.Optional; import io.shardingsphere.core.constant.ShardingConstant; import io.shardingsphere.core.merger.QueryResult; -import io.shardingsphere.core.merger.dql.common.MemoryMergedResult; -import io.shardingsphere.core.merger.dql.common.MemoryQueryResultRow; import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.rule.ShardingRule; -import io.shardingsphere.core.rule.TableRule; import java.sql.SQLException; import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Set; /** * Merged result for show tables. @@ -41,58 +33,15 @@ * @author zhangliang * @author panjuan */ -public final class ShowTablesMergedResult extends MemoryMergedResult { +public final class ShowTablesMergedResult extends LogicTablesMergedResult { private static final Map LABEL_AND_INDEX_MAP = new HashMap<>(1, 1); - private final ShardingRule shardingRule; - - private final Iterator memoryResultSetRows; - - private final Set tableNames = new HashSet<>(); - - private final ShardingTableMetaData shardingTableMetaData; - static { LABEL_AND_INDEX_MAP.put("Tables_in_" + ShardingConstant.LOGIC_SCHEMA_NAME, 1); } public ShowTablesMergedResult(final ShardingRule shardingRule, final List queryResults, final ShardingTableMetaData shardingTableMetaData) throws SQLException { - super(LABEL_AND_INDEX_MAP); - this.shardingRule = shardingRule; - this.shardingTableMetaData = shardingTableMetaData; - memoryResultSetRows = init(queryResults); - } - - private Iterator init(final List queryResults) throws SQLException { - List result = new LinkedList<>(); - for (QueryResult each : queryResults) { - while (each.next()) { - MemoryQueryResultRow memoryResultSetRow = new MemoryQueryResultRow(each); - String actualTableName = memoryResultSetRow.getCell(1).toString(); - Optional tableRule = shardingRule.tryFindTableRuleByActualTable(actualTableName); - if (!tableRule.isPresent()) { - if (shardingRule.getTableRules().isEmpty() || shardingTableMetaData.containsTable(actualTableName) && tableNames.add(actualTableName)) { - result.add(memoryResultSetRow); - } - } else if (tableNames.add(tableRule.get().getLogicTable())) { - memoryResultSetRow.setCell(1, tableRule.get().getLogicTable()); - result.add(memoryResultSetRow); - } - } - } - if (!result.isEmpty()) { - setCurrentResultSetRow(result.get(0)); - } - return result.iterator(); - } - - @Override - public boolean next() { - if (memoryResultSetRows.hasNext()) { - setCurrentResultSetRow(memoryResultSetRows.next()); - return true; - } - return false; + super(LABEL_AND_INDEX_MAP, shardingRule, queryResults, shardingTableMetaData); } } From 5321e46a42ed52966f3c155a9b62a4507c8f42e7 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 11:36:34 +0800 Subject: [PATCH 142/198] for #1119, refactor ShowCreateTableMergedResult to extends LogicTablesMergedResult --- .../core/merger/dal/DALMergeEngine.java | 2 +- .../dal/show/ShowCreateTableMergedResult.java | 53 +++---------------- .../show/ShowCreateTableMergedResultTest.java | 20 +++++-- 3 files changed, 22 insertions(+), 53 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java index 7b83523da785a..1f778f74af949 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java @@ -66,7 +66,7 @@ public MergedResult merge() throws SQLException { return new ShowTablesMergedResult(shardingRule, queryResults, shardingTableMetaData); } if (dalStatement instanceof ShowCreateTableStatement) { - return new ShowCreateTableMergedResult(shardingRule, queryResults); + return new ShowCreateTableMergedResult(shardingRule, queryResults, shardingTableMetaData); } return new ShowOtherMergedResult(queryResults.get(0)); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowCreateTableMergedResult.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowCreateTableMergedResult.java index a88698a964b2b..67a147176085a 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowCreateTableMergedResult.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowCreateTableMergedResult.java @@ -17,18 +17,13 @@ package io.shardingsphere.core.merger.dal.show; -import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.merger.QueryResult; -import io.shardingsphere.core.merger.dql.common.MemoryMergedResult; import io.shardingsphere.core.merger.dql.common.MemoryQueryResultRow; -import io.shardingsphere.core.parsing.SQLParsingEngine; +import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.rule.ShardingRule; -import io.shardingsphere.core.rule.TableRule; import java.sql.SQLException; import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -37,56 +32,20 @@ * * @author zhangliang */ -public final class ShowCreateTableMergedResult extends MemoryMergedResult { +public final class ShowCreateTableMergedResult extends LogicTablesMergedResult { private static final Map LABEL_AND_INDEX_MAP = new HashMap<>(2, 1); - private final ShardingRule shardingRule; - - private final Iterator memoryResultSetRows; - static { LABEL_AND_INDEX_MAP.put("Table", 1); LABEL_AND_INDEX_MAP.put("Create Table", 2); } - public ShowCreateTableMergedResult(final ShardingRule shardingRule, final List queryResults) throws SQLException { - super(LABEL_AND_INDEX_MAP); - this.shardingRule = shardingRule; - memoryResultSetRows = init(queryResults); - } - - private Iterator init(final List queryResults) throws SQLException { - List result = new LinkedList<>(); - for (QueryResult each : queryResults) { - while (each.next()) { - MemoryQueryResultRow memoryResultSetRow = new MemoryQueryResultRow(each); - String tableName = memoryResultSetRow.getCell(1).toString(); - TableRule tableRule = shardingRule.getTableRuleByActualTableName(tableName); - String logicTableName = tableRule.getLogicTable(); - memoryResultSetRow.setCell(1, logicTableName); - String createTableDDL = memoryResultSetRow.getCell(2).toString(); - SQLParsingEngine sqlParsingEngine = new SQLParsingEngine(DatabaseType.MySQL, createTableDDL, shardingRule, null); - String actualTableName = sqlParsingEngine.parse(true).getTables().getSingleTableName(); - if (actualTableName.startsWith("`")) { - logicTableName = "`" + logicTableName + "`"; - } - memoryResultSetRow.setCell(2, createTableDDL.replaceFirst(actualTableName, logicTableName)); - result.add(memoryResultSetRow); - } - } - if (!result.isEmpty()) { - setCurrentResultSetRow(result.get(0)); - } - return result.iterator(); + public ShowCreateTableMergedResult(final ShardingRule shardingRule, final List queryResults, final ShardingTableMetaData shardingTableMetaData) throws SQLException { + super(LABEL_AND_INDEX_MAP, shardingRule, queryResults, shardingTableMetaData); } - @Override - public boolean next() { - if (memoryResultSetRows.hasNext()) { - setCurrentResultSetRow(memoryResultSetRows.next()); - return true; - } - return false; + protected void setCellValue(final MemoryQueryResultRow memoryResultSetRow, final String logicTableName, final String actualTableName) { + memoryResultSetRow.setCell(2, memoryResultSetRow.getCell(2).toString().replaceFirst(actualTableName, logicTableName)); } } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/show/ShowCreateTableMergedResultTest.java b/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/show/ShowCreateTableMergedResultTest.java index 416e58b473811..2e3ef1a882546 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/show/ShowCreateTableMergedResultTest.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/show/ShowCreateTableMergedResultTest.java @@ -24,6 +24,9 @@ import io.shardingsphere.core.api.config.strategy.ComplexShardingStrategyConfiguration; import io.shardingsphere.core.merger.QueryResult; import io.shardingsphere.core.merger.fixture.TestQueryResult; +import io.shardingsphere.core.metadata.table.ColumnMetaData; +import io.shardingsphere.core.metadata.table.ShardingTableMetaData; +import io.shardingsphere.core.metadata.table.TableMetaData; import io.shardingsphere.core.rule.ShardingRule; import org.junit.Before; import org.junit.Test; @@ -32,10 +35,13 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -47,6 +53,8 @@ public final class ShowCreateTableMergedResultTest { private ResultSet resultSet; + private ShardingTableMetaData shardingTableMetaData; + @Before public void setUp() throws SQLException { TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration(); @@ -56,7 +64,9 @@ public void setUp() throws SQLException { ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration(); shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig); shardingRule = new ShardingRule(shardingRuleConfig, Lists.newArrayList("ds")); - + Map tableMetaDataMap = new HashMap<>(1, 1); + tableMetaDataMap.put("table", new TableMetaData(Collections.emptyList())); + shardingTableMetaData = new ShardingTableMetaData(tableMetaDataMap); resultSet = mock(ResultSet.class); ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class); when(resultSet.getMetaData()).thenReturn(resultSetMetaData); @@ -73,7 +83,7 @@ public void setUp() throws SQLException { @Test public void assertNextForEmptyQueryResult() throws SQLException { - ShowCreateTableMergedResult showCreateTableMergedResult = new ShowCreateTableMergedResult(shardingRule, new ArrayList()); + ShowCreateTableMergedResult showCreateTableMergedResult = new ShowCreateTableMergedResult(shardingRule, new ArrayList(), shardingTableMetaData); assertFalse(showCreateTableMergedResult.next()); } @@ -88,7 +98,7 @@ public void assertNextForTableRuleIsPresentForBackQuotes() throws SQLException { + " `created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n" + " PRIMARY KEY (`id`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=121 DEFAULT CHARSET=utf8 COLLATE=utf8_bin"); - ShowCreateTableMergedResult showCreateTableMergedResult = new ShowCreateTableMergedResult(shardingRule, queryResults); + ShowCreateTableMergedResult showCreateTableMergedResult = new ShowCreateTableMergedResult(shardingRule, queryResults, shardingTableMetaData); assertTrue(showCreateTableMergedResult.next()); } @@ -103,7 +113,7 @@ public void assertNextForTableRuleIsPresentForNoBackQuotes() throws SQLException + " `created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n" + " PRIMARY KEY (`id`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=121 DEFAULT CHARSET=utf8 COLLATE=utf8_bin"); - ShowCreateTableMergedResult showCreateTableMergedResult = new ShowCreateTableMergedResult(shardingRule, queryResults); + ShowCreateTableMergedResult showCreateTableMergedResult = new ShowCreateTableMergedResult(shardingRule, queryResults, shardingTableMetaData); assertTrue(showCreateTableMergedResult.next()); } } From 0af2cbd8bab2b99833d5759983b65c0c4fbd1c04 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 12:28:45 +0800 Subject: [PATCH 143/198] for #1120, filter derived column for sharding-proxy --- .../backend/jdbc/JDBCBackendHandler.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java index 723fc981d2253..5b668e9702939 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java @@ -27,6 +27,7 @@ import io.shardingsphere.core.parsing.parser.sql.dml.insert.InsertStatement; import io.shardingsphere.core.routing.SQLRouteResult; import io.shardingsphere.proxy.backend.AbstractBackendHandler; +import io.shardingsphere.proxy.backend.BackendExecutorContext; import io.shardingsphere.proxy.backend.ResultPacket; import io.shardingsphere.proxy.backend.jdbc.execute.JDBCExecuteEngine; import io.shardingsphere.proxy.backend.jdbc.execute.response.ExecuteQueryResponse; @@ -36,15 +37,18 @@ import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.transport.mysql.constant.ServerErrorCode; import io.shardingsphere.proxy.transport.mysql.packet.command.CommandResponsePackets; +import io.shardingsphere.proxy.transport.mysql.packet.command.query.ColumnDefinition41Packet; +import io.shardingsphere.proxy.transport.mysql.packet.command.query.FieldCountPacket; import io.shardingsphere.proxy.transport.mysql.packet.command.query.QueryResponsePackets; +import io.shardingsphere.proxy.transport.mysql.packet.generic.EofPacket; import io.shardingsphere.proxy.transport.mysql.packet.generic.ErrPacket; import io.shardingsphere.proxy.transport.mysql.packet.generic.OKPacket; -import io.shardingsphere.proxy.backend.BackendExecutorContext; import lombok.RequiredArgsConstructor; import javax.transaction.Status; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -103,11 +107,25 @@ private CommandResponsePackets merge(final SQLStatement sqlStatement) throws SQL } mergedResult = MergeEngineFactory.newInstance( RULE_REGISTRY.getShardingRule(), ((ExecuteQueryResponse) executeResponse).getQueryResults(), sqlStatement, RULE_REGISTRY.getMetaData().getTable()).merge(); - QueryResponsePackets result = ((ExecuteQueryResponse) executeResponse).getQueryResponsePackets(); + QueryResponsePackets result = getQueryResponsePacketsWithoutDerivedColumns(((ExecuteQueryResponse) executeResponse).getQueryResponsePackets()); currentSequenceId = result.getPackets().size(); return result; } + private QueryResponsePackets getQueryResponsePacketsWithoutDerivedColumns(final QueryResponsePackets queryResponsePackets) { + Collection columnDefinition41Packets = new ArrayList<>(queryResponsePackets.getColumnCount()); + int columnCount = 0; + for (ColumnDefinition41Packet each : queryResponsePackets.getColumnDefinition41Packets()) { + if (!each.getName().startsWith("AVG_DERIVED_COUNT_") && !each.getName().startsWith("AVG_DERIVED_SUM_") + && !each.getName().startsWith("ORDER_BY_DERIVED_") && !each.getName().startsWith("GROUP_BY_DERIVED_")) { + columnDefinition41Packets.add(each); + columnCount++; + } + } + FieldCountPacket fieldCountPacket = new FieldCountPacket(1, columnCount); + return new QueryResponsePackets(fieldCountPacket, columnDefinition41Packets, new EofPacket(columnCount + 2)); + } + @Override public boolean next() throws SQLException { return null != mergedResult && mergedResult.next(); From 5869d6acfdf517cbd271e1e5de9cf8042524946c Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 12:47:13 +0800 Subject: [PATCH 144/198] for #1119, add DerivedColumn --- .../parser/constant/DerivedColumn.java | 100 ++++++++++++++++++ .../sql/dql/select/AbstractSelectParser.java | 32 +++--- .../backend/jdbc/JDBCBackendHandler.java | 5 +- 3 files changed, 121 insertions(+), 16 deletions(-) create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java new file mode 100644 index 0000000000000..fe896240779e0 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java @@ -0,0 +1,100 @@ +/* + * 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.core.parsing.parser.constant; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +import java.util.HashSet; +import java.util.Set; + +/** + * Derived column alias. + * + * @author zhangliang + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class DerivedColumn { + + public static final String AVG_COUNT_ALIAS = "AVG_DERIVED_COUNT_"; + + public static final String AVG_SUM_ALIAS = "AVG_DERIVED_SUM_"; + + public static final String ORDER_BY_ALIAS = "ORDER_BY_DERIVED_"; + + public static final String GROUP_BY_ALIAS = "GROUP_BY_DERIVED_"; + + private static final Set DERIVED_COLUMNS = new HashSet<>(4, 1); + + static { + DERIVED_COLUMNS.add(AVG_COUNT_ALIAS); + DERIVED_COLUMNS.add(AVG_SUM_ALIAS); + DERIVED_COLUMNS.add(ORDER_BY_ALIAS); + DERIVED_COLUMNS.add(GROUP_BY_ALIAS); + } + + /** + * Get alias of avg derived count column. + * + * @param derivedColumnCount derived column count + * @return alias of avg derived count column + */ + public static String getDerivedAvgCountAlias(final int derivedColumnCount) { + return String.format(AVG_COUNT_ALIAS + "_%s", derivedColumnCount); + } + + /** + * Get alias of avg derived sum column. + * + * @param derivedColumnCount derived column count + * @return alias of avg derived sum column + */ + public static String getDerivedAvgSumAlias(final int derivedColumnCount) { + return String.format(AVG_SUM_ALIAS + "_%s", derivedColumnCount); + } + + /** + * Get alias of order by derived column. + * + * @param derivedColumnCount derived column count + * @return alias of order by derived column + */ + public static String getDerivedOrderByAlias(final int derivedColumnCount) { + return String.format(ORDER_BY_ALIAS + "_%s", derivedColumnCount); + } + + /** + * Get alias of group by derived column. + * + * @param derivedColumnCount derived column count + * @return alias of group by derived column + */ + public static String getDerivedGroupByAlias(final int derivedColumnCount) { + return String.format(GROUP_BY_ALIAS + "_%s", derivedColumnCount); + } + + /** + * Judge is derived column or not. + * + * @param columnName column name to be judged + * @return is derived column or not + */ + public static boolean isDerivedColumn(final String columnName) { + return DERIVED_COLUMNS.contains(columnName); + } +} 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 4ae7b6d77716b..e9022f50eaf7f 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 @@ -26,6 +26,7 @@ import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword; import io.shardingsphere.core.parsing.lexer.token.Symbol; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractSelectClauseParserFacade; +import io.shardingsphere.core.parsing.parser.constant.DerivedColumn; import io.shardingsphere.core.parsing.parser.context.OrderItem; import io.shardingsphere.core.parsing.parser.context.selectitem.AggregationSelectItem; import io.shardingsphere.core.parsing.parser.context.selectitem.SelectItem; @@ -51,14 +52,6 @@ @Getter(AccessLevel.PROTECTED) public abstract class AbstractSelectParser implements SQLParser { - private static final String DERIVED_COUNT_ALIAS = "AVG_DERIVED_COUNT_%s"; - - private static final String DERIVED_SUM_ALIAS = "AVG_DERIVED_SUM_%s"; - - private static final String ORDER_BY_DERIVED_ALIAS = "ORDER_BY_DERIVED_%s"; - - private static final String GROUP_BY_DERIVED_ALIAS = "GROUP_BY_DERIVED_%s"; - private final ShardingRule shardingRule; private final LexerEngine lexerEngine; @@ -138,8 +131,8 @@ protected final void parseSelectRest() { private void appendDerivedColumns(final SelectStatement selectStatement) { ItemsToken itemsToken = new ItemsToken(selectStatement.getSelectListLastPosition()); appendAvgDerivedColumns(itemsToken, selectStatement); - appendDerivedOrderColumns(itemsToken, selectStatement.getOrderByItems(), ORDER_BY_DERIVED_ALIAS, selectStatement); - appendDerivedOrderColumns(itemsToken, selectStatement.getGroupByItems(), GROUP_BY_DERIVED_ALIAS, selectStatement); + appendDerivedOrderColumns(itemsToken, selectStatement.getOrderByItems(), selectStatement); + appendDerivedGroupColumns(itemsToken, selectStatement.getGroupByItems(), selectStatement); if (!itemsToken.getItems().isEmpty()) { selectStatement.getSqlTokens().add(itemsToken); } @@ -152,9 +145,9 @@ private void appendAvgDerivedColumns(final ItemsToken itemsToken, final SelectSt continue; } AggregationSelectItem avgItem = (AggregationSelectItem) each; - String countAlias = String.format(DERIVED_COUNT_ALIAS, derivedColumnOffset); + String countAlias = DerivedColumn.getDerivedAvgCountAlias(derivedColumnOffset); AggregationSelectItem countItem = new AggregationSelectItem(AggregationType.COUNT, avgItem.getInnerExpression(), Optional.of(countAlias)); - String sumAlias = String.format(DERIVED_SUM_ALIAS, derivedColumnOffset); + String sumAlias = DerivedColumn.getDerivedAvgSumAlias(derivedColumnOffset); AggregationSelectItem sumItem = new AggregationSelectItem(AggregationType.SUM, avgItem.getInnerExpression(), Optional.of(sumAlias)); avgItem.getDerivedAggregationSelectItems().add(countItem); avgItem.getDerivedAggregationSelectItems().add(sumItem); @@ -165,11 +158,22 @@ private void appendAvgDerivedColumns(final ItemsToken itemsToken, final SelectSt } } - private void appendDerivedOrderColumns(final ItemsToken itemsToken, final List orderItems, final String aliasPattern, final SelectStatement selectStatement) { + private void appendDerivedOrderColumns(final ItemsToken itemsToken, final List orderItems, final SelectStatement selectStatement) { + int derivedColumnOffset = 0; + for (OrderItem each : orderItems) { + if (!containsItem(selectStatement, each)) { + String alias = DerivedColumn.getDerivedOrderByAlias(derivedColumnOffset++); + each.setAlias(Optional.of(alias)); + itemsToken.getItems().add(each.getQualifiedName().get() + " AS " + alias + " "); + } + } + } + + private void appendDerivedGroupColumns(final ItemsToken itemsToken, final List orderItems, final SelectStatement selectStatement) { int derivedColumnOffset = 0; for (OrderItem each : orderItems) { if (!containsItem(selectStatement, each)) { - String alias = String.format(aliasPattern, derivedColumnOffset++); + String alias = DerivedColumn.getDerivedGroupByAlias(derivedColumnOffset++); each.setAlias(Optional.of(alias)); itemsToken.getItems().add(each.getQualifiedName().get() + " AS " + alias + " "); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java index 5b668e9702939..c6ddf493f2c7f 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java @@ -23,6 +23,7 @@ import io.shardingsphere.core.merger.MergeEngineFactory; import io.shardingsphere.core.merger.MergedResult; import io.shardingsphere.core.metadata.table.executor.TableMetaDataLoader; +import io.shardingsphere.core.parsing.parser.constant.DerivedColumn; import io.shardingsphere.core.parsing.parser.sql.SQLStatement; import io.shardingsphere.core.parsing.parser.sql.dml.insert.InsertStatement; import io.shardingsphere.core.routing.SQLRouteResult; @@ -116,8 +117,8 @@ private QueryResponsePackets getQueryResponsePacketsWithoutDerivedColumns(final Collection columnDefinition41Packets = new ArrayList<>(queryResponsePackets.getColumnCount()); int columnCount = 0; for (ColumnDefinition41Packet each : queryResponsePackets.getColumnDefinition41Packets()) { - if (!each.getName().startsWith("AVG_DERIVED_COUNT_") && !each.getName().startsWith("AVG_DERIVED_SUM_") - && !each.getName().startsWith("ORDER_BY_DERIVED_") && !each.getName().startsWith("GROUP_BY_DERIVED_")) { + if (!each.getName().startsWith(DerivedColumn.AVG_COUNT_ALIAS) && !each.getName().startsWith(DerivedColumn.AVG_SUM_ALIAS) + && !each.getName().startsWith(DerivedColumn.ORDER_BY_ALIAS) && !each.getName().startsWith(DerivedColumn.GROUP_BY_ALIAS)) { columnDefinition41Packets.add(each); columnCount++; } From 18a81160780a86c8a66a0f074029e5d09c515ef5 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 12:55:05 +0800 Subject: [PATCH 145/198] for #1120, fix test cases --- .../parser/constant/DerivedColumn.java | 31 ++++++------------- .../backend/jdbc/JDBCBackendHandler.java | 3 +- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java index fe896240779e0..9e68d0e0a356f 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java @@ -20,9 +20,6 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; -import java.util.HashSet; -import java.util.Set; - /** * Derived column alias. * @@ -31,22 +28,13 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class DerivedColumn { - public static final String AVG_COUNT_ALIAS = "AVG_DERIVED_COUNT_"; - - public static final String AVG_SUM_ALIAS = "AVG_DERIVED_SUM_"; + private static final String AVG_COUNT_ALIAS = "AVG_DERIVED_COUNT_"; - public static final String ORDER_BY_ALIAS = "ORDER_BY_DERIVED_"; + private static final String AVG_SUM_ALIAS = "AVG_DERIVED_SUM_"; - public static final String GROUP_BY_ALIAS = "GROUP_BY_DERIVED_"; + private static final String ORDER_BY_ALIAS = "ORDER_BY_DERIVED_"; - private static final Set DERIVED_COLUMNS = new HashSet<>(4, 1); - - static { - DERIVED_COLUMNS.add(AVG_COUNT_ALIAS); - DERIVED_COLUMNS.add(AVG_SUM_ALIAS); - DERIVED_COLUMNS.add(ORDER_BY_ALIAS); - DERIVED_COLUMNS.add(GROUP_BY_ALIAS); - } + private static final String GROUP_BY_ALIAS = "GROUP_BY_DERIVED_"; /** * Get alias of avg derived count column. @@ -55,7 +43,7 @@ public final class DerivedColumn { * @return alias of avg derived count column */ public static String getDerivedAvgCountAlias(final int derivedColumnCount) { - return String.format(AVG_COUNT_ALIAS + "_%s", derivedColumnCount); + return String.format(AVG_COUNT_ALIAS + "%s", derivedColumnCount); } /** @@ -65,7 +53,7 @@ public static String getDerivedAvgCountAlias(final int derivedColumnCount) { * @return alias of avg derived sum column */ public static String getDerivedAvgSumAlias(final int derivedColumnCount) { - return String.format(AVG_SUM_ALIAS + "_%s", derivedColumnCount); + return String.format(AVG_SUM_ALIAS + "%s", derivedColumnCount); } /** @@ -75,7 +63,7 @@ public static String getDerivedAvgSumAlias(final int derivedColumnCount) { * @return alias of order by derived column */ public static String getDerivedOrderByAlias(final int derivedColumnCount) { - return String.format(ORDER_BY_ALIAS + "_%s", derivedColumnCount); + return String.format(ORDER_BY_ALIAS + "%s", derivedColumnCount); } /** @@ -85,7 +73,7 @@ public static String getDerivedOrderByAlias(final int derivedColumnCount) { * @return alias of group by derived column */ public static String getDerivedGroupByAlias(final int derivedColumnCount) { - return String.format(GROUP_BY_ALIAS + "_%s", derivedColumnCount); + return String.format(GROUP_BY_ALIAS + "%s", derivedColumnCount); } /** @@ -95,6 +83,7 @@ public static String getDerivedGroupByAlias(final int derivedColumnCount) { * @return is derived column or not */ public static boolean isDerivedColumn(final String columnName) { - return DERIVED_COLUMNS.contains(columnName); + return columnName.startsWith(DerivedColumn.AVG_COUNT_ALIAS) || columnName.startsWith(DerivedColumn.AVG_SUM_ALIAS) + || columnName.startsWith(DerivedColumn.ORDER_BY_ALIAS) || columnName.startsWith(DerivedColumn.GROUP_BY_ALIAS); } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java index c6ddf493f2c7f..bf6b901e907a0 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java @@ -117,8 +117,7 @@ private QueryResponsePackets getQueryResponsePacketsWithoutDerivedColumns(final Collection columnDefinition41Packets = new ArrayList<>(queryResponsePackets.getColumnCount()); int columnCount = 0; for (ColumnDefinition41Packet each : queryResponsePackets.getColumnDefinition41Packets()) { - if (!each.getName().startsWith(DerivedColumn.AVG_COUNT_ALIAS) && !each.getName().startsWith(DerivedColumn.AVG_SUM_ALIAS) - && !each.getName().startsWith(DerivedColumn.ORDER_BY_ALIAS) && !each.getName().startsWith(DerivedColumn.GROUP_BY_ALIAS)) { + if (!DerivedColumn.isDerivedColumn(each.getName())) { columnDefinition41Packets.add(each); columnCount++; } From 3dd50bd3debf1f0273e40db1347c9bd4440a62e0 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 14:26:12 +0800 Subject: [PATCH 146/198] for #1120, filter derived column for sharding-jdbc --- .../adapter/AbstractResultSetAdapter.java | 3 +- .../GeneratedKeysResultSetMetaData.java | 2 +- .../resultset/ShardingResultSetMetaData.java | 147 +++++++++++++ .../cases/dql/dataset/db/select_avg.xml | 4 +- .../dataset/db/select_group_by_with_avg.xml | 42 ++-- ...select_group_by_without_grouped_column.xml | 5 +- .../db/select_order_by_desc_and_index_asc.xml | 161 +++++++------- .../dataset/db/select_order_by_with_date.xml | 161 +++++++------- ...t_pagination_with_row_number_and_limit.xml | 5 +- .../dql/dataset/db/select_with_expression.xml | 81 ++++--- .../dbtbl_with_masterslave/select_avg.xml | 4 +- .../select_group_by_with_avg.xml | 22 +- ...select_group_by_without_grouped_column.xml | 5 +- .../select_order_by_desc_and_index_asc.xml | 1 - .../select_order_by_with_date.xml | 1 - ...t_pagination_with_row_number_and_limit.xml | 5 +- .../select_with_expression.xml | 201 +++++++++--------- .../cases/dql/dataset/tbl/select_avg.xml | 4 +- .../dataset/tbl/select_group_by_with_avg.xml | 6 +- ...select_group_by_without_grouped_column.xml | 5 +- .../select_order_by_desc_and_index_asc.xml | 81 ++++--- .../dataset/tbl/select_order_by_with_date.xml | 81 ++++--- ...t_pagination_with_row_number_and_limit.xml | 5 +- .../dataset/tbl/select_with_expression.xml | 41 ++-- 24 files changed, 597 insertions(+), 476 deletions(-) create mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/ShardingResultSetMetaData.java diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractResultSetAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractResultSetAdapter.java index ec19397d821bf..d941614ffc850 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractResultSetAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractResultSetAdapter.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.jdbc.adapter; import com.google.common.base.Preconditions; +import io.shardingsphere.core.jdbc.core.resultset.ShardingResultSetMetaData; import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationResultSet; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -55,7 +56,7 @@ public AbstractResultSetAdapter(final List resultSets, final Statemen @Override public final ResultSetMetaData getMetaData() throws SQLException { - return resultSets.get(0).getMetaData(); + return new ShardingResultSetMetaData(resultSets.get(0).getMetaData()); } @Override diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/GeneratedKeysResultSetMetaData.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/GeneratedKeysResultSetMetaData.java index 13c4ee37ffef8..3a26c7c4f1c21 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/GeneratedKeysResultSetMetaData.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/GeneratedKeysResultSetMetaData.java @@ -25,7 +25,7 @@ import java.sql.Types; /** - * ResultSet metadata for generated keys. + * Result set meta data for generated keys. * * @author gaohongtao */ diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/ShardingResultSetMetaData.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/ShardingResultSetMetaData.java new file mode 100644 index 0000000000000..0550da4ba8d6a --- /dev/null +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/ShardingResultSetMetaData.java @@ -0,0 +1,147 @@ +/* + * 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.core.jdbc.core.resultset; + +import io.shardingsphere.core.jdbc.adapter.WrapperAdapter; +import io.shardingsphere.core.parsing.parser.constant.DerivedColumn; +import lombok.RequiredArgsConstructor; + +import java.sql.ResultSetMetaData; +import java.sql.SQLException; + +/** + * Sharding result set meta data. + * + * @author zhangliang + */ +@RequiredArgsConstructor +public final class ShardingResultSetMetaData extends WrapperAdapter implements ResultSetMetaData { + + private final ResultSetMetaData resultSetMetaData; + + @Override + public int getColumnCount() throws SQLException { + int result = 0; + for (int columnIndex = 1; columnIndex <= resultSetMetaData.getColumnCount(); columnIndex++) { + if (!DerivedColumn.isDerivedColumn(resultSetMetaData.getColumnLabel(columnIndex))) { + result++; + } + } + return result; + } + + @Override + public boolean isAutoIncrement(final int column) throws SQLException { + return resultSetMetaData.isAutoIncrement(column); + } + + @Override + public boolean isCaseSensitive(final int column) throws SQLException { + return resultSetMetaData.isCaseSensitive(column); + } + + @Override + public boolean isSearchable(final int column) throws SQLException { + return resultSetMetaData.isSearchable(column); + } + + @Override + public boolean isCurrency(final int column) throws SQLException { + return resultSetMetaData.isCurrency(column); + } + + @Override + public int isNullable(final int column) throws SQLException { + return resultSetMetaData.isNullable(column); + } + + @Override + public boolean isSigned(final int column) throws SQLException { + return resultSetMetaData.isSigned(column); + } + + @Override + public int getColumnDisplaySize(final int column) throws SQLException { + return resultSetMetaData.getColumnDisplaySize(column); + } + + @Override + public String getColumnLabel(final int column) throws SQLException { + return resultSetMetaData.getColumnLabel(column); + } + + @Override + public String getColumnName(final int column) throws SQLException { + return resultSetMetaData.getColumnName(column); + } + + @Override + public String getSchemaName(final int column) throws SQLException { + return resultSetMetaData.getSchemaName(column); + } + + @Override + public int getPrecision(final int column) throws SQLException { + return resultSetMetaData.getPrecision(column); + } + + @Override + public int getScale(final int column) throws SQLException { + return resultSetMetaData.getScale(column); + } + + @Override + public String getTableName(final int column) throws SQLException { + return resultSetMetaData.getTableName(column); + } + + @Override + public String getCatalogName(final int column) throws SQLException { + return resultSetMetaData.getCatalogName(column); + } + + @Override + public int getColumnType(final int column) throws SQLException { + return resultSetMetaData.getColumnType(column); + } + + @Override + public String getColumnTypeName(final int column) throws SQLException { + return resultSetMetaData.getColumnTypeName(column); + } + + @Override + public boolean isReadOnly(final int column) throws SQLException { + return resultSetMetaData.isReadOnly(column); + } + + @Override + public boolean isWritable(final int column) throws SQLException { + return resultSetMetaData.isWritable(column); + } + + @Override + public boolean isDefinitelyWritable(final int column) throws SQLException { + return resultSetMetaData.isDefinitelyWritable(column); + } + + @Override + public String getColumnClassName(final int column) throws SQLException { + return resultSetMetaData.getColumnClassName(column); + } +} diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_avg.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_avg.xml index 401ecdb6b83d1..290cc8b0f3ab9 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_avg.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_avg.xml @@ -1,8 +1,6 @@ - - - + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_avg.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_avg.xml index 5076e53c7db99..a7f7c6e274bf9 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_avg.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_avg.xml @@ -2,27 +2,25 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_without_grouped_column.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_without_grouped_column.xml index 9bcbb53b85eee..26b1167c7d6e9 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_without_grouped_column.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_without_grouped_column.xml @@ -1,8 +1,7 @@ - - - + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml index d1bef7a93e65f..07200bcec11cd 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml @@ -5,86 +5,85 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_date.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_date.xml index d1bef7a93e65f..07200bcec11cd 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_date.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_date.xml @@ -5,86 +5,85 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_row_number_and_limit.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_row_number_and_limit.xml index 00ecc07eb0dd2..03dbe69922bc1 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_row_number_and_limit.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_row_number_and_limit.xml @@ -5,8 +5,7 @@ - - - + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_expression.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_expression.xml index 4342bb10faa03..7aeb183d0b9f5 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_expression.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_expression.xml @@ -1,46 +1,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml index 68ef4ca247351..9b6b22ab882c7 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml @@ -1,8 +1,6 @@ - - - + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml index a3948f0d84a86..e8f8a0260655f 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml @@ -2,17 +2,15 @@ - - - - - - - - - - - - + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_without_grouped_column.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_without_grouped_column.xml index 3005656eb6725..f8f37eb485f3f 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_without_grouped_column.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_without_grouped_column.xml @@ -1,8 +1,7 @@ - - - + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_desc_and_index_asc.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_desc_and_index_asc.xml index f4ba798bf509e..ab55cf4a2d0d0 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_desc_and_index_asc.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_desc_and_index_asc.xml @@ -5,6 +5,5 @@ - diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_date.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_date.xml index f4ba798bf509e..ab55cf4a2d0d0 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_date.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_date.xml @@ -5,6 +5,5 @@ - diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_and_limit.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_and_limit.xml index 0d99717a60553..d1de128735a24 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_and_limit.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_and_limit.xml @@ -5,8 +5,7 @@ - - - + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_expression.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_expression.xml index 75104707db64e..5e75601385ce5 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_expression.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_expression.xml @@ -1,106 +1,105 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_avg.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_avg.xml index 6c135954eef86..0d54113846a80 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_avg.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_avg.xml @@ -1,8 +1,6 @@ - - - + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_avg.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_avg.xml index 53fa098cf0b1f..c95e5e8ac5bec 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_avg.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_avg.xml @@ -2,9 +2,7 @@ - - - - + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_without_grouped_column.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_without_grouped_column.xml index 3005656eb6725..f8f37eb485f3f 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_without_grouped_column.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_without_grouped_column.xml @@ -1,8 +1,7 @@ - - - + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_desc_and_index_asc.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_desc_and_index_asc.xml index 5fe27842bcd30..36739c810117d 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_desc_and_index_asc.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_desc_and_index_asc.xml @@ -5,46 +5,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_date.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_date.xml index 5fe27842bcd30..36739c810117d 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_date.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_date.xml @@ -5,46 +5,45 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_row_number_and_limit.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_row_number_and_limit.xml index a84f46a14a9b3..a2c10abce6831 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_row_number_and_limit.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_row_number_and_limit.xml @@ -5,8 +5,7 @@ - - - + + diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_expression.xml b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_expression.xml index 6c6fc3e759ad2..40644b52f7e84 100644 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_expression.xml +++ b/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_expression.xml @@ -1,26 +1,25 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + From 74706d4fce9d1b20f8d80ec35e42961f42ef2857 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 14:28:53 +0800 Subject: [PATCH 147/198] fix #1120 --- RELEASE-NOTES.md | 2 +- RELEASE-NOTES_ZH.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 77b8f581ef3b1..d0377a569a19f 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -53,7 +53,7 @@ 1. [ISSUE #629](https://github.com/sharding-sphere/sharding-sphere/issues/629) Support transaction isolation on JDBC 1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) Unexpected slave datasource routing result when using `Round-robin` load-balance algorithm in Mybatis 1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) Can't resolve placeholder in `Spring Boot YAML` configuration - +1. [ISSUE #1020](https://github.com/sharding-sphere/sharding-sphere/issues/1020) Derived columns of `GROUP BY / ORDER BY` appear in query result ## 2.0.3 diff --git a/RELEASE-NOTES_ZH.md b/RELEASE-NOTES_ZH.md index 7c2345f64e34c..0f13a0cc00c2c 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -54,7 +54,7 @@ 1. [ISSUE #629](https://github.com/sharding-sphere/sharding-sphere/issues/629) 支持JDBC中设置事务隔离级别 1. [ISSUE #735](https://github.com/sharding-sphere/sharding-sphere/issues/735) 在Mybatis中使用`Round-robin`的读写分离算法路由存在问题 1. [ISSUE #1011](https://github.com/sharding-sphere/sharding-sphere/issues/1011) 无法在`Spring Boot`的`YAML`中处理占位符 - +1. [ISSUE #1020](https://github.com/sharding-sphere/sharding-sphere/issues/1020) `GROUP BY / ORDER BY`产生的补列不应展现在查询结果中 ## 2.0.3 From 3491fa4c526eb8a2d1e834f5b3e54d3e2f1828ab Mon Sep 17 00:00:00 2001 From: saaav Date: Thu, 9 Aug 2018 17:16:48 +0800 Subject: [PATCH 148/198] change a TODO and checkstyle --- .../reg/newzk/client/action/IClient.java | 7 +++ .../reg/newzk/client/cache/PathTree.java | 16 +++---- .../newzk/client/zookeeper/CacheClient.java | 6 +-- .../newzk/client/zookeeper/UsualClient.java | 48 +++++++++---------- .../zookeeper/SyncRetryStrategyTest.java | 4 +- 5 files changed, 43 insertions(+), 38 deletions(-) diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java index 5d2d2c0f6914f..af1249083fc56 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java @@ -82,6 +82,13 @@ public interface IClient extends IAction, IGroupAction { */ void useExecStrategy(StrategyType strategyType); + /** + * Get provider. + * + * @return execute strategy + */ + IExecStrategy getExecStrategy(); + /** * Create zookeeper transaction. * diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java index 025cfa6ff2bf1..37e47adfa58c9 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java @@ -23,14 +23,7 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.action.IProvider; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.PathUtil; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.ZookeeperConstants; -import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.UsualClient; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.ZookeeperEventListener; -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.WatchedEvent; - import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executors; @@ -38,6 +31,11 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.ReentrantLock; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; /** * Zookeeper cache tree. @@ -70,9 +68,9 @@ public final class PathTree implements AutoCloseable { public PathTree(final String root, final IClient client) { rootNode.set(new PathNode(root)); status = PathStatus.RELEASE; + // TODO consider whether to use a new client alternative to the current this.client = client; - // TODO It looks unpleasant - provider = ((UsualClient) client).getStrategy().getProvider(); + provider = client.getExecStrategy().getProvider(); } /** diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/CacheClient.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/CacheClient.java index f6f3d580570ed..7e9bc54bef129 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/CacheClient.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/CacheClient.java @@ -117,18 +117,18 @@ public byte[] getData(final String key) throws KeeperException, InterruptedExcep return data; } log.debug("getData cache not hit: {}", key); - return getStrategy().getData(key); + return getExecStrategy().getData(key); } @Override public List getChildren(final String key) throws KeeperException, InterruptedException { String path = PathUtil.getRealPath(getRootNode(), key); List keys = pathTree.getChildren(path); - if (!keys.isEmpty()) { + if (keys != null && !keys.isEmpty()) { log.debug("getChildren cache hit: {}", keys); return keys; } log.debug("getChildren cache not hit: {}", keys); - return getStrategy().getChildren(PathUtil.getRealPath(getRootNode(), key)); + return getExecStrategy().getChildren(PathUtil.getRealPath(getRootNode(), key)); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/UsualClient.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/UsualClient.java index 650b1ce85463e..1d45a411068ab 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/UsualClient.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/UsualClient.java @@ -53,7 +53,7 @@ public class UsualClient extends BaseClient { private final Map strategies = new ConcurrentHashMap<>(); @Getter - private IExecStrategy strategy; + private IExecStrategy execStrategy; protected UsualClient(final BaseContext context) { super(context); @@ -69,63 +69,63 @@ public void close() { public synchronized void useExecStrategy(final StrategyType strategyType) { log.debug("useExecStrategy:{}", strategyType); if (strategies.containsKey(strategyType)) { - strategy = strategies.get(strategyType); + execStrategy = strategies.get(strategyType); return; } ITransactionProvider provider = new TransactionProvider(getRootNode(), getHolder(), ZookeeperConstants.WATCHED, getAuthorities()); switch (strategyType) { case USUAL: - strategy = new UsualStrategy(provider); + execStrategy = new UsualStrategy(provider); break; case CONTEND: - strategy = new ContentionStrategy(provider); + execStrategy = new ContentionStrategy(provider); break; case TRANSACTION_CONTEND: - strategy = new TransactionContendStrategy(provider); + execStrategy = new TransactionContendStrategy(provider); break; case SYNC_RETRY: - strategy = new SyncRetryStrategy(provider, ((ClientContext) getContext()).getDelayRetryPolicy()); + execStrategy = new SyncRetryStrategy(provider, ((ClientContext) getContext()).getDelayRetryPolicy()); break; case ASYNC_RETRY: - strategy = new AsyncRetryStrategy(provider, ((ClientContext) getContext()).getDelayRetryPolicy()); + execStrategy = new AsyncRetryStrategy(provider, ((ClientContext) getContext()).getDelayRetryPolicy()); break; default: - strategy = new UsualStrategy(provider); + execStrategy = new UsualStrategy(provider); break; } - strategies.put(strategyType, strategy); + strategies.put(strategyType, execStrategy); } @Override public String getDataString(final String key) throws KeeperException, InterruptedException { - return strategy.getDataString(key); + return execStrategy.getDataString(key); } @Override public byte[] getData(final String key) throws KeeperException, InterruptedException { - return strategy.getData(key); + return execStrategy.getData(key); } @Override public void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) throws KeeperException, InterruptedException { - strategy.getData(key, callback, ctx); + execStrategy.getData(key, callback, ctx); } @Override public boolean checkExists(final String key) throws KeeperException, InterruptedException { - return strategy.checkExists(key); + return execStrategy.checkExists(key); } @Override public boolean checkExists(final String key, final Watcher watcher) throws KeeperException, InterruptedException { - return strategy.checkExists(key, watcher); + return execStrategy.checkExists(key, watcher); } @Override public List getChildren(final String key) throws KeeperException, InterruptedException { - return strategy.getChildren(key); + return execStrategy.getChildren(key); } @Override @@ -134,7 +134,7 @@ public void createCurrentOnly(final String key, final String value, final Create if (getRootNode().equals(key)) { return; } - strategy.createCurrentOnly(key, value, createMode); + execStrategy.createCurrentOnly(key, value, createMode); } @Override @@ -143,12 +143,12 @@ public void createAllNeedPath(final String key, final String value, final Create if (getRootNode().equals(key)) { return; } - strategy.createAllNeedPath(key, value, createMode); + execStrategy.createAllNeedPath(key, value, createMode); } @Override public void update(final String key, final String value) throws KeeperException, InterruptedException { - strategy.update(key, value); + execStrategy.update(key, value); } @Override @@ -157,7 +157,7 @@ public void deleteOnlyCurrent(final String key) throws KeeperException, Interrup deleteNamespace(); return; } - strategy.deleteOnlyCurrent(key); + execStrategy.deleteOnlyCurrent(key); } @Override @@ -166,12 +166,12 @@ public void deleteOnlyCurrent(final String key, final AsyncCallback.VoidCallback deleteNamespace(); return; } - strategy.deleteOnlyCurrent(key, callback, ctx); + execStrategy.deleteOnlyCurrent(key, callback, ctx); } @Override public void deleteAllChildren(final String key) throws KeeperException, InterruptedException { - strategy.deleteAllChildren(key); + execStrategy.deleteAllChildren(key); if (getRootNode().equals(key)) { setRootExist(false); log.debug("deleteAllChildren delete root: {}", getRootNode()); @@ -180,8 +180,8 @@ public void deleteAllChildren(final String key) throws KeeperException, Interrup @Override public void deleteCurrentBranch(final String key) throws KeeperException, InterruptedException { - strategy.deleteCurrentBranch(key); - if (!strategy.checkExists(getRootNode())) { + execStrategy.deleteCurrentBranch(key); + if (!execStrategy.checkExists(getRootNode())) { setRootExist(false); log.debug("deleteCurrentBranch delete root: {}", getRootNode()); } @@ -189,6 +189,6 @@ public void deleteCurrentBranch(final String key) throws KeeperException, Interr @Override public BaseTransaction transaction() { - return strategy.transaction(); + return execStrategy.transaction(); } } diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/SyncRetryStrategyTest.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/SyncRetryStrategyTest.java index f9ee5ed67d8d1..d43436d0aaaac 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/SyncRetryStrategyTest.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/SyncRetryStrategyTest.java @@ -36,8 +36,8 @@ import org.apache.zookeeper.ZooDefs; import org.junit.Test; -import static junit.framework.TestCase.assertFalse; import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; @@ -53,7 +53,7 @@ protected IClient createClient(final ClientFactory creator) throws IOException, final IClient client = creator.setClientNamespace(TestSupport.ROOT).authorization(TestSupport.AUTH, TestSupport.AUTH.getBytes(), ZooDefs.Ids.CREATOR_ALL_ACL) .newClient(TestSupport.SERVERS, TestSupport.SESSION_TIMEOUT).watch(TestSupport.buildListener()).start(); client.useExecStrategy(StrategyType.SYNC_RETRY); - provider = ((UsualClient) client).getStrategy().getProvider(); + provider = client.getExecStrategy().getProvider(); return client; } From 6d91f613211cda9a044416b38be5efb4bc8e322d Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 17:34:51 +0800 Subject: [PATCH 149/198] refactor DerivedColumn to enum --- .../parser/constant/DerivedColumn.java | 63 ++++++------------- .../sql/dql/select/AbstractSelectParser.java | 8 +-- .../transaction/TransactionContextHolder.java | 1 + 3 files changed, 23 insertions(+), 49 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java index 9e68d0e0a356f..50408632b6633 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java @@ -18,62 +18,31 @@ package io.shardingsphere.core.parsing.parser.constant; import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; /** * Derived column alias. * * @author zhangliang */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class DerivedColumn { +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum DerivedColumn { - private static final String AVG_COUNT_ALIAS = "AVG_DERIVED_COUNT_"; + AVG_COUNT_ALIAS("AVG_DERIVED_COUNT_"), + AVG_SUM_ALIAS("AVG_DERIVED_SUM_"), + ORDER_BY_ALIAS("ORDER_BY_DERIVED_"), + GROUP_BY_ALIAS("GROUP_BY_DERIVED_"); - private static final String AVG_SUM_ALIAS = "AVG_DERIVED_SUM_"; - - private static final String ORDER_BY_ALIAS = "ORDER_BY_DERIVED_"; - - private static final String GROUP_BY_ALIAS = "GROUP_BY_DERIVED_"; - - /** - * Get alias of avg derived count column. - * - * @param derivedColumnCount derived column count - * @return alias of avg derived count column - */ - public static String getDerivedAvgCountAlias(final int derivedColumnCount) { - return String.format(AVG_COUNT_ALIAS + "%s", derivedColumnCount); - } - - /** - * Get alias of avg derived sum column. - * - * @param derivedColumnCount derived column count - * @return alias of avg derived sum column - */ - public static String getDerivedAvgSumAlias(final int derivedColumnCount) { - return String.format(AVG_SUM_ALIAS + "%s", derivedColumnCount); - } - - /** - * Get alias of order by derived column. - * - * @param derivedColumnCount derived column count - * @return alias of order by derived column - */ - public static String getDerivedOrderByAlias(final int derivedColumnCount) { - return String.format(ORDER_BY_ALIAS + "%s", derivedColumnCount); - } + private final String pattern; /** - * Get alias of group by derived column. + * Get alias of derived column. * * @param derivedColumnCount derived column count - * @return alias of group by derived column + * @return alias of derived column */ - public static String getDerivedGroupByAlias(final int derivedColumnCount) { - return String.format(GROUP_BY_ALIAS + "%s", derivedColumnCount); + public String getDerivedColumnAlias(final int derivedColumnCount) { + return String.format(pattern + "%s", derivedColumnCount); } /** @@ -83,7 +52,11 @@ public static String getDerivedGroupByAlias(final int derivedColumnCount) { * @return is derived column or not */ public static boolean isDerivedColumn(final String columnName) { - return columnName.startsWith(DerivedColumn.AVG_COUNT_ALIAS) || columnName.startsWith(DerivedColumn.AVG_SUM_ALIAS) - || columnName.startsWith(DerivedColumn.ORDER_BY_ALIAS) || columnName.startsWith(DerivedColumn.GROUP_BY_ALIAS); + for (DerivedColumn each : DerivedColumn.values()) { + if (columnName.startsWith(each.pattern)) { + return true; + } + } + return false; } } 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 e9022f50eaf7f..4ae74504dd468 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 @@ -145,9 +145,9 @@ private void appendAvgDerivedColumns(final ItemsToken itemsToken, final SelectSt continue; } AggregationSelectItem avgItem = (AggregationSelectItem) each; - String countAlias = DerivedColumn.getDerivedAvgCountAlias(derivedColumnOffset); + String countAlias = DerivedColumn.AVG_COUNT_ALIAS.getDerivedColumnAlias(derivedColumnOffset); AggregationSelectItem countItem = new AggregationSelectItem(AggregationType.COUNT, avgItem.getInnerExpression(), Optional.of(countAlias)); - String sumAlias = DerivedColumn.getDerivedAvgSumAlias(derivedColumnOffset); + String sumAlias = DerivedColumn.AVG_SUM_ALIAS.getDerivedColumnAlias(derivedColumnOffset); AggregationSelectItem sumItem = new AggregationSelectItem(AggregationType.SUM, avgItem.getInnerExpression(), Optional.of(sumAlias)); avgItem.getDerivedAggregationSelectItems().add(countItem); avgItem.getDerivedAggregationSelectItems().add(sumItem); @@ -162,7 +162,7 @@ private void appendDerivedOrderColumns(final ItemsToken itemsToken, final List CONTEXT = new ThreadLocal() { + @Override protected TransactionContext initialValue() { return new TransactionContext(); From ac1c4f94e4e06bec00cbe5ae3ee765715cd17bd1 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Thu, 9 Aug 2018 17:47:20 +0800 Subject: [PATCH 150/198] add test case for DerivedColumn --- .../core/parsing/AllParsingTests.java | 4 +- .../parser/constant/DerivedColumnTest.java | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumnTest.java diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/AllParsingTests.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/AllParsingTests.java index ed872f102741d..7d699e017d860 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/AllParsingTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/AllParsingTests.java @@ -19,6 +19,7 @@ import io.shardingsphere.core.parsing.integrate.AllParsingIntegrateTests; import io.shardingsphere.core.parsing.lexer.AllLexerTests; +import io.shardingsphere.core.parsing.parser.constant.DerivedColumnTest; import io.shardingsphere.core.parsing.parser.context.OrderItemTest; import io.shardingsphere.core.parsing.parser.sql.AllSQLTests; import io.shardingsphere.core.parsing.parser.sql.AllStatementParserTests; @@ -31,7 +32,8 @@ AllStatementParserTests.class, AllSQLTests.class, SQLJudgeEngineTest.class, - OrderItemTest.class, + OrderItemTest.class, + DerivedColumnTest.class, AllParsingIntegrateTests.class }) public class AllParsingTests { diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumnTest.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumnTest.java new file mode 100644 index 0000000000000..13df5e9f1c4e6 --- /dev/null +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumnTest.java @@ -0,0 +1,49 @@ +/* + * 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.core.parsing.parser.constant; + +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +public final class DerivedColumnTest { + + @Test + public void assertGetDerivedColumnAlias() { + assertThat(DerivedColumn.AVG_COUNT_ALIAS.getDerivedColumnAlias(0), is("AVG_DERIVED_COUNT_0")); + assertThat(DerivedColumn.AVG_SUM_ALIAS.getDerivedColumnAlias(1), is("AVG_DERIVED_SUM_1")); + assertThat(DerivedColumn.ORDER_BY_ALIAS.getDerivedColumnAlias(0), is("ORDER_BY_DERIVED_0")); + assertThat(DerivedColumn.GROUP_BY_ALIAS.getDerivedColumnAlias(1), is("GROUP_BY_DERIVED_1")); + } + + @Test + public void assertIsDerivedColumn() { + assertTrue(DerivedColumn.isDerivedColumn("AVG_DERIVED_COUNT_0")); + assertTrue(DerivedColumn.isDerivedColumn("AVG_DERIVED_SUM_1")); + assertTrue(DerivedColumn.isDerivedColumn("ORDER_BY_DERIVED_0")); + assertTrue(DerivedColumn.isDerivedColumn("GROUP_BY_DERIVED_1")); + } + + @Test + public void assertIsNotDerivedColumn() { + assertFalse(DerivedColumn.isDerivedColumn("OTHER_DERIVED_COLUMN_0")); + } +} From 162672cb7d1b02368706ac1431f2eb2af9dac579 Mon Sep 17 00:00:00 2001 From: saaav Date: Thu, 9 Aug 2018 18:24:46 +0800 Subject: [PATCH 151/198] javadoc --- .../jdbc/orchestration/reg/newzk/client/action/IClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java index af1249083fc56..f897dafab9c6e 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/action/IClient.java @@ -83,9 +83,9 @@ public interface IClient extends IAction, IGroupAction { void useExecStrategy(StrategyType strategyType); /** - * Get provider. + * Get execution strategy. * - * @return execute strategy + * @return execution strategy */ IExecStrategy getExecStrategy(); From 50a9da1ec0ace083af1d69904dc9197f3bf1833b Mon Sep 17 00:00:00 2001 From: haocao Date: Sat, 4 Aug 2018 10:30:33 +0800 Subject: [PATCH 152/198] for #601, removed useless codes of DeleteStatementParserTest --- .../parser/sql/DeleteStatementParserTest.java | 74 +------------------ 1 file changed, 2 insertions(+), 72 deletions(-) diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/DeleteStatementParserTest.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/DeleteStatementParserTest.java index 3059064157ecf..d52e480e95fff 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/DeleteStatementParserTest.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/DeleteStatementParserTest.java @@ -17,9 +17,7 @@ package io.shardingsphere.core.parsing.parser.sql; -import com.google.common.collect.Range; import io.shardingsphere.core.api.algorithm.sharding.ListShardingValue; -import io.shardingsphere.core.api.algorithm.sharding.RangeShardingValue; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.constant.ShardingOperator; import io.shardingsphere.core.parsing.SQLParsingEngine; @@ -27,84 +25,16 @@ import io.shardingsphere.core.parsing.parser.context.condition.Condition; import io.shardingsphere.core.parsing.parser.sql.dml.DMLStatement; import io.shardingsphere.core.rule.ShardingRule; -import org.hamcrest.CoreMatchers; import org.junit.Test; -import java.util.Arrays; import java.util.Collections; -import java.util.Iterator; -import java.util.List; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; public final class DeleteStatementParserTest extends AbstractStatementParserTest { - - @Test - public void parseWithoutCondition() { - ShardingRule shardingRule = createShardingRule(); - SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, "DELETE FROM TABLE_XXX", shardingRule, null); - DMLStatement deleteStatement = (DMLStatement) statementParser.parse(false); - assertThat(deleteStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX")); - } - - @Test - public void parseWithoutParameter() { - ShardingRule shardingRule = createShardingRule(); - SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, - "DELETE FROM TABLE_XXX xxx WHERE field4<10 AND TABLE_XXX.field1=1 AND field5>10 AND xxx.field2 IN (1,3) AND field6<=10 AND field3 BETWEEN 5 AND 20 AND field7>=10", shardingRule, null); - DMLStatement deleteStatement = (DMLStatement) statementParser.parse(false); - assertDeleteStatementWithoutParameter(deleteStatement); - } - - private void assertDeleteStatementWithoutParameter(final DMLStatement deleteStatement) { - assertThat(deleteStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX")); - assertThat(deleteStatement.getTables().find("xxx").get().getAlias().get(), is("xxx")); - Condition condition1 = deleteStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get(); - assertThat(condition1.getOperator(), CoreMatchers.is(ShardingOperator.EQUAL)); - assertThat(((ListShardingValue) condition1.getShardingValue(Collections.emptyList())).getValues().iterator().next(), is((Object) 1)); - Condition condition2 = deleteStatement.getConditions().find(new Column("field2", "TABLE_XXX")).get(); - assertThat(condition2.getOperator(), is(ShardingOperator.IN)); - Iterator shardingValues2 = ((ListShardingValue) condition2.getShardingValue(Collections.emptyList())).getValues().iterator(); - assertThat(shardingValues2.next(), is((Object) 1)); - assertThat(shardingValues2.next(), is((Object) 3)); - assertFalse(shardingValues2.hasNext()); - Condition condition3 = deleteStatement.getConditions().find(new Column("field3", "TABLE_XXX")).get(); - assertThat(condition3.getOperator(), is(ShardingOperator.BETWEEN)); - Range shardingValues3 = ((RangeShardingValue) condition3.getShardingValue(Collections.emptyList())).getValueRange(); - assertThat(shardingValues3.lowerEndpoint(), is((Comparable) 5)); - assertThat(shardingValues3.upperEndpoint(), is((Comparable) 20)); - } - - @Test - public void parseWithParameter() { - ShardingRule shardingRule = createShardingRule(); - SQLParsingEngine statementParser = new SQLParsingEngine(DatabaseType.MySQL, - "DELETE FROM TABLE_XXX xxx WHERE field4? AND field2 IN (?,?) AND field6<=? AND field3 BETWEEN ? AND ? AND field7>=?", shardingRule, null); - DMLStatement deleteStatement = (DMLStatement) statementParser.parse(false); - assertDeleteStatementWithParameter(deleteStatement); - } - - private void assertDeleteStatementWithParameter(final DMLStatement deleteStatement) { - assertThat(deleteStatement.getTables().find("TABLE_XXX").get().getName(), is("TABLE_XXX")); - assertThat(deleteStatement.getTables().find("xxx").get().getAlias().get(), is("xxx")); - List actualParameters = Arrays.asList(0, 10, 20, 30, 40, 50, 60, 70, 80); - Condition condition1 = deleteStatement.getConditions().find(new Column("field1", "TABLE_XXX")).get(); - assertThat(condition1.getOperator(), is(ShardingOperator.EQUAL)); - assertThat(((ListShardingValue) condition1.getShardingValue(actualParameters)).getValues().iterator().next(), is((Object) 10)); - Condition condition2 = deleteStatement.getConditions().find(new Column("field2", "TABLE_XXX")).get(); - assertThat(condition2.getOperator(), is(ShardingOperator.IN)); - Iterator shardingValues2 = ((ListShardingValue) condition2.getShardingValue(actualParameters)).getValues().iterator(); - assertThat(shardingValues2.next(), is((Object) 30)); - assertThat(shardingValues2.next(), is((Object) 40)); - Condition condition3 = deleteStatement.getConditions().find(new Column("field3", "TABLE_XXX")).get(); - assertThat(condition3.getOperator(), is(ShardingOperator.BETWEEN)); - Range shardingValues3 = ((RangeShardingValue) condition3.getShardingValue(actualParameters)).getValueRange(); - assertThat(shardingValues3.lowerEndpoint(), is((Comparable) 60)); - assertThat(shardingValues3.upperEndpoint(), is((Comparable) 70)); - } - + @Test(expected = UnsupportedOperationException.class) public void parseStatementWithDeleteMultipleTable() { ShardingRule shardingRule = createShardingRule(); @@ -119,7 +49,7 @@ public void parseStatementWithDeleteMultipleTableWithUsing() { @Test public void parseWithSpecialSyntax() { -// parseWithSpecialSyntax(DatabaseType.MySQL, "DELETE `TABLE_XXX` WHERE `field1`=1"); + parseWithSpecialSyntax(DatabaseType.MySQL, "DELETE `TABLE_XXX` WHERE `field1`=1"); parseWithSpecialSyntax(DatabaseType.Oracle, "DELETE /*+ index(field1) */ ONLY (TABLE_XXX) WHERE field1=1 RETURN * LOG ERRORS INTO TABLE_LOG"); parseWithSpecialSyntax(DatabaseType.Oracle, "DELETE /*+ index(field1) */ ONLY (TABLE_XXX) WHERE field1=1 RETURNING *"); } From edc388f3984fbcaa1a093b822a3c2e20f33f7de4 Mon Sep 17 00:00:00 2001 From: haocao Date: Thu, 9 Aug 2018 22:12:46 +0800 Subject: [PATCH 153/198] Removed useless codes in YamlTableRuleConfiguration. --- .../core/yaml/sharding/YamlTableRuleConfiguration.java | 1 - 1 file changed, 1 deletion(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/yaml/sharding/YamlTableRuleConfiguration.java b/sharding-core/src/main/java/io/shardingsphere/core/yaml/sharding/YamlTableRuleConfiguration.java index f3da6b79f472a..301574e757fa1 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/yaml/sharding/YamlTableRuleConfiguration.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/yaml/sharding/YamlTableRuleConfiguration.java @@ -58,7 +58,6 @@ public YamlTableRuleConfiguration(final TableRuleConfiguration tableRuleConfigur keyGeneratorColumnName = tableRuleConfiguration.getKeyGeneratorColumnName(); keyGeneratorClassName = null == tableRuleConfiguration.getKeyGenerator() ? null : tableRuleConfiguration.getKeyGenerator().getClass().getName(); - logicTable = tableRuleConfiguration.getLogicTable(); } /** From d68a0f4fa7329703fcbcd820f39904bd6ebd6bd9 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Fri, 10 Aug 2018 10:13:56 +0800 Subject: [PATCH 154/198] for #1116, resolve transactionManager is null when receiving new request from client application. --- .../core/jdbc/adapter/AbstractConnectionAdapter.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index 67cc0548ee685..a8ae2449a3f0c 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -19,9 +19,13 @@ import com.google.common.base.Preconditions; import io.shardingsphere.core.constant.TCLType; +import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.hint.HintManagerHolder; +import io.shardingsphere.core.jdbc.core.transaction.WeakXaTransactionManager; import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection; import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager; +import io.shardingsphere.core.transaction.TransactionContext; +import io.shardingsphere.core.transaction.TransactionContextHolder; import io.shardingsphere.core.transaction.event.TransactionEvent; import io.shardingsphere.core.transaction.event.TransactionEventFactory; import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent; @@ -62,6 +66,7 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera * @throws SQLException SQL exception */ public final Connection getConnection(final String dataSourceName) throws SQLException { + TransactionContextHolder.set(new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class)); DataSource dataSource = getDataSourceMap().get(dataSourceName); Preconditions.checkState(null != dataSource, "Missing the data source name: '%s'", dataSourceName); Connection result = dataSource.getConnection(); From 02db08bd2a66ba237e58ad88084f510c9d49bc11 Mon Sep 17 00:00:00 2001 From: cherrylzhao Date: Fri, 10 Aug 2018 10:43:50 +0800 Subject: [PATCH 155/198] for #1116, resolve transactionManager is null when receiving new request from client application. this problem will be completely resolved in 3.1.0 --- .../core/jdbc/adapter/AbstractConnectionAdapter.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index a8ae2449a3f0c..c320fec3622e3 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -89,6 +89,7 @@ public final boolean getAutoCommit() { @Override public final void setAutoCommit(final boolean autoCommit) { this.autoCommit = autoCommit; + TransactionContextHolder.set(new TransactionContext(new WeakXaTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class)); recordMethodInvocation(Connection.class, "setAutoCommit", new Class[] {boolean.class}, new Object[] {autoCommit}); EventBusInstance.getInstance().post(buildTransactionEvent(TCLType.BEGIN)); } From bc687bc2c16a4dbe66ef3e3b4b4fe0e9565160bd Mon Sep 17 00:00:00 2001 From: saaav Date: Fri, 10 Aug 2018 11:12:39 +0800 Subject: [PATCH 156/198] adjust import package sequence --- .../reg/newzk/client/cache/PathTree.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java index 37e47adfa58c9..651831c4c6938 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/cache/PathTree.java @@ -24,6 +24,12 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.PathUtil; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.utility.ZookeeperConstants; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.ZookeeperEventListener; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.WatchedEvent; + import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executors; @@ -31,11 +37,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.ReentrantLock; -import lombok.Getter; -import lombok.Setter; -import lombok.extern.slf4j.Slf4j; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.WatchedEvent; /** * Zookeeper cache tree. From e6918f90d426363d3e127c7be8ac0a092d9328f1 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Fri, 10 Aug 2018 11:30:10 +0800 Subject: [PATCH 157/198] Merge remote-tracking branch 'origin/dev' into dev-3.1.0 # Conflicts: # sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java # sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java --- .../adapter/AbstractConnectionAdapter.java | 2 +- .../jdbc/adapter/ConnectionAdapterTest.java | 30 +++++++------- .../connection/ShardingConnectionTest.java | 4 +- .../proxy/config/RuleRegistry.java | 40 +++++++++---------- sharding-transaction/pom.xml | 2 +- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index d5fa32626b918..e10e15c880fce 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -181,7 +181,7 @@ private TransactionEvent buildTransactionEvent(final TCLType tclType) { TransactionEvent result = TransactionEventFactory.create(tclType); if (result instanceof WeakXaTransactionEvent) { WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) result; - weakXaTransactionEvent.setCachedConnections(cachedConnections); + weakXaTransactionEvent.setCachedConnections(cachedConnections.values()); weakXaTransactionEvent.setAutoCommit(autoCommit); } return result; diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java index f51f18af0ea7f..150f4919c267f 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/ConnectionAdapterTest.java @@ -26,7 +26,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Collection; +import java.util.Map; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNull; @@ -51,9 +51,9 @@ public void assertSetAutoCommit() throws SQLException { private void assertAutoCommit(final ShardingConnection actual, final boolean autoCommit) throws SQLException { assertThat(actual.getAutoCommit(), is(autoCommit)); - Collection cachedConnections = getCachedConnections(actual); - assertThat(cachedConnections.size(), is(4)); - for (Connection each : cachedConnections) { + Map cachedConnections = getCachedConnections(actual); + assertThat(cachedConnections.size(), is(2)); + for (Connection each : cachedConnections.values()) { assertThat(each.getAutoCommit(), is(autoCommit)); } } @@ -90,9 +90,9 @@ public void assertClose() throws SQLException { private void assertClose(final ShardingConnection actual, final boolean closed) throws SQLException { assertThat(actual.isClosed(), is(closed)); - Collection cachedConnections = getCachedConnections(actual); - assertThat(cachedConnections.size(), is(4)); - for (Connection each : cachedConnections) { + Map cachedConnections = getCachedConnections(actual); + assertThat(cachedConnections.size(), is(2)); + for (Connection each : cachedConnections.values()) { assertThat(each.isClosed(), is(closed)); } } @@ -111,9 +111,9 @@ public void assertSetReadOnly() throws SQLException { private void assertReadOnly(final ShardingConnection actual, final boolean readOnly) throws SQLException { assertThat(actual.isReadOnly(), is(readOnly)); - Collection cachedConnections = getCachedConnections(actual); - assertThat(cachedConnections.size(), is(4)); - for (Connection each : cachedConnections) { + Map cachedConnections = getCachedConnections(actual); + assertThat(cachedConnections.size(), is(2)); + for (Connection each : cachedConnections.values()) { assertThat(each.isReadOnly(), is(readOnly)); } } @@ -140,9 +140,9 @@ public void assertSetTransactionIsolation() throws SQLException { private void assertTransactionIsolation(final ShardingConnection actual, final int transactionIsolation) throws SQLException { assertThat(actual.getTransactionIsolation(), is(transactionIsolation)); - Collection cachedConnections = getCachedConnections(actual); - assertThat(cachedConnections.size(), is(4)); - for (Connection each : cachedConnections) { + Map cachedConnections = getCachedConnections(actual); + assertThat(cachedConnections.size(), is(2)); + for (Connection each : cachedConnections.values()) { assertThat(each.getTransactionIsolation(), is(transactionIsolation)); } } @@ -177,11 +177,11 @@ public void assertSetHoldability() throws SQLException { } @SuppressWarnings("unchecked") - private Collection getCachedConnections(final AbstractConnectionAdapter connectionAdapter) { + private Map getCachedConnections(final AbstractConnectionAdapter connectionAdapter) { try { Field field = AbstractConnectionAdapter.class.getDeclaredField("cachedConnections"); field.setAccessible(true); - return (Collection) field.get(connectionAdapter); + return (Map) field.get(connectionAdapter); } catch (final ReflectiveOperationException ex) { throw new RuntimeException(ex); } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java index 4b916b1b9032e..2c95f373d18fa 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java @@ -41,7 +41,9 @@ import java.util.Map; import java.util.Properties; +import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertThat; public final class ShardingConnectionTest { @@ -86,7 +88,7 @@ public void clear() { @Test public void assertGetConnectionFromCache() throws SQLException { - assertNotSame(connection.getConnection(DS_NAME), connection.getConnection(DS_NAME)); + assertThat(connection.getConnection(DS_NAME), is(connection.getConnection(DS_NAME))); } @Test(expected = IllegalStateException.class) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 11b27f12d7637..87bae9d00cc79 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -60,35 +60,35 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) @Getter public final class RuleRegistry { - + private static final RuleRegistry INSTANCE = new RuleRegistry(); - + private ShardingRule shardingRule; - + private MasterSlaveRule masterSlaveRule; - + private JDBCBackendDataSource backendDataSource; - + private Map dataSourceConfigurationMap; - + private boolean showSQL; - + private ConnectionMode connectionMode; - + private int acceptorSize; - + private int executorSize; - + private BackendNIOConfiguration backendNIOConfig; - + private TransactionType transactionType; - + private TransactionManager transactionManager; - + private ProxyAuthority proxyAuthority; - + private ShardingMetaData metaData; - + /** * Get instance of sharding rule registry. * @@ -97,7 +97,7 @@ public final class RuleRegistry { public static RuleRegistry getInstance() { return INSTANCE; } - + /** * Initialize rule registry. * @@ -129,7 +129,7 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { dataSourceConfigurationMap = config.getDataSources(); proxyAuthority = config.getProxyAuthority(); } - + /** * Initialize rule registry. * @@ -141,7 +141,7 @@ public void initShardingMetaData(final ExecutorService executorService) { new TableMetaDataInitializer(MoreExecutors.listeningDecorator(executorService), new ProxyTableMetaDataConnectionManager(backendDataSource)).load(shardingRule)); metaData = new ShardingMetaData(shardingDataSourceMetaData, shardingTableMetaData); } - + private static Map getDataSourceURLs(final Map dataSourceParameters) { Map result = new LinkedHashMap<>(dataSourceParameters.size(), 1); for (Entry entry : dataSourceParameters.entrySet()) { @@ -149,7 +149,7 @@ private static Map getDataSourceURLs(final Map getDataSourceURLs(final Map sharding-sphere io.shardingsphere - 3.0.0.M2 + 3.0.0.M3-SNAPSHOT sharding-transaction From 1343e5b9646915d74e481933ff3d9e1bdc542250 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Fri, 10 Aug 2018 20:37:52 +0800 Subject: [PATCH 158/198] #1127, Put getConnection() in multithreading --- .../execute/memory/ConnectionStrictlyExecuteEngine.java | 6 ++++-- .../jdbc/execute/stream/MemoryStrictlyExecuteEngine.java | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java index b6674b3f5335f..909776579636f 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java @@ -67,15 +67,17 @@ public ExecuteResponse execute(final SQLRouteResult routeResult, final boolean i return getExecuteQueryResponse(firstExecuteResponseUnits, futureList); } - private List>> asyncExecute(final boolean isReturnGeneratedKeys, final Map> sqlUnitGroups) throws SQLException { + private List>> asyncExecute(final boolean isReturnGeneratedKeys, final Map> sqlUnitGroups) { List>> result = new LinkedList<>(); for (Entry> entry : sqlUnitGroups.entrySet()) { - final Map sqlUnitStatementMap = createSQLUnitStatement(entry.getKey(), entry.getValue(), isReturnGeneratedKeys); + final String dataSourceName = entry.getKey(); + final Collection sqlUnits = entry.getValue(); result.add(getExecutorService().submit(new Callable>() { @Override public Collection call() throws SQLException { Collection result = new LinkedList<>(); + final Map sqlUnitStatementMap = createSQLUnitStatement(dataSourceName, sqlUnits, isReturnGeneratedKeys); for (Entry each : sqlUnitStatementMap.entrySet()) { result.add(executeWithoutMetadata(each.getValue(), each.getKey().getSql(), isReturnGeneratedKeys)); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java index e5f65394c6e4d..0584c1c81d552 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java @@ -67,15 +67,16 @@ public ExecuteResponse execute(final SQLRouteResult routeResult, final boolean i ? getExecuteQueryResponse((ExecuteQueryResponseUnit) firstResponseUnit, futureList) : getExecuteUpdateResponse((ExecuteUpdateResponseUnit) firstResponseUnit, futureList); } - private List> asyncExecute(final boolean isReturnGeneratedKeys, final Collection sqlExecutionUnits) throws SQLException { + private List> asyncExecute(final boolean isReturnGeneratedKeys, final Collection sqlExecutionUnits) { List> result = new LinkedList<>(); for (SQLExecutionUnit each : sqlExecutionUnits) { - final String actualSQL = each.getSqlUnit().getSql(); - final Statement statement = getJdbcExecutorWrapper().createStatement(getBackendConnection().getConnection(each.getDataSource()), actualSQL, isReturnGeneratedKeys); + final SQLExecutionUnit sqlExecutionUnit = each; result.add(getExecutorService().submit(new Callable() { @Override public ExecuteResponseUnit call() throws SQLException { + final String actualSQL = sqlExecutionUnit.getSqlUnit().getSql(); + final Statement statement = getJdbcExecutorWrapper().createStatement(getBackendConnection().getConnection(sqlExecutionUnit.getDataSource()), actualSQL, isReturnGeneratedKeys); return executeWithoutMetadata(statement, actualSQL, isReturnGeneratedKeys); } })); From 38fbc0c2d12c6c2ced8c25a647d5fa5e2acaf154 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Fri, 10 Aug 2018 23:52:15 +0800 Subject: [PATCH 159/198] refactor TableMetaDataLoader --- .../table/executor/TableMetaDataLoader.java | 44 +++++++++---------- .../core/rule/ShardingRule.java | 17 ------- 2 files changed, 20 insertions(+), 41 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java index a783f7f8ec3f2..07cb790c25010 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java @@ -26,7 +26,6 @@ import io.shardingsphere.core.rule.DataNode; import io.shardingsphere.core.rule.ShardingDataSourceNames; import io.shardingsphere.core.rule.ShardingRule; -import io.shardingsphere.core.rule.TableRule; import lombok.RequiredArgsConstructor; import java.sql.Connection; @@ -60,13 +59,28 @@ public final class TableMetaDataLoader { * @return table meta data */ public TableMetaData load(final String logicTableName, final ShardingRule shardingRule) { - return load(shardingRule.getTableRuleByLogicTableName(logicTableName), shardingRule.getShardingDataSourceNames()); + List actualTableMetaDataList = load( + shardingRule.getTableRuleByLogicTableName(logicTableName).getActualDataNodes(), shardingRule.getShardingDataSourceNames()); + checkUniformed(logicTableName, actualTableMetaDataList); + return actualTableMetaDataList.iterator().next(); } - private TableMetaData load(final TableRule tableRule, final ShardingDataSourceNames shardingDataSourceNames) { - List actualTableMetaDataList = loadActualTableMetaDataList(tableRule.getActualDataNodes(), shardingDataSourceNames); - checkUniformed(tableRule.getLogicTable(), actualTableMetaDataList); - return actualTableMetaDataList.iterator().next(); + private List load(final List actualDataNodes, final ShardingDataSourceNames shardingDataSourceNames) { + List> result = new LinkedList<>(); + for (final DataNode each : actualDataNodes) { + result.add(executorService.submit(new Callable() { + + @Override + public TableMetaData call() throws SQLException { + return load(new DataNode(shardingDataSourceNames.getRawMasterDataSourceName(each.getDataSourceName()), each.getTableName())); + } + })); + } + try { + return Futures.allAsList(result).get(); + } catch (final InterruptedException | ExecutionException ex) { + throw new ShardingException(ex); + } } private TableMetaData load(final DataNode dataNode) throws SQLException { @@ -111,24 +125,6 @@ private Collection getPrimaryKeys(final Connection connection, final Str return result; } - private List loadActualTableMetaDataList(final List actualDataNodes, final ShardingDataSourceNames shardingDataSourceNames) { - List> result = new LinkedList<>(); - for (final DataNode each : actualDataNodes) { - result.add(executorService.submit(new Callable() { - - @Override - public TableMetaData call() throws SQLException { - return load(new DataNode(shardingDataSourceNames.getRawMasterDataSourceName(each.getDataSourceName()), each.getTableName())); - } - })); - } - try { - return Futures.allAsList(result).get(); - } catch (final InterruptedException | ExecutionException ex) { - throw new ShardingException(ex); - } - } - private void checkUniformed(final String logicTableName, final List actualTableMetaDataList) { final TableMetaData sample = actualTableMetaDataList.iterator().next(); for (TableMetaData each : actualTableMetaDataList) { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java b/sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java index 2116015adad56..1114f15583b01 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/rule/ShardingRule.java @@ -121,23 +121,6 @@ public Optional tryFindTableRuleByActualTable(final String actualTabl return Optional.absent(); } - /** - * Find table rule though actual table name. - * - * @param actualTableName actual table name - * @return table rule - */ - public TableRule getTableRuleByActualTableName(final String actualTableName) { - Optional tableRule = tryFindTableRuleByActualTable(actualTableName.toLowerCase()); - if (tableRule.isPresent()) { - return tableRule.get(); - } - if (!Strings.isNullOrEmpty(shardingDataSourceNames.getDefaultDataSourceName())) { - return createTableRuleWithDefaultDataSource(actualTableName.toLowerCase()); - } - throw new ShardingConfigurationException("Cannot find table rule and default data source with actual table: '%s'", actualTableName); - } - /** * Find table rule though logic table name. * From 05f65801bf347c3df143df71e49efa7ba43e8551 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sat, 11 Aug 2018 01:32:14 +0800 Subject: [PATCH 160/198] for #1130 Loading table meta data should be one data source use one connection --- .../table/executor/TableMetaDataLoader.java | 40 +++++++++++-------- .../shardingsphere/core/rule/TableRule.java | 19 +++++++++ .../statement/ShardingPreparedStatement.java | 4 +- .../core/statement/ShardingStatement.java | 4 +- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java index 07cb790c25010..beff59fd40744 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java @@ -23,7 +23,6 @@ import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.metadata.table.ColumnMetaData; import io.shardingsphere.core.metadata.table.TableMetaData; -import io.shardingsphere.core.rule.DataNode; import io.shardingsphere.core.rule.ShardingDataSourceNames; import io.shardingsphere.core.rule.ShardingRule; import lombok.RequiredArgsConstructor; @@ -36,6 +35,8 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; @@ -59,41 +60,48 @@ public final class TableMetaDataLoader { * @return table meta data */ public TableMetaData load(final String logicTableName, final ShardingRule shardingRule) { - List actualTableMetaDataList = load( - shardingRule.getTableRuleByLogicTableName(logicTableName).getActualDataNodes(), shardingRule.getShardingDataSourceNames()); + List actualTableMetaDataList = load(shardingRule.getTableRuleByLogicTableName(logicTableName).getDataNodeGroups(), shardingRule.getShardingDataSourceNames()); checkUniformed(logicTableName, actualTableMetaDataList); return actualTableMetaDataList.iterator().next(); } - private List load(final List actualDataNodes, final ShardingDataSourceNames shardingDataSourceNames) { - List> result = new LinkedList<>(); - for (final DataNode each : actualDataNodes) { - result.add(executorService.submit(new Callable() { + private List load(final Map> dataNodeGroups, final ShardingDataSourceNames shardingDataSourceNames) { + List>> futures = new LinkedList<>(); + for (final Entry> entry : dataNodeGroups.entrySet()) { + futures.add(executorService.submit(new Callable>() { @Override - public TableMetaData call() throws SQLException { - return load(new DataNode(shardingDataSourceNames.getRawMasterDataSourceName(each.getDataSourceName()), each.getTableName())); + public Collection call() throws SQLException { + return load(shardingDataSourceNames.getRawMasterDataSourceName(entry.getKey()), entry.getValue()); } })); } + List result = new LinkedList<>(); try { - return Futures.allAsList(result).get(); + for (Collection each : Futures.allAsList(futures).get()) { + result.addAll(each); + } + return result; } catch (final InterruptedException | ExecutionException ex) { throw new ShardingException(ex); } } - private TableMetaData load(final DataNode dataNode) throws SQLException { + private Collection load(final String dataSourceName, final Collection actualTableNames) throws SQLException { if (connectionManager.isAutoClose()) { - try (Connection connection = connectionManager.getConnection(dataNode.getDataSourceName())) { - return load(connection, dataNode); + try (Connection connection = connectionManager.getConnection(dataSourceName)) { + return load(connection, actualTableNames); } } - return load(connectionManager.getConnection(dataNode.getDataSourceName()), dataNode); + return load(connectionManager.getConnection(dataSourceName), actualTableNames); } - private TableMetaData load(final Connection connection, final DataNode dataNode) throws SQLException { - return new TableMetaData(isTableExist(connection, dataNode.getTableName()) ? getColumnMetaDataList(connection, dataNode.getTableName()) : Collections.emptyList()); + private Collection load(final Connection connection, final Collection actualTableNames) throws SQLException { + Collection result = new LinkedList<>(); + for (String each : actualTableNames) { + result.add(new TableMetaData(isTableExist(connection, each) ? getColumnMetaDataList(connection, each) : Collections.emptyList())); + } + return result; } private boolean isTableExist(final Connection connection, final String actualTableName) throws SQLException { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/rule/TableRule.java b/sharding-core/src/main/java/io/shardingsphere/core/rule/TableRule.java index 9e5eb49ccd60f..f2cd56f4b9cac 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/rule/TableRule.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/rule/TableRule.java @@ -28,9 +28,11 @@ import lombok.ToString; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; +import java.util.Map; /** * Table rule configuration. @@ -92,6 +94,23 @@ private List generateDataNodes(final List actualDataNodes, fin return result; } + /** + * Get data node groups. + * + * @return data node groups, key is data source name, value is tables belong to this data source + */ + public Map> getDataNodeGroups() { + Map> result = new LinkedHashMap<>(actualDataNodes.size(), 1); + for (DataNode each : actualDataNodes) { + String dataSourceName = each.getDataSourceName(); + if (!result.containsKey(dataSourceName)) { + result.put(dataSourceName, new LinkedList()); + } + result.get(dataSourceName).add(each.getTableName()); + } + return result; + } + /** * Get actual data source names. * diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java index 2429937b4579f..2de5a4ee21d86 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java @@ -33,7 +33,7 @@ import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; import io.shardingsphere.core.jdbc.core.resultset.GeneratedKeysResultSet; import io.shardingsphere.core.jdbc.core.resultset.ShardingResultSet; -import io.shardingsphere.core.jdbc.metadata.ShardingConnectionTableMetaDataConnectionManager; +import io.shardingsphere.core.jdbc.metadata.DataSourceMapTableMetaDataConnectionManager; import io.shardingsphere.core.merger.MergeEngine; import io.shardingsphere.core.merger.MergeEngineFactory; import io.shardingsphere.core.merger.MergedResult; @@ -249,7 +249,7 @@ private void refreshTableMetaData() { if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( - connection.getShardingContext().getExecutorEngine().getExecutorService(), new ShardingConnectionTableMetaDataConnectionManager(logicTableName, connection)); + connection.getShardingContext().getExecutorEngine().getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, connection.getShardingContext().getShardingRule())); } } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java index 028a1525c4e75..2ef24e56a55b4 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java @@ -29,7 +29,7 @@ import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; import io.shardingsphere.core.jdbc.core.resultset.GeneratedKeysResultSet; import io.shardingsphere.core.jdbc.core.resultset.ShardingResultSet; -import io.shardingsphere.core.jdbc.metadata.ShardingConnectionTableMetaDataConnectionManager; +import io.shardingsphere.core.jdbc.metadata.DataSourceMapTableMetaDataConnectionManager; import io.shardingsphere.core.merger.MergeEngine; import io.shardingsphere.core.merger.MergeEngineFactory; import io.shardingsphere.core.merger.MergedResult; @@ -287,7 +287,7 @@ private void refreshTableMetaData() { if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( - connection.getShardingContext().getExecutorEngine().getExecutorService(), new ShardingConnectionTableMetaDataConnectionManager(logicTableName, connection)); + connection.getShardingContext().getExecutorEngine().getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, connection.getShardingContext().getShardingRule())); } } From 97037d18709ee55d2835ad5762bb08ccc9f48790 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sat, 11 Aug 2018 01:36:46 +0800 Subject: [PATCH 161/198] for #1130 always use new connection to refresh table meta data, because ddl is rare, and use connection may hold connection for long time --- .../TableMetaDataConnectionManager.java | 7 --- .../table/executor/TableMetaDataLoader.java | 15 ++---- .../core/datasource/ShardingDataSource.java | 6 +-- .../statement/ShardingPreparedStatement.java | 7 +-- .../core/statement/ShardingStatement.java | 4 +- ...> JDBCTableMetaDataConnectionManager.java} | 9 +--- ...nectionTableMetaDataConnectionManager.java | 48 ------------------- .../ProxyTableMetaDataConnectionManager.java | 5 -- 8 files changed, 15 insertions(+), 86 deletions(-) rename sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/metadata/{DataSourceMapTableMetaDataConnectionManager.java => JDBCTableMetaDataConnectionManager.java} (81%) delete mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/metadata/ShardingConnectionTableMetaDataConnectionManager.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataConnectionManager.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataConnectionManager.java index 63d86a9197bb8..02c1cab6d557e 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataConnectionManager.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataConnectionManager.java @@ -35,11 +35,4 @@ public interface TableMetaDataConnectionManager { * @throws SQLException SQL exception */ Connection getConnection(String dataSourceName) throws SQLException; - - /** - * Is auto close created connection or not. - * - * @return auto close or not - */ - boolean isAutoClose(); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java index beff59fd40744..813a2bd1a0b5d 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java @@ -88,18 +88,11 @@ public Collection call() throws SQLException { } private Collection load(final String dataSourceName, final Collection actualTableNames) throws SQLException { - if (connectionManager.isAutoClose()) { - try (Connection connection = connectionManager.getConnection(dataSourceName)) { - return load(connection, actualTableNames); - } - } - return load(connectionManager.getConnection(dataSourceName), actualTableNames); - } - - private Collection load(final Connection connection, final Collection actualTableNames) throws SQLException { Collection result = new LinkedList<>(); - for (String each : actualTableNames) { - result.add(new TableMetaData(isTableExist(connection, each) ? getColumnMetaDataList(connection, each) : Collections.emptyList())); + try (Connection connection = connectionManager.getConnection(dataSourceName)) { + for (String each : actualTableNames) { + result.add(new TableMetaData(isTableExist(connection, each) ? getColumnMetaDataList(connection, each) : Collections.emptyList())); + } } return result; } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java index 890bdd44cc9c9..d20cf19b087c8 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java @@ -29,7 +29,7 @@ import io.shardingsphere.core.jdbc.adapter.AbstractDataSourceAdapter; import io.shardingsphere.core.jdbc.core.ShardingContext; import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; -import io.shardingsphere.core.jdbc.metadata.DataSourceMapTableMetaDataConnectionManager; +import io.shardingsphere.core.jdbc.metadata.JDBCTableMetaDataConnectionManager; import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.metadata.table.executor.TableMetaDataInitializer; import io.shardingsphere.core.rule.MasterSlaveRule; @@ -75,7 +75,7 @@ public ShardingDataSource(final Map dataSourceMap, final Sha ConnectionMode connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); executorEngine = ConnectionMode.MEMORY_STRICTLY == connectionMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData( - new TableMetaDataInitializer(executorEngine.getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule)); + new TableMetaDataInitializer(executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule)); boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL, connectionMode); } @@ -100,7 +100,7 @@ public void renew(final Map newDataSourceMap, final Sharding } boolean newShowSQL = newShardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); ShardingTableMetaData shardingMetaData = new ShardingTableMetaData( - new TableMetaDataInitializer(executorEngine.getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(newDataSourceMap)).load(newShardingRule)); + new TableMetaDataInitializer(executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(newDataSourceMap)).load(newShardingRule)); shardingProperties = newShardingProperties; shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, shardingMetaData, newShowSQL, newConnectionMode); } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java index 2de5a4ee21d86..0540e6ae899f0 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java @@ -33,7 +33,7 @@ import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; import io.shardingsphere.core.jdbc.core.resultset.GeneratedKeysResultSet; import io.shardingsphere.core.jdbc.core.resultset.ShardingResultSet; -import io.shardingsphere.core.jdbc.metadata.DataSourceMapTableMetaDataConnectionManager; +import io.shardingsphere.core.jdbc.metadata.JDBCTableMetaDataConnectionManager; import io.shardingsphere.core.merger.MergeEngine; import io.shardingsphere.core.merger.MergeEngineFactory; import io.shardingsphere.core.merger.MergedResult; @@ -249,7 +249,7 @@ private void refreshTableMetaData() { if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( - connection.getShardingContext().getExecutorEngine().getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); + connection.getShardingContext().getExecutorEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, connection.getShardingContext().getShardingRule())); } } @@ -299,7 +299,8 @@ public boolean apply(final BatchPreparedStatementUnit input) { preparedBatchStatement.get().getSqlExecutionUnit().getSqlUnit().getParameterSets().add(sqlExecutionUnit.getSqlUnit().getParameterSets().get(0)); return preparedBatchStatement.get(); } - BatchPreparedStatementUnit result = new BatchPreparedStatementUnit(sqlExecutionUnit, generatePreparedStatement(connection.getConnection(sqlExecutionUnit.getDataSource()), sqlExecutionUnit.getSqlUnit().getSql())); + BatchPreparedStatementUnit result = new BatchPreparedStatementUnit( + sqlExecutionUnit, generatePreparedStatement(connection.getConnection(sqlExecutionUnit.getDataSource()), sqlExecutionUnit.getSqlUnit().getSql())); batchStatementUnits.add(result); return result; } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java index 2ef24e56a55b4..f1325bf4a0681 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java @@ -29,7 +29,7 @@ import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; import io.shardingsphere.core.jdbc.core.resultset.GeneratedKeysResultSet; import io.shardingsphere.core.jdbc.core.resultset.ShardingResultSet; -import io.shardingsphere.core.jdbc.metadata.DataSourceMapTableMetaDataConnectionManager; +import io.shardingsphere.core.jdbc.metadata.JDBCTableMetaDataConnectionManager; import io.shardingsphere.core.merger.MergeEngine; import io.shardingsphere.core.merger.MergeEngineFactory; import io.shardingsphere.core.merger.MergedResult; @@ -287,7 +287,7 @@ private void refreshTableMetaData() { if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( - connection.getShardingContext().getExecutorEngine().getExecutorService(), new DataSourceMapTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); + connection.getShardingContext().getExecutorEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, connection.getShardingContext().getShardingRule())); } } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/metadata/DataSourceMapTableMetaDataConnectionManager.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/metadata/JDBCTableMetaDataConnectionManager.java similarity index 81% rename from sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/metadata/DataSourceMapTableMetaDataConnectionManager.java rename to sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/metadata/JDBCTableMetaDataConnectionManager.java index 6650d0ae2e33c..1ffaa277f5b56 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/metadata/DataSourceMapTableMetaDataConnectionManager.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/metadata/JDBCTableMetaDataConnectionManager.java @@ -26,12 +26,12 @@ import java.util.Map; /** - * Manager of connection which for table meta data loader of data source map. + * Manager of connection which for table meta data loader of JDBC. * * @author zhangliang */ @RequiredArgsConstructor -public final class DataSourceMapTableMetaDataConnectionManager implements TableMetaDataConnectionManager { +public final class JDBCTableMetaDataConnectionManager implements TableMetaDataConnectionManager { private final Map dataSourceMap; @@ -39,9 +39,4 @@ public final class DataSourceMapTableMetaDataConnectionManager implements TableM public Connection getConnection(final String dataSourceName) throws SQLException { return dataSourceMap.get(dataSourceName).getConnection(); } - - @Override - public boolean isAutoClose() { - return true; - } } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/metadata/ShardingConnectionTableMetaDataConnectionManager.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/metadata/ShardingConnectionTableMetaDataConnectionManager.java deleted file mode 100644 index 303161481967a..0000000000000 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/metadata/ShardingConnectionTableMetaDataConnectionManager.java +++ /dev/null @@ -1,48 +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.core.jdbc.metadata; - -import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; -import io.shardingsphere.core.metadata.table.executor.TableMetaDataConnectionManager; -import lombok.RequiredArgsConstructor; - -import java.sql.Connection; -import java.sql.SQLException; - -/** - * Manager of connection which for table meta data loader of sharding connection. - * - * @author zhangliang - */ -@RequiredArgsConstructor -public final class ShardingConnectionTableMetaDataConnectionManager implements TableMetaDataConnectionManager { - - private final String logicTableName; - - private final ShardingConnection shardingConnection; - - @Override - public Connection getConnection(final String dataSourceName) throws SQLException { - return shardingConnection.getConnections(logicTableName).get(dataSourceName); - } - - @Override - public boolean isAutoClose() { - return false; - } -} diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/ProxyTableMetaDataConnectionManager.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/ProxyTableMetaDataConnectionManager.java index 7fb194dc5267a..b38cf1e4182a8 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/ProxyTableMetaDataConnectionManager.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/ProxyTableMetaDataConnectionManager.java @@ -38,9 +38,4 @@ public final class ProxyTableMetaDataConnectionManager implements TableMetaDataC public Connection getConnection(final String dataSourceName) throws SQLException { return backendDataSource.getDataSource(dataSourceName).getConnection(); } - - @Override - public boolean isAutoClose() { - return true; - } } From 6651c35d5583d15ccdf2d7faa28f1f4ae0f93262 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sat, 11 Aug 2018 01:39:34 +0800 Subject: [PATCH 162/198] fix #1130 add todo for refresh table meta data by SQL parse result --- .../core/jdbc/core/statement/ShardingPreparedStatement.java | 1 + .../core/jdbc/core/statement/ShardingStatement.java | 1 + .../io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java | 1 + .../shardingsphere/proxy/backend/netty/NettyBackendHandler.java | 1 + 4 files changed, 4 insertions(+) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java index 0540e6ae899f0..b06f67f7d596e 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java @@ -245,6 +245,7 @@ private void sqlRoute() { EventBusInstance.getInstance().post(event); } + // TODO refresh table meta data by SQL parse result private void refreshTableMetaData() { if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java index f1325bf4a0681..bf6ae1efbfb57 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java @@ -283,6 +283,7 @@ private void sqlRoute(final String sql) { EventBusInstance.getInstance().post(event); } + // TODO refresh table meta data by SQL parse result private void refreshTableMetaData() { if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java index bf6b901e907a0..e41e0700ef11c 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java @@ -91,6 +91,7 @@ private CommandResponsePackets execute(final SQLRouteResult routeResult) throws executeResponse = executeEngine.execute(routeResult, isReturnGeneratedKeys); if (!RULE_REGISTRY.isMasterSlaveOnly() && SQLType.DDL == sqlStatement.getType() && !sqlStatement.getTables().isEmpty()) { String logicTableName = sqlStatement.getTables().getSingleTableName(); + // TODO refresh table meta data by SQL parse result TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( BackendExecutorContext.getInstance().getExecutorService(), new ProxyTableMetaDataConnectionManager(RULE_REGISTRY.getBackendDataSource())); RULE_REGISTRY.getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, RULE_REGISTRY.getShardingRule())); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java index 8f4c7bd76ebd5..e506e17148d94 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java @@ -201,6 +201,7 @@ private CommandResponsePackets mergeDQLorDAL(final SQLStatement sqlStatement, fi } // TODO :jiaqi use sql packet to refresh meta data + // TODO refresh table meta data by SQL parse result private void refreshTableMetaData(final String logicTableName) { TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( BackendExecutorContext.getInstance().getExecutorService(), new ProxyTableMetaDataConnectionManager(RULE_REGISTRY.getBackendDataSource())); From 526c81c9369e594341e1e5fbe7c0944bb124fe22 Mon Sep 17 00:00:00 2001 From: haocao Date: Sat, 11 Aug 2018 11:14:59 +0800 Subject: [PATCH 163/198] for #601, refactor the integrate test cases package position --- .../io/shardingsphere/dbtest/env/EnvironmentPath.java | 8 ++++---- .../resources/{asserts => integrate}/env/db/authority.xml | 0 .../resources/{asserts => integrate}/env/db/dataset.xml | 0 .../resources/{asserts => integrate}/env/db/schema.xml | 0 .../{asserts => integrate}/env/db/sharding-rule.yaml | 0 .../env/dbtbl_with_masterslave/authority.xml | 0 .../env/dbtbl_with_masterslave/dataset.xml | 0 .../env/dbtbl_with_masterslave/schema.xml | 0 .../env/dbtbl_with_masterslave/sharding-rule.yaml | 0 .../{asserts => integrate}/env/masterslave/authority.xml | 0 .../{asserts => integrate}/env/masterslave/dataset.xml | 0 .../{asserts => integrate}/env/masterslave/schema.xml | 0 .../env/masterslave/sharding-rule.yaml | 0 .../{asserts => integrate}/env/tbl/authority.xml | 0 .../resources/{asserts => integrate}/env/tbl/dataset.xml | 0 .../resources/{asserts => integrate}/env/tbl/schema.xml | 0 .../{asserts => integrate}/env/tbl/sharding-rule.yaml | 0 17 files changed, 4 insertions(+), 4 deletions(-) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/db/authority.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/db/dataset.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/db/schema.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/db/sharding-rule.yaml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/dbtbl_with_masterslave/authority.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/dbtbl_with_masterslave/dataset.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/dbtbl_with_masterslave/schema.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/dbtbl_with_masterslave/sharding-rule.yaml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/masterslave/authority.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/masterslave/dataset.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/masterslave/schema.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/masterslave/sharding-rule.yaml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/tbl/authority.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/tbl/dataset.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/tbl/schema.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/env/tbl/sharding-rule.yaml (100%) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/env/EnvironmentPath.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/env/EnvironmentPath.java index ceee66b1588c0..cb364e68f4e4e 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/env/EnvironmentPath.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/env/EnvironmentPath.java @@ -33,13 +33,13 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class EnvironmentPath { - private static final String DATABASE_ENVIRONMENT_RESOURCES_PATH = "asserts/env/%s/schema.xml"; + private static final String DATABASE_ENVIRONMENT_RESOURCES_PATH = "integrate/env/%s/schema.xml"; - private static final String DATA_INITIALIZE_RESOURCES_PATH = "asserts/env/%s/dataset.xml"; + private static final String DATA_INITIALIZE_RESOURCES_PATH = "integrate/env/%s/dataset.xml"; - private static final String SHARDING_RULE_RESOURCES_PATH = "asserts/env/%s/sharding-rule.yaml"; + private static final String SHARDING_RULE_RESOURCES_PATH = "integrate/env/%s/sharding-rule.yaml"; - private static final String AUTHORITY_RESOURCES_PATH = "asserts/env/%s/authority.xml"; + private static final String AUTHORITY_RESOURCES_PATH = "integrate/env/%s/authority.xml"; /** * Get database environment resource File. diff --git a/sharding-jdbc/src/test/resources/asserts/env/db/authority.xml b/sharding-jdbc/src/test/resources/integrate/env/db/authority.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/db/authority.xml rename to sharding-jdbc/src/test/resources/integrate/env/db/authority.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/db/dataset.xml b/sharding-jdbc/src/test/resources/integrate/env/db/dataset.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/db/dataset.xml rename to sharding-jdbc/src/test/resources/integrate/env/db/dataset.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/db/schema.xml b/sharding-jdbc/src/test/resources/integrate/env/db/schema.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/db/schema.xml rename to sharding-jdbc/src/test/resources/integrate/env/db/schema.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/db/sharding-rule.yaml b/sharding-jdbc/src/test/resources/integrate/env/db/sharding-rule.yaml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/db/sharding-rule.yaml rename to sharding-jdbc/src/test/resources/integrate/env/db/sharding-rule.yaml diff --git a/sharding-jdbc/src/test/resources/asserts/env/dbtbl_with_masterslave/authority.xml b/sharding-jdbc/src/test/resources/integrate/env/dbtbl_with_masterslave/authority.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/dbtbl_with_masterslave/authority.xml rename to sharding-jdbc/src/test/resources/integrate/env/dbtbl_with_masterslave/authority.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/dbtbl_with_masterslave/dataset.xml b/sharding-jdbc/src/test/resources/integrate/env/dbtbl_with_masterslave/dataset.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/dbtbl_with_masterslave/dataset.xml rename to sharding-jdbc/src/test/resources/integrate/env/dbtbl_with_masterslave/dataset.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/dbtbl_with_masterslave/schema.xml b/sharding-jdbc/src/test/resources/integrate/env/dbtbl_with_masterslave/schema.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/dbtbl_with_masterslave/schema.xml rename to sharding-jdbc/src/test/resources/integrate/env/dbtbl_with_masterslave/schema.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/dbtbl_with_masterslave/sharding-rule.yaml b/sharding-jdbc/src/test/resources/integrate/env/dbtbl_with_masterslave/sharding-rule.yaml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/dbtbl_with_masterslave/sharding-rule.yaml rename to sharding-jdbc/src/test/resources/integrate/env/dbtbl_with_masterslave/sharding-rule.yaml diff --git a/sharding-jdbc/src/test/resources/asserts/env/masterslave/authority.xml b/sharding-jdbc/src/test/resources/integrate/env/masterslave/authority.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/masterslave/authority.xml rename to sharding-jdbc/src/test/resources/integrate/env/masterslave/authority.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/masterslave/dataset.xml b/sharding-jdbc/src/test/resources/integrate/env/masterslave/dataset.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/masterslave/dataset.xml rename to sharding-jdbc/src/test/resources/integrate/env/masterslave/dataset.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/masterslave/schema.xml b/sharding-jdbc/src/test/resources/integrate/env/masterslave/schema.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/masterslave/schema.xml rename to sharding-jdbc/src/test/resources/integrate/env/masterslave/schema.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/masterslave/sharding-rule.yaml b/sharding-jdbc/src/test/resources/integrate/env/masterslave/sharding-rule.yaml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/masterslave/sharding-rule.yaml rename to sharding-jdbc/src/test/resources/integrate/env/masterslave/sharding-rule.yaml diff --git a/sharding-jdbc/src/test/resources/asserts/env/tbl/authority.xml b/sharding-jdbc/src/test/resources/integrate/env/tbl/authority.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/tbl/authority.xml rename to sharding-jdbc/src/test/resources/integrate/env/tbl/authority.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/tbl/dataset.xml b/sharding-jdbc/src/test/resources/integrate/env/tbl/dataset.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/tbl/dataset.xml rename to sharding-jdbc/src/test/resources/integrate/env/tbl/dataset.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/tbl/schema.xml b/sharding-jdbc/src/test/resources/integrate/env/tbl/schema.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/tbl/schema.xml rename to sharding-jdbc/src/test/resources/integrate/env/tbl/schema.xml diff --git a/sharding-jdbc/src/test/resources/asserts/env/tbl/sharding-rule.yaml b/sharding-jdbc/src/test/resources/integrate/env/tbl/sharding-rule.yaml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/env/tbl/sharding-rule.yaml rename to sharding-jdbc/src/test/resources/integrate/env/tbl/sharding-rule.yaml From fc0c22bc0978696a6a086ef1eb7040b8e688a580 Mon Sep 17 00:00:00 2001 From: haocao Date: Sat, 11 Aug 2018 11:18:21 +0800 Subject: [PATCH 164/198] for #601, removed the useless asserts package --- .../dbtest/cases/assertion/IntegrateTestCasesLoader.java | 2 +- .../cases/dcl/dcl-integrate-test-cases.xml | 0 .../{asserts => integrate}/cases/ddl/dataset/alter_table.xml | 0 .../{asserts => integrate}/cases/ddl/dataset/create_index.xml | 0 .../{asserts => integrate}/cases/ddl/dataset/create_table.xml | 0 .../cases/ddl/dataset/create_temporary_table.xml | 0 .../cases/ddl/dataset/create_unique_index.xml | 0 .../{asserts => integrate}/cases/ddl/dataset/empty_log.xml | 0 .../{asserts => integrate}/cases/ddl/dataset/empty_temp_log.xml | 0 .../cases/ddl/ddl-integrate-test-cases.xml | 0 .../cases/dml/dataset/db/batch_insert_for_order.xml | 0 .../dml/dataset/db/batch_insert_with_generate_key_column.xml | 0 .../dml/dataset/db/batch_insert_without_generate_key_column.xml | 0 .../cases/dml/dataset/db/delete_with_sharding_value.xml | 0 .../cases/dml/dataset/db/delete_without_sharding_value.xml | 0 .../cases/dml/dataset/db/insert_for_order_1.xml | 0 .../cases/dml/dataset/db/insert_for_order_2.xml | 0 .../cases/dml/dataset/db/insert_with_generate_key_column.xml | 0 .../cases/dml/dataset/db/insert_without_generate_key_column.xml | 0 .../{asserts => integrate}/cases/dml/dataset/db/update.xml | 0 .../dataset/dbtbl_with_masterslave/batch_insert_for_order.xml | 0 .../batch_insert_with_generate_key_column.xml | 0 .../batch_insert_without_generate_key_column.xml | 0 .../dbtbl_with_masterslave/delete_with_sharding_value.xml | 0 .../dbtbl_with_masterslave/delete_without_sharding_value.xml | 0 .../dml/dataset/dbtbl_with_masterslave/insert_for_order_1.xml | 0 .../dml/dataset/dbtbl_with_masterslave/insert_for_order_2.xml | 0 .../dbtbl_with_masterslave/insert_with_generate_key_column.xml | 0 .../insert_without_generate_key_column.xml | 0 .../cases/dml/dataset/dbtbl_with_masterslave/update.xml | 0 .../{asserts => integrate}/cases/dml/dataset/delete.xml | 0 .../cases/dml/dataset/masterslave/batch_insert_for_order.xml | 0 .../masterslave/batch_insert_with_generate_key_column.xml | 0 .../masterslave/batch_insert_without_generate_key_column.xml | 0 .../dml/dataset/masterslave/delete_with_sharding_value.xml | 0 .../dml/dataset/masterslave/delete_without_sharding_value.xml | 0 .../cases/dml/dataset/masterslave/insert_for_order_1.xml | 0 .../cases/dml/dataset/masterslave/insert_for_order_2.xml | 0 .../dml/dataset/masterslave/insert_with_generate_key_column.xml | 0 .../dataset/masterslave/insert_without_generate_key_column.xml | 0 .../cases/dml/dataset/masterslave/update.xml | 0 .../cases/dml/dataset/tbl/batch_insert_for_order.xml | 0 .../dml/dataset/tbl/batch_insert_with_generate_key_column.xml | 0 .../dataset/tbl/batch_insert_without_generate_key_column.xml | 0 .../cases/dml/dataset/tbl/delete_with_sharding_value.xml | 0 .../cases/dml/dataset/tbl/delete_without_sharding_value.xml | 0 .../cases/dml/dataset/tbl/insert_for_order_1.xml | 0 .../cases/dml/dataset/tbl/insert_for_order_2.xml | 0 .../cases/dml/dataset/tbl/insert_with_generate_key_column.xml | 0 .../dml/dataset/tbl/insert_without_generate_key_column.xml | 0 .../{asserts => integrate}/cases/dml/dataset/tbl/update.xml | 0 .../cases/dml/dml-integrate-test-cases.xml | 0 .../cases/dql/dataset/db/select_alias_as_keyword.xml | 0 .../{asserts => integrate}/cases/dql/dataset/db/select_avg.xml | 0 .../cases/dql/dataset/db/select_between_with_single_table.xml | 0 .../cases/dql/dataset/db/select_count.xml | 0 .../cases/dql/dataset/db/select_count_like_concat.xml | 0 .../cases/dql/dataset/db/select_count_with_binding_tables.xml | 0 .../cases/dql/dataset/db/select_count_with_sub.xml | 0 .../dql/dataset/db/select_count_with_sub_with_whitespace.xml | 0 .../cases/dql/dataset/db/select_equal_with_single_table.xml | 0 .../dql/dataset/db/select_full_route_with_binding_tables.xml | 0 .../cases/dql/dataset/db/select_group_by_with_avg.xml | 0 .../cases/dql/dataset/db/select_group_by_with_count.xml | 0 .../db/select_group_by_with_count_without_column_name.xml | 0 .../cases/dql/dataset/db/select_group_by_with_date_function.xml | 0 .../dql/dataset/db/select_group_by_with_key_word_alias.xml | 0 .../cases/dql/dataset/db/select_group_by_with_limit.xml | 0 .../cases/dql/dataset/db/select_group_by_with_max.xml | 0 .../cases/dql/dataset/db/select_group_by_with_min.xml | 0 .../dql/dataset/db/select_group_by_with_order_by_and_limit.xml | 0 .../cases/dql/dataset/db/select_group_by_with_order_by_desc.xml | 0 .../cases/dql/dataset/db/select_group_by_with_sum.xml | 0 .../dql/dataset/db/select_group_by_without_grouped_column.xml | 0 .../dql/dataset/db/select_in_with_same_sharding_column.xml | 0 .../cases/dql/dataset/db/select_in_with_single_table.xml | 0 .../cases/dql/dataset/db/select_inner_join.xml | 0 .../{asserts => integrate}/cases/dql/dataset/db/select_max.xml | 0 .../{asserts => integrate}/cases/dql/dataset/db/select_min.xml | 0 .../cases/dql/dataset/db/select_not_equal_with_single_table.xml | 0 .../cases/dql/dataset/db/select_not_in_with_single_table.xml | 0 .../dql/dataset/db/select_or_mix_and_for_complex_pattern.xml | 0 .../dql/dataset/db/select_or_mix_and_for_simple_pattern.xml | 0 .../db/select_or_mix_and_with_binding_and_broadcast_tables.xml | 0 .../dql/dataset/db/select_or_mix_and_with_binding_tables.xml | 0 .../dataset/db/select_or_with_different_sharding_columns.xml | 0 .../dql/dataset/db/select_or_with_none_sharding_columns.xml | 0 .../dql/dataset/db/select_or_with_same_sharding_columns.xml | 0 .../cases/dql/dataset/db/select_order_by_asc_and_index_desc.xml | 0 .../cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml | 0 .../dataset/db/select_order_by_with_alias_star_alias_name.xml | 0 .../cases/dql/dataset/db/select_order_by_with_date.xml | 0 .../dql/dataset/db/select_order_by_with_multiple_stars.xml | 0 .../dql/dataset/db/select_order_by_with_ordered_column.xml | 0 .../dql/dataset/db/select_order_by_with_star_no_table_alias.xml | 0 .../dql/dataset/db/select_order_by_with_star_table_alias.xml | 0 .../dataset/db/select_order_by_with_table_star_table_name.xml | 0 .../db/select_order_by_with_table_star_without_table_name.xml | 0 .../cases/dql/dataset/db/select_pagination_with_offset.xml | 0 .../dql/dataset/db/select_pagination_with_offset_and_limit.xml | 0 .../dataset/db/select_pagination_with_offset_and_row_count.xml | 0 .../cases/dql/dataset/db/select_pagination_with_row_count.xml | 0 .../dataset/db/select_pagination_with_row_number_and_limit.xml | 0 .../dql/dataset/db/select_pagination_with_top_and_limit.xml | 0 .../dataset/db/select_sharding_route_with_binding_tables.xml | 0 .../dataset/db/select_sharding_route_with_broadcast_table.xml | 0 .../cases/dql/dataset/db/select_sub_query_with_group_by.xml | 0 .../dql/dataset/db/select_sub_query_with_multiple_tables.xml | 0 .../cases/dql/dataset/db/select_sub_query_with_order_by.xml | 0 .../cases/dql/dataset/db/select_sub_query_with_single_table.xml | 0 .../{asserts => integrate}/cases/dql/dataset/db/select_sum.xml | 0 .../cases/dql/dataset/db/select_with_date_function.xml | 0 .../cases/dql/dataset/db/select_with_expression.xml | 0 .../cases/dql/dataset/db/select_with_force_index_join.xml | 0 ...select_with_item_alias_match_order_by_and_group_by_items.xml | 0 .../cases/dql/dataset/db/select_with_regexp.xml | 0 .../dataset/dbtbl_with_masterslave/select_alias_as_keyword.xml | 0 .../cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml | 0 .../dbtbl_with_masterslave/select_between_with_single_table.xml | 0 .../cases/dql/dataset/dbtbl_with_masterslave/select_count.xml | 0 .../dataset/dbtbl_with_masterslave/select_count_like_concat.xml | 0 .../dbtbl_with_masterslave/select_count_with_binding_tables.xml | 0 .../dataset/dbtbl_with_masterslave/select_count_with_sub.xml | 0 .../select_count_with_sub_with_whitespace.xml | 0 .../dbtbl_with_masterslave/select_equal_with_single_table.xml | 0 .../select_full_route_with_binding_tables.xml | 0 .../dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml | 0 .../dbtbl_with_masterslave/select_group_by_with_count.xml | 0 .../select_group_by_with_count_without_column_name.xml | 0 .../select_group_by_with_date_function.xml | 0 .../select_group_by_with_key_word_alias.xml | 0 .../dbtbl_with_masterslave/select_group_by_with_limit.xml | 0 .../dataset/dbtbl_with_masterslave/select_group_by_with_max.xml | 0 .../dataset/dbtbl_with_masterslave/select_group_by_with_min.xml | 0 .../select_group_by_with_order_by_and_limit.xml | 0 .../select_group_by_with_order_by_desc.xml | 0 .../dataset/dbtbl_with_masterslave/select_group_by_with_sum.xml | 0 .../select_group_by_without_grouped_column.xml | 0 .../select_in_with_same_sharding_column.xml | 0 .../dbtbl_with_masterslave/select_in_with_single_table.xml | 0 .../dql/dataset/dbtbl_with_masterslave/select_inner_join.xml | 0 .../cases/dql/dataset/dbtbl_with_masterslave/select_max.xml | 0 .../cases/dql/dataset/dbtbl_with_masterslave/select_min.xml | 0 .../select_not_equal_with_single_table.xml | 0 .../dbtbl_with_masterslave/select_not_in_with_single_table.xml | 0 .../select_or_mix_and_for_complex_pattern.xml | 0 .../select_or_mix_and_for_simple_pattern.xml | 0 .../select_or_mix_and_with_binding_and_broadcast_tables.xml | 0 .../select_or_mix_and_with_binding_tables.xml | 0 .../select_or_with_different_sharding_columns.xml | 0 .../select_or_with_none_sharding_columns.xml | 0 .../select_or_with_same_sharding_columns.xml | 0 .../select_order_by_asc_and_index_desc.xml | 0 .../select_order_by_desc_and_index_asc.xml | 0 .../select_order_by_with_alias_star_alias_name.xml | 0 .../dbtbl_with_masterslave/select_order_by_with_date.xml | 0 .../select_order_by_with_multiple_stars.xml | 0 .../select_order_by_with_ordered_column.xml | 0 .../select_order_by_with_star_no_table_alias.xml | 0 .../select_order_by_with_star_table_alias.xml | 0 .../select_order_by_with_table_star_table_name.xml | 0 .../select_order_by_with_table_star_without_table_name.xml | 0 .../dbtbl_with_masterslave/select_pagination_with_offset.xml | 0 .../select_pagination_with_offset_and_limit.xml | 0 .../select_pagination_with_offset_and_row_count.xml | 0 .../dbtbl_with_masterslave/select_pagination_with_row_count.xml | 0 .../select_pagination_with_row_number_and_limit.xml | 0 .../select_pagination_with_top_and_limit.xml | 0 .../select_sharding_route_with_binding_tables.xml | 0 .../select_sharding_route_with_broadcast_table.xml | 0 .../dbtbl_with_masterslave/select_sub_query_with_group_by.xml | 0 .../select_sub_query_with_multiple_tables.xml | 0 .../dbtbl_with_masterslave/select_sub_query_with_order_by.xml | 0 .../select_sub_query_with_single_table.xml | 0 .../cases/dql/dataset/dbtbl_with_masterslave/select_sum.xml | 0 .../dbtbl_with_masterslave/select_with_date_function.xml | 0 .../dataset/dbtbl_with_masterslave/select_with_expression.xml | 0 .../dbtbl_with_masterslave/select_with_force_index_join.xml | 0 ...select_with_item_alias_match_order_by_and_group_by_items.xml | 0 .../dql/dataset/dbtbl_with_masterslave/select_with_regexp.xml | 0 .../{asserts => integrate}/cases/dql/dataset/empty_order.xml | 0 .../cases/dql/dataset/empty_order_item.xml | 0 .../cases/dql/dataset/masterslave/mysql/select_avg.xml | 0 .../dql/dataset/masterslave/mysql/select_group_by_with_avg.xml | 0 .../cases/dql/dataset/masterslave/postgresql/select_avg.xml | 0 .../dataset/masterslave/postgresql/select_group_by_with_avg.xml | 0 .../cases/dql/dataset/masterslave/select_alias_as_keyword.xml | 0 .../cases/dql/dataset/masterslave/select_avg.xml | 0 .../dataset/masterslave/select_between_with_single_table.xml | 0 .../cases/dql/dataset/masterslave/select_count.xml | 0 .../cases/dql/dataset/masterslave/select_count_like_concat.xml | 0 .../dataset/masterslave/select_count_with_binding_tables.xml | 0 .../cases/dql/dataset/masterslave/select_count_with_sub.xml | 0 .../masterslave/select_count_with_sub_with_whitespace.xml | 0 .../dql/dataset/masterslave/select_equal_with_single_table.xml | 0 .../masterslave/select_full_route_with_binding_tables.xml | 0 .../cases/dql/dataset/masterslave/select_group_by_with_avg.xml | 0 .../dql/dataset/masterslave/select_group_by_with_count.xml | 0 .../select_group_by_with_count_without_column_name.xml | 0 .../dataset/masterslave/select_group_by_with_key_word_alias.xml | 0 .../dql/dataset/masterslave/select_group_by_with_limit.xml | 0 .../cases/dql/dataset/masterslave/select_group_by_with_max.xml | 0 .../cases/dql/dataset/masterslave/select_group_by_with_min.xml | 0 .../masterslave/select_group_by_with_order_by_and_limit.xml | 0 .../dataset/masterslave/select_group_by_with_order_by_desc.xml | 0 .../cases/dql/dataset/masterslave/select_group_by_with_sum.xml | 0 .../masterslave/select_group_by_without_grouped_column.xml | 0 .../dataset/masterslave/select_in_with_same_sharding_column.xml | 0 .../dql/dataset/masterslave/select_in_with_single_table.xml | 0 .../cases/dql/dataset/masterslave/select_inner_join.xml | 0 .../cases/dql/dataset/masterslave/select_max.xml | 0 .../cases/dql/dataset/masterslave/select_min.xml | 0 .../dataset/masterslave/select_not_equal_with_single_table.xml | 0 .../dql/dataset/masterslave/select_not_in_with_single_table.xml | 0 .../masterslave/select_or_mix_and_for_complex_pattern.xml | 0 .../masterslave/select_or_mix_and_for_simple_pattern.xml | 0 .../select_or_mix_and_with_binding_and_broadcast_tables.xml | 0 .../masterslave/select_or_mix_and_with_binding_tables.xml | 0 .../masterslave/select_or_with_different_sharding_columns.xml | 0 .../masterslave/select_or_with_none_sharding_columns.xml | 0 .../masterslave/select_or_with_same_sharding_columns.xml | 0 .../dataset/masterslave/select_order_by_asc_and_index_desc.xml | 0 .../dataset/masterslave/select_order_by_desc_and_index_asc.xml | 0 .../masterslave/select_order_by_with_alias_star_alias_name.xml | 0 .../cases/dql/dataset/masterslave/select_order_by_with_date.xml | 0 .../dataset/masterslave/select_order_by_with_multiple_stars.xml | 0 .../dataset/masterslave/select_order_by_with_ordered_column.xml | 0 .../masterslave/select_order_by_with_star_no_table_alias.xml | 0 .../masterslave/select_order_by_with_star_table_alias.xml | 0 .../masterslave/select_order_by_with_table_star_table_name.xml | 0 .../select_order_by_with_table_star_without_table_name.xml | 0 .../dql/dataset/masterslave/select_pagination_with_offset.xml | 0 .../masterslave/select_pagination_with_offset_and_limit.xml | 0 .../masterslave/select_pagination_with_offset_and_row_count.xml | 0 .../dataset/masterslave/select_pagination_with_row_count.xml | 0 .../masterslave/select_pagination_with_row_number_and_limit.xml | 0 .../masterslave/select_pagination_with_top_and_limit.xml | 0 .../masterslave/select_sharding_route_with_binding_tables.xml | 0 .../masterslave/select_sharding_route_with_broadcast_table.xml | 0 .../dql/dataset/masterslave/select_sub_query_with_group_by.xml | 0 .../masterslave/select_sub_query_with_multiple_tables.xml | 0 .../dql/dataset/masterslave/select_sub_query_with_order_by.xml | 0 .../dataset/masterslave/select_sub_query_with_single_table.xml | 0 .../cases/dql/dataset/masterslave/select_sum.xml | 0 .../cases/dql/dataset/masterslave/select_with_date_function.xml | 0 .../cases/dql/dataset/masterslave/select_with_expression.xml | 0 .../dql/dataset/masterslave/select_with_force_index_join.xml | 0 ...select_with_item_alias_match_order_by_and_group_by_items.xml | 0 .../cases/dql/dataset/masterslave/select_with_regexp.xml | 0 .../cases/dql/dataset/select_constant_without_table.xml | 0 .../cases/dql/dataset/tbl/select_alias_as_keyword.xml | 0 .../{asserts => integrate}/cases/dql/dataset/tbl/select_avg.xml | 0 .../cases/dql/dataset/tbl/select_between_with_single_table.xml | 0 .../cases/dql/dataset/tbl/select_count.xml | 0 .../cases/dql/dataset/tbl/select_count_like_concat.xml | 0 .../cases/dql/dataset/tbl/select_count_with_binding_tables.xml | 0 .../cases/dql/dataset/tbl/select_count_with_sub.xml | 0 .../dql/dataset/tbl/select_count_with_sub_with_whitespace.xml | 0 .../cases/dql/dataset/tbl/select_equal_with_single_table.xml | 0 .../dql/dataset/tbl/select_full_route_with_binding_tables.xml | 0 .../cases/dql/dataset/tbl/select_group_by_with_avg.xml | 0 .../cases/dql/dataset/tbl/select_group_by_with_count.xml | 0 .../tbl/select_group_by_with_count_without_column_name.xml | 0 .../dql/dataset/tbl/select_group_by_with_date_function.xml | 0 .../dql/dataset/tbl/select_group_by_with_key_word_alias.xml | 0 .../cases/dql/dataset/tbl/select_group_by_with_limit.xml | 0 .../cases/dql/dataset/tbl/select_group_by_with_max.xml | 0 .../cases/dql/dataset/tbl/select_group_by_with_min.xml | 0 .../dql/dataset/tbl/select_group_by_with_order_by_and_limit.xml | 0 .../dql/dataset/tbl/select_group_by_with_order_by_desc.xml | 0 .../cases/dql/dataset/tbl/select_group_by_with_sum.xml | 0 .../dql/dataset/tbl/select_group_by_without_grouped_column.xml | 0 .../dql/dataset/tbl/select_in_with_same_sharding_column.xml | 0 .../cases/dql/dataset/tbl/select_in_with_single_table.xml | 0 .../cases/dql/dataset/tbl/select_inner_join.xml | 0 .../{asserts => integrate}/cases/dql/dataset/tbl/select_max.xml | 0 .../{asserts => integrate}/cases/dql/dataset/tbl/select_min.xml | 0 .../dql/dataset/tbl/select_not_equal_with_single_table.xml | 0 .../cases/dql/dataset/tbl/select_not_in_with_single_table.xml | 0 .../dql/dataset/tbl/select_or_mix_and_for_complex_pattern.xml | 0 .../dql/dataset/tbl/select_or_mix_and_for_simple_pattern.xml | 0 .../tbl/select_or_mix_and_with_binding_and_broadcast_tables.xml | 0 .../dql/dataset/tbl/select_or_mix_and_with_binding_tables.xml | 0 .../dataset/tbl/select_or_with_different_sharding_columns.xml | 0 .../dql/dataset/tbl/select_or_with_none_sharding_columns.xml | 0 .../dql/dataset/tbl/select_or_with_same_sharding_columns.xml | 0 .../dql/dataset/tbl/select_order_by_asc_and_index_desc.xml | 0 .../dql/dataset/tbl/select_order_by_desc_and_index_asc.xml | 0 .../dataset/tbl/select_order_by_with_alias_star_alias_name.xml | 0 .../cases/dql/dataset/tbl/select_order_by_with_date.xml | 0 .../dql/dataset/tbl/select_order_by_with_multiple_stars.xml | 0 .../dql/dataset/tbl/select_order_by_with_ordered_column.xml | 0 .../dataset/tbl/select_order_by_with_star_no_table_alias.xml | 0 .../dql/dataset/tbl/select_order_by_with_star_table_alias.xml | 0 .../dataset/tbl/select_order_by_with_table_star_table_name.xml | 0 .../tbl/select_order_by_with_table_star_without_table_name.xml | 0 .../cases/dql/dataset/tbl/select_pagination_with_offset.xml | 0 .../dql/dataset/tbl/select_pagination_with_offset_and_limit.xml | 0 .../dataset/tbl/select_pagination_with_offset_and_row_count.xml | 0 .../cases/dql/dataset/tbl/select_pagination_with_row_count.xml | 0 .../dataset/tbl/select_pagination_with_row_number_and_limit.xml | 0 .../dql/dataset/tbl/select_pagination_with_top_and_limit.xml | 0 .../dataset/tbl/select_sharding_route_with_binding_tables.xml | 0 .../dataset/tbl/select_sharding_route_with_broadcast_table.xml | 0 .../cases/dql/dataset/tbl/select_sub_query_with_group_by.xml | 0 .../dql/dataset/tbl/select_sub_query_with_multiple_tables.xml | 0 .../cases/dql/dataset/tbl/select_sub_query_with_order_by.xml | 0 .../dql/dataset/tbl/select_sub_query_with_single_table.xml | 0 .../{asserts => integrate}/cases/dql/dataset/tbl/select_sum.xml | 0 .../cases/dql/dataset/tbl/select_with_date_function.xml | 0 .../cases/dql/dataset/tbl/select_with_expression.xml | 0 .../cases/dql/dataset/tbl/select_with_force_index_join.xml | 0 ...select_with_item_alias_match_order_by_and_group_by_items.xml | 0 .../cases/dql/dataset/tbl/select_with_regexp.xml | 0 .../cases/dql/dql-integrate-test-cases.xml | 0 315 files changed, 1 insertion(+), 1 deletion(-) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dcl/dcl-integrate-test-cases.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/ddl/dataset/alter_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/ddl/dataset/create_index.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/ddl/dataset/create_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/ddl/dataset/create_temporary_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/ddl/dataset/create_unique_index.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/ddl/dataset/empty_log.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/ddl/dataset/empty_temp_log.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/ddl/ddl-integrate-test-cases.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/db/batch_insert_for_order.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/db/batch_insert_with_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/db/batch_insert_without_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/db/delete_with_sharding_value.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/db/delete_without_sharding_value.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/db/insert_for_order_1.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/db/insert_for_order_2.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/db/insert_with_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/db/insert_without_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/db/update.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_for_order.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_with_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_without_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/dbtbl_with_masterslave/delete_with_sharding_value.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/dbtbl_with_masterslave/delete_without_sharding_value.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/dbtbl_with_masterslave/insert_for_order_1.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/dbtbl_with_masterslave/insert_for_order_2.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/dbtbl_with_masterslave/insert_with_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/dbtbl_with_masterslave/insert_without_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/dbtbl_with_masterslave/update.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/delete.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/masterslave/batch_insert_for_order.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/masterslave/batch_insert_with_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/masterslave/batch_insert_without_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/masterslave/delete_with_sharding_value.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/masterslave/delete_without_sharding_value.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/masterslave/insert_for_order_1.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/masterslave/insert_for_order_2.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/masterslave/insert_with_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/masterslave/insert_without_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/masterslave/update.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/tbl/batch_insert_for_order.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/tbl/batch_insert_with_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/tbl/batch_insert_without_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/tbl/delete_with_sharding_value.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/tbl/delete_without_sharding_value.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/tbl/insert_for_order_1.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/tbl/insert_for_order_2.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/tbl/insert_with_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/tbl/insert_without_generate_key_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dataset/tbl/update.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dml/dml-integrate-test-cases.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_alias_as_keyword.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_between_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_count_like_concat.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_count_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_count_with_sub.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_count_with_sub_with_whitespace.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_equal_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_full_route_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_with_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_with_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_with_count_without_column_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_with_date_function.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_with_key_word_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_with_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_with_max.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_with_min.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_with_order_by_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_with_order_by_desc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_with_sum.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_group_by_without_grouped_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_in_with_same_sharding_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_in_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_inner_join.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_max.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_min.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_not_equal_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_not_in_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_or_mix_and_for_complex_pattern.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_or_mix_and_for_simple_pattern.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_or_mix_and_with_binding_and_broadcast_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_or_mix_and_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_or_with_different_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_or_with_none_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_or_with_same_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_order_by_asc_and_index_desc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_order_by_with_alias_star_alias_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_order_by_with_date.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_order_by_with_multiple_stars.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_order_by_with_ordered_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_order_by_with_star_no_table_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_order_by_with_star_table_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_order_by_with_table_star_table_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_order_by_with_table_star_without_table_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_pagination_with_offset.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_pagination_with_offset_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_pagination_with_offset_and_row_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_pagination_with_row_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_pagination_with_row_number_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_pagination_with_top_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_sharding_route_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_sharding_route_with_broadcast_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_sub_query_with_group_by.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_sub_query_with_multiple_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_sub_query_with_order_by.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_sub_query_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_sum.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_with_date_function.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_with_expression.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_with_force_index_join.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_with_item_alias_match_order_by_and_group_by_items.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/db/select_with_regexp.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_alias_as_keyword.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_between_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_count_like_concat.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_sub.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_sub_with_whitespace.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_equal_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_full_route_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_count_without_column_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_date_function.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_key_word_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_max.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_min.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_order_by_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_order_by_desc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_sum.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_without_grouped_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_in_with_same_sharding_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_in_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_inner_join.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_max.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_min.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_not_equal_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_not_in_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_for_complex_pattern.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_for_simple_pattern.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_with_binding_and_broadcast_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_different_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_none_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_same_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_asc_and_index_desc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_desc_and_index_asc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_alias_star_alias_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_date.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_multiple_stars.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_ordered_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_star_no_table_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_star_table_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_table_star_table_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_table_star_without_table_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset_and_row_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_top_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_sharding_route_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_sharding_route_with_broadcast_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_group_by.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_multiple_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_order_by.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_sum.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_with_date_function.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_with_expression.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_with_force_index_join.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_with_item_alias_match_order_by_and_group_by_items.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/dbtbl_with_masterslave/select_with_regexp.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/empty_order.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/empty_order_item.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/mysql/select_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/mysql/select_group_by_with_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/postgresql/select_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/postgresql/select_group_by_with_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_alias_as_keyword.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_between_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_count_like_concat.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_count_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_count_with_sub.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_count_with_sub_with_whitespace.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_equal_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_full_route_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_group_by_with_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_group_by_with_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_group_by_with_count_without_column_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_group_by_with_key_word_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_group_by_with_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_group_by_with_max.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_group_by_with_min.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_group_by_with_order_by_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_group_by_with_order_by_desc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_group_by_with_sum.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_group_by_without_grouped_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_in_with_same_sharding_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_in_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_inner_join.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_max.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_min.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_not_equal_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_not_in_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_or_mix_and_for_complex_pattern.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_or_mix_and_for_simple_pattern.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_or_mix_and_with_binding_and_broadcast_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_or_mix_and_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_or_with_different_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_or_with_none_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_or_with_same_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_order_by_asc_and_index_desc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_order_by_desc_and_index_asc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_order_by_with_alias_star_alias_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_order_by_with_date.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_order_by_with_multiple_stars.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_order_by_with_ordered_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_order_by_with_star_no_table_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_order_by_with_star_table_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_order_by_with_table_star_table_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_order_by_with_table_star_without_table_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_pagination_with_offset.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_pagination_with_offset_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_pagination_with_offset_and_row_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_pagination_with_row_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_pagination_with_row_number_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_pagination_with_top_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_sharding_route_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_sharding_route_with_broadcast_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_sub_query_with_group_by.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_sub_query_with_multiple_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_sub_query_with_order_by.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_sub_query_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_sum.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_with_date_function.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_with_expression.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_with_force_index_join.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_with_item_alias_match_order_by_and_group_by_items.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/masterslave/select_with_regexp.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/select_constant_without_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_alias_as_keyword.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_between_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_count_like_concat.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_count_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_count_with_sub.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_count_with_sub_with_whitespace.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_equal_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_full_route_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_with_avg.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_with_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_with_count_without_column_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_with_date_function.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_with_key_word_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_with_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_with_max.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_with_min.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_with_order_by_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_with_order_by_desc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_with_sum.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_group_by_without_grouped_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_in_with_same_sharding_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_in_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_inner_join.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_max.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_min.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_not_equal_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_not_in_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_or_mix_and_for_complex_pattern.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_or_mix_and_for_simple_pattern.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_or_mix_and_with_binding_and_broadcast_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_or_mix_and_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_or_with_different_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_or_with_none_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_or_with_same_sharding_columns.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_order_by_asc_and_index_desc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_order_by_desc_and_index_asc.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_order_by_with_alias_star_alias_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_order_by_with_date.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_order_by_with_multiple_stars.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_order_by_with_ordered_column.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_order_by_with_star_no_table_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_order_by_with_star_table_alias.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_order_by_with_table_star_table_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_order_by_with_table_star_without_table_name.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_pagination_with_offset.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_pagination_with_offset_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_pagination_with_offset_and_row_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_pagination_with_row_count.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_pagination_with_row_number_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_pagination_with_top_and_limit.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_sharding_route_with_binding_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_sharding_route_with_broadcast_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_sub_query_with_group_by.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_sub_query_with_multiple_tables.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_sub_query_with_order_by.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_sub_query_with_single_table.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_sum.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_with_date_function.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_with_expression.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_with_force_index_join.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_with_item_alias_match_order_by_and_group_by_items.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dataset/tbl/select_with_regexp.xml (100%) rename sharding-jdbc/src/test/resources/{asserts => integrate}/cases/dql/dql-integrate-test-cases.xml (100%) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/cases/assertion/IntegrateTestCasesLoader.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/cases/assertion/IntegrateTestCasesLoader.java index dda7ee54356fb..9c0f94b4cee43 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/cases/assertion/IntegrateTestCasesLoader.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/cases/assertion/IntegrateTestCasesLoader.java @@ -95,7 +95,7 @@ public static IntegrateTestCasesLoader getInstance() { } private Map loadIntegrateTestCases(final String filePrefix) throws IOException, URISyntaxException, JAXBException { - URL url = IntegrateTestCasesLoader.class.getClassLoader().getResource("asserts/cases/"); + URL url = IntegrateTestCasesLoader.class.getClassLoader().getResource("integrate/cases/"); Preconditions.checkNotNull(url, "Cannot found integrate test cases."); return new HashMap<>(loadIntegrateTestCases(url, filePrefix)); } diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dcl/dcl-integrate-test-cases.xml b/sharding-jdbc/src/test/resources/integrate/cases/dcl/dcl-integrate-test-cases.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dcl/dcl-integrate-test-cases.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dcl/dcl-integrate-test-cases.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/alter_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/alter_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/alter_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/alter_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/create_index.xml b/sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/create_index.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/create_index.xml rename to sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/create_index.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/create_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/create_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/create_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/create_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/create_temporary_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/create_temporary_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/create_temporary_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/create_temporary_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/create_unique_index.xml b/sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/create_unique_index.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/create_unique_index.xml rename to sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/create_unique_index.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/empty_log.xml b/sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/empty_log.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/empty_log.xml rename to sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/empty_log.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/empty_temp_log.xml b/sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/empty_temp_log.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/ddl/dataset/empty_temp_log.xml rename to sharding-jdbc/src/test/resources/integrate/cases/ddl/dataset/empty_temp_log.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/ddl/ddl-integrate-test-cases.xml b/sharding-jdbc/src/test/resources/integrate/cases/ddl/ddl-integrate-test-cases.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/ddl/ddl-integrate-test-cases.xml rename to sharding-jdbc/src/test/resources/integrate/cases/ddl/ddl-integrate-test-cases.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/batch_insert_for_order.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/batch_insert_for_order.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/batch_insert_for_order.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/batch_insert_for_order.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/batch_insert_with_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/batch_insert_with_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/batch_insert_with_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/batch_insert_with_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/batch_insert_without_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/batch_insert_without_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/batch_insert_without_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/batch_insert_without_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/delete_with_sharding_value.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/delete_with_sharding_value.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/delete_with_sharding_value.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/delete_with_sharding_value.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/delete_without_sharding_value.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/delete_without_sharding_value.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/delete_without_sharding_value.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/delete_without_sharding_value.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/insert_for_order_1.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/insert_for_order_1.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/insert_for_order_1.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/insert_for_order_1.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/insert_for_order_2.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/insert_for_order_2.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/insert_for_order_2.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/insert_for_order_2.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/insert_with_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/insert_with_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/insert_with_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/insert_with_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/insert_without_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/insert_without_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/insert_without_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/insert_without_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/update.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/update.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/db/update.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/db/update.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_for_order.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_for_order.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_for_order.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_for_order.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_with_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_with_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_with_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_with_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_without_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_without_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_without_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/batch_insert_without_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/delete_with_sharding_value.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/delete_with_sharding_value.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/delete_with_sharding_value.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/delete_with_sharding_value.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/delete_without_sharding_value.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/delete_without_sharding_value.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/delete_without_sharding_value.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/delete_without_sharding_value.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/insert_for_order_1.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_for_order_1.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/insert_for_order_1.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_for_order_1.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/insert_for_order_2.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_for_order_2.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/insert_for_order_2.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_for_order_2.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/insert_with_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_with_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/insert_with_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_with_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/insert_without_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_without_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/insert_without_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/insert_without_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/update.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/update.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/dbtbl_with_masterslave/update.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/dbtbl_with_masterslave/update.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/delete.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/delete.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/delete.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/delete.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/batch_insert_for_order.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/batch_insert_for_order.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/batch_insert_for_order.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/batch_insert_for_order.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/batch_insert_with_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/batch_insert_with_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/batch_insert_with_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/batch_insert_with_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/batch_insert_without_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/batch_insert_without_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/batch_insert_without_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/batch_insert_without_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/delete_with_sharding_value.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/delete_with_sharding_value.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/delete_with_sharding_value.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/delete_with_sharding_value.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/delete_without_sharding_value.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/delete_without_sharding_value.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/delete_without_sharding_value.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/delete_without_sharding_value.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/insert_for_order_1.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/insert_for_order_1.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/insert_for_order_1.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/insert_for_order_1.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/insert_for_order_2.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/insert_for_order_2.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/insert_for_order_2.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/insert_for_order_2.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/insert_with_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/insert_with_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/insert_with_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/insert_with_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/insert_without_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/insert_without_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/insert_without_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/insert_without_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/update.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/update.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/masterslave/update.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/masterslave/update.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/batch_insert_for_order.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/batch_insert_for_order.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/batch_insert_for_order.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/batch_insert_for_order.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/batch_insert_with_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/batch_insert_with_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/batch_insert_with_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/batch_insert_with_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/batch_insert_without_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/batch_insert_without_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/batch_insert_without_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/batch_insert_without_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/delete_with_sharding_value.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/delete_with_sharding_value.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/delete_with_sharding_value.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/delete_with_sharding_value.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/delete_without_sharding_value.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/delete_without_sharding_value.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/delete_without_sharding_value.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/delete_without_sharding_value.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/insert_for_order_1.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/insert_for_order_1.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/insert_for_order_1.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/insert_for_order_1.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/insert_for_order_2.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/insert_for_order_2.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/insert_for_order_2.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/insert_for_order_2.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/insert_with_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/insert_with_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/insert_with_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/insert_with_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/insert_without_generate_key_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/insert_without_generate_key_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/insert_without_generate_key_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/insert_without_generate_key_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/update.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/update.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dataset/tbl/update.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dataset/tbl/update.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dml/dml-integrate-test-cases.xml b/sharding-jdbc/src/test/resources/integrate/cases/dml/dml-integrate-test-cases.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dml/dml-integrate-test-cases.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dml/dml-integrate-test-cases.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_alias_as_keyword.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_alias_as_keyword.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_alias_as_keyword.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_alias_as_keyword.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_between_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_between_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_between_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_between_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_count_like_concat.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_count_like_concat.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_count_like_concat.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_count_like_concat.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_count_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_count_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_count_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_count_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_count_with_sub.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_count_with_sub.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_count_with_sub.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_count_with_sub.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_count_with_sub_with_whitespace.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_count_with_sub_with_whitespace.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_count_with_sub_with_whitespace.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_count_with_sub_with_whitespace.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_equal_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_equal_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_equal_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_equal_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_full_route_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_full_route_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_full_route_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_full_route_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_count_without_column_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_count_without_column_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_count_without_column_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_count_without_column_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_date_function.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_date_function.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_date_function.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_date_function.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_key_word_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_key_word_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_key_word_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_key_word_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_max.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_max.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_max.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_max.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_min.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_min.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_min.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_min.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_order_by_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_order_by_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_order_by_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_order_by_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_order_by_desc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_order_by_desc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_order_by_desc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_order_by_desc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_sum.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_sum.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_sum.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_with_sum.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_without_grouped_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_without_grouped_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_without_grouped_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_group_by_without_grouped_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_in_with_same_sharding_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_in_with_same_sharding_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_in_with_same_sharding_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_in_with_same_sharding_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_in_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_in_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_in_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_in_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_inner_join.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_inner_join.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_inner_join.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_inner_join.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_max.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_max.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_max.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_max.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_min.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_min.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_min.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_min.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_not_equal_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_not_equal_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_not_equal_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_not_equal_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_not_in_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_not_in_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_not_in_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_not_in_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_mix_and_for_complex_pattern.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_mix_and_for_complex_pattern.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_mix_and_for_complex_pattern.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_mix_and_for_complex_pattern.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_mix_and_for_simple_pattern.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_mix_and_for_simple_pattern.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_mix_and_for_simple_pattern.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_mix_and_for_simple_pattern.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_mix_and_with_binding_and_broadcast_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_mix_and_with_binding_and_broadcast_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_mix_and_with_binding_and_broadcast_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_mix_and_with_binding_and_broadcast_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_mix_and_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_mix_and_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_mix_and_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_mix_and_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_with_different_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_with_different_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_with_different_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_with_different_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_with_none_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_with_none_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_with_none_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_with_none_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_with_same_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_with_same_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_or_with_same_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_or_with_same_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_asc_and_index_desc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_asc_and_index_desc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_asc_and_index_desc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_asc_and_index_desc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_alias_star_alias_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_alias_star_alias_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_alias_star_alias_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_alias_star_alias_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_date.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_date.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_date.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_date.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_multiple_stars.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_multiple_stars.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_multiple_stars.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_multiple_stars.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_ordered_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_ordered_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_ordered_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_ordered_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_star_no_table_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_star_no_table_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_star_no_table_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_star_no_table_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_star_table_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_star_table_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_star_table_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_star_table_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_table_star_table_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_table_star_table_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_table_star_table_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_table_star_table_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_table_star_without_table_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_table_star_without_table_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_table_star_without_table_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_table_star_without_table_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_offset.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_offset.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_offset.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_offset.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_offset_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_offset_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_offset_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_offset_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_offset_and_row_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_offset_and_row_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_offset_and_row_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_offset_and_row_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_row_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_row_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_row_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_row_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_row_number_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_row_number_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_row_number_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_row_number_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_top_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_top_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_pagination_with_top_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_pagination_with_top_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sharding_route_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sharding_route_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sharding_route_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sharding_route_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sharding_route_with_broadcast_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sharding_route_with_broadcast_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sharding_route_with_broadcast_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sharding_route_with_broadcast_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sub_query_with_group_by.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sub_query_with_group_by.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sub_query_with_group_by.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sub_query_with_group_by.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sub_query_with_multiple_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sub_query_with_multiple_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sub_query_with_multiple_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sub_query_with_multiple_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sub_query_with_order_by.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sub_query_with_order_by.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sub_query_with_order_by.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sub_query_with_order_by.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sub_query_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sub_query_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sub_query_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sub_query_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sum.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sum.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_sum.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_sum.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_date_function.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_with_date_function.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_date_function.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_with_date_function.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_expression.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_with_expression.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_expression.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_with_expression.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_force_index_join.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_with_force_index_join.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_force_index_join.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_with_force_index_join.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_item_alias_match_order_by_and_group_by_items.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_with_item_alias_match_order_by_and_group_by_items.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_item_alias_match_order_by_and_group_by_items.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_with_item_alias_match_order_by_and_group_by_items.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_regexp.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_with_regexp.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_regexp.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_with_regexp.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_alias_as_keyword.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_alias_as_keyword.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_alias_as_keyword.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_alias_as_keyword.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_between_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_between_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_between_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_between_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_count_like_concat.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_count_like_concat.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_count_like_concat.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_count_like_concat.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_sub.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_sub.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_sub.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_sub.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_sub_with_whitespace.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_sub_with_whitespace.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_sub_with_whitespace.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_count_with_sub_with_whitespace.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_equal_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_equal_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_equal_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_equal_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_full_route_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_full_route_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_full_route_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_full_route_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_count_without_column_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_count_without_column_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_count_without_column_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_count_without_column_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_date_function.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_date_function.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_date_function.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_date_function.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_key_word_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_key_word_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_key_word_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_key_word_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_max.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_max.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_max.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_max.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_min.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_min.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_min.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_min.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_order_by_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_order_by_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_order_by_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_order_by_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_order_by_desc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_order_by_desc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_order_by_desc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_order_by_desc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_sum.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_sum.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_sum.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_sum.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_without_grouped_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_without_grouped_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_without_grouped_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_without_grouped_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_in_with_same_sharding_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_in_with_same_sharding_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_in_with_same_sharding_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_in_with_same_sharding_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_in_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_in_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_in_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_in_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_inner_join.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_inner_join.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_inner_join.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_inner_join.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_max.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_max.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_max.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_max.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_min.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_min.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_min.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_min.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_not_equal_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_not_equal_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_not_equal_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_not_equal_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_not_in_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_not_in_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_not_in_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_not_in_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_for_complex_pattern.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_for_complex_pattern.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_for_complex_pattern.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_for_complex_pattern.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_for_simple_pattern.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_for_simple_pattern.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_for_simple_pattern.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_for_simple_pattern.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_with_binding_and_broadcast_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_with_binding_and_broadcast_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_with_binding_and_broadcast_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_with_binding_and_broadcast_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_mix_and_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_different_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_different_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_different_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_different_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_none_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_none_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_none_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_none_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_same_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_same_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_same_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_or_with_same_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_asc_and_index_desc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_asc_and_index_desc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_asc_and_index_desc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_asc_and_index_desc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_desc_and_index_asc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_desc_and_index_asc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_desc_and_index_asc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_desc_and_index_asc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_alias_star_alias_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_alias_star_alias_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_alias_star_alias_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_alias_star_alias_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_date.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_date.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_date.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_date.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_multiple_stars.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_multiple_stars.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_multiple_stars.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_multiple_stars.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_ordered_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_ordered_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_ordered_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_ordered_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_star_no_table_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_star_no_table_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_star_no_table_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_star_no_table_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_star_table_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_star_table_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_star_table_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_star_table_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_table_star_table_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_table_star_table_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_table_star_table_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_table_star_table_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_table_star_without_table_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_table_star_without_table_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_table_star_without_table_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_order_by_with_table_star_without_table_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset_and_row_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset_and_row_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset_and_row_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_offset_and_row_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_top_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_top_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_top_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_top_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sharding_route_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sharding_route_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sharding_route_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sharding_route_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sharding_route_with_broadcast_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sharding_route_with_broadcast_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sharding_route_with_broadcast_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sharding_route_with_broadcast_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_group_by.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_group_by.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_group_by.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_group_by.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_multiple_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_multiple_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_multiple_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_multiple_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_order_by.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_order_by.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_order_by.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_order_by.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sub_query_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sum.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sum.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_sum.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_sum.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_date_function.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_with_date_function.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_date_function.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_with_date_function.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_expression.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_with_expression.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_expression.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_with_expression.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_force_index_join.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_with_force_index_join.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_force_index_join.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_with_force_index_join.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_item_alias_match_order_by_and_group_by_items.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_with_item_alias_match_order_by_and_group_by_items.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_item_alias_match_order_by_and_group_by_items.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_with_item_alias_match_order_by_and_group_by_items.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_regexp.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_with_regexp.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_regexp.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_with_regexp.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/empty_order.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/empty_order.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/empty_order.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/empty_order.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/empty_order_item.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/empty_order_item.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/empty_order_item.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/empty_order_item.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/mysql/select_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/mysql/select_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/mysql/select_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/mysql/select_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/mysql/select_group_by_with_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/mysql/select_group_by_with_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/mysql/select_group_by_with_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/mysql/select_group_by_with_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/postgresql/select_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/postgresql/select_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/postgresql/select_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/postgresql/select_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/postgresql/select_group_by_with_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/postgresql/select_group_by_with_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/postgresql/select_group_by_with_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/postgresql/select_group_by_with_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_alias_as_keyword.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_alias_as_keyword.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_alias_as_keyword.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_alias_as_keyword.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_between_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_between_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_between_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_between_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_count_like_concat.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_count_like_concat.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_count_like_concat.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_count_like_concat.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_count_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_count_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_count_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_count_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_count_with_sub.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_count_with_sub.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_count_with_sub.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_count_with_sub.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_count_with_sub_with_whitespace.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_count_with_sub_with_whitespace.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_count_with_sub_with_whitespace.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_count_with_sub_with_whitespace.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_equal_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_equal_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_equal_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_equal_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_full_route_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_full_route_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_full_route_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_full_route_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_count_without_column_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_count_without_column_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_count_without_column_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_count_without_column_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_key_word_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_key_word_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_key_word_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_key_word_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_max.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_max.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_max.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_max.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_min.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_min.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_min.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_min.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_order_by_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_order_by_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_order_by_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_order_by_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_order_by_desc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_order_by_desc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_order_by_desc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_order_by_desc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_sum.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_sum.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_with_sum.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_with_sum.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_without_grouped_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_without_grouped_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_group_by_without_grouped_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_without_grouped_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_in_with_same_sharding_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_in_with_same_sharding_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_in_with_same_sharding_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_in_with_same_sharding_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_in_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_in_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_in_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_in_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_inner_join.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_inner_join.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_inner_join.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_inner_join.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_max.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_max.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_max.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_max.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_min.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_min.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_min.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_min.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_not_equal_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_not_equal_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_not_equal_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_not_equal_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_not_in_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_not_in_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_not_in_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_not_in_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_mix_and_for_complex_pattern.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_mix_and_for_complex_pattern.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_mix_and_for_complex_pattern.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_mix_and_for_complex_pattern.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_mix_and_for_simple_pattern.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_mix_and_for_simple_pattern.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_mix_and_for_simple_pattern.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_mix_and_for_simple_pattern.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_mix_and_with_binding_and_broadcast_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_mix_and_with_binding_and_broadcast_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_mix_and_with_binding_and_broadcast_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_mix_and_with_binding_and_broadcast_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_mix_and_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_mix_and_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_mix_and_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_mix_and_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_with_different_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_with_different_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_with_different_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_with_different_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_with_none_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_with_none_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_with_none_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_with_none_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_with_same_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_with_same_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_or_with_same_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_or_with_same_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_asc_and_index_desc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_asc_and_index_desc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_asc_and_index_desc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_asc_and_index_desc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_desc_and_index_asc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_desc_and_index_asc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_desc_and_index_asc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_desc_and_index_asc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_alias_star_alias_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_alias_star_alias_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_alias_star_alias_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_alias_star_alias_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_date.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_date.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_date.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_date.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_multiple_stars.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_multiple_stars.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_multiple_stars.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_multiple_stars.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_ordered_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_ordered_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_ordered_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_ordered_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_star_no_table_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_star_no_table_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_star_no_table_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_star_no_table_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_star_table_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_star_table_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_star_table_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_star_table_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_table_star_table_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_table_star_table_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_table_star_table_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_table_star_table_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_table_star_without_table_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_table_star_without_table_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_order_by_with_table_star_without_table_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_order_by_with_table_star_without_table_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_offset.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_offset.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_offset.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_offset.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_offset_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_offset_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_offset_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_offset_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_offset_and_row_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_offset_and_row_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_offset_and_row_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_offset_and_row_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_row_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_row_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_row_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_row_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_row_number_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_row_number_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_row_number_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_row_number_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_top_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_top_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_pagination_with_top_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_pagination_with_top_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sharding_route_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sharding_route_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sharding_route_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sharding_route_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sharding_route_with_broadcast_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sharding_route_with_broadcast_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sharding_route_with_broadcast_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sharding_route_with_broadcast_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sub_query_with_group_by.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sub_query_with_group_by.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sub_query_with_group_by.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sub_query_with_group_by.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sub_query_with_multiple_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sub_query_with_multiple_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sub_query_with_multiple_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sub_query_with_multiple_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sub_query_with_order_by.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sub_query_with_order_by.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sub_query_with_order_by.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sub_query_with_order_by.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sub_query_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sub_query_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sub_query_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sub_query_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sum.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sum.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_sum.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sum.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_with_date_function.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_date_function.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_with_date_function.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_date_function.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_with_expression.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_expression.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_with_expression.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_expression.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_with_force_index_join.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_force_index_join.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_with_force_index_join.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_force_index_join.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_with_item_alias_match_order_by_and_group_by_items.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_item_alias_match_order_by_and_group_by_items.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_with_item_alias_match_order_by_and_group_by_items.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_item_alias_match_order_by_and_group_by_items.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_with_regexp.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_regexp.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/masterslave/select_with_regexp.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_regexp.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/select_constant_without_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/select_constant_without_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/select_constant_without_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/select_constant_without_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_alias_as_keyword.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_alias_as_keyword.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_alias_as_keyword.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_alias_as_keyword.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_between_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_between_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_between_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_between_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_count_like_concat.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_count_like_concat.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_count_like_concat.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_count_like_concat.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_count_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_count_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_count_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_count_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_count_with_sub.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_count_with_sub.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_count_with_sub.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_count_with_sub.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_count_with_sub_with_whitespace.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_count_with_sub_with_whitespace.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_count_with_sub_with_whitespace.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_count_with_sub_with_whitespace.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_equal_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_equal_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_equal_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_equal_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_full_route_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_full_route_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_full_route_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_full_route_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_avg.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_avg.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_avg.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_count_without_column_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_count_without_column_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_count_without_column_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_count_without_column_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_date_function.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_date_function.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_date_function.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_date_function.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_key_word_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_key_word_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_key_word_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_key_word_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_max.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_max.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_max.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_max.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_min.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_min.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_min.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_min.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_order_by_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_order_by_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_order_by_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_order_by_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_order_by_desc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_order_by_desc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_order_by_desc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_order_by_desc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_sum.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_sum.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_sum.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_sum.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_without_grouped_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_without_grouped_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_without_grouped_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_without_grouped_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_in_with_same_sharding_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_in_with_same_sharding_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_in_with_same_sharding_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_in_with_same_sharding_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_in_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_in_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_in_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_in_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_inner_join.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_inner_join.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_inner_join.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_inner_join.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_max.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_max.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_max.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_max.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_min.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_min.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_min.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_min.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_not_equal_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_not_equal_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_not_equal_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_not_equal_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_not_in_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_not_in_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_not_in_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_not_in_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_mix_and_for_complex_pattern.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_mix_and_for_complex_pattern.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_mix_and_for_complex_pattern.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_mix_and_for_complex_pattern.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_mix_and_for_simple_pattern.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_mix_and_for_simple_pattern.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_mix_and_for_simple_pattern.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_mix_and_for_simple_pattern.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_mix_and_with_binding_and_broadcast_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_mix_and_with_binding_and_broadcast_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_mix_and_with_binding_and_broadcast_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_mix_and_with_binding_and_broadcast_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_mix_and_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_mix_and_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_mix_and_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_mix_and_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_with_different_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_with_different_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_with_different_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_with_different_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_with_none_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_with_none_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_with_none_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_with_none_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_with_same_sharding_columns.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_with_same_sharding_columns.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_or_with_same_sharding_columns.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_or_with_same_sharding_columns.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_asc_and_index_desc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_asc_and_index_desc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_asc_and_index_desc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_asc_and_index_desc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_desc_and_index_asc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_desc_and_index_asc.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_desc_and_index_asc.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_desc_and_index_asc.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_alias_star_alias_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_alias_star_alias_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_alias_star_alias_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_alias_star_alias_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_date.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_date.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_date.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_date.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_multiple_stars.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_multiple_stars.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_multiple_stars.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_multiple_stars.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_ordered_column.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_ordered_column.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_ordered_column.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_ordered_column.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_star_no_table_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_star_no_table_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_star_no_table_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_star_no_table_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_star_table_alias.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_star_table_alias.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_star_table_alias.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_star_table_alias.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_table_star_table_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_table_star_table_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_table_star_table_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_table_star_table_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_table_star_without_table_name.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_table_star_without_table_name.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_table_star_without_table_name.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_table_star_without_table_name.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_offset.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_offset.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_offset.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_offset.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_offset_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_offset_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_offset_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_offset_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_offset_and_row_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_offset_and_row_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_offset_and_row_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_offset_and_row_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_row_count.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_row_count.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_row_count.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_row_count.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_row_number_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_row_number_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_row_number_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_row_number_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_top_and_limit.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_top_and_limit.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_pagination_with_top_and_limit.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_top_and_limit.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sharding_route_with_binding_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sharding_route_with_binding_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sharding_route_with_binding_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sharding_route_with_binding_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sharding_route_with_broadcast_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sharding_route_with_broadcast_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sharding_route_with_broadcast_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sharding_route_with_broadcast_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sub_query_with_group_by.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sub_query_with_group_by.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sub_query_with_group_by.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sub_query_with_group_by.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sub_query_with_multiple_tables.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sub_query_with_multiple_tables.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sub_query_with_multiple_tables.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sub_query_with_multiple_tables.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sub_query_with_order_by.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sub_query_with_order_by.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sub_query_with_order_by.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sub_query_with_order_by.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sub_query_with_single_table.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sub_query_with_single_table.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sub_query_with_single_table.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sub_query_with_single_table.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sum.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sum.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_sum.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_sum.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_date_function.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_date_function.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_date_function.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_date_function.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_expression.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_expression.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_expression.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_expression.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_force_index_join.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_force_index_join.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_force_index_join.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_force_index_join.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_item_alias_match_order_by_and_group_by_items.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_item_alias_match_order_by_and_group_by_items.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_item_alias_match_order_by_and_group_by_items.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_item_alias_match_order_by_and_group_by_items.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_regexp.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_regexp.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_regexp.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_regexp.xml diff --git a/sharding-jdbc/src/test/resources/asserts/cases/dql/dql-integrate-test-cases.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dql-integrate-test-cases.xml similarity index 100% rename from sharding-jdbc/src/test/resources/asserts/cases/dql/dql-integrate-test-cases.xml rename to sharding-jdbc/src/test/resources/integrate/cases/dql/dql-integrate-test-cases.xml From afb9fdb4d2adc1ebe044ab17ddddb58235f5321e Mon Sep 17 00:00:00 2001 From: haocao Date: Sat, 11 Aug 2018 11:33:34 +0800 Subject: [PATCH 165/198] for #601, refacotr the integrate test jdbc package location --- .../io/shardingsphere/core/common/base/AbstractSQLTest.java | 4 ++-- .../test/resources/integrate/{ => cases}/jdbc/jdbc_data.sql | 0 .../test/resources/integrate/{ => cases}/jdbc/jdbc_init.sql | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename sharding-jdbc/src/test/resources/integrate/{ => cases}/jdbc/jdbc_data.sql (100%) rename sharding-jdbc/src/test/resources/integrate/{ => cases}/jdbc/jdbc_init.sql (100%) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java index a88e4287312e3..1245622d21352 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java @@ -69,7 +69,7 @@ private static void createJdbcSchema(final DatabaseType dbType) { Connection conn; for (int i = 0; i < 2; i++) { conn = initialConnection("jdbc_" + i, dbType); - RunScript.execute(conn, new InputStreamReader(AbstractSQLTest.class.getClassLoader().getResourceAsStream("integrate/jdbc/jdbc_init.sql"))); + RunScript.execute(conn, new InputStreamReader(AbstractSQLTest.class.getClassLoader().getResourceAsStream("integrate/cases/jdbc/jdbc_init.sql"))); conn.close(); } } catch (final SQLException ex) { @@ -158,7 +158,7 @@ private static void closeDataSources(final Collection dataSources) t protected final void importDataSet() { try { ShardingConnection conn = shardingDataSource.getConnection(); - RunScript.execute(conn, new InputStreamReader(AbstractSQLTest.class.getClassLoader().getResourceAsStream("integrate/jdbc/jdbc_data.sql"))); + RunScript.execute(conn, new InputStreamReader(AbstractSQLTest.class.getClassLoader().getResourceAsStream("integrate/cases/jdbc/jdbc_data.sql"))); conn.close(); } catch (final SQLException ex) { ex.printStackTrace(); diff --git a/sharding-jdbc/src/test/resources/integrate/jdbc/jdbc_data.sql b/sharding-jdbc/src/test/resources/integrate/cases/jdbc/jdbc_data.sql similarity index 100% rename from sharding-jdbc/src/test/resources/integrate/jdbc/jdbc_data.sql rename to sharding-jdbc/src/test/resources/integrate/cases/jdbc/jdbc_data.sql diff --git a/sharding-jdbc/src/test/resources/integrate/jdbc/jdbc_init.sql b/sharding-jdbc/src/test/resources/integrate/cases/jdbc/jdbc_init.sql similarity index 100% rename from sharding-jdbc/src/test/resources/integrate/jdbc/jdbc_init.sql rename to sharding-jdbc/src/test/resources/integrate/cases/jdbc/jdbc_init.sql From bd4e1ff557fe3608f8b239e15560f98d6f23dd75 Mon Sep 17 00:00:00 2001 From: tuohai666 Date: Sat, 11 Aug 2018 15:03:25 +0800 Subject: [PATCH 166/198] #1127, separate AtomikosCP and HikariCP in multithreading condition --- .../ConnectionStrictlyExecuteEngine.java | 30 +++++++++++++++++-- .../stream/MemoryStrictlyExecuteEngine.java | 27 +++++++++++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java index 909776579636f..80b196052bdf2 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java @@ -17,6 +17,7 @@ package io.shardingsphere.proxy.backend.jdbc.execute.memory; +import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.merger.QueryResult; import io.shardingsphere.core.routing.SQLRouteResult; @@ -30,6 +31,7 @@ import io.shardingsphere.proxy.backend.jdbc.execute.response.unit.ExecuteResponseUnit; import io.shardingsphere.proxy.backend.jdbc.execute.response.unit.ExecuteUpdateResponseUnit; import io.shardingsphere.proxy.backend.jdbc.wrapper.JDBCExecutorWrapper; +import io.shardingsphere.proxy.config.RuleRegistry; import java.sql.Connection; import java.sql.ResultSet; @@ -62,12 +64,36 @@ public ExecuteResponse execute(final SQLRouteResult routeResult, final boolean i Map> sqlExecutionUnits = routeResult.getSQLUnitGroups(); Entry> firstEntry = sqlExecutionUnits.entrySet().iterator().next(); sqlExecutionUnits.remove(firstEntry.getKey()); - List>> futureList = asyncExecute(isReturnGeneratedKeys, sqlExecutionUnits); + List>> futureList; + if (TransactionType.XA == RuleRegistry.getInstance().getTransactionType()) { + futureList = asyncExecuteWithAtomikosCP(isReturnGeneratedKeys, sqlExecutionUnits); + } else { + futureList = asyncExecuteWithHikariCP(isReturnGeneratedKeys, sqlExecutionUnits); + } Collection firstExecuteResponseUnits = syncExecute(isReturnGeneratedKeys, firstEntry.getKey(), firstEntry.getValue()); return getExecuteQueryResponse(firstExecuteResponseUnits, futureList); } - private List>> asyncExecute(final boolean isReturnGeneratedKeys, final Map> sqlUnitGroups) { + private List>> asyncExecuteWithAtomikosCP(final boolean isReturnGeneratedKeys, final Map> sqlUnitGroups) throws SQLException { + List>> result = new LinkedList<>(); + for (Entry> entry : sqlUnitGroups.entrySet()) { + final Map sqlUnitStatementMap = createSQLUnitStatement(entry.getKey(), entry.getValue(), isReturnGeneratedKeys); + result.add(getExecutorService().submit(new Callable>() { + + @Override + public Collection call() throws SQLException { + Collection result = new LinkedList<>(); + for (Entry each : sqlUnitStatementMap.entrySet()) { + result.add(executeWithoutMetadata(each.getValue(), each.getKey().getSql(), isReturnGeneratedKeys)); + } + return result; + } + })); + } + return result; + } + + private List>> asyncExecuteWithHikariCP(final boolean isReturnGeneratedKeys, final Map> sqlUnitGroups) { List>> result = new LinkedList<>(); for (Entry> entry : sqlUnitGroups.entrySet()) { final String dataSourceName = entry.getKey(); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java index 0584c1c81d552..6638df2351f08 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java @@ -18,6 +18,7 @@ package io.shardingsphere.proxy.backend.jdbc.execute.stream; import com.google.common.collect.Lists; +import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.merger.QueryResult; import io.shardingsphere.core.routing.SQLExecutionUnit; @@ -31,6 +32,7 @@ import io.shardingsphere.proxy.backend.jdbc.execute.response.unit.ExecuteResponseUnit; import io.shardingsphere.proxy.backend.jdbc.execute.response.unit.ExecuteUpdateResponseUnit; import io.shardingsphere.proxy.backend.jdbc.wrapper.JDBCExecutorWrapper; +import io.shardingsphere.proxy.config.RuleRegistry; import java.sql.ResultSet; import java.sql.SQLException; @@ -61,13 +63,34 @@ public MemoryStrictlyExecuteEngine(final BackendConnection backendConnection, fi public ExecuteResponse execute(final SQLRouteResult routeResult, final boolean isReturnGeneratedKeys) throws SQLException { Iterator executionUnits = routeResult.getExecutionUnits().iterator(); SQLExecutionUnit firstSQLExecutionUnit = executionUnits.next(); - List> futureList = asyncExecute(isReturnGeneratedKeys, Lists.newArrayList(executionUnits)); + List> futureList; + if (TransactionType.XA == RuleRegistry.getInstance().getTransactionType()) { + futureList = asyncExecuteWithAtomikosCP(isReturnGeneratedKeys, Lists.newArrayList(executionUnits)); + } else { + futureList = asyncExecuteWithHikariCP(isReturnGeneratedKeys, Lists.newArrayList(executionUnits)); + } ExecuteResponseUnit firstResponseUnit = syncExecute(isReturnGeneratedKeys, firstSQLExecutionUnit); return firstResponseUnit instanceof ExecuteQueryResponseUnit ? getExecuteQueryResponse((ExecuteQueryResponseUnit) firstResponseUnit, futureList) : getExecuteUpdateResponse((ExecuteUpdateResponseUnit) firstResponseUnit, futureList); } - private List> asyncExecute(final boolean isReturnGeneratedKeys, final Collection sqlExecutionUnits) { + private List> asyncExecuteWithAtomikosCP(final boolean isReturnGeneratedKeys, final Collection sqlExecutionUnits) throws SQLException { + List> result = new LinkedList<>(); + for (SQLExecutionUnit each : sqlExecutionUnits) { + final String actualSQL = each.getSqlUnit().getSql(); + final Statement statement = getJdbcExecutorWrapper().createStatement(getBackendConnection().getConnection(each.getDataSource()), actualSQL, isReturnGeneratedKeys); + result.add(getExecutorService().submit(new Callable() { + + @Override + public ExecuteResponseUnit call() throws SQLException { + return executeWithoutMetadata(statement, actualSQL, isReturnGeneratedKeys); + } + })); + } + return result; + } + + private List> asyncExecuteWithHikariCP(final boolean isReturnGeneratedKeys, final Collection sqlExecutionUnits) { List> result = new LinkedList<>(); for (SQLExecutionUnit each : sqlExecutionUnits) { final SQLExecutionUnit sqlExecutionUnit = each; From f321c09496ae77488a349eab9a5a2a99328aacd7 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sat, 11 Aug 2018 21:58:02 +0800 Subject: [PATCH 167/198] revise for #1129 --- .../memory/ConnectionStrictlyExecuteEngine.java | 10 +++++----- .../execute/stream/MemoryStrictlyExecuteEngine.java | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java index 80b196052bdf2..ce7f4d107cdb9 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java @@ -66,15 +66,15 @@ public ExecuteResponse execute(final SQLRouteResult routeResult, final boolean i sqlExecutionUnits.remove(firstEntry.getKey()); List>> futureList; if (TransactionType.XA == RuleRegistry.getInstance().getTransactionType()) { - futureList = asyncExecuteWithAtomikosCP(isReturnGeneratedKeys, sqlExecutionUnits); + futureList = asyncExecuteWithXA(isReturnGeneratedKeys, sqlExecutionUnits); } else { - futureList = asyncExecuteWithHikariCP(isReturnGeneratedKeys, sqlExecutionUnits); + futureList = asyncExecuteWithoutXA(isReturnGeneratedKeys, sqlExecutionUnits); } Collection firstExecuteResponseUnits = syncExecute(isReturnGeneratedKeys, firstEntry.getKey(), firstEntry.getValue()); return getExecuteQueryResponse(firstExecuteResponseUnits, futureList); } - private List>> asyncExecuteWithAtomikosCP(final boolean isReturnGeneratedKeys, final Map> sqlUnitGroups) throws SQLException { + private List>> asyncExecuteWithXA(final boolean isReturnGeneratedKeys, final Map> sqlUnitGroups) throws SQLException { List>> result = new LinkedList<>(); for (Entry> entry : sqlUnitGroups.entrySet()) { final Map sqlUnitStatementMap = createSQLUnitStatement(entry.getKey(), entry.getValue(), isReturnGeneratedKeys); @@ -93,7 +93,7 @@ public Collection call() throws SQLException { return result; } - private List>> asyncExecuteWithHikariCP(final boolean isReturnGeneratedKeys, final Map> sqlUnitGroups) { + private List>> asyncExecuteWithoutXA(final boolean isReturnGeneratedKeys, final Map> sqlUnitGroups) { List>> result = new LinkedList<>(); for (Entry> entry : sqlUnitGroups.entrySet()) { final String dataSourceName = entry.getKey(); @@ -103,7 +103,7 @@ private List>> asyncExecuteWithHikariCP(f @Override public Collection call() throws SQLException { Collection result = new LinkedList<>(); - final Map sqlUnitStatementMap = createSQLUnitStatement(dataSourceName, sqlUnits, isReturnGeneratedKeys); + Map sqlUnitStatementMap = createSQLUnitStatement(dataSourceName, sqlUnits, isReturnGeneratedKeys); for (Entry each : sqlUnitStatementMap.entrySet()) { result.add(executeWithoutMetadata(each.getValue(), each.getKey().getSql(), isReturnGeneratedKeys)); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java index 6638df2351f08..6d4715b4cf876 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java @@ -65,16 +65,16 @@ public ExecuteResponse execute(final SQLRouteResult routeResult, final boolean i SQLExecutionUnit firstSQLExecutionUnit = executionUnits.next(); List> futureList; if (TransactionType.XA == RuleRegistry.getInstance().getTransactionType()) { - futureList = asyncExecuteWithAtomikosCP(isReturnGeneratedKeys, Lists.newArrayList(executionUnits)); + futureList = asyncExecuteWithXA(isReturnGeneratedKeys, Lists.newArrayList(executionUnits)); } else { - futureList = asyncExecuteWithHikariCP(isReturnGeneratedKeys, Lists.newArrayList(executionUnits)); + futureList = asyncExecuteWithoutXA(isReturnGeneratedKeys, Lists.newArrayList(executionUnits)); } ExecuteResponseUnit firstResponseUnit = syncExecute(isReturnGeneratedKeys, firstSQLExecutionUnit); return firstResponseUnit instanceof ExecuteQueryResponseUnit ? getExecuteQueryResponse((ExecuteQueryResponseUnit) firstResponseUnit, futureList) : getExecuteUpdateResponse((ExecuteUpdateResponseUnit) firstResponseUnit, futureList); } - private List> asyncExecuteWithAtomikosCP(final boolean isReturnGeneratedKeys, final Collection sqlExecutionUnits) throws SQLException { + private List> asyncExecuteWithXA(final boolean isReturnGeneratedKeys, final Collection sqlExecutionUnits) throws SQLException { List> result = new LinkedList<>(); for (SQLExecutionUnit each : sqlExecutionUnits) { final String actualSQL = each.getSqlUnit().getSql(); @@ -90,7 +90,7 @@ public ExecuteResponseUnit call() throws SQLException { return result; } - private List> asyncExecuteWithHikariCP(final boolean isReturnGeneratedKeys, final Collection sqlExecutionUnits) { + private List> asyncExecuteWithoutXA(final boolean isReturnGeneratedKeys, final Collection sqlExecutionUnits) { List> result = new LinkedList<>(); for (SQLExecutionUnit each : sqlExecutionUnits) { final SQLExecutionUnit sqlExecutionUnit = each; @@ -98,8 +98,8 @@ private List> asyncExecuteWithHikariCP(final boolean @Override public ExecuteResponseUnit call() throws SQLException { - final String actualSQL = sqlExecutionUnit.getSqlUnit().getSql(); - final Statement statement = getJdbcExecutorWrapper().createStatement(getBackendConnection().getConnection(sqlExecutionUnit.getDataSource()), actualSQL, isReturnGeneratedKeys); + String actualSQL = sqlExecutionUnit.getSqlUnit().getSql(); + Statement statement = getJdbcExecutorWrapper().createStatement(getBackendConnection().getConnection(sqlExecutionUnit.getDataSource()), actualSQL, isReturnGeneratedKeys); return executeWithoutMetadata(statement, actualSQL, isReturnGeneratedKeys); } })); From 92d008607ec3488bdc982be570ef50807cab4989 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sat, 11 Aug 2018 22:07:51 +0800 Subject: [PATCH 168/198] for #1131, add DropTableStatement --- .../parsing/parser/sql/ddl/DDLStatement.java | 2 +- .../drop/table/AbstractDropTableParser.java | 2 +- .../ddl/drop/table/DropTableStatement.java | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/DropTableStatement.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/DDLStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/DDLStatement.java index 5e04f42432725..a96c929ecdb47 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/DDLStatement.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/DDLStatement.java @@ -33,7 +33,7 @@ * @author zhangliang */ @ToString(callSuper = true) -public final class DDLStatement extends AbstractSQLStatement { +public class DDLStatement extends AbstractSQLStatement { private static final Collection PRIMARY_STATEMENT_PREFIX = Arrays.asList(DefaultKeyword.CREATE, DefaultKeyword.ALTER, DefaultKeyword.DROP, DefaultKeyword.TRUNCATE); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/AbstractDropTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/AbstractDropTableParser.java index f7518b8f013ba..d7dc0207882e0 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/AbstractDropTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/AbstractDropTableParser.java @@ -52,7 +52,7 @@ public AbstractDropTableParser(final ShardingRule shardingRule, final LexerEngin @Override public DDLStatement parse() { lexerEngine.skipAll(getSkippedKeywordsBetweenDropAndTable()); - DDLStatement result = new DDLStatement(); + DropTableStatement result = new DropTableStatement(); if (lexerEngine.skipIfEqual(DefaultKeyword.TABLE)) { lexerEngine.skipAll(getSkippedKeywordsBetweenDropTableAndTableName()); tableReferencesClauseParser.parseSingleTableWithoutAlias(result); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/DropTableStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/DropTableStatement.java new file mode 100644 index 0000000000000..10fbdea41da21 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/DropTableStatement.java @@ -0,0 +1,28 @@ +/* + * 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.core.parsing.parser.sql.ddl.drop.table; + +import io.shardingsphere.core.parsing.parser.sql.ddl.DDLStatement; + +/** + * Drop table statement. + * + * @author zhangliang + */ +public final class DropTableStatement extends DDLStatement { +} From 0bc39fa0701d743682fba2bf5ee2cc42cb29b83e Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 00:25:10 +0800 Subject: [PATCH 169/198] for #1131, parse table meta for create table --- .../lexer/dialect/mysql/MySQLKeyword.java | 6 +- .../mysql/sql/MySQLCreateTableParser.java | 5 ++ .../table/AbstractCreateTableParser.java | 62 ++++++++++++++++++- .../create/table/CreateTableStatement.java | 39 ++++++++++++ .../integrate/asserts/SQLStatementAssert.java | 12 ++++ .../asserts/meta/TableMetaDataAssert.java | 56 +++++++++++++++++ .../jaxb/meta/ExpectedTableMetaData.java | 40 ++++++++++++ .../integrate/jaxb/root/ParserResult.java | 4 ++ .../src/test/resources/parser/create.xml | 6 ++ .../src/main/resources/sql/ddl/create.xml | 2 +- 10 files changed, 229 insertions(+), 3 deletions(-) create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/CreateTableStatement.java create mode 100644 sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/meta/TableMetaDataAssert.java create mode 100644 sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/jaxb/meta/ExpectedTableMetaData.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/mysql/MySQLKeyword.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/mysql/MySQLKeyword.java index 3f61d9f22030f..8162c9eb3c521 100755 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/mysql/MySQLKeyword.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/mysql/MySQLKeyword.java @@ -99,5 +99,9 @@ public enum MySQLKeyword implements Keyword { REGEXP, INDEXES, KEYS, - STATUS + STATUS, + GENERATED, + ALWAYS, + BTREE, + HASH } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateTableParser.java index 1ed5e513ee4a1..4db1dccfa6484 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateTableParser.java @@ -50,4 +50,9 @@ protected Keyword[] getSkippedKeywordsBetweenCreateTableAndTableName() { protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() { return new Keyword[] {DefaultKeyword.UNIQUE, DefaultKeyword.FULLTEXT, MySQLKeyword.SPATIAL}; } + + @Override + protected Keyword[] getSkippedKeywordsBeforeTableConstraint() { + return new Keyword[] {DefaultKeyword.USING, MySQLKeyword.BTREE, MySQLKeyword.HASH}; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java index f9e5d76ae9d6a..05c47d3ca0609 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java @@ -20,6 +20,7 @@ import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword; import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.lexer.token.Symbol; import io.shardingsphere.core.parsing.parser.clause.TableReferencesClauseParser; import io.shardingsphere.core.parsing.parser.exception.SQLParsingException; import io.shardingsphere.core.parsing.parser.sql.SQLParser; @@ -28,6 +29,9 @@ import lombok.AccessLevel; import lombok.Getter; +import java.util.Collection; +import java.util.LinkedList; + /** * Create parser. * @@ -53,13 +57,18 @@ public AbstractCreateTableParser(final ShardingRule shardingRule, final LexerEng public DDLStatement parse() { lexerEngine.skipAll(getSkippedKeywordsBetweenCreateIndexAndKeyword()); lexerEngine.skipAll(getSkippedKeywordsBetweenCreateAndKeyword()); - DDLStatement result = new DDLStatement(); + CreateTableStatement result = new CreateTableStatement(); if (lexerEngine.skipIfEqual(DefaultKeyword.TABLE)) { lexerEngine.skipAll(getSkippedKeywordsBetweenCreateTableAndTableName()); } else { throw new SQLParsingException("Can't support other CREATE grammar unless CREATE TABLE."); } tableReferencesClauseParser.parseSingleTableWithoutAlias(result); + lexerEngine.accept(Symbol.LEFT_PAREN); + do { + parseCreateDefinition(result); + } while (lexerEngine.skipIfEqual(Symbol.COMMA)); + lexerEngine.accept(Symbol.RIGHT_PAREN); return result; } @@ -68,4 +77,55 @@ public DDLStatement parse() { protected abstract Keyword[] getSkippedKeywordsBetweenCreateAndKeyword(); protected abstract Keyword[] getSkippedKeywordsBetweenCreateTableAndTableName(); + + private void parseCreateDefinition(final CreateTableStatement statement) { + String columnName = parseColumnName(statement); + parseColumnDefinition(columnName, statement); + } + + private String parseColumnName(final CreateTableStatement statement) { + String result = getLexerEngine().getCurrentToken().getLiterals(); + statement.getColumnNames().add(result); + return result; + } + + private void parseColumnDefinition(final String columnName, final CreateTableStatement statement) { + parseDataType(statement); + getLexerEngine().skipUntil(DefaultKeyword.PRIMARY, Symbol.COMMA, Symbol.RIGHT_PAREN); + if (getLexerEngine().skipIfEqual(DefaultKeyword.PRIMARY)) { + getLexerEngine().accept(DefaultKeyword.KEY); + getLexerEngine().skipAll(getSkippedKeywordsBeforeTableConstraint()); + if (getLexerEngine().skipIfEqual(Symbol.LEFT_PAREN)) { + parseTableConstraint(statement); + } else { + parseInlineConstraint(columnName, statement); + } + } + } + + private void parseDataType(final CreateTableStatement statement) { + getLexerEngine().nextToken(); + statement.getColumnTypes().add(getLexerEngine().getCurrentToken().getLiterals()); + getLexerEngine().skipParentheses(statement); + } + + protected Keyword[] getSkippedKeywordsBeforeTableConstraint() { + return new Keyword[0]; + } + + private void parseTableConstraint(final CreateTableStatement statement) { + Collection columnNames = new LinkedList<>(); + do { + columnNames.add(getLexerEngine().getCurrentToken().getLiterals()); + getLexerEngine().nextToken(); + getLexerEngine().skipParentheses(statement); + getLexerEngine().skipUntil(Symbol.COMMA, Symbol.RIGHT_PAREN); + } while (getLexerEngine().skipIfEqual(Symbol.COMMA)); + statement.getPrimaryKeyColumns().addAll(columnNames); + } + + private void parseInlineConstraint(final String columnName, final CreateTableStatement statement) { + statement.getPrimaryKeyColumns().add(columnName); + getLexerEngine().skipUntil(Symbol.COMMA, Symbol.RIGHT_PAREN); + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/CreateTableStatement.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/CreateTableStatement.java new file mode 100644 index 0000000000000..d4740a5769983 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/CreateTableStatement.java @@ -0,0 +1,39 @@ +/* + * 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.core.parsing.parser.sql.ddl.create.table; + +import io.shardingsphere.core.parsing.parser.sql.ddl.DDLStatement; +import lombok.Getter; + +import java.util.LinkedList; +import java.util.List; + +/** + * Create table statement. + * + * @author zhangliang + */ +@Getter +public final class CreateTableStatement extends DDLStatement { + + private final List columnNames = new LinkedList<>(); + + private final List columnTypes = new LinkedList<>(); + + private final List primaryKeyColumns = new LinkedList<>(); +} diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/SQLStatementAssert.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/SQLStatementAssert.java index cb1e608c8a897..23d508d030d9d 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/SQLStatementAssert.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/SQLStatementAssert.java @@ -22,11 +22,13 @@ import io.shardingsphere.core.parsing.integrate.asserts.index.IndexAssert; import io.shardingsphere.core.parsing.integrate.asserts.item.ItemAssert; import io.shardingsphere.core.parsing.integrate.asserts.limit.LimitAssert; +import io.shardingsphere.core.parsing.integrate.asserts.meta.TableMetaDataAssert; import io.shardingsphere.core.parsing.integrate.asserts.orderby.OrderByAssert; import io.shardingsphere.core.parsing.integrate.asserts.table.TableAssert; import io.shardingsphere.core.parsing.integrate.asserts.token.TokenAssert; import io.shardingsphere.core.parsing.integrate.jaxb.root.ParserResult; import io.shardingsphere.core.parsing.parser.sql.SQLStatement; +import io.shardingsphere.core.parsing.parser.sql.ddl.create.table.CreateTableStatement; import io.shardingsphere.core.parsing.parser.sql.dql.select.SelectStatement; import io.shardingsphere.test.sql.SQLCaseType; @@ -57,6 +59,8 @@ public final class SQLStatementAssert { private final LimitAssert limitAssert; + private final TableMetaDataAssert metaAssert; + public SQLStatementAssert(final SQLStatement actual, final String sqlCaseId, final SQLCaseType sqlCaseType) { SQLStatementAssertMessage assertMessage = new SQLStatementAssertMessage(sqlCaseId, sqlCaseType); this.actual = actual; @@ -70,6 +74,7 @@ public SQLStatementAssert(final SQLStatement actual, final String sqlCaseId, fin groupByAssert = new GroupByAssert(assertMessage); orderByAssert = new OrderByAssert(assertMessage); limitAssert = new LimitAssert(sqlCaseType, assertMessage); + metaAssert = new TableMetaDataAssert(assertMessage); } /** @@ -83,6 +88,9 @@ public void assertSQLStatement() { if (actual instanceof SelectStatement) { assertSelectStatement((SelectStatement) actual); } + if (actual instanceof CreateTableStatement) { + assertCreateTableStatement((CreateTableStatement) actual); + } } private void assertSelectStatement(final SelectStatement actual) { @@ -91,4 +99,8 @@ private void assertSelectStatement(final SelectStatement actual) { orderByAssert.assertOrderByItems(actual.getOrderByItems(), expected.getOrderByColumns()); limitAssert.assertLimit(actual.getLimit(), expected.getLimit()); } + + private void assertCreateTableStatement(final CreateTableStatement actual) { + metaAssert.assertMeta(actual.getColumnNames(), actual.getColumnTypes(), actual.getPrimaryKeyColumns(), expected.getMeta()); + } } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/meta/TableMetaDataAssert.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/meta/TableMetaDataAssert.java new file mode 100644 index 0000000000000..17dcf1f01254c --- /dev/null +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/meta/TableMetaDataAssert.java @@ -0,0 +1,56 @@ +/* + * 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.core.parsing.integrate.asserts.meta; + +import com.google.common.base.Joiner; +import io.shardingsphere.core.parsing.integrate.asserts.SQLStatementAssertMessage; +import io.shardingsphere.core.parsing.integrate.jaxb.meta.ExpectedTableMetaData; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; + +/** + * Table meta data assert. + * + * @author zhangliang + */ +@RequiredArgsConstructor +public final class TableMetaDataAssert { + + private final SQLStatementAssertMessage assertMessage; + + /** + * Assert table meta data. + * + * @param actualColumnNames actual column names + * @param actualColumnTypes actual column types + * @param actualPrimaryKeyColumns actual primary key columns + * @param expected expected meta data + */ + public void assertMeta(final List actualColumnNames, final List actualColumnTypes, final List actualPrimaryKeyColumns, final ExpectedTableMetaData expected) { + assertFalse(assertMessage.getFullAssertMessage("Column names should exist: "), actualColumnNames.isEmpty()); + assertThat(assertMessage.getFullAssertMessage("Column names assertion error: "), Joiner.on(",").join(actualColumnNames), is(expected.getColumnNames())); + assertFalse(assertMessage.getFullAssertMessage("Column types should exist: "), actualColumnTypes.isEmpty()); + assertThat(assertMessage.getFullAssertMessage("Column types assertion error: "), Joiner.on(",").join(actualColumnTypes), is(expected.getColumnTypes())); + assertThat(assertMessage.getFullAssertMessage("Column primary key columns assertion error: "), Joiner.on(",").join(actualPrimaryKeyColumns), is(expected.getPrimaryKeyColumns())); + } +} diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/jaxb/meta/ExpectedTableMetaData.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/jaxb/meta/ExpectedTableMetaData.java new file mode 100644 index 0000000000000..865064088c057 --- /dev/null +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/jaxb/meta/ExpectedTableMetaData.java @@ -0,0 +1,40 @@ +/* + * 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.core.parsing.integrate.jaxb.meta; + +import lombok.Getter; +import lombok.Setter; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; + +@Getter +@Setter +@XmlAccessorType(XmlAccessType.FIELD) +public final class ExpectedTableMetaData { + + @XmlAttribute(name = "column-names") + private String columnNames = ""; + + @XmlAttribute(name = "column-types") + private String columnTypes = ""; + + @XmlAttribute(name = "primary-key-columns") + private String primaryKeyColumns = ""; +} diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/jaxb/root/ParserResult.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/jaxb/root/ParserResult.java index 331d4a42d5e35..86f0ed57ef324 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/jaxb/root/ParserResult.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/jaxb/root/ParserResult.java @@ -22,6 +22,7 @@ import io.shardingsphere.core.parsing.integrate.jaxb.groupby.ExpectedGroupByColumn; import io.shardingsphere.core.parsing.integrate.jaxb.item.ExpectedAggregationSelectItem; import io.shardingsphere.core.parsing.integrate.jaxb.limit.ExpectedLimit; +import io.shardingsphere.core.parsing.integrate.jaxb.meta.ExpectedTableMetaData; import io.shardingsphere.core.parsing.integrate.jaxb.orderby.ExpectedOrderByColumn; import io.shardingsphere.core.parsing.integrate.jaxb.table.ExpectedTable; import io.shardingsphere.core.parsing.integrate.jaxb.token.ExpectedTokens; @@ -77,6 +78,9 @@ public final class ParserResult { @XmlElement private ExpectedLimit limit; + @XmlElement + private ExpectedTableMetaData meta; + /** * Get parameters. * diff --git a/sharding-core/src/test/resources/parser/create.xml b/sharding-core/src/test/resources/parser/create.xml index edf63dfea9f66..572ae14715956 100644 --- a/sharding-core/src/test/resources/parser/create.xml +++ b/sharding-core/src/test/resources/parser/create.xml @@ -7,6 +7,7 @@ + @@ -16,6 +17,7 @@ + @@ -25,6 +27,7 @@ + @@ -34,6 +37,7 @@ + @@ -43,6 +47,7 @@ + @@ -52,6 +57,7 @@ + diff --git a/sharding-sql-test/src/main/resources/sql/ddl/create.xml b/sharding-sql-test/src/main/resources/sql/ddl/create.xml index 8703e9d12d331..06ecb1adf46ea 100644 --- a/sharding-sql-test/src/main/resources/sql/ddl/create.xml +++ b/sharding-sql-test/src/main/resources/sql/ddl/create.xml @@ -1,6 +1,6 @@ - + From 4ba2a7946f14d878bc5ab61a80d203b596686109 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 00:44:11 +0800 Subject: [PATCH 170/198] for #1131, refactor AbstractCreateTableParser --- .../table/AbstractCreateTableParser.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java index 05c47d3ca0609..70e14f168ad3a 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java @@ -84,18 +84,18 @@ private void parseCreateDefinition(final CreateTableStatement statement) { } private String parseColumnName(final CreateTableStatement statement) { - String result = getLexerEngine().getCurrentToken().getLiterals(); + String result = lexerEngine.getCurrentToken().getLiterals(); statement.getColumnNames().add(result); return result; } private void parseColumnDefinition(final String columnName, final CreateTableStatement statement) { parseDataType(statement); - getLexerEngine().skipUntil(DefaultKeyword.PRIMARY, Symbol.COMMA, Symbol.RIGHT_PAREN); - if (getLexerEngine().skipIfEqual(DefaultKeyword.PRIMARY)) { - getLexerEngine().accept(DefaultKeyword.KEY); - getLexerEngine().skipAll(getSkippedKeywordsBeforeTableConstraint()); - if (getLexerEngine().skipIfEqual(Symbol.LEFT_PAREN)) { + lexerEngine.skipUntil(DefaultKeyword.PRIMARY, Symbol.COMMA, Symbol.RIGHT_PAREN); + if (lexerEngine.skipIfEqual(DefaultKeyword.PRIMARY)) { + lexerEngine.accept(DefaultKeyword.KEY); + lexerEngine.skipAll(getSkippedKeywordsBeforeTableConstraint()); + if (lexerEngine.skipIfEqual(Symbol.LEFT_PAREN)) { parseTableConstraint(statement); } else { parseInlineConstraint(columnName, statement); @@ -104,9 +104,9 @@ private void parseColumnDefinition(final String columnName, final CreateTableSta } private void parseDataType(final CreateTableStatement statement) { - getLexerEngine().nextToken(); - statement.getColumnTypes().add(getLexerEngine().getCurrentToken().getLiterals()); - getLexerEngine().skipParentheses(statement); + lexerEngine.nextToken(); + statement.getColumnTypes().add(lexerEngine.getCurrentToken().getLiterals()); + lexerEngine.skipParentheses(statement); } protected Keyword[] getSkippedKeywordsBeforeTableConstraint() { @@ -116,16 +116,16 @@ protected Keyword[] getSkippedKeywordsBeforeTableConstraint() { private void parseTableConstraint(final CreateTableStatement statement) { Collection columnNames = new LinkedList<>(); do { - columnNames.add(getLexerEngine().getCurrentToken().getLiterals()); - getLexerEngine().nextToken(); - getLexerEngine().skipParentheses(statement); - getLexerEngine().skipUntil(Symbol.COMMA, Symbol.RIGHT_PAREN); - } while (getLexerEngine().skipIfEqual(Symbol.COMMA)); + columnNames.add(lexerEngine.getCurrentToken().getLiterals()); + lexerEngine.nextToken(); + lexerEngine.skipParentheses(statement); + lexerEngine.skipUntil(Symbol.COMMA, Symbol.RIGHT_PAREN); + } while (lexerEngine.skipIfEqual(Symbol.COMMA)); statement.getPrimaryKeyColumns().addAll(columnNames); } private void parseInlineConstraint(final String columnName, final CreateTableStatement statement) { statement.getPrimaryKeyColumns().add(columnName); - getLexerEngine().skipUntil(Symbol.COMMA, Symbol.RIGHT_PAREN); + lexerEngine.skipUntil(Symbol.COMMA, Symbol.RIGHT_PAREN); } } From e9f760995c07acdf58abe5dc8f0e636dbb0b9154 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 01:51:44 +0800 Subject: [PATCH 171/198] for #1123, use db catalog to load meta data --- .../core/metadata/ShardingMetaData.java | 2 +- .../executor/TableMetaDataInitializer.java | 8 +++-- .../table/executor/TableMetaDataLoader.java | 30 ++++++++++------ ...ationShardingMasterSlaveNamespaceTest.java | 4 +-- .../core/jdbc/core/ShardingContext.java | 29 ++-------------- .../core/datasource/ShardingDataSource.java | 34 ++++++++++++++++--- .../statement/ShardingPreparedStatement.java | 2 +- .../core/statement/ShardingStatement.java | 2 +- .../connection/ShardingConnectionTest.java | 9 ++--- .../opentracing/MergeEventListenerTest.java | 4 ++- .../SqlRoutingEventListenerTest.java | 4 ++- .../backend/jdbc/JDBCBackendHandler.java | 2 +- .../backend/netty/NettyBackendHandler.java | 2 +- .../proxy/config/RuleRegistry.java | 4 +-- 14 files changed, 76 insertions(+), 60 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java index 54a0701ac4a6e..3e66374f81c50 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java @@ -29,7 +29,7 @@ */ @RequiredArgsConstructor @Getter -public final class ShardingMetaData { +public class ShardingMetaData { private final ShardingDataSourceMetaData dataSource; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataInitializer.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataInitializer.java index 2a1b4b9f3ef48..69362b7845f3d 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataInitializer.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataInitializer.java @@ -20,6 +20,7 @@ import com.google.common.base.Optional; import com.google.common.util.concurrent.ListeningExecutorService; import io.shardingsphere.core.exception.ShardingException; +import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData; import io.shardingsphere.core.metadata.table.TableMetaData; import io.shardingsphere.core.rule.ShardingRule; import io.shardingsphere.core.rule.TableRule; @@ -43,9 +44,10 @@ public final class TableMetaDataInitializer { private final TableMetaDataLoader tableMetaDataLoader; - public TableMetaDataInitializer(final ListeningExecutorService executorService, final TableMetaDataConnectionManager connectionManager) { + public TableMetaDataInitializer( + final ShardingDataSourceMetaData shardingDataSourceMetaData, final ListeningExecutorService executorService, final TableMetaDataConnectionManager connectionManager) { this.connectionManager = connectionManager; - tableMetaDataLoader = new TableMetaDataLoader(executorService, connectionManager); + tableMetaDataLoader = new TableMetaDataLoader(shardingDataSourceMetaData, executorService, connectionManager); } /** @@ -87,7 +89,7 @@ private Map loadDefaultTables(final ShardingRule sharding private Collection getAllTableNames(final String dataSourceName) throws SQLException { Collection result = new LinkedList<>(); try (Connection connection = connectionManager.getConnection(dataSourceName); - ResultSet resultSet = connection.getMetaData().getTables(null, null, null, null)) { + ResultSet resultSet = connection.getMetaData().getTables(dataSourceName, null, null, null)) { while (resultSet.next()) { result.add(resultSet.getString("TABLE_NAME")); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java index 813a2bd1a0b5d..e39f9a1d788c6 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataLoader.java @@ -21,6 +21,8 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import io.shardingsphere.core.exception.ShardingException; +import io.shardingsphere.core.metadata.datasource.DataSourceMetaData; +import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData; import io.shardingsphere.core.metadata.table.ColumnMetaData; import io.shardingsphere.core.metadata.table.TableMetaData; import io.shardingsphere.core.rule.ShardingDataSourceNames; @@ -48,6 +50,8 @@ @RequiredArgsConstructor public final class TableMetaDataLoader { + private final ShardingDataSourceMetaData shardingDataSourceMetaData; + private final ListeningExecutorService executorService; private final TableMetaDataConnectionManager connectionManager; @@ -67,12 +71,16 @@ public TableMetaData load(final String logicTableName, final ShardingRule shardi private List load(final Map> dataNodeGroups, final ShardingDataSourceNames shardingDataSourceNames) { List>> futures = new LinkedList<>(); - for (final Entry> entry : dataNodeGroups.entrySet()) { + for (Entry> entry : dataNodeGroups.entrySet()) { + final String dataSourceName = shardingDataSourceNames.getRawMasterDataSourceName(entry.getKey()); + DataSourceMetaData dataSourceMetaData = shardingDataSourceMetaData.getActualDataSourceMetaData(entry.getKey()); + final String catalog = null == dataSourceMetaData ? null : dataSourceMetaData.getSchemeName(); + final Collection actualTableNames = entry.getValue(); futures.add(executorService.submit(new Callable>() { @Override public Collection call() throws SQLException { - return load(shardingDataSourceNames.getRawMasterDataSourceName(entry.getKey()), entry.getValue()); + return load(dataSourceName, catalog, actualTableNames); } })); } @@ -87,26 +95,26 @@ public Collection call() throws SQLException { } } - private Collection load(final String dataSourceName, final Collection actualTableNames) throws SQLException { + private Collection load(final String dataSourceName, final String catalog, final Collection actualTableNames) throws SQLException { Collection result = new LinkedList<>(); try (Connection connection = connectionManager.getConnection(dataSourceName)) { for (String each : actualTableNames) { - result.add(new TableMetaData(isTableExist(connection, each) ? getColumnMetaDataList(connection, each) : Collections.emptyList())); + result.add(new TableMetaData(isTableExist(connection, catalog, each) ? getColumnMetaDataList(connection, catalog, each) : Collections.emptyList())); } } return result; } - private boolean isTableExist(final Connection connection, final String actualTableName) throws SQLException { - try (ResultSet resultSet = connection.getMetaData().getTables(null, null, actualTableName, null)) { + private boolean isTableExist(final Connection connection, final String catalog, final String actualTableName) throws SQLException { + try (ResultSet resultSet = connection.getMetaData().getTables(catalog, null, actualTableName, null)) { return resultSet.next(); } } - private List getColumnMetaDataList(final Connection connection, final String actualTableName) throws SQLException { + private List getColumnMetaDataList(final Connection connection, final String catalog, final String actualTableName) throws SQLException { List result = new LinkedList<>(); - Collection primaryKeys = getPrimaryKeys(connection, actualTableName); - try (ResultSet resultSet = connection.getMetaData().getColumns(null, null, actualTableName, null)) { + Collection primaryKeys = getPrimaryKeys(connection, catalog, actualTableName); + try (ResultSet resultSet = connection.getMetaData().getColumns(catalog, null, actualTableName, null)) { while (resultSet.next()) { String columnName = resultSet.getString("COLUMN_NAME"); String columnType = resultSet.getString("TYPE_NAME"); @@ -116,9 +124,9 @@ private List getColumnMetaDataList(final Connection connection, return result; } - private Collection getPrimaryKeys(final Connection connection, final String actualTableName) throws SQLException { + private Collection getPrimaryKeys(final Connection connection, final String catalog, final String actualTableName) throws SQLException { Collection result = new HashSet<>(); - try (ResultSet resultSet = connection.getMetaData().getPrimaryKeys(null, null, actualTableName)) { + try (ResultSet resultSet = connection.getMetaData().getPrimaryKeys(catalog, null, actualTableName)) { while (resultSet.next()) { result.add(resultSet.getString("COLUMN_NAME")); } diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/OrchestrationShardingMasterSlaveNamespaceTest.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/OrchestrationShardingMasterSlaveNamespaceTest.java index 35708a9d76047..4baf9008f57ee 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/OrchestrationShardingMasterSlaveNamespaceTest.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/OrchestrationShardingMasterSlaveNamespaceTest.java @@ -58,13 +58,13 @@ public void assertDefaultShardingDataSource() { @SuppressWarnings("unchecked") private Map getDataSourceMap() { - ShardingDataSource shardingDataSource = this.applicationContext.getBean("defaultShardingDataSource", ShardingDataSource.class); + ShardingDataSource shardingDataSource = applicationContext.getBean("defaultShardingDataSource", ShardingDataSource.class); Object shardingContext = FieldValueUtil.getFieldValue(shardingDataSource, "shardingContext", true); return (Map) FieldValueUtil.getFieldValue(shardingContext, "dataSourceMap"); } private ShardingRule getShardingRule() { - ShardingDataSource shardingDataSource = this.applicationContext.getBean("defaultShardingDataSource", ShardingDataSource.class); + ShardingDataSource shardingDataSource = applicationContext.getBean("defaultShardingDataSource", ShardingDataSource.class); Object shardingContext = FieldValueUtil.getFieldValue(shardingDataSource, "shardingContext", true); return (ShardingRule) FieldValueUtil.getFieldValue(shardingContext, "shardingRule"); } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java index 461771161e7e9..00ea41f46b3a3 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java @@ -17,23 +17,16 @@ package io.shardingsphere.core.jdbc.core; -import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.constant.ConnectionMode; -import io.shardingsphere.core.exception.ShardingException; +import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.executor.ExecutorEngine; import io.shardingsphere.core.metadata.ShardingMetaData; -import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData; -import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.rule.ShardingRule; import lombok.Getter; import lombok.RequiredArgsConstructor; import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.LinkedHashMap; import java.util.Map; -import java.util.Map.Entry; /** * Sharding runtime context. @@ -60,29 +53,13 @@ public final class ShardingContext { private final ShardingMetaData metaData; public ShardingContext(final Map dataSourceMap, final ShardingRule shardingRule, - final DatabaseType databaseType, final ExecutorEngine executorEngine, final ShardingTableMetaData shardingTableMetaData, final boolean showSQL, final ConnectionMode connectionMode) { + final DatabaseType databaseType, final ExecutorEngine executorEngine, final ShardingMetaData metaData, final boolean showSQL, final ConnectionMode connectionMode) { this.dataSourceMap = dataSourceMap; this.shardingRule = shardingRule; this.databaseType = databaseType; this.executorEngine = executorEngine; this.showSQL = showSQL; this.connectionMode = connectionMode; - metaData = new ShardingMetaData(new ShardingDataSourceMetaData(getDataSourceURLs(dataSourceMap), shardingRule, databaseType), shardingTableMetaData); - } - - private static Map getDataSourceURLs(final Map dataSourceMap) { - Map result = new LinkedHashMap<>(dataSourceMap.size(), 1); - for (Entry entry : dataSourceMap.entrySet()) { - result.put(entry.getKey(), getDataSourceURL(entry.getValue())); - } - return result; - } - - private static String getDataSourceURL(final DataSource dataSource) { - try (Connection connection = dataSource.getConnection()) { - return connection.getMetaData().getURL(); - } catch (final SQLException ex) { - throw new ShardingException(ex); - } + this.metaData = metaData; } } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java index d20cf19b087c8..bf3bd2ebe55c8 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java @@ -23,6 +23,7 @@ import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.ShardingProperties; import io.shardingsphere.core.constant.ShardingPropertiesConstant; +import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.core.executor.ExecutorEngine; import io.shardingsphere.core.executor.type.connection.ConnectionStrictlyExecutorEngine; import io.shardingsphere.core.executor.type.memory.MemoryStrictlyExecutorEngine; @@ -30,6 +31,8 @@ import io.shardingsphere.core.jdbc.core.ShardingContext; import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; import io.shardingsphere.core.jdbc.metadata.JDBCTableMetaDataConnectionManager; +import io.shardingsphere.core.metadata.ShardingMetaData; +import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData; import io.shardingsphere.core.metadata.table.ShardingTableMetaData; import io.shardingsphere.core.metadata.table.executor.TableMetaDataInitializer; import io.shardingsphere.core.rule.MasterSlaveRule; @@ -37,6 +40,7 @@ import lombok.Getter; import javax.sql.DataSource; +import java.sql.Connection; import java.sql.SQLException; import java.util.Collection; import java.util.LinkedHashMap; @@ -74,10 +78,28 @@ public ShardingDataSource(final Map dataSourceMap, final Sha int executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); ConnectionMode connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); executorEngine = ConnectionMode.MEMORY_STRICTLY == connectionMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); + ShardingDataSourceMetaData shardingDataSourceMetaData = new ShardingDataSourceMetaData(getDataSourceURLs(dataSourceMap), shardingRule, getDatabaseType()); ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData( - new TableMetaDataInitializer(executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule)); + new TableMetaDataInitializer(shardingDataSourceMetaData, executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule)); boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); - shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingTableMetaData, showSQL, connectionMode); + shardingContext = new ShardingContext( + dataSourceMap, shardingRule, getDatabaseType(), executorEngine, new ShardingMetaData(shardingDataSourceMetaData, shardingTableMetaData), showSQL, connectionMode); + } + + private static Map getDataSourceURLs(final Map dataSourceMap) { + Map result = new LinkedHashMap<>(dataSourceMap.size(), 1); + for (Map.Entry entry : dataSourceMap.entrySet()) { + result.put(entry.getKey(), getDataSourceURL(entry.getValue())); + } + return result; + } + + private static String getDataSourceURL(final DataSource dataSource) { + try (Connection connection = dataSource.getConnection()) { + return connection.getMetaData().getURL(); + } catch (final SQLException ex) { + throw new ShardingException(ex); + } } /** @@ -99,10 +121,12 @@ public void renew(final Map newDataSourceMap, final Sharding originalExecutorEngine.close(); } boolean newShowSQL = newShardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); - ShardingTableMetaData shardingMetaData = new ShardingTableMetaData( - new TableMetaDataInitializer(executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(newDataSourceMap)).load(newShardingRule)); + ShardingDataSourceMetaData shardingDataSourceMetaData = new ShardingDataSourceMetaData(getDataSourceURLs(newDataSourceMap), newShardingRule, getDatabaseType()); + ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData( + new TableMetaDataInitializer(shardingDataSourceMetaData, executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(newDataSourceMap)).load(newShardingRule)); shardingProperties = newShardingProperties; - shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, shardingMetaData, newShowSQL, newConnectionMode); + shardingContext = new ShardingContext( + newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, new ShardingMetaData(shardingDataSourceMetaData, shardingTableMetaData), newShowSQL, newConnectionMode); } @Override diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java index b06f67f7d596e..0f8caf67ffe01 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java @@ -249,7 +249,7 @@ private void sqlRoute() { private void refreshTableMetaData() { if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); - TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( + TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader(connection.getShardingContext().getMetaData().getDataSource(), connection.getShardingContext().getExecutorEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, connection.getShardingContext().getShardingRule())); } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java index bf6ae1efbfb57..7d2f101676c9f 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java @@ -287,7 +287,7 @@ private void sqlRoute(final String sql) { private void refreshTableMetaData() { if (null != routeResult && null != connection && SQLType.DDL == routeResult.getSqlStatement().getType() && !routeResult.getSqlStatement().getTables().isEmpty()) { String logicTableName = routeResult.getSqlStatement().getTables().getSingleTableName(); - TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( + TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader(connection.getShardingContext().getMetaData().getDataSource(), connection.getShardingContext().getExecutorEngine().getExecutorService(), new JDBCTableMetaDataConnectionManager(connection.getShardingContext().getDataSourceMap())); connection.getShardingContext().getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, connection.getShardingContext().getShardingRule())); } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java index 4b916b1b9032e..362ade3e2b95e 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java @@ -20,13 +20,12 @@ import io.shardingsphere.core.api.config.MasterSlaveRuleConfiguration; import io.shardingsphere.core.api.config.ShardingRuleConfiguration; import io.shardingsphere.core.api.config.TableRuleConfiguration; -import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.constant.ConnectionMode; +import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.fixture.TestDataSource; import io.shardingsphere.core.jdbc.core.ShardingContext; import io.shardingsphere.core.jdbc.core.datasource.MasterSlaveDataSource; -import io.shardingsphere.core.metadata.table.ShardingTableMetaData; -import io.shardingsphere.core.metadata.table.TableMetaData; +import io.shardingsphere.core.metadata.ShardingMetaData; import io.shardingsphere.core.rule.ShardingRule; import org.junit.After; import org.junit.Before; @@ -42,6 +41,7 @@ import java.util.Properties; import static org.junit.Assert.assertNotSame; +import static org.mockito.Mockito.mock; public final class ShardingConnectionTest { @@ -72,7 +72,8 @@ public void setUp() { Map dataSourceMap = new HashMap<>(1, 1); dataSourceMap.put(DS_NAME, masterSlaveDataSource); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()); - ShardingContext shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.H2, null, new ShardingTableMetaData(Collections.emptyMap()), false, ConnectionMode.MEMORY_STRICTLY); + ShardingMetaData shardingMetaData = mock(ShardingMetaData.class); + ShardingContext shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.H2, null, shardingMetaData, false, ConnectionMode.MEMORY_STRICTLY); connection = new ShardingConnection(shardingContext); } diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java index 1a484b72bee6b..3065e74856355 100644 --- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java +++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java @@ -34,6 +34,7 @@ import io.shardingsphere.core.jdbc.core.statement.ShardingStatement; import io.shardingsphere.core.merger.MergeEngine; import io.shardingsphere.core.merger.dal.DALMergeEngine; +import io.shardingsphere.core.metadata.ShardingMetaData; import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowColumnsStatement; import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement; import io.shardingsphere.core.rule.ShardingRule; @@ -88,7 +89,8 @@ public void setUp() throws SQLException { dataSourceMap.put("ds_0", mockDataSource()); dataSourceMap.put("ds_1", mockDataSource()); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()); - shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, null, true, ConnectionMode.MEMORY_STRICTLY); + ShardingMetaData shardingMetaData = mock(ShardingMetaData.class); + shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, shardingMetaData, true, ConnectionMode.MEMORY_STRICTLY); mergeEngine = new DALMergeEngine(null, null, new ShowDatabasesStatement(), null); } diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java index 23ea9e5015aca..b10ef3ae9d760 100644 --- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java +++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java @@ -32,6 +32,7 @@ import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; import io.shardingsphere.core.jdbc.core.statement.ShardingPreparedStatement; import io.shardingsphere.core.jdbc.core.statement.ShardingStatement; +import io.shardingsphere.core.metadata.ShardingMetaData; import io.shardingsphere.core.rule.ShardingRule; import io.shardingsphere.core.util.EventBusInstance; import org.junit.AfterClass; @@ -82,7 +83,8 @@ public void setUp() throws SQLException { dataSourceMap.put("ds_0", mockDataSource()); dataSourceMap.put("ds_1", mockDataSource()); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()); - shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, null, true, ConnectionMode.MEMORY_STRICTLY); + ShardingMetaData shardingMetaData = mock(ShardingMetaData.class); + shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, shardingMetaData, true, ConnectionMode.MEMORY_STRICTLY); } private DataSource mockDataSource() throws SQLException { diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java index e41e0700ef11c..48620f1a0c14b 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java @@ -92,7 +92,7 @@ private CommandResponsePackets execute(final SQLRouteResult routeResult) throws if (!RULE_REGISTRY.isMasterSlaveOnly() && SQLType.DDL == sqlStatement.getType() && !sqlStatement.getTables().isEmpty()) { String logicTableName = sqlStatement.getTables().getSingleTableName(); // TODO refresh table meta data by SQL parse result - TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( + TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader(RULE_REGISTRY.getMetaData().getDataSource(), BackendExecutorContext.getInstance().getExecutorService(), new ProxyTableMetaDataConnectionManager(RULE_REGISTRY.getBackendDataSource())); RULE_REGISTRY.getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, RULE_REGISTRY.getShardingRule())); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java index e506e17148d94..b742abda0ddd4 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/NettyBackendHandler.java @@ -204,7 +204,7 @@ private CommandResponsePackets mergeDQLorDAL(final SQLStatement sqlStatement, fi // TODO refresh table meta data by SQL parse result private void refreshTableMetaData(final String logicTableName) { TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( - BackendExecutorContext.getInstance().getExecutorService(), new ProxyTableMetaDataConnectionManager(RULE_REGISTRY.getBackendDataSource())); + RULE_REGISTRY.getMetaData().getDataSource(), BackendExecutorContext.getInstance().getExecutorService(), new ProxyTableMetaDataConnectionManager(RULE_REGISTRY.getBackendDataSource())); RULE_REGISTRY.getMetaData().getTable().put(logicTableName, tableMetaDataLoader.load(logicTableName, RULE_REGISTRY.getShardingRule())); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 06cc91d133404..54ef6e9cf685d 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -138,8 +138,8 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { */ public void initShardingMetaData(final ExecutorService executorService) { ShardingDataSourceMetaData shardingDataSourceMetaData = new ShardingDataSourceMetaData(getDataSourceURLs(dataSourceConfigurationMap), shardingRule, DatabaseType.MySQL); - ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData( - new TableMetaDataInitializer(MoreExecutors.listeningDecorator(executorService), new ProxyTableMetaDataConnectionManager(backendDataSource)).load(shardingRule)); + ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData(new TableMetaDataInitializer( + shardingDataSourceMetaData, MoreExecutors.listeningDecorator(executorService), new ProxyTableMetaDataConnectionManager(backendDataSource)).load(shardingRule)); metaData = new ShardingMetaData(shardingDataSourceMetaData, shardingTableMetaData); } From e7cd3b2ac75fe30ef8445cecb986d245eac0b347 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 01:54:32 +0800 Subject: [PATCH 172/198] for #1123, refactor ShardingContext --- .../core/jdbc/core/ShardingContext.java | 15 ++------------- .../jdbc/core/datasource/ShardingDataSource.java | 4 ++-- .../core/connection/ShardingConnectionTest.java | 2 +- .../opentracing/MergeEventListenerTest.java | 2 +- .../opentracing/SqlRoutingEventListenerTest.java | 2 +- 5 files changed, 7 insertions(+), 18 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java index 00ea41f46b3a3..7cdb8cd60a81e 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java @@ -46,20 +46,9 @@ public final class ShardingContext { private final ExecutorEngine executorEngine; - private final boolean showSQL; + private final ShardingMetaData metaData; private final ConnectionMode connectionMode; - private final ShardingMetaData metaData; - - public ShardingContext(final Map dataSourceMap, final ShardingRule shardingRule, - final DatabaseType databaseType, final ExecutorEngine executorEngine, final ShardingMetaData metaData, final boolean showSQL, final ConnectionMode connectionMode) { - this.dataSourceMap = dataSourceMap; - this.shardingRule = shardingRule; - this.databaseType = databaseType; - this.executorEngine = executorEngine; - this.showSQL = showSQL; - this.connectionMode = connectionMode; - this.metaData = metaData; - } + private final boolean showSQL; } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java index bf3bd2ebe55c8..5c8f07d6cb78b 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java @@ -83,7 +83,7 @@ public ShardingDataSource(final Map dataSourceMap, final Sha new TableMetaDataInitializer(shardingDataSourceMetaData, executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule)); boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); shardingContext = new ShardingContext( - dataSourceMap, shardingRule, getDatabaseType(), executorEngine, new ShardingMetaData(shardingDataSourceMetaData, shardingTableMetaData), showSQL, connectionMode); + dataSourceMap, shardingRule, getDatabaseType(), executorEngine, new ShardingMetaData(shardingDataSourceMetaData, shardingTableMetaData), connectionMode, showSQL); } private static Map getDataSourceURLs(final Map dataSourceMap) { @@ -126,7 +126,7 @@ public void renew(final Map newDataSourceMap, final Sharding new TableMetaDataInitializer(shardingDataSourceMetaData, executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(newDataSourceMap)).load(newShardingRule)); shardingProperties = newShardingProperties; shardingContext = new ShardingContext( - newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, new ShardingMetaData(shardingDataSourceMetaData, shardingTableMetaData), newShowSQL, newConnectionMode); + newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, new ShardingMetaData(shardingDataSourceMetaData, shardingTableMetaData), newConnectionMode, newShowSQL); } @Override diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java index 362ade3e2b95e..ab7b7468fb9f2 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java @@ -73,7 +73,7 @@ public void setUp() { dataSourceMap.put(DS_NAME, masterSlaveDataSource); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()); ShardingMetaData shardingMetaData = mock(ShardingMetaData.class); - ShardingContext shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.H2, null, shardingMetaData, false, ConnectionMode.MEMORY_STRICTLY); + ShardingContext shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.H2, null, shardingMetaData, ConnectionMode.MEMORY_STRICTLY, false); connection = new ShardingConnection(shardingContext); } diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java index 3065e74856355..813a44896544b 100644 --- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java +++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java @@ -90,7 +90,7 @@ public void setUp() throws SQLException { dataSourceMap.put("ds_1", mockDataSource()); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()); ShardingMetaData shardingMetaData = mock(ShardingMetaData.class); - shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, shardingMetaData, true, ConnectionMode.MEMORY_STRICTLY); + shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, shardingMetaData, ConnectionMode.MEMORY_STRICTLY, true); mergeEngine = new DALMergeEngine(null, null, new ShowDatabasesStatement(), null); } diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java index b10ef3ae9d760..2df27f5a9ee5f 100644 --- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java +++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java @@ -84,7 +84,7 @@ public void setUp() throws SQLException { dataSourceMap.put("ds_1", mockDataSource()); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()); ShardingMetaData shardingMetaData = mock(ShardingMetaData.class); - shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, shardingMetaData, true, ConnectionMode.MEMORY_STRICTLY); + shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, shardingMetaData, ConnectionMode.MEMORY_STRICTLY, true); } private DataSource mockDataSource() throws SQLException { From fbdeecb24dad5a16c92ee9d17b37259c50f28a88 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 02:08:46 +0800 Subject: [PATCH 173/198] fix #1123, refactor ShardingMetaData --- .../core/metadata/ShardingMetaData.java | 16 ++++++++++++-- .../core/datasource/ShardingDataSource.java | 21 +++++++------------ .../proxy/config/RuleRegistry.java | 9 ++------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java index 3e66374f81c50..1c62465742542 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java @@ -17,21 +17,33 @@ package io.shardingsphere.core.metadata; +import com.google.common.util.concurrent.MoreExecutors; +import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData; import io.shardingsphere.core.metadata.table.ShardingTableMetaData; +import io.shardingsphere.core.metadata.table.executor.TableMetaDataConnectionManager; +import io.shardingsphere.core.metadata.table.executor.TableMetaDataInitializer; +import io.shardingsphere.core.rule.ShardingRule; import lombok.Getter; -import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.concurrent.ExecutorService; /** * Sharding meta data. * * @author zhangliang */ -@RequiredArgsConstructor @Getter public class ShardingMetaData { private final ShardingDataSourceMetaData dataSource; private final ShardingTableMetaData table; + + public ShardingMetaData(final Map dataSourceURLs, final ShardingRule shardingRule, + final DatabaseType databaseType, final ExecutorService executorService, final TableMetaDataConnectionManager connectionManager) { + dataSource = new ShardingDataSourceMetaData(dataSourceURLs, shardingRule, databaseType); + table = new ShardingTableMetaData(new TableMetaDataInitializer(dataSource, MoreExecutors.listeningDecorator(executorService), connectionManager).load(shardingRule)); + } } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java index 5c8f07d6cb78b..d67ac54bf85b9 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java @@ -32,9 +32,6 @@ import io.shardingsphere.core.jdbc.core.connection.ShardingConnection; import io.shardingsphere.core.jdbc.metadata.JDBCTableMetaDataConnectionManager; import io.shardingsphere.core.metadata.ShardingMetaData; -import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData; -import io.shardingsphere.core.metadata.table.ShardingTableMetaData; -import io.shardingsphere.core.metadata.table.executor.TableMetaDataInitializer; import io.shardingsphere.core.rule.MasterSlaveRule; import io.shardingsphere.core.rule.ShardingRule; import lombok.Getter; @@ -78,12 +75,10 @@ public ShardingDataSource(final Map dataSourceMap, final Sha int executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); ConnectionMode connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); executorEngine = ConnectionMode.MEMORY_STRICTLY == connectionMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); - ShardingDataSourceMetaData shardingDataSourceMetaData = new ShardingDataSourceMetaData(getDataSourceURLs(dataSourceMap), shardingRule, getDatabaseType()); - ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData( - new TableMetaDataInitializer(shardingDataSourceMetaData, executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(dataSourceMap)).load(shardingRule)); + ShardingMetaData shardingMetaData = new ShardingMetaData( + getDataSourceURLs(dataSourceMap), shardingRule, getDatabaseType(), executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(dataSourceMap)); boolean showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); - shardingContext = new ShardingContext( - dataSourceMap, shardingRule, getDatabaseType(), executorEngine, new ShardingMetaData(shardingDataSourceMetaData, shardingTableMetaData), connectionMode, showSQL); + shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingMetaData, connectionMode, showSQL); } private static Map getDataSourceURLs(final Map dataSourceMap) { @@ -120,13 +115,11 @@ public void renew(final Map newDataSourceMap, final Sharding executorEngine = ConnectionMode.MEMORY_STRICTLY == newConnectionMode ? new MemoryStrictlyExecutorEngine(newExecutorSize) : new ConnectionStrictlyExecutorEngine(newExecutorSize); originalExecutorEngine.close(); } - boolean newShowSQL = newShardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); - ShardingDataSourceMetaData shardingDataSourceMetaData = new ShardingDataSourceMetaData(getDataSourceURLs(newDataSourceMap), newShardingRule, getDatabaseType()); - ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData( - new TableMetaDataInitializer(shardingDataSourceMetaData, executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(newDataSourceMap)).load(newShardingRule)); shardingProperties = newShardingProperties; - shardingContext = new ShardingContext( - newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, new ShardingMetaData(shardingDataSourceMetaData, shardingTableMetaData), newConnectionMode, newShowSQL); + ShardingMetaData shardingMetaData = new ShardingMetaData( + getDataSourceURLs(newDataSourceMap), newShardingRule, getDatabaseType(), executorEngine.getExecutorService(), new JDBCTableMetaDataConnectionManager(newDataSourceMap)); + boolean newShowSQL = newShardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); + shardingContext = new ShardingContext(newDataSourceMap, newShardingRule, getDatabaseType(), executorEngine, shardingMetaData, newConnectionMode, newShowSQL); } @Override diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 54ef6e9cf685d..d31eccab5625d 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -26,9 +26,6 @@ import io.shardingsphere.core.constant.ShardingPropertiesConstant; import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.metadata.ShardingMetaData; -import io.shardingsphere.core.metadata.datasource.ShardingDataSourceMetaData; -import io.shardingsphere.core.metadata.table.ShardingTableMetaData; -import io.shardingsphere.core.metadata.table.executor.TableMetaDataInitializer; import io.shardingsphere.core.rule.DataSourceParameter; import io.shardingsphere.core.rule.MasterSlaveRule; import io.shardingsphere.core.rule.ProxyAuthority; @@ -137,10 +134,8 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { * @param executorService executor service */ public void initShardingMetaData(final ExecutorService executorService) { - ShardingDataSourceMetaData shardingDataSourceMetaData = new ShardingDataSourceMetaData(getDataSourceURLs(dataSourceConfigurationMap), shardingRule, DatabaseType.MySQL); - ShardingTableMetaData shardingTableMetaData = new ShardingTableMetaData(new TableMetaDataInitializer( - shardingDataSourceMetaData, MoreExecutors.listeningDecorator(executorService), new ProxyTableMetaDataConnectionManager(backendDataSource)).load(shardingRule)); - metaData = new ShardingMetaData(shardingDataSourceMetaData, shardingTableMetaData); + metaData = new ShardingMetaData(getDataSourceURLs(dataSourceConfigurationMap), shardingRule, DatabaseType.MySQL, + MoreExecutors.listeningDecorator(executorService), new ProxyTableMetaDataConnectionManager(backendDataSource)); } private static Map getDataSourceURLs(final Map dataSourceParameters) { From 7f544c0d597ba88d9d77b9a933d63fd56735d840 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 02:19:19 +0800 Subject: [PATCH 174/198] fix #1134, add mock-maker-inline --- .../java/io/shardingsphere/core/metadata/ShardingMetaData.java | 2 +- .../resources/mockito-extensions/org.mockito.plugins.MockMaker | 1 + .../resources/mockito-extensions/org.mockito.plugins.MockMaker | 1 + .../proxy/transport/mysql/codec/MySQLPacketCodecTest.java | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 sharding-jdbc/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker create mode 100644 sharding-opentracing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java index 1c62465742542..e5239cfdf5d7f 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java @@ -35,7 +35,7 @@ * @author zhangliang */ @Getter -public class ShardingMetaData { +public final class ShardingMetaData { private final ShardingDataSourceMetaData dataSource; diff --git a/sharding-jdbc/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/sharding-jdbc/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000000000..1f0955d450f0d --- /dev/null +++ b/sharding-jdbc/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline diff --git a/sharding-opentracing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/sharding-opentracing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000000000..1f0955d450f0d --- /dev/null +++ b/sharding-opentracing/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline diff --git a/sharding-proxy/src/test/java/io/shardingsphere/proxy/transport/mysql/codec/MySQLPacketCodecTest.java b/sharding-proxy/src/test/java/io/shardingsphere/proxy/transport/mysql/codec/MySQLPacketCodecTest.java index b4d1884ec6bb8..82720ae1a73e4 100644 --- a/sharding-proxy/src/test/java/io/shardingsphere/proxy/transport/mysql/codec/MySQLPacketCodecTest.java +++ b/sharding-proxy/src/test/java/io/shardingsphere/proxy/transport/mysql/codec/MySQLPacketCodecTest.java @@ -36,6 +36,7 @@ import static org.mockito.Mockito.when; public class MySQLPacketCodecTest { + private MySQLPacketCodec mySQLPacketCodec; private ChannelHandlerContext channelHandlerContext; From fb390c56cecba61690b54a48fe46057532a5d13f Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 02:33:19 +0800 Subject: [PATCH 175/198] for checkstyle --- .../core/constant/ShardingConstant.java | 8 ++++++-- .../integrate/asserts/meta/TableMetaDataAssert.java | 2 +- .../dbtest/engine/BatchIntegrateTest.java | 2 +- .../dbtest/engine/dcl/BaseDCLIntegrateTest.java | 2 +- .../dbtest/engine/ddl/BaseDDLIntegrateTest.java | 2 +- .../dbtest/engine/dml/BaseDMLIntegrateTest.java | 2 +- .../backend/netty/client/BackendNettyClient.java | 3 ++- .../proxy/transport/mysql/constant/ServerInfo.java | 12 ++++++++---- .../query/binary/prepare/ComStmtPrepareOKPacket.java | 4 ++-- 9 files changed, 23 insertions(+), 14 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingConstant.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingConstant.java index baad5f89c2088..1376705c99091 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingConstant.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingConstant.java @@ -17,12 +17,16 @@ package io.shardingsphere.core.constant; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + /** * Sharding constant. * * @author zhangliang */ -public interface ShardingConstant { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ShardingConstant { /** * Logic database schema name. @@ -32,5 +36,5 @@ public interface ShardingConstant { * Default: sharding_db *

*/ - String LOGIC_SCHEMA_NAME = "sharding_db"; + public static final String LOGIC_SCHEMA_NAME = "sharding_db"; } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/meta/TableMetaDataAssert.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/meta/TableMetaDataAssert.java index 17dcf1f01254c..27e618209506b 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/meta/TableMetaDataAssert.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/asserts/meta/TableMetaDataAssert.java @@ -24,7 +24,7 @@ import java.util.List; -import static org.hamcrest.core.Is.is; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BatchIntegrateTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BatchIntegrateTest.java index 6fc1db79e1346..448d3ea5ea540 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BatchIntegrateTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BatchIntegrateTest.java @@ -97,7 +97,7 @@ public static void initDatabasesAndTables() { } @AfterClass - public static void destroyDatabasesAndTables(){ + public static void destroyDatabasesAndTables() { dropDatabases(); } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dcl/BaseDCLIntegrateTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dcl/BaseDCLIntegrateTest.java index 6eb22f5717dc5..8b6965abada4f 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dcl/BaseDCLIntegrateTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dcl/BaseDCLIntegrateTest.java @@ -51,7 +51,7 @@ public static void initDatabasesAndTables() { } @AfterClass - public static void destroyDatabasesAndTables(){ + public static void destroyDatabasesAndTables() { dropDatabases(); } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/BaseDDLIntegrateTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/BaseDDLIntegrateTest.java index 330183c13d1fd..6c8104ce01564 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/BaseDDLIntegrateTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/BaseDDLIntegrateTest.java @@ -72,7 +72,7 @@ public static void initDatabases() { } @AfterClass - public static void destroyDatabasesAndTables(){ + public static void destroyDatabasesAndTables() { dropDatabases(); } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/BaseDMLIntegrateTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/BaseDMLIntegrateTest.java index 4bd329cdd49e3..1224e56fdafdd 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/BaseDMLIntegrateTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/BaseDMLIntegrateTest.java @@ -67,7 +67,7 @@ public static void initDatabasesAndTables() { } @AfterClass - public static void destroyDatabasesAndTables(){ + public static void destroyDatabasesAndTables() { dropDatabases(); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java index beaa25373fc17..98132f50d5621 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/BackendNettyClient.java @@ -128,7 +128,8 @@ private void initPoolMap(final Bootstrap bootstrap) throws InterruptedException @Override protected SimpleChannelPool newPool(final String dataSourceName) { DataSourceMetaData dataSourceMetaData = RULE_REGISTRY.getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); - return new FixedChannelPool(bootstrap.remoteAddress(dataSourceMetaData.getHostName(), dataSourceMetaData.getPort()), new BackendNettyClientChannelPoolHandler(dataSourceName), MAX_CONNECTIONS); + return new FixedChannelPool( + bootstrap.remoteAddress(dataSourceMetaData.getHostName(), dataSourceMetaData.getPort()), new BackendNettyClientChannelPoolHandler(dataSourceName), MAX_CONNECTIONS); } }; for (String each : RULE_REGISTRY.getDataSourceConfigurationMap().keySet()) { diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java index bad3e8af0fe1c..674411410f621 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/ServerInfo.java @@ -17,25 +17,29 @@ package io.shardingsphere.proxy.transport.mysql.constant; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + /** * Sharding-Proxy's information. * * @author zhangliang */ -public interface ServerInfo { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ServerInfo { /** * Protocol version is always 0x0A. */ - int PROTOCOL_VERSION = 0x0A; + public static final int PROTOCOL_VERSION = 0x0A; /** * Server version. */ - String SERVER_VERSION = "5.6.0-Sharding-Proxy 3.0.0.M3"; + public static final String SERVER_VERSION = "5.6.0-Sharding-Proxy 3.0.0.M3"; /** * Charset code 0x21 is utf8_general_ci. */ - int CHARSET = 0x21; + public static final int CHARSET = 0x21; } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/prepare/ComStmtPrepareOKPacket.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/prepare/ComStmtPrepareOKPacket.java index 0c355a9facf30..c0a21d356c5a0 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/prepare/ComStmtPrepareOKPacket.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/prepare/ComStmtPrepareOKPacket.java @@ -41,7 +41,7 @@ public final class ComStmtPrepareOKPacket implements MySQLPacket { private final int columnsCount; - private final int ParametersCount; + private final int parametersCount; private final int warningCount; @@ -52,7 +52,7 @@ public void write(final MySQLPacketPayload payload) { // TODO Set columnsCount=0 is a workaround to escape jdbc check for now, there's no issues found during a few tests. // TODO Column Definition Block should be added in future when the metadata of the columns is cached. payload.writeInt2(0); - payload.writeInt2(ParametersCount); + payload.writeInt2(parametersCount); payload.writeReserved(1); payload.writeInt2(warningCount); } From 6ea48d257dde78a57bd33aa21dd300098c95e413 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 12:28:50 +0800 Subject: [PATCH 176/198] final for all test suites --- .../src/test/java/io/shardingsphere/core/AllTests.java | 2 +- .../src/test/java/io/shardingsphere/core/api/AllApiTests.java | 2 +- .../java/io/shardingsphere/core/constant/AllConstantsTests.java | 2 +- .../src/test/java/io/shardingsphere/core/hint/AllHintTests.java | 2 +- .../test/java/io/shardingsphere/core/keygen/AllKeygenTests.java | 2 +- .../test/java/io/shardingsphere/core/merger/AllMergerTests.java | 2 +- .../merger/dql/groupby/aggregation/AllAggregationTests.java | 2 +- .../java/io/shardingsphere/core/metadata/AllMetaDataTests.java | 2 +- .../io/shardingsphere/core/optimizer/AllOptimizerTests.java | 2 +- .../java/io/shardingsphere/core/parsing/AllParsingTests.java | 2 +- .../core/parsing/integrate/AllParsingIntegrateTests.java | 2 +- .../io/shardingsphere/core/parsing/lexer/AllLexerTests.java | 2 +- .../io/shardingsphere/core/parsing/parser/sql/AllSQLTests.java | 2 +- .../core/parsing/parser/sql/AllStatementParserTests.java | 2 +- .../java/io/shardingsphere/core/rewrite/AllRewriteTests.java | 2 +- .../java/io/shardingsphere/core/routing/AllRoutingTests.java | 2 +- .../src/test/java/io/shardingsphere/core/rule/AllRuleTests.java | 2 +- .../src/test/java/io/shardingsphere/core/util/AllUtilTests.java | 2 +- .../src/test/java/io/shardingsphere/core/yaml/AllYamlTests.java | 2 +- .../test/java/io/shardingsphere/jdbc/spring/boot/AllTests.java | 2 +- .../io/shardingsphere/jdbc/orchestration/spring/AllTests.java | 2 +- .../java/io/shardingsphere/jdbc/orchestration/AllTests.java | 2 +- .../jdbc/orchestration/internal/AllInternalTests.java | 2 +- .../jdbc/orchestration/internal/jdbc/AllJdbcTests.java | 2 +- .../io/shardingsphere/jdbc/orchestration/yaml/AllYamlTests.java | 2 +- .../src/test/java/io/shardingsphere/plugin/keygen/AllTests.java | 2 +- .../test/java/io/shardingsphere/jdbc/spring/boot/AllTests.java | 2 +- .../src/test/java/io/shardingsphere/jdbc/spring/AllTests.java | 2 +- .../src/test/java/io/shardingsphere/transaction/AllTests.java | 2 +- .../shardingsphere/transaction/integrate/AllIntegrateTests.java | 2 +- .../io/shardingsphere/transaction/storage/AllStorageTest.java | 2 +- .../src/test/java/io/shardingsphere/transaction/AllTests.java | 2 +- .../src/test/java/io/shardingsphere/core/AllTests.java | 2 +- .../src/test/java/io/shardingsphere/core/AllUnitTests.java | 2 +- .../src/test/java/io/shardingsphere/core/api/AllApiTests.java | 2 +- .../java/io/shardingsphere/core/executor/AllExecutorTests.java | 2 +- .../src/test/java/io/shardingsphere/core/jdbc/AllJDBCTests.java | 2 +- .../io/shardingsphere/core/jdbc/adapter/AllAdapterTests.java | 2 +- .../java/io/shardingsphere/core/jdbc/core/AllCoreTests.java | 2 +- .../core/jdbc/unsupported/AllUnsupportedTests.java | 2 +- .../src/test/java/io/shardingsphere/core/util/AllUtilTests.java | 2 +- .../test/java/io/shardingsphere/dbtest/AllIntegrateTests.java | 2 +- .../java/io/shardingsphere/dbtest/engine/dcl/AllDCLTests.java | 2 +- .../java/io/shardingsphere/dbtest/engine/ddl/AllDDLTests.java | 2 +- .../java/io/shardingsphere/dbtest/engine/dml/AllDMLTests.java | 2 +- .../java/io/shardingsphere/dbtest/engine/dql/AllDQLTests.java | 2 +- .../src/test/java/io/shardingsphere/opentracing/AllTests.java | 2 +- .../src/test/java/io/shardingsphere/proxy/AllTests.java | 2 +- 48 files changed, 48 insertions(+), 48 deletions(-) diff --git a/sharding-core/src/test/java/io/shardingsphere/core/AllTests.java b/sharding-core/src/test/java/io/shardingsphere/core/AllTests.java index aef122d001746..09afb23ad2356 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/AllTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/AllTests.java @@ -46,5 +46,5 @@ AllHintTests.class, AllYamlTests.class }) -public class AllTests { +public final class AllTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/api/AllApiTests.java b/sharding-core/src/test/java/io/shardingsphere/core/api/AllApiTests.java index 207c5272ed9ef..2fdd3e97ceab9 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/api/AllApiTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/api/AllApiTests.java @@ -34,5 +34,5 @@ RandomMasterSlaveLoadBalanceAlgorithmTest.class, HintManagerTest.class }) -public class AllApiTests { +public final class AllApiTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/constant/AllConstantsTests.java b/sharding-core/src/test/java/io/shardingsphere/core/constant/AllConstantsTests.java index 5ed4ac0c68980..62223d688932e 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/constant/AllConstantsTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/constant/AllConstantsTests.java @@ -26,5 +26,5 @@ ShardingPropertiesConstantTest.class, ShardingPropertiesTest.class }) -public class AllConstantsTests { +public final class AllConstantsTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/hint/AllHintTests.java b/sharding-core/src/test/java/io/shardingsphere/core/hint/AllHintTests.java index 26a6f9e885bfb..043b2dc4e4827 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/hint/AllHintTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/hint/AllHintTests.java @@ -22,5 +22,5 @@ @RunWith(Suite.class) @Suite.SuiteClasses(HintManagerHolderTest.class) -public class AllHintTests { +public final class AllHintTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/keygen/AllKeygenTests.java b/sharding-core/src/test/java/io/shardingsphere/core/keygen/AllKeygenTests.java index 9646615f7f259..9469fae09217b 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/keygen/AllKeygenTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/keygen/AllKeygenTests.java @@ -25,5 +25,5 @@ DefaultKeyGeneratorTest.class, KeyGeneratorFactoryTest.class }) -public class AllKeygenTests { +public final class AllKeygenTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/merger/AllMergerTests.java b/sharding-core/src/test/java/io/shardingsphere/core/merger/AllMergerTests.java index 8a39f0f08effa..6363db9d401c3 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/merger/AllMergerTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/merger/AllMergerTests.java @@ -68,5 +68,5 @@ ShowTablesMergedResultTest.class, MergeEngineFactoryTest.class }) -public class AllMergerTests { +public final class AllMergerTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/merger/dql/groupby/aggregation/AllAggregationTests.java b/sharding-core/src/test/java/io/shardingsphere/core/merger/dql/groupby/aggregation/AllAggregationTests.java index 64735b0f888dc..c54076dd7c8d7 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/merger/dql/groupby/aggregation/AllAggregationTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/merger/dql/groupby/aggregation/AllAggregationTests.java @@ -27,5 +27,5 @@ AccumulationAggregationUnitTest.class, AverageAggregationUnitTest.class }) -public class AllAggregationTests { +public final class AllAggregationTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/metadata/AllMetaDataTests.java b/sharding-core/src/test/java/io/shardingsphere/core/metadata/AllMetaDataTests.java index 7b93141885c92..a5dc7d0435774 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/metadata/AllMetaDataTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/metadata/AllMetaDataTests.java @@ -37,5 +37,5 @@ DataSourceMetaDataFactoryTest.class, ShardingDataSourceMetaDataTest.class }) -public class AllMetaDataTests { +public final class AllMetaDataTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/optimizer/AllOptimizerTests.java b/sharding-core/src/test/java/io/shardingsphere/core/optimizer/AllOptimizerTests.java index f1028e9331c61..add2f259e4bee 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/optimizer/AllOptimizerTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/optimizer/AllOptimizerTests.java @@ -25,5 +25,5 @@ InsertOptimizeEngineTest.class, QueryOptimizeEngineTest.class }) -public class AllOptimizerTests { +public final class AllOptimizerTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/AllParsingTests.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/AllParsingTests.java index 7d699e017d860..1aef878b517dd 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/AllParsingTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/AllParsingTests.java @@ -36,5 +36,5 @@ DerivedColumnTest.class, AllParsingIntegrateTests.class }) -public class AllParsingTests { +public final class AllParsingTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/AllParsingIntegrateTests.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/AllParsingIntegrateTests.java index 7008dabba4cad..ab777b782f48c 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/AllParsingIntegrateTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/integrate/AllParsingIntegrateTests.java @@ -27,5 +27,5 @@ IntegrateSupportedSQLParsingTest.class, IntegrateUnsupportedSQLParsingTest.class }) -public class AllParsingIntegrateTests { +public final class AllParsingIntegrateTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/lexer/AllLexerTests.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/lexer/AllLexerTests.java index 31d8330b9f397..b9bb2b9e48002 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/lexer/AllLexerTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/lexer/AllLexerTests.java @@ -36,5 +36,5 @@ SQLServerLexerTest.class, PostgreSQLLexerTest.class }) -public class AllLexerTests { +public final class AllLexerTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/AllSQLTests.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/AllSQLTests.java index ccdbfa51081df..7cc2abcb5b110 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/AllSQLTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/AllSQLTests.java @@ -35,5 +35,5 @@ TCLStatementTest.class, DALStatementTest.class }) -public class AllSQLTests { +public final class AllSQLTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/AllStatementParserTests.java b/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/AllStatementParserTests.java index 6c8e08079f0b1..b170d4a5de66b 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/AllStatementParserTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/parsing/parser/sql/AllStatementParserTests.java @@ -27,5 +27,5 @@ UpdateStatementParserTest.class, DeleteStatementParserTest.class }) -public class AllStatementParserTests { +public final class AllStatementParserTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/rewrite/AllRewriteTests.java b/sharding-core/src/test/java/io/shardingsphere/core/rewrite/AllRewriteTests.java index 462ec70c67b0a..c4ed871881185 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/rewrite/AllRewriteTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/rewrite/AllRewriteTests.java @@ -26,5 +26,5 @@ SQLBuilderTest.class, SQLRewriteEngineTest.class }) -public class AllRewriteTests { +public final class AllRewriteTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/routing/AllRoutingTests.java b/sharding-core/src/test/java/io/shardingsphere/core/routing/AllRoutingTests.java index 582dbe40b62d0..3b4eb24ab8dbe 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/routing/AllRoutingTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/routing/AllRoutingTests.java @@ -26,5 +26,5 @@ DatabaseTest.class, DatabaseHintSQLRouterTest.class }) -public class AllRoutingTests { +public final class AllRoutingTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/rule/AllRuleTests.java b/sharding-core/src/test/java/io/shardingsphere/core/rule/AllRuleTests.java index 996db729ed204..de9aaf417a2ae 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/rule/AllRuleTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/rule/AllRuleTests.java @@ -29,5 +29,5 @@ BindingTableRuleTest.class, MasterSlaveRuleTest.class }) -public class AllRuleTests { +public final class AllRuleTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/util/AllUtilTests.java b/sharding-core/src/test/java/io/shardingsphere/core/util/AllUtilTests.java index 673260ef66d64..36d01b4c1a8c6 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/util/AllUtilTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/util/AllUtilTests.java @@ -27,5 +27,5 @@ InlineExpressionParserTest.class, SQLUtilTest.class }) -public class AllUtilTests { +public final class AllUtilTests { } diff --git a/sharding-core/src/test/java/io/shardingsphere/core/yaml/AllYamlTests.java b/sharding-core/src/test/java/io/shardingsphere/core/yaml/AllYamlTests.java index cdaa848040a12..1f9f238aa9b96 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/yaml/AllYamlTests.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/yaml/AllYamlTests.java @@ -36,5 +36,5 @@ YamlMasterSlaveConfigurationTest.class, YamlMasterSlaveRuleConfigurationTest.class }) -public class AllYamlTests { +public final class AllYamlTests { } diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/AllTests.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/AllTests.java index 987f6c5f190af..36bf5b3bbe5db 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/AllTests.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/AllTests.java @@ -28,5 +28,5 @@ OrchestrationSpringBootMasterSlaveTest.class, OrchestrationSpringBootShardingTest.class }) -public class AllTests { +public final class AllTests { } diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/AllTests.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/AllTests.java index 84b208f8e53fd..4dc103e791370 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/AllTests.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/AllTests.java @@ -27,5 +27,5 @@ OrchestrationShardingNamespaceTest.class, OrchestrationShardingMasterSlaveNamespaceTest.class }) -public class AllTests { +public final class AllTests { } diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/AllTests.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/AllTests.java index 32d3333885458..b4d7371d9be1b 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/AllTests.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/AllTests.java @@ -28,5 +28,5 @@ AllYamlTests.class, AllInternalTests.class }) -public class AllTests { +public final class AllTests { } diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/internal/AllInternalTests.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/internal/AllInternalTests.java index 9ab08b24299f0..ebdff181976b8 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/internal/AllInternalTests.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/internal/AllInternalTests.java @@ -23,5 +23,5 @@ @RunWith(Suite.class) @Suite.SuiteClasses(AllJdbcTests.class) -public class AllInternalTests { +public final class AllInternalTests { } diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/internal/jdbc/AllJdbcTests.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/internal/jdbc/AllJdbcTests.java index cdfc59ecfc0bf..7b4820cbaa0d9 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/internal/jdbc/AllJdbcTests.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/internal/jdbc/AllJdbcTests.java @@ -29,5 +29,5 @@ CircuitBreakerDataSourceTest.class, CircuitBreakerDatabaseMetaDataTest.class }) -public class AllJdbcTests { +public final class AllJdbcTests { } diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/AllYamlTests.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/AllYamlTests.java index 92e7243c96c0c..23e9746489628 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/AllYamlTests.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/AllYamlTests.java @@ -29,5 +29,5 @@ YamlOrchestrationMasterSlaveIntegrateTest.class, YamlOrchestrationShardingWithMasterSlaveIntegrateTest.class }) -public class AllYamlTests { +public final class AllYamlTests { } diff --git a/sharding-jdbc-plugin/src/test/java/io/shardingsphere/plugin/keygen/AllTests.java b/sharding-jdbc-plugin/src/test/java/io/shardingsphere/plugin/keygen/AllTests.java index bd79ab87971fe..da06a5cf84b7d 100644 --- a/sharding-jdbc-plugin/src/test/java/io/shardingsphere/plugin/keygen/AllTests.java +++ b/sharding-jdbc-plugin/src/test/java/io/shardingsphere/plugin/keygen/AllTests.java @@ -25,5 +25,5 @@ HostNameKeyGeneratorTest.class, IPKeyGeneratorTest.class }) -public class AllTests { +public final class AllTests { } diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/AllTests.java b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/AllTests.java index 05a5e83f31447..c62fba9e54b17 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/AllTests.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/test/java/io/shardingsphere/jdbc/spring/boot/AllTests.java @@ -28,5 +28,5 @@ SpringBootMasterSlaveTest.class, SpringBootShardingTest.class }) -public class AllTests { +public final class AllTests { } diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/AllTests.java b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/AllTests.java index 0849507daa87e..4ed6f7f1b141d 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/AllTests.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/AllTests.java @@ -44,5 +44,5 @@ MasterSlaveNamespaceTest.class, ShardingNamespaceTest.class }) -public class AllTests { +public final class AllTests { } diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/AllTests.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/AllTests.java index 2552552600cfa..dc08fccb3d456 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/AllTests.java +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/AllTests.java @@ -28,5 +28,5 @@ AllStorageTest.class, AllIntegrateTests.class }) -public class AllTests { +public final class AllTests { } diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/AllIntegrateTests.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/AllIntegrateTests.java index 52de21a92b86e..43d6f438bbdb6 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/AllIntegrateTests.java +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/AllIntegrateTests.java @@ -28,5 +28,5 @@ MemoryTransactionLogStorageOperationsTest.class, RdbTransactionLogStorageOperationsTest.class }) -public class AllIntegrateTests { +public final class AllIntegrateTests { } diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/storage/AllStorageTest.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/storage/AllStorageTest.java index 45fa15ef42720..14dd960bc3234 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/storage/AllStorageTest.java +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/storage/AllStorageTest.java @@ -28,5 +28,5 @@ MemoryTransactionLogStorageTest.class, RdbTransactionLogStorageTest.class }) -public class AllStorageTest { +public final class AllStorageTest { } diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/test/java/io/shardingsphere/transaction/AllTests.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/test/java/io/shardingsphere/transaction/AllTests.java index 0050411a4dd8f..96a3123546bce 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/test/java/io/shardingsphere/transaction/AllTests.java +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/test/java/io/shardingsphere/transaction/AllTests.java @@ -29,5 +29,5 @@ BEDSoftTransactionTest.class, SoftTransactionTest.class }) -public class AllTests { +public final class AllTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/AllTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/AllTests.java index eff3bff96223d..e67c2fbad32c3 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/AllTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/AllTests.java @@ -27,5 +27,5 @@ AllUnitTests.class, AllIntegrateTests.class }) -public class AllTests { +public final class AllTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/AllUnitTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/AllUnitTests.java index 4bec3b9aff8f4..9b613e670f106 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/AllUnitTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/AllUnitTests.java @@ -32,5 +32,5 @@ AllJDBCTests.class, AllUtilTests.class }) -public class AllUnitTests { +public final class AllUnitTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/api/AllApiTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/api/AllApiTests.java index 01923cf5c9448..146ab343c3993 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/api/AllApiTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/api/AllApiTests.java @@ -25,5 +25,5 @@ ShardingDataSourceFactoryTest.class, MasterSlaveDataSourceFactoryTest.class }) -public class AllApiTests { +public final class AllApiTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/AllExecutorTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/AllExecutorTests.java index e20e454b9f0d9..b9e5814de6d99 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/AllExecutorTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/executor/AllExecutorTests.java @@ -31,5 +31,5 @@ PreparedStatementExecutorTest.class, BatchPreparedStatementExecutorTest.class }) -public class AllExecutorTests { +public final class AllExecutorTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/AllJDBCTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/AllJDBCTests.java index 5676bffaeab0e..088a23074d05e 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/AllJDBCTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/AllJDBCTests.java @@ -29,5 +29,5 @@ AllAdapterTests.class, AllCoreTests.class }) -public class AllJDBCTests { +public final class AllJDBCTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/AllAdapterTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/AllAdapterTests.java index 294cb3ba8b37f..13050271f9d49 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/AllAdapterTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/adapter/AllAdapterTests.java @@ -33,5 +33,5 @@ JdbcMethodInvocationTest.class, SetParameterMethodInvocationTest.class }) -public class AllAdapterTests { +public final class AllAdapterTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/AllCoreTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/AllCoreTests.java index f5365aeb3dea5..e95ab08a9b5e8 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/AllCoreTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/AllCoreTests.java @@ -41,5 +41,5 @@ GeneratedKeysResultSetTest.class, GeneratedKeysResultSetMetaDataTest.class }) -public class AllCoreTests { +public final class AllCoreTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/unsupported/AllUnsupportedTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/unsupported/AllUnsupportedTests.java index 736a206c42029..41d95308a0513 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/unsupported/AllUnsupportedTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/unsupported/AllUnsupportedTests.java @@ -30,5 +30,5 @@ UnsupportedUpdateOperationResultSetTest.class, UnsupportedGeneratedKeysResultSetTest.class }) -public class AllUnsupportedTests { +public final class AllUnsupportedTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/util/AllUtilTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/util/AllUtilTests.java index c0173ce511bf9..e84e652f0a90e 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/util/AllUtilTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/util/AllUtilTests.java @@ -25,5 +25,5 @@ EventBusInstanceTest.class, DataSourceUtilTest.class }) -public class AllUtilTests { +public final class AllUtilTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/AllIntegrateTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/AllIntegrateTests.java index f8c1297b232e8..3b39b903078a5 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/AllIntegrateTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/AllIntegrateTests.java @@ -32,5 +32,5 @@ AllDDLTests.class, AllDCLTests.class }) -public class AllIntegrateTests { +public final class AllIntegrateTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dcl/AllDCLTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dcl/AllDCLTests.java index c7480b4733bb4..e917660cc7818 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dcl/AllDCLTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dcl/AllDCLTests.java @@ -23,5 +23,5 @@ @RunWith(Suite.class) @SuiteClasses(GeneralDCLIntegrateTest.class) -public class AllDCLTests { +public final class AllDCLTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/AllDDLTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/AllDDLTests.java index 800e5e2de1736..ffc13e80401ab 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/AllDDLTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/AllDDLTests.java @@ -23,5 +23,5 @@ @RunWith(Suite.class) @SuiteClasses(GeneralDDLIntegrateTest.class) -public class AllDDLTests { +public final class AllDDLTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/AllDMLTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/AllDMLTests.java index 634424cf3b988..bfc5ba62627aa 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/AllDMLTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/AllDMLTests.java @@ -27,5 +27,5 @@ BatchDMLIntegrateTest.class, AdditionalDMLIntegrateTest.class }) -public class AllDMLTests { +public final class AllDMLTests { } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dql/AllDQLTests.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dql/AllDQLTests.java index 4349ec70280e1..b1236c00f39ff 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dql/AllDQLTests.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dql/AllDQLTests.java @@ -26,5 +26,5 @@ GeneralDQLIntegrateTest.class, AdditionalDQLIntegrateTest.class }) -public class AllDQLTests { +public final class AllDQLTests { } diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/AllTests.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/AllTests.java index 15826520eb466..0a0e5d2f5a6f8 100644 --- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/AllTests.java +++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/AllTests.java @@ -31,5 +31,5 @@ MergeEventListenerTest.class, ShardingJDBCTracerTest.class }) -public class AllTests { +public final class AllTests { } diff --git a/sharding-proxy/src/test/java/io/shardingsphere/proxy/AllTests.java b/sharding-proxy/src/test/java/io/shardingsphere/proxy/AllTests.java index b69910ccb9637..980cde2332b4e 100644 --- a/sharding-proxy/src/test/java/io/shardingsphere/proxy/AllTests.java +++ b/sharding-proxy/src/test/java/io/shardingsphere/proxy/AllTests.java @@ -36,5 +36,5 @@ HandshakeResponse41PacketTest.class, RandomGeneratorTest.class }) -public class AllTests { +public final class AllTests { } From 18971b960b54f8173b137ce699d624d07ad17a1b Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 12:44:22 +0800 Subject: [PATCH 177/198] checkstyle for HideUtilityClassConstructor --- .../alter/table/AbstractAlterTableParser.java | 2 +- .../spring/boot/util/PropertyUtil.java | 16 +++++++++------- .../parser/ShardingStrategyBeanDefinition.java | 2 +- .../ShardingConfigurationConverter.java | 2 +- .../client/zookeeper/section/Connection.java | 3 +++ .../client/zookeeper/section/WatcherCreator.java | 5 ++++- .../newzk/client/zookeeper/base/TestSupport.java | 5 ++++- .../jdbc/spring/boot/util/PropertyUtil.java | 16 +++++++++------- .../parser/ShardingStrategyBeanDefinition.java | 2 +- .../job/BASETransactionJobBootStrap.java | 3 +++ .../transaction/xa/AtomikosUserTransaction.java | 3 +++ .../io/shardingsphere/core/jdbc/JDBCTestSQL.java | 6 +++++- .../core/jdbc/util/JDBCTestSQL.java | 8 +++++--- .../engine/util/IntegrateTestParameters.java | 3 +++ .../java/io/shardingsphere/proxy/Bootstrap.java | 8 +++++--- .../packet/command/CommandPacketFactory.java | 9 ++++++--- src/resources/sharding_checks.xml | 4 +++- 17 files changed, 66 insertions(+), 31 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java index d0695e3068f89..eb99cd4fb442b 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java @@ -49,7 +49,7 @@ public AbstractAlterTableParser(final ShardingRule shardingRule, final LexerEngi } @Override - public DDLStatement parse() { + public final DDLStatement parse() { lexerEngine.unsupportedIfNotSkip(DefaultKeyword.TABLE); lexerEngine.skipAll(getSkippedKeywordsBetweenAlterTableAndTableName()); DDLStatement result = new DDLStatement(); diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/orchestration/spring/boot/util/PropertyUtil.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/orchestration/spring/boot/util/PropertyUtil.java index adc74df4ca0e4..700841b6c4820 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/orchestration/spring/boot/util/PropertyUtil.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/orchestration/spring/boot/util/PropertyUtil.java @@ -17,6 +17,13 @@ package io.shardingsphere.jdbc.orchestration.spring.boot.util; +import io.shardingsphere.core.exception.ShardingException; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.springframework.beans.factory.config.PlaceholderConfigurerSupport; +import org.springframework.core.env.Environment; +import org.springframework.core.env.PropertyResolver; + import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -24,13 +31,8 @@ import java.util.HashMap; import java.util.Map; -import org.springframework.beans.factory.config.PlaceholderConfigurerSupport; -import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertyResolver; - -import io.shardingsphere.core.exception.ShardingException; - -public class PropertyUtil { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class PropertyUtil { private static int springBootVersion = 1; diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/ShardingStrategyBeanDefinition.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/ShardingStrategyBeanDefinition.java index 5177eef3cc7f3..a991c002372dc 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/ShardingStrategyBeanDefinition.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/ShardingStrategyBeanDefinition.java @@ -37,7 +37,7 @@ * @author caohao */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ShardingStrategyBeanDefinition { +public final class ShardingStrategyBeanDefinition { static AbstractBeanDefinition getBeanDefinitionByElement(final Element element) { String type = element.getLocalName(); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/converter/ShardingConfigurationConverter.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/converter/ShardingConfigurationConverter.java index 23160eb84fbd9..771f7e844ad23 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/converter/ShardingConfigurationConverter.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/converter/ShardingConfigurationConverter.java @@ -35,7 +35,7 @@ */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ShardingConfigurationConverter { +public final class ShardingConfigurationConverter { private static final Yaml YAML = new Yaml(new DefaultConfigurationRepresenter()); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/Connection.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/Connection.java index c384f5b6fc0b7..6e67b89f76383 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/Connection.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/Connection.java @@ -17,6 +17,8 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.zookeeper.KeeperException; import java.util.Map; @@ -27,6 +29,7 @@ * * @author lidongbo */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class Connection { //is need reset diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/WatcherCreator.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/WatcherCreator.java index 7cb165b873e41..17ec47f1adb79 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/WatcherCreator.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/WatcherCreator.java @@ -17,6 +17,8 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; @@ -26,8 +28,9 @@ * * @author lidongbo */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) @Slf4j -public class WatcherCreator { +public final class WatcherCreator { /** * Get string type data. diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestSupport.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestSupport.java index 72753f1111f70..f4fdf081c1c22 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestSupport.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestSupport.java @@ -18,11 +18,14 @@ package io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.base; import io.shardingsphere.jdbc.orchestration.reg.newzk.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 class TestSupport { +public final class TestSupport { public static final String AUTH = "digest"; diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/spring/boot/util/PropertyUtil.java b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/spring/boot/util/PropertyUtil.java index e6943dc5cb889..2d2979f7abd3a 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/spring/boot/util/PropertyUtil.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/spring/boot/util/PropertyUtil.java @@ -17,6 +17,13 @@ package io.shardingsphere.jdbc.spring.boot.util; +import io.shardingsphere.core.exception.ShardingException; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.springframework.beans.factory.config.PlaceholderConfigurerSupport; +import org.springframework.core.env.Environment; +import org.springframework.core.env.PropertyResolver; + import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -24,13 +31,8 @@ import java.util.HashMap; import java.util.Map; -import org.springframework.beans.factory.config.PlaceholderConfigurerSupport; -import org.springframework.core.env.Environment; -import org.springframework.core.env.PropertyResolver; - -import io.shardingsphere.core.exception.ShardingException; - -public class PropertyUtil { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class PropertyUtil { private static int springBootVersion = 1; diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingStrategyBeanDefinition.java b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingStrategyBeanDefinition.java index 6e013dd5c705e..d73409870080a 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingStrategyBeanDefinition.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingStrategyBeanDefinition.java @@ -37,7 +37,7 @@ * @author caohao */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ShardingStrategyBeanDefinition { +public final class ShardingStrategyBeanDefinition { static AbstractBeanDefinition getBeanDefinitionByElement(final Element element) { String type = element.getLocalName(); diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/src/main/java/io/shardingsphere/transaction/job/BASETransactionJobBootStrap.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/src/main/java/io/shardingsphere/transaction/job/BASETransactionJobBootStrap.java index f3ab3055f2c06..d1214ca1d6372 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/src/main/java/io/shardingsphere/transaction/job/BASETransactionJobBootStrap.java +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-async-job/src/main/java/io/shardingsphere/transaction/job/BASETransactionJobBootStrap.java @@ -17,6 +17,8 @@ package io.shardingsphere.transaction.job; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.quartz.SchedulerException; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; @@ -31,6 +33,7 @@ * @author caohao * @author wangkai */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class BASETransactionJobBootStrap { /** diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java index bd05b40e2ee29..b6cf99367ccd2 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/src/main/java/io/shardingsphere/transaction/xa/AtomikosUserTransaction.java @@ -18,12 +18,15 @@ package io.shardingsphere.transaction.xa; import com.atomikos.icatch.jta.UserTransactionManager; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; /** * Hold singleton atomikos userTransaction. * * @author zhaojun */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class AtomikosUserTransaction { // TODO why not new here? diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/JDBCTestSQL.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/JDBCTestSQL.java index c67c20fdd2571..7e68845f0442e 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/JDBCTestSQL.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/JDBCTestSQL.java @@ -17,7 +17,11 @@ package io.shardingsphere.core.jdbc; -public class JDBCTestSQL { +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class JDBCTestSQL { public static final String INSERT_ORDER_ITEM_WITH_ALL_PLACEHOLDERS_SQL = "INSERT INTO t_order_item (item_id, order_id, user_id, status) VALUES (?, ?, ?, ?)"; diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/util/JDBCTestSQL.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/util/JDBCTestSQL.java index 3bada5821deea..d6c8714972b0c 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/util/JDBCTestSQL.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/util/JDBCTestSQL.java @@ -17,11 +17,13 @@ package io.shardingsphere.core.jdbc.util; -public class JDBCTestSQL { +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class JDBCTestSQL { public static final String SELECT_GROUP_BY_USER_ID_SQL = "SELECT user_id FROM t_order GROUP BY user_id"; public static final String SELECT_ORDER_BY_USER_ID_SQL = "SELECT user_id FROM t_order WHERE status = 'init' ORDER BY user_id"; - - public static final String SELECT_COUNT_ALIAS_SQL = "SELECT COUNT(*) AS orders_count FROM t_order"; } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/util/IntegrateTestParameters.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/util/IntegrateTestParameters.java index da351ee0cbaca..f8b2c2de09799 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/util/IntegrateTestParameters.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/util/IntegrateTestParameters.java @@ -27,6 +27,8 @@ import io.shardingsphere.dbtest.env.IntegrateTestEnvironment; import io.shardingsphere.test.sql.SQLCaseType; import io.shardingsphere.test.sql.SQLCasesLoader; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import java.util.Arrays; import java.util.Collection; @@ -39,6 +41,7 @@ * @author zhangliang * @author panjuan */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class IntegrateTestParameters { private static SQLCasesLoader sqlCasesLoader = SQLCasesLoader.getInstance(); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/Bootstrap.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/Bootstrap.java index 52d90233e566b..1ada19b7c21bc 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/Bootstrap.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/Bootstrap.java @@ -25,6 +25,8 @@ import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusInstance; import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.frontend.ShardingProxy; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; @@ -32,7 +34,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.net.MalformedURLException; /** * Sharding-Proxy Bootstrap. @@ -41,6 +42,7 @@ * @author wangkai * @author panjuan */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class Bootstrap { private static final int DEFAULT_PORT = 3307; @@ -101,12 +103,12 @@ private static String getConfig(final String[] args) { return DEFAULT_CONFIG_PATH + args[1]; } - private static void startWithoutRegistryCenter(final OrchestrationProxyConfiguration config, final int port) throws InterruptedException, MalformedURLException { + private static void startWithoutRegistryCenter(final OrchestrationProxyConfiguration config, final int port) throws InterruptedException { RULE_REGISTRY.init(config); new ShardingProxy().start(port); } - private static void startWithRegistryCenter(final OrchestrationProxyConfiguration localConfig, final int port) throws InterruptedException, MalformedURLException { + private static void startWithRegistryCenter(final OrchestrationProxyConfiguration localConfig, final int port) throws InterruptedException { try (OrchestrationFacade orchestrationFacade = new OrchestrationFacade(localConfig.getOrchestration().getOrchestrationConfiguration())) { if (null != localConfig.getShardingRule() || null != localConfig.getMasterSlaveRule()) { orchestrationFacade.init(localConfig); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/CommandPacketFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/CommandPacketFactory.java index 86ef0d4c435b3..e186f1e07eb69 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/CommandPacketFactory.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/CommandPacketFactory.java @@ -20,14 +20,16 @@ import io.shardingsphere.proxy.backend.jdbc.connection.BackendConnection; import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload; import io.shardingsphere.proxy.transport.mysql.packet.command.admin.UnsupportedCommandPacket; +import io.shardingsphere.proxy.transport.mysql.packet.command.admin.initdb.ComInitDbPacket; +import io.shardingsphere.proxy.transport.mysql.packet.command.admin.ping.ComPingPacket; +import io.shardingsphere.proxy.transport.mysql.packet.command.admin.quit.ComQuitPacket; import io.shardingsphere.proxy.transport.mysql.packet.command.query.binary.close.ComStmtClosePacket; import io.shardingsphere.proxy.transport.mysql.packet.command.query.binary.execute.ComStmtExecutePacket; import io.shardingsphere.proxy.transport.mysql.packet.command.query.binary.prepare.ComStmtPreparePacket; import io.shardingsphere.proxy.transport.mysql.packet.command.query.text.fieldlist.ComFieldListPacket; -import io.shardingsphere.proxy.transport.mysql.packet.command.admin.initdb.ComInitDbPacket; -import io.shardingsphere.proxy.transport.mysql.packet.command.admin.ping.ComPingPacket; import io.shardingsphere.proxy.transport.mysql.packet.command.query.text.query.ComQueryPacket; -import io.shardingsphere.proxy.transport.mysql.packet.command.admin.quit.ComQuitPacket; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; /** * Command packet factory. @@ -35,6 +37,7 @@ * @author zhangliang * @author wangkai */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class CommandPacketFactory { /** diff --git a/src/resources/sharding_checks.xml b/src/resources/sharding_checks.xml index 90f0c09fa663c..a9c9f75972a5c 100644 --- a/src/resources/sharding_checks.xml +++ b/src/resources/sharding_checks.xml @@ -180,8 +180,10 @@ - + + + From e20816a66f39896129e8dd77a4f0f35bafafc08a Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 13:10:57 +0800 Subject: [PATCH 178/198] checkstyle for DesignForExtension 1 --- .../dialect/mysql/sql/MySQLAlterTableParser.java | 6 ++++++ .../dialect/mysql/sql/MySQLCreateIndexParser.java | 5 +++++ .../parser/dialect/mysql/sql/MySQLDeleteParser.java | 5 +++++ .../dialect/mysql/sql/MySQLDropIndexParser.java | 5 +++++ .../dialect/oracle/sql/OracleAlterTableParser.java | 6 ++++++ .../dialect/oracle/sql/OracleCreateIndexParser.java | 5 +++++ .../dialect/oracle/sql/OracleCreateTableParser.java | 5 +++++ .../parser/dialect/oracle/sql/OracleDeleteParser.java | 7 ++++++- .../dialect/oracle/sql/OracleDropIndexParser.java | 11 +++++++++++ .../dialect/oracle/sql/OracleDropTableParser.java | 5 +++++ .../postgresql/sql/PostgreSQLCreateTableParser.java | 5 +++++ .../postgresql/sql/PostgreSQLDeleteParser.java | 5 +++++ .../postgresql/sql/PostgreSQLDropIndexParser.java | 5 +++++ .../postgresql/sql/PostgreSQLDropTableParser.java | 7 ++++++- .../sqlserver/sql/SQLServerAlterTableParser.java | 6 ++++++ .../sqlserver/sql/SQLServerCreateIndexParser.java | 5 +++++ .../sqlserver/sql/SQLServerCreateTableParser.java | 5 +++++ .../sqlserver/sql/SQLServerDropIndexParser.java | 11 +++++++++++ .../sqlserver/sql/SQLServerDropTableParser.java | 5 +++++ .../sql/ddl/alter/table/AbstractAlterTableParser.java | 4 +--- .../ddl/create/index/AbstractCreateIndexParser.java | 6 ++---- .../ddl/create/table/AbstractCreateTableParser.java | 6 ++---- .../sql/ddl/drop/index/AbstractDropIndexParser.java | 10 +++------- .../sql/ddl/drop/table/AbstractDropTableParser.java | 6 ++---- .../parser/sql/dml/delete/AbstractDeleteParser.java | 6 ++---- .../AbstractTransactionLogStorageOperationsTest.java | 2 +- .../RdbTransactionLogStorageOperationsTest.java | 3 +-- .../core/jdbc/adapter/AbstractConnectionAdapter.java | 6 +++--- .../core/jdbc/adapter/AbstractDataSourceAdapter.java | 2 +- .../AbstractMasterSlavePreparedStatementAdapter.java | 10 +++++----- 30 files changed, 135 insertions(+), 40 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLAlterTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLAlterTableParser.java index e9d94731ce5cf..215241f6fc819 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLAlterTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLAlterTableParser.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.parsing.parser.dialect.mysql.sql; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.sql.ddl.alter.table.AbstractAlterTableParser; import io.shardingsphere.core.rule.ShardingRule; @@ -32,4 +33,9 @@ public final class MySQLAlterTableParser extends AbstractAlterTableParser { public MySQLAlterTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); } + + @Override + protected Keyword[] getSkippedKeywordsBetweenAlterTableAndTableName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateIndexParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateIndexParser.java index 1e100d632197b..fd5ac103c7e4f 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateIndexParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateIndexParser.java @@ -45,4 +45,9 @@ protected Keyword[] getSkippedKeywordsBetweenCreateAndKeyword() { protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() { return new Keyword[] {DefaultKeyword.UNIQUE, DefaultKeyword.FULLTEXT, MySQLKeyword.SPATIAL}; } + + @Override + protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndIndexName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDeleteParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDeleteParser.java index a26a2a701d65b..224576bc31ab4 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDeleteParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDeleteParser.java @@ -40,4 +40,9 @@ public MySQLDeleteParser(final ShardingRule shardingRule, final LexerEngine lexe protected Keyword[] getSkippedKeywordsBetweenDeleteAndTable() { return new Keyword[] {MySQLKeyword.LOW_PRIORITY, MySQLKeyword.QUICK, MySQLKeyword.IGNORE, DefaultKeyword.FROM}; } + + @Override + protected Keyword[] getUnsupportedKeywordsBetweenDeleteAndTable() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDropIndexParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDropIndexParser.java index 3e8971c16fe23..1bc76de30e0e3 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDropIndexParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDropIndexParser.java @@ -39,4 +39,9 @@ public MySQLDropIndexParser(final ShardingRule shardingRule, final LexerEngine l protected Keyword[] getSkippedKeywordsBetweenDropAndTable() { return new Keyword[] {DefaultKeyword.TEMPORARY}; } + + @Override + protected Keyword[] getSkippedKeywordsBetweenDropIndexAndIndexName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleAlterTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleAlterTableParser.java index e80663d0d835b..a2535f5fce172 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleAlterTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleAlterTableParser.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.parsing.parser.dialect.oracle.sql; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.sql.ddl.alter.table.AbstractAlterTableParser; import io.shardingsphere.core.rule.ShardingRule; @@ -32,4 +33,9 @@ public final class OracleAlterTableParser extends AbstractAlterTableParser { public OracleAlterTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); } + + @Override + protected Keyword[] getSkippedKeywordsBetweenAlterTableAndTableName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateIndexParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateIndexParser.java index 7ccfc07e781f4..6bdd904dc6e98 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateIndexParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateIndexParser.java @@ -44,4 +44,9 @@ protected Keyword[] getSkippedKeywordsBetweenCreateAndKeyword() { protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() { return new Keyword[] {DefaultKeyword.UNIQUE, DefaultKeyword.BITMAP}; } + + @Override + protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndIndexName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateTableParser.java index 0985718f234cb..74b0b58d4e1d1 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateTableParser.java @@ -49,4 +49,9 @@ protected Keyword[] getSkippedKeywordsBetweenCreateTableAndTableName() { protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() { return new Keyword[] {DefaultKeyword.UNIQUE, DefaultKeyword.BITMAP}; } + + @Override + protected Keyword[] getSkippedKeywordsBeforeTableConstraint() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDeleteParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDeleteParser.java index d3c0699453652..4a34c0bb071a0 100755 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDeleteParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDeleteParser.java @@ -29,7 +29,7 @@ * * @author zhangliang */ -public class OracleDeleteParser extends AbstractDeleteParser { +public final class OracleDeleteParser extends AbstractDeleteParser { public OracleDeleteParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine, new OracleDeleteClauseParserFacade(shardingRule, lexerEngine)); @@ -39,4 +39,9 @@ public OracleDeleteParser(final ShardingRule shardingRule, final LexerEngine lex protected Keyword[] getSkippedKeywordsBetweenDeleteAndTable() { return new Keyword[] {DefaultKeyword.FROM}; } + + @Override + protected Keyword[] getUnsupportedKeywordsBetweenDeleteAndTable() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropIndexParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropIndexParser.java index 42a2f36e15d6c..fecafc3bf4dd9 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropIndexParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropIndexParser.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.parsing.parser.dialect.oracle.sql; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.sql.ddl.drop.index.AbstractDropIndexParser; import io.shardingsphere.core.rule.ShardingRule; @@ -32,4 +33,14 @@ public final class OracleDropIndexParser extends AbstractDropIndexParser { public OracleDropIndexParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); } + + @Override + protected Keyword[] getSkippedKeywordsBetweenDropAndTable() { + return new Keyword[0]; + } + + @Override + protected Keyword[] getSkippedKeywordsBetweenDropIndexAndIndexName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropTableParser.java index 08fb1c4caafa6..707df23819c3e 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropTableParser.java @@ -34,6 +34,11 @@ public OracleDropTableParser(final ShardingRule shardingRule, final LexerEngine super(shardingRule, lexerEngine); } + @Override + protected Keyword[] getSkippedKeywordsBetweenDropAndTable() { + return new Keyword[0]; + } + @Override protected Keyword[] getSkippedKeywordsBetweenDropTableAndTableName() { return new Keyword[] {}; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLCreateTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLCreateTableParser.java index 700a6e484d4f7..90e2d9d52da05 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLCreateTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLCreateTableParser.java @@ -50,4 +50,9 @@ protected Keyword[] getSkippedKeywordsBetweenCreateTableAndTableName() { protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() { return new Keyword[] {DefaultKeyword.UNIQUE}; } + + @Override + protected Keyword[] getSkippedKeywordsBeforeTableConstraint() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDeleteParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDeleteParser.java index 8277137a603a7..f2b21c524e0ac 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDeleteParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDeleteParser.java @@ -40,4 +40,9 @@ public PostgreSQLDeleteParser(final ShardingRule shardingRule, final LexerEngine protected Keyword[] getSkippedKeywordsBetweenDeleteAndTable() { return new Keyword[] {DefaultKeyword.FROM, PostgreSQLKeyword.ONLY}; } + + @Override + protected Keyword[] getUnsupportedKeywordsBetweenDeleteAndTable() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropIndexParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropIndexParser.java index 489dcca85c099..0a6c4596ef724 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropIndexParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropIndexParser.java @@ -39,4 +39,9 @@ public PostgreSQLDropIndexParser(final ShardingRule shardingRule, final LexerEng protected Keyword[] getSkippedKeywordsBetweenDropIndexAndIndexName() { return new Keyword[] {DefaultKeyword.IF, DefaultKeyword.EXISTS}; } + + @Override + protected Keyword[] getSkippedKeywordsBetweenDropAndTable() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropTableParser.java index 984cc84317f00..69da3feee7b2c 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropTableParser.java @@ -34,7 +34,12 @@ public final class PostgreSQLDropTableParser extends AbstractDropTableParser { public PostgreSQLDropTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); } - + + @Override + protected Keyword[] getSkippedKeywordsBetweenDropAndTable() { + return new Keyword[0]; + } + @Override protected Keyword[] getSkippedKeywordsBetweenDropTableAndTableName() { return new Keyword[] {DefaultKeyword.IF, DefaultKeyword.EXISTS}; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerAlterTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerAlterTableParser.java index 961b0d4227395..bbfdab6cf7005 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerAlterTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerAlterTableParser.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.sql.ddl.alter.table.AbstractAlterTableParser; import io.shardingsphere.core.rule.ShardingRule; @@ -32,4 +33,9 @@ public final class SQLServerAlterTableParser extends AbstractAlterTableParser { public SQLServerAlterTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); } + + @Override + protected Keyword[] getSkippedKeywordsBetweenAlterTableAndTableName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateIndexParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateIndexParser.java index a6074dad18392..c929c72e5186a 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateIndexParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateIndexParser.java @@ -44,4 +44,9 @@ protected Keyword[] getSkippedKeywordsBetweenCreateAndKeyword() { protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() { return new Keyword[] {DefaultKeyword.UNIQUE, DefaultKeyword.FULLTEXT}; } + + @Override + protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndIndexName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateTableParser.java index d65ccdb351176..62225f364ff43 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateTableParser.java @@ -49,4 +49,9 @@ protected Keyword[] getSkippedKeywordsBetweenCreateTableAndTableName() { protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() { return new Keyword[] {DefaultKeyword.UNIQUE, DefaultKeyword.FULLTEXT}; } + + @Override + protected Keyword[] getSkippedKeywordsBeforeTableConstraint() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerDropIndexParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerDropIndexParser.java index 75c79fa735869..0cd17fa06a029 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerDropIndexParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerDropIndexParser.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.sql.ddl.drop.index.AbstractDropIndexParser; import io.shardingsphere.core.rule.ShardingRule; @@ -32,4 +33,14 @@ public final class SQLServerDropIndexParser extends AbstractDropIndexParser { public SQLServerDropIndexParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); } + + @Override + protected Keyword[] getSkippedKeywordsBetweenDropAndTable() { + return new Keyword[0]; + } + + @Override + protected Keyword[] getSkippedKeywordsBetweenDropIndexAndIndexName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerDropTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerDropTableParser.java index aa64aacfcf4ee..83bdcb432d47f 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerDropTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerDropTableParser.java @@ -35,6 +35,11 @@ public SQLServerDropTableParser(final ShardingRule shardingRule, final LexerEngi super(shardingRule, lexerEngine); } + @Override + protected Keyword[] getSkippedKeywordsBetweenDropAndTable() { + return new Keyword[0]; + } + @Override protected Keyword[] getSkippedKeywordsBetweenDropTableAndTableName() { return new Keyword[] {DefaultKeyword.IF, DefaultKeyword.EXISTS}; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java index eb99cd4fb442b..13bac516e209c 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java @@ -57,7 +57,5 @@ public final DDLStatement parse() { return result; } - protected Keyword[] getSkippedKeywordsBetweenAlterTableAndTableName() { - return new Keyword[0]; - } + protected abstract Keyword[] getSkippedKeywordsBetweenAlterTableAndTableName(); } 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 ffc8d80499718..8282df1aa7e93 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 @@ -52,7 +52,7 @@ public AbstractCreateIndexParser(final ShardingRule shardingRule, final LexerEng } @Override - public DDLStatement parse() { + public final DDLStatement parse() { lexerEngine.skipAll(getSkippedKeywordsBetweenCreateIndexAndKeyword()); lexerEngine.skipAll(getSkippedKeywordsBetweenCreateAndKeyword()); DDLStatement result = new DDLStatement(); @@ -70,9 +70,7 @@ public DDLStatement parse() { protected abstract Keyword[] getSkippedKeywordsBetweenCreateAndKeyword(); - protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndIndexName() { - return new Keyword[] {}; - } + protected abstract Keyword[] getSkippedKeywordsBetweenCreateIndexAndIndexName(); private void parseIndex(final DDLStatement ddlStatement) { Token currentToken = lexerEngine.getCurrentToken(); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java index 70e14f168ad3a..ea32cf684a4a8 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java @@ -54,7 +54,7 @@ public AbstractCreateTableParser(final ShardingRule shardingRule, final LexerEng } @Override - public DDLStatement parse() { + public final DDLStatement parse() { lexerEngine.skipAll(getSkippedKeywordsBetweenCreateIndexAndKeyword()); lexerEngine.skipAll(getSkippedKeywordsBetweenCreateAndKeyword()); CreateTableStatement result = new CreateTableStatement(); @@ -109,9 +109,7 @@ private void parseDataType(final CreateTableStatement statement) { lexerEngine.skipParentheses(statement); } - protected Keyword[] getSkippedKeywordsBeforeTableConstraint() { - return new Keyword[0]; - } + protected abstract Keyword[] getSkippedKeywordsBeforeTableConstraint(); private void parseTableConstraint(final CreateTableStatement statement) { Collection columnNames = new LinkedList<>(); 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 12fcab6c58b6a..cad59726011e8 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 @@ -52,7 +52,7 @@ public AbstractDropIndexParser(final ShardingRule shardingRule, final LexerEngin } @Override - public DDLStatement parse() { + public final DDLStatement parse() { lexerEngine.skipAll(getSkippedKeywordsBetweenDropAndTable()); DDLStatement result = new DDLStatement(); if (lexerEngine.skipIfEqual(DefaultKeyword.INDEX)) { @@ -64,13 +64,9 @@ public DDLStatement parse() { return result; } - protected Keyword[] getSkippedKeywordsBetweenDropAndTable() { - return new Keyword[0]; - } + protected abstract Keyword[] getSkippedKeywordsBetweenDropAndTable(); - protected Keyword[] getSkippedKeywordsBetweenDropIndexAndIndexName() { - return new Keyword[] {}; - } + protected abstract Keyword[] getSkippedKeywordsBetweenDropIndexAndIndexName(); private void parseIndex(final DDLStatement ddlStatement) { Token currentToken = lexerEngine.getCurrentToken(); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/AbstractDropTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/AbstractDropTableParser.java index d7dc0207882e0..bcd8d169153f6 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/AbstractDropTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/AbstractDropTableParser.java @@ -50,7 +50,7 @@ public AbstractDropTableParser(final ShardingRule shardingRule, final LexerEngin } @Override - public DDLStatement parse() { + public final DDLStatement parse() { lexerEngine.skipAll(getSkippedKeywordsBetweenDropAndTable()); DropTableStatement result = new DropTableStatement(); if (lexerEngine.skipIfEqual(DefaultKeyword.TABLE)) { @@ -62,9 +62,7 @@ public DDLStatement parse() { return result; } - protected Keyword[] getSkippedKeywordsBetweenDropAndTable() { - return new Keyword[0]; - } + protected abstract Keyword[] getSkippedKeywordsBetweenDropAndTable(); protected abstract Keyword[] getSkippedKeywordsBetweenDropTableAndTableName(); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/delete/AbstractDeleteParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/delete/AbstractDeleteParser.java index 34dc5a9853ff6..68ec76580b680 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/delete/AbstractDeleteParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/delete/AbstractDeleteParser.java @@ -44,7 +44,7 @@ public abstract class AbstractDeleteParser implements SQLParser { private final AbstractDeleteClauseParserFacade deleteClauseParserFacade; @Override - public DMLStatement parse() { + public final DMLStatement parse() { lexerEngine.nextToken(); lexerEngine.skipAll(getSkippedKeywordsBetweenDeleteAndTable()); lexerEngine.unsupportedIfEqual(getUnsupportedKeywordsBetweenDeleteAndTable()); @@ -57,7 +57,5 @@ public DMLStatement parse() { protected abstract Keyword[] getSkippedKeywordsBetweenDeleteAndTable(); - protected Keyword[] getUnsupportedKeywordsBetweenDeleteAndTable() { - return new Keyword[0]; - } + protected abstract Keyword[] getUnsupportedKeywordsBetweenDeleteAndTable(); } diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/storage/AbstractTransactionLogStorageOperationsTest.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/storage/AbstractTransactionLogStorageOperationsTest.java index 4bb4ac03363eb..c2f5bfd534d71 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/storage/AbstractTransactionLogStorageOperationsTest.java +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/storage/AbstractTransactionLogStorageOperationsTest.java @@ -29,7 +29,7 @@ public abstract class AbstractTransactionLogStorageOperationsTest { - protected void assertTransactionLogStorageOperations(final TransactionLogStorage storage) { + protected final void assertTransactionLogStorageOperations(final TransactionLogStorage storage) { String id = UUID.randomUUID().toString(); String transactionId = UUID.randomUUID().toString(); TransactionLog transactionLog = new TransactionLog(id, transactionId, SoftTransactionType.BestEffortsDelivery, diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/storage/RdbTransactionLogStorageOperationsTest.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/storage/RdbTransactionLogStorageOperationsTest.java index 74cf013e112ea..814facb811bce 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/storage/RdbTransactionLogStorageOperationsTest.java +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/test/java/io/shardingsphere/transaction/integrate/storage/RdbTransactionLogStorageOperationsTest.java @@ -51,8 +51,7 @@ private void createTable(final DataSource dataSource) throws SQLException { + "`creation_time` LONG NOT NULL, " + "`async_delivery_try_times` INT NOT NULL DEFAULT 0, " + "PRIMARY KEY (`id`));"; - try ( - Connection conn = dataSource.getConnection(); + try (Connection conn = dataSource.getConnection(); PreparedStatement preparedStatement = conn.prepareStatement(dbSchema)) { preparedStatement.executeUpdate(); } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index c320fec3622e3..8138f0c7ebe5a 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -77,7 +77,7 @@ public final Connection getConnection(final String dataSourceName) throws SQLExc protected abstract Map getDataSourceMap(); - protected void removeCache(final Connection connection) { + protected final void removeCache(final Connection connection) { cachedConnections.remove(connection); } @@ -105,7 +105,7 @@ public final void rollback() { } @Override - public void close() throws SQLException { + public final void close() throws SQLException { closed = true; HintManagerHolder.clear(); MasterVisitedManager.clear(); @@ -159,7 +159,7 @@ public final void setTransactionIsolation(final int level) throws SQLException { // ------- Consist with MySQL driver implementation ------- @Override - public SQLWarning getWarnings() { + public final SQLWarning getWarnings() { return null; } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java index a078f0912180d..1effc0e33c1dd 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java @@ -50,7 +50,7 @@ public AbstractDataSourceAdapter(final Collection dataSources) throw databaseType = getDatabaseType(dataSources); } - protected DatabaseType getDatabaseType(final Collection dataSources) throws SQLException { + protected final DatabaseType getDatabaseType(final Collection dataSources) throws SQLException { DatabaseType result = null; for (DataSource each : dataSources) { DatabaseType databaseType = getDatabaseType(each); diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractMasterSlavePreparedStatementAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractMasterSlavePreparedStatementAdapter.java index dee14ffa422de..7d40b5fd8344b 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractMasterSlavePreparedStatementAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractMasterSlavePreparedStatementAdapter.java @@ -213,27 +213,27 @@ public final void setCharacterStream(final int parameterIndex, final Reader x, f } @Override - public void setSQLXML(final int parameterIndex, final SQLXML x) throws SQLException { + public final void setSQLXML(final int parameterIndex, final SQLXML x) throws SQLException { getTargetPreparedStatement().setSQLXML(parameterIndex, x); } @Override - public void setURL(final int parameterIndex, final URL x) throws SQLException { + public final void setURL(final int parameterIndex, final URL x) throws SQLException { getTargetPreparedStatement().setURL(parameterIndex, x); } @Override - public void setObject(final int parameterIndex, final Object x) throws SQLException { + public final void setObject(final int parameterIndex, final Object x) throws SQLException { getTargetPreparedStatement().setObject(parameterIndex, x); } @Override - public void setObject(final int parameterIndex, final Object x, final int targetSqlType) throws SQLException { + public final void setObject(final int parameterIndex, final Object x, final int targetSqlType) throws SQLException { getTargetPreparedStatement().setObject(parameterIndex, x, targetSqlType); } @Override - public void setObject(final int parameterIndex, final Object x, final int targetSqlType, final int scaleOrLength) throws SQLException { + public final void setObject(final int parameterIndex, final Object x, final int targetSqlType, final int scaleOrLength) throws SQLException { getTargetPreparedStatement().setObject(parameterIndex, x, targetSqlType, scaleOrLength); } From c9d98c8c3b6ac70b713108b9f252cfdbb43691d5 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 13:38:25 +0800 Subject: [PATCH 179/198] checkstyle for DesignForExtension 2 --- .../dql/common/DecoratorMergedResult.java | 14 ++-- .../expression/AliasExpressionParser.java | 10 +-- .../mysql/sql/MySQLTruncateTableParser.java | 6 ++ .../dialect/mysql/sql/MySQLUpdateParser.java | 5 ++ .../oracle/sql/OracleTruncateTableParser.java | 6 ++ .../oracle/sql/OracleUpdateParser.java | 13 +++- .../sql/PostgreSQLUpdateParser.java | 5 ++ .../sql/SQLServerTruncateTableParser.java | 6 ++ .../sqlserver/sql/SQLServerUpdateParser.java | 5 ++ .../parser/sql/AbstractSQLStatement.java | 2 +- .../parser/sql/dcl/alter/AlterUserParser.java | 2 +- .../sql/dcl/create/CreateUserParser.java | 2 +- .../table/AbstractTruncateTableParser.java | 6 +- .../sql/dml/update/AbstractUpdateParser.java | 10 +-- ...ractOrchestrationBeanDefinitionParser.java | 4 +- .../DefaultComplexKeysShardingAlgorithm.java | 2 +- .../DefaultHintShardingAlgorithm.java | 2 +- .../statement/CircuitBreakerStatement.java | 11 +-- .../representer/DataSourceRepresenter.java | 2 +- .../client/zookeeper/base/BaseClient.java | 8 +-- .../client/zookeeper/base/BaseOperation.java | 4 +- .../operation/DeleteCurrentOperation.java | 2 +- .../zookeeper/provider/BaseProvider.java | 30 ++++---- .../client/zookeeper/section/ClientTask.java | 2 +- .../strategy/AsyncRetryStrategy.java | 2 +- .../zookeeper/strategy/BaseStrategy.java | 4 +- .../strategy/ContentionStrategy.java | 10 +-- .../client/zookeeper/base/BaseClientTest.java | 28 ++++---- .../newzk/client/zookeeper/base/BaseTest.java | 6 +- .../DefaultComplexKeysShardingAlgorithm.java | 2 +- .../DefaultHintShardingAlgorithm.java | 2 +- .../adapter/AbstractResultSetAdapter.java | 2 +- ...tractShardingPreparedStatementAdapter.java | 2 +- .../adapter/AbstractStatementAdapter.java | 4 +- ...ractUnsupportedGeneratedKeysResultSet.java | 70 +++++++++---------- ...tractShardingJDBCDatabaseAndTableTest.java | 4 +- .../dbtest/engine/BaseIntegrateTest.java | 2 +- .../dbtest/engine/BatchIntegrateTest.java | 2 +- .../engine/ddl/BaseDDLIntegrateTest.java | 4 +- .../engine/dml/BaseDMLIntegrateTest.java | 2 +- .../engine/dql/BaseDQLIntegrateTest.java | 2 +- .../transaction/DefaultTransactionEngine.java | 2 +- .../binary/close/ComStmtClosePacket.java | 4 +- 43 files changed, 169 insertions(+), 144 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/DecoratorMergedResult.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/DecoratorMergedResult.java index 466b9ee5049e1..b4f55fb3d4b58 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/DecoratorMergedResult.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/DecoratorMergedResult.java @@ -37,37 +37,37 @@ public abstract class DecoratorMergedResult implements MergedResult { private final MergedResult mergedResult; @Override - public Object getValue(final int columnIndex, final Class type) throws SQLException { + public final Object getValue(final int columnIndex, final Class type) throws SQLException { return mergedResult.getValue(columnIndex, type); } @Override - public Object getValue(final String columnLabel, final Class type) throws SQLException { + public final Object getValue(final String columnLabel, final Class type) throws SQLException { return mergedResult.getValue(columnLabel, type); } @Override - public Object getCalendarValue(final int columnIndex, final Class type, final Calendar calendar) throws SQLException { + public final Object getCalendarValue(final int columnIndex, final Class type, final Calendar calendar) throws SQLException { return mergedResult.getCalendarValue(columnIndex, type, calendar); } @Override - public Object getCalendarValue(final String columnLabel, final Class type, final Calendar calendar) throws SQLException { + public final Object getCalendarValue(final String columnLabel, final Class type, final Calendar calendar) throws SQLException { return mergedResult.getCalendarValue(columnLabel, type, calendar); } @Override - public InputStream getInputStream(final int columnIndex, final String type) throws SQLException { + public final InputStream getInputStream(final int columnIndex, final String type) throws SQLException { return mergedResult.getInputStream(columnIndex, type); } @Override - public InputStream getInputStream(final String columnLabel, final String type) throws SQLException { + public final InputStream getInputStream(final String columnLabel, final String type) throws SQLException { return mergedResult.getInputStream(columnLabel, type); } @Override - public boolean wasNull() throws SQLException { + public final boolean wasNull() throws SQLException { return mergedResult.wasNull(); } } 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 3e1fd68e305bf..f1daee035c9ef 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 @@ -32,7 +32,7 @@ * @author zhangliang */ @RequiredArgsConstructor -public class AliasExpressionParser { +public abstract class AliasExpressionParser { private final LexerEngine lexerEngine; @@ -73,9 +73,7 @@ private TokenType[] getDefaultAvailableKeywordsForSelectItemAlias() { }; } - protected TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias() { - return new TokenType[0]; - } + protected abstract TokenType[] getCustomizedAvailableKeywordsForSelectItemAlias(); /** * Parse alias for table. @@ -103,7 +101,5 @@ private TokenType[] getDefaultAvailableKeywordsForTableAlias() { }; } - protected TokenType[] getCustomizedAvailableKeywordsForTableAlias() { - return new TokenType[0]; - } + protected abstract TokenType[] getCustomizedAvailableKeywordsForTableAlias(); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLTruncateTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLTruncateTableParser.java index 0a8ce40e58fa7..fa953200e5864 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLTruncateTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLTruncateTableParser.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.parsing.parser.dialect.mysql.sql; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.sql.ddl.truncate.table.AbstractTruncateTableParser; import io.shardingsphere.core.rule.ShardingRule; @@ -32,4 +33,9 @@ public final class MySQLTruncateTableParser extends AbstractTruncateTableParser public MySQLTruncateTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); } + + @Override + protected Keyword[] getSkippedKeywordsBetweenTruncateTableAndTableName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLUpdateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLUpdateParser.java index 2f8a69b4ec809..2a9eba9abf600 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLUpdateParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLUpdateParser.java @@ -39,4 +39,9 @@ public MySQLUpdateParser(final ShardingRule shardingRule, final LexerEngine lexe protected Keyword[] getSkippedKeywordsBetweenUpdateAndTable() { return new Keyword[] {MySQLKeyword.LOW_PRIORITY, MySQLKeyword.IGNORE}; } + + @Override + protected Keyword[] getUnsupportedKeywordsBetweenUpdateAndTable() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleTruncateTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleTruncateTableParser.java index 00ffacb34d5f7..0a11ac43fef04 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleTruncateTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleTruncateTableParser.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.parsing.parser.dialect.oracle.sql; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.sql.ddl.truncate.table.AbstractTruncateTableParser; import io.shardingsphere.core.rule.ShardingRule; @@ -32,4 +33,9 @@ public final class OracleTruncateTableParser extends AbstractTruncateTableParser public OracleTruncateTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); } + + @Override + protected Keyword[] getSkippedKeywordsBetweenTruncateTableAndTableName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleUpdateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleUpdateParser.java index 291868c108701..b55d0e07c63eb 100755 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleUpdateParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleUpdateParser.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.parsing.parser.dialect.oracle.sql; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.facade.OracleUpdateClauseParserFacade; import io.shardingsphere.core.parsing.parser.sql.dml.update.AbstractUpdateParser; import io.shardingsphere.core.rule.ShardingRule; @@ -27,9 +28,19 @@ * * @author zhangliang */ -public class OracleUpdateParser extends AbstractUpdateParser { +public final class OracleUpdateParser extends AbstractUpdateParser { public OracleUpdateParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine, new OracleUpdateClauseParserFacade(shardingRule, lexerEngine)); } + + @Override + protected Keyword[] getSkippedKeywordsBetweenUpdateAndTable() { + return new Keyword[0]; + } + + @Override + protected Keyword[] getUnsupportedKeywordsBetweenUpdateAndTable() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLUpdateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLUpdateParser.java index 3ce45e3ae72b9..be56f937dd2c6 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLUpdateParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLUpdateParser.java @@ -39,4 +39,9 @@ public PostgreSQLUpdateParser(final ShardingRule shardingRule, final LexerEngine protected Keyword[] getSkippedKeywordsBetweenUpdateAndTable() { return new Keyword[] {PostgreSQLKeyword.ONLY}; } + + @Override + protected Keyword[] getUnsupportedKeywordsBetweenUpdateAndTable() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerTruncateTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerTruncateTableParser.java index 8f4a1a93db1c8..800b01ccf83c9 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerTruncateTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerTruncateTableParser.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.sql.ddl.truncate.table.AbstractTruncateTableParser; import io.shardingsphere.core.rule.ShardingRule; @@ -32,4 +33,9 @@ public final class SQLServerTruncateTableParser extends AbstractTruncateTablePar public SQLServerTruncateTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); } + + @Override + protected Keyword[] getSkippedKeywordsBetweenTruncateTableAndTableName() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerUpdateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerUpdateParser.java index f73b7b6638dbf..6738705c9209b 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerUpdateParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerUpdateParser.java @@ -35,6 +35,11 @@ public SQLServerUpdateParser(final ShardingRule shardingRule, final LexerEngine super(shardingRule, lexerEngine, new SQLServerUpdateClauseParserFacade(shardingRule, lexerEngine)); } + @Override + protected Keyword[] getSkippedKeywordsBetweenUpdateAndTable() { + return new Keyword[0]; + } + @Override protected Keyword[] getUnsupportedKeywordsBetweenUpdateAndTable() { return new Keyword[] {SQLServerKeyword.TOP}; 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 54239daaed50b..82b1ce137984c 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 @@ -56,7 +56,7 @@ public final SQLType getType() { } @Override - public int increaseParametersIndex() { + public final int increaseParametersIndex() { return ++parametersIndex; } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/alter/AlterUserParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/alter/AlterUserParser.java index daa60d75728d3..9b43f3d7505a1 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/alter/AlterUserParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/alter/AlterUserParser.java @@ -35,7 +35,7 @@ public class AlterUserParser implements SQLParser { private final LexerEngine lexerEngine; @Override - public DCLStatement parse() { + public final DCLStatement parse() { if (lexerEngine.skipIfEqual(DefaultKeyword.USER) || lexerEngine.skipIfEqual(DefaultKeyword.ROLE) || lexerEngine.skipIfEqual(DefaultKeyword.LOGIN)) { return new DCLStatement(); } else { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/create/CreateUserParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/create/CreateUserParser.java index 68d2da0ff4654..cb69b6ff9d3b3 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/create/CreateUserParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/create/CreateUserParser.java @@ -35,7 +35,7 @@ public class CreateUserParser implements SQLParser { private final LexerEngine lexerEngine; @Override - public DCLStatement parse() { + public final DCLStatement parse() { if (lexerEngine.skipIfEqual(DefaultKeyword.USER) || lexerEngine.skipIfEqual(DefaultKeyword.ROLE) || lexerEngine.skipIfEqual(DefaultKeyword.LOGIN)) { return new DCLStatement(); } else { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/table/AbstractTruncateTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/table/AbstractTruncateTableParser.java index 4c1bf99d417b6..d3c86a7117c7b 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/table/AbstractTruncateTableParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/table/AbstractTruncateTableParser.java @@ -49,7 +49,7 @@ public AbstractTruncateTableParser(final ShardingRule shardingRule, final LexerE } @Override - public DDLStatement parse() { + public final DDLStatement parse() { lexerEngine.skipIfEqual(DefaultKeyword.TABLE); lexerEngine.skipAll(getSkippedKeywordsBetweenTruncateTableAndTableName()); DDLStatement result = new DDLStatement(); @@ -57,7 +57,5 @@ public DDLStatement parse() { return result; } - protected Keyword[] getSkippedKeywordsBetweenTruncateTableAndTableName() { - return new Keyword[0]; - } + protected abstract Keyword[] getSkippedKeywordsBetweenTruncateTableAndTableName(); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/update/AbstractUpdateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/update/AbstractUpdateParser.java index 8badbf2c42a08..b0a6c270ccb3d 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/update/AbstractUpdateParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dml/update/AbstractUpdateParser.java @@ -44,7 +44,7 @@ public abstract class AbstractUpdateParser implements SQLParser { private final AbstractUpdateClauseParserFacade updateClauseParserFacade; @Override - public DMLStatement parse() { + public final DMLStatement parse() { lexerEngine.nextToken(); lexerEngine.skipAll(getSkippedKeywordsBetweenUpdateAndTable()); lexerEngine.unsupportedIfEqual(getUnsupportedKeywordsBetweenUpdateAndTable()); @@ -56,11 +56,7 @@ public DMLStatement parse() { return result; } - protected Keyword[] getSkippedKeywordsBetweenUpdateAndTable() { - return new Keyword[0]; - } + protected abstract Keyword[] getSkippedKeywordsBetweenUpdateAndTable(); - protected Keyword[] getUnsupportedKeywordsBetweenUpdateAndTable() { - return new Keyword[0]; - } + protected abstract Keyword[] getUnsupportedKeywordsBetweenUpdateAndTable(); } diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/AbstractOrchestrationBeanDefinitionParser.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/AbstractOrchestrationBeanDefinitionParser.java index 394e86ad07aaf..5c05c70215ce1 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/AbstractOrchestrationBeanDefinitionParser.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/AbstractOrchestrationBeanDefinitionParser.java @@ -31,11 +31,11 @@ */ public abstract class AbstractOrchestrationBeanDefinitionParser extends AbstractBeanDefinitionParser { - protected String parseRegistryCenterRef(final Element element) { + protected final String parseRegistryCenterRef(final Element element) { return element.getAttribute("registry-center-ref"); } - protected BeanDefinition parseOrchestrationConfiguration(final Element element, final OrchestrationType type) { + protected final BeanDefinition parseOrchestrationConfiguration(final Element element, final OrchestrationType type) { BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(OrchestrationConfiguration.class); factory.addConstructorArgValue(element.getAttribute("id")); factory.addConstructorArgReference(element.getAttribute("registry-center-ref")); diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/DefaultComplexKeysShardingAlgorithm.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/DefaultComplexKeysShardingAlgorithm.java index 6910b3afd8bdc..924ca94023d8f 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/DefaultComplexKeysShardingAlgorithm.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/DefaultComplexKeysShardingAlgorithm.java @@ -22,7 +22,7 @@ import java.util.Collection; -public class DefaultComplexKeysShardingAlgorithm implements ComplexKeysShardingAlgorithm { +public final class DefaultComplexKeysShardingAlgorithm implements ComplexKeysShardingAlgorithm { @Override public Collection doSharding(final Collection availableTargetNames, final Collection shardingValues) { diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/DefaultHintShardingAlgorithm.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/DefaultHintShardingAlgorithm.java index 8f2b430aed929..3f001493040bf 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/DefaultHintShardingAlgorithm.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/DefaultHintShardingAlgorithm.java @@ -22,7 +22,7 @@ import java.util.Collection; -public class DefaultHintShardingAlgorithm implements HintShardingAlgorithm { +public final class DefaultHintShardingAlgorithm implements HintShardingAlgorithm { @Override public Collection doSharding(final Collection availableTargetNames, final ShardingValue shardingValue) { diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/jdbc/statement/CircuitBreakerStatement.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/jdbc/statement/CircuitBreakerStatement.java index 4048a63989e7b..01042aafad933 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/jdbc/statement/CircuitBreakerStatement.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/jdbc/statement/CircuitBreakerStatement.java @@ -31,11 +31,10 @@ * @author caohao */ @Getter -public class CircuitBreakerStatement extends AbstractUnsupportedOperationStatement { +public final class CircuitBreakerStatement extends AbstractUnsupportedOperationStatement { @Override public void close() { - } @Override @@ -45,7 +44,6 @@ public int getMaxFieldSize() { @Override public void setMaxFieldSize(final int max) { - } @Override @@ -55,12 +53,10 @@ public int getMaxRows() { @Override public void setMaxRows(final int max) { - } @Override public void setEscapeProcessing(final boolean enable) { - } @Override @@ -70,12 +66,10 @@ public int getQueryTimeout() { @Override public void setQueryTimeout(final int seconds) { - } @Override public void cancel() { - } @Override @@ -85,7 +79,6 @@ public SQLWarning getWarnings() { @Override public void clearWarnings() { - } @Override @@ -100,7 +93,6 @@ public int getUpdateCount() { @Override public void setFetchSize(final int rows) { - } @Override @@ -195,7 +187,6 @@ public boolean isClosed() { @Override public void setPoolable(final boolean poolable) { - } @Override diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/DataSourceRepresenter.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/DataSourceRepresenter.java index caecaf0e8b958..96839a45b48aa 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/DataSourceRepresenter.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/DataSourceRepresenter.java @@ -36,7 +36,7 @@ * * @author panjuan */ -public class DataSourceRepresenter extends Representer { +public final class DataSourceRepresenter extends Representer { private static Collection> generalClassType; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClient.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClient.java index 368f24c408f44..fb3924e036842 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClient.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClient.java @@ -124,7 +124,7 @@ void registerWatch(final ZookeeperEventListener globalZookeeperEventListener) { } @Override - public void registerWatch(final String key, final ZookeeperEventListener zookeeperEventListener) { + public final void registerWatch(final String key, final ZookeeperEventListener zookeeperEventListener) { final String path = PathUtil.getRealPath(rootNode, key); zookeeperEventListener.setPath(path); context.getWatchers().put(zookeeperEventListener.getKey(), zookeeperEventListener); @@ -132,7 +132,7 @@ public void registerWatch(final String key, final ZookeeperEventListener zookeep } @Override - public void unregisterWatch(final String key) { + public final void unregisterWatch(final String key) { if (Strings.isNullOrEmpty(key)) { throw new IllegalArgumentException("key should not be blank"); } @@ -172,7 +172,7 @@ public void process(final WatchedEvent event) { log.debug("created root:{}", rootNode); } - protected void deleteNamespace() throws KeeperException, InterruptedException { + protected final void deleteNamespace() throws KeeperException, InterruptedException { try { holder.getZooKeeper().delete(rootNode, ZookeeperConstants.VERSION); } catch (final KeeperException.NodeExistsException | KeeperException.NotEmptyException ex) { @@ -182,7 +182,7 @@ protected void deleteNamespace() throws KeeperException, InterruptedException { log.debug("delete root:{}", rootNode); } - void setAuthorities(final String scheme, final byte[] auth, final List authorities) { + final void setAuthorities(final String scheme, final byte[] auth, final List authorities) { context.setScheme(scheme); context.setAuth(auth); this.authorities = authorities; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseOperation.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseOperation.java index fbbef2f0c98d9..57d98c8b0c0eb 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseOperation.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseOperation.java @@ -45,14 +45,14 @@ public abstract class BaseOperation implements Delayed { private DelayPolicyExecutor delayPolicyExecutor; @Override - public long getDelay(final TimeUnit timeUnit) { + public final long getDelay(final TimeUnit timeUnit) { long absoluteBlock = this.delayPolicyExecutor.getNextTick() - System.currentTimeMillis(); log.debug("queue getDelay block: {}", absoluteBlock); return timeUnit.convert(absoluteBlock, TimeUnit.MILLISECONDS); } @Override - public int compareTo(final Delayed delayed) { + public final int compareTo(final Delayed delayed) { return (int) (this.getDelay(TimeUnit.MILLISECONDS) - delayed.getDelay(TimeUnit.MILLISECONDS)); } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentOperation.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentOperation.java index fabdd081e464a..04afe73bdb78b 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentOperation.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/DeleteCurrentOperation.java @@ -26,7 +26,7 @@ * * @author lidongbo */ -public class DeleteCurrentOperation extends BaseOperation { +public final class DeleteCurrentOperation extends BaseOperation { private final String key; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/BaseProvider.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/BaseProvider.java index 162b811b6877f..c94858be9b889 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/BaseProvider.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/provider/BaseProvider.java @@ -59,37 +59,37 @@ public class BaseProvider implements IProvider { private final List authorities; @Override - public String getDataString(final String key) throws KeeperException, InterruptedException { + public final String getDataString(final String key) throws KeeperException, InterruptedException { return new String(getData(key)); } @Override - public byte[] getData(final String key) throws KeeperException, InterruptedException { + public final byte[] getData(final String key) throws KeeperException, InterruptedException { return holder.getZooKeeper().getData(key, watched, null); } @Override - public void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) { + public final void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) { holder.getZooKeeper().getData(key, watched, callback, ctx); } @Override - public boolean exists(final String key) throws KeeperException, InterruptedException { + public final boolean exists(final String key) throws KeeperException, InterruptedException { return null != holder.getZooKeeper().exists(key, watched); } @Override - public boolean exists(final String key, final Watcher watcher) throws KeeperException, InterruptedException { + public final boolean exists(final String key, final Watcher watcher) throws KeeperException, InterruptedException { return null != holder.getZooKeeper().exists(key, watcher); } @Override - public List getChildren(final String key) throws KeeperException, InterruptedException { + public final List getChildren(final String key) throws KeeperException, InterruptedException { return holder.getZooKeeper().getChildren(key, watched); } @Override - public void create(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException { + public final void create(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException { if (exists(key)) { log.debug("node exist: {}", key); return; @@ -99,7 +99,7 @@ public void create(final String key, final String value, final CreateMode create } @Override - public boolean update(final String key, final String value) throws KeeperException, InterruptedException { + 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; @@ -108,36 +108,36 @@ public boolean update(final String key, final String value) throws KeeperExcepti } @Override - public void delete(final String key) throws KeeperException, InterruptedException { + public final void delete(final String key) throws KeeperException, InterruptedException { holder.getZooKeeper().delete(key, ZookeeperConstants.VERSION); log.debug("BaseProvider deleteOnlyCurrent: {}", key); } @Override - public void delete(final String key, final AsyncCallback.VoidCallback callback, final Object ctx) { + public final void delete(final String key, final AsyncCallback.VoidCallback callback, final Object ctx) { holder.getZooKeeper().delete(key, ZookeeperConstants.VERSION, callback, ctx); log.debug("BaseProvider deleteOnlyCurrent: {}, ctx: {}", key, ctx); } @Override - public String getRealPath(final String path) { + public final String getRealPath(final String path) { return PathUtil.getRealPath(rootNode, path); } @Override - public List getNecessaryPaths(final String key) { + public final List getNecessaryPaths(final String key) { List nodes = PathUtil.getPathOrderNodes(rootNode, key); nodes.remove(rootNode); return nodes; } @Override - public Stack getDeletingPaths(final String key) { + public final Stack getDeletingPaths(final String key) { return PathUtil.getPathReverseNodes(rootNode, key); } @Override - public void executeContention(final LeaderElection election) throws KeeperException, InterruptedException { + public final void executeContention(final LeaderElection election) throws KeeperException, InterruptedException { this.executeContention(rootNode, election); } @@ -146,7 +146,7 @@ private void executeContention(final String nodeBeCompete, final LeaderElection } @Override - public void resetConnection() { + public final void resetConnection() { try { holder.reset(); } catch (final InterruptedException | IOException ex) { diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientTask.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientTask.java index f23604aac656a..62016a191af0a 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientTask.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/ClientTask.java @@ -43,7 +43,7 @@ public abstract class ClientTask implements Runnable { public abstract void run(IProvider provider) throws KeeperException, InterruptedException; @Override - public void run() { + public final void run() { try { run(provider); } catch (final KeeperException | InterruptedException ex) { diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/AsyncRetryStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/AsyncRetryStrategy.java index 90c7f2a964319..f7607a4a75fb7 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/AsyncRetryStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/AsyncRetryStrategy.java @@ -37,7 +37,7 @@ * @author lidongbo */ @Slf4j -public class AsyncRetryStrategy extends SyncRetryStrategy { +public final class AsyncRetryStrategy extends SyncRetryStrategy { public AsyncRetryStrategy(final IProvider provider, final DelayRetryPolicy delayRetryPolicy) { super(provider, delayRetryPolicy); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/BaseStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/BaseStrategy.java index a6b85959eaa80..0b29da0ca9911 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/BaseStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/BaseStrategy.java @@ -36,12 +36,12 @@ public abstract class BaseStrategy implements IExecStrategy { private final IProvider provider; @Override - public String getDataString(final String key) throws KeeperException, InterruptedException { + public final String getDataString(final String key) throws KeeperException, InterruptedException { return new String(getData(key)); } @Override - public BaseTransaction transaction() { + public final BaseTransaction transaction() { return provider.transaction(); } } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java index a86e6631ab003..b98e145e62281 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/strategy/ContentionStrategy.java @@ -46,7 +46,7 @@ public ContentionStrategy(final IProvider provider) { * Don't use this if you don't have to use it. */ @Override - public void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) throws KeeperException, InterruptedException { + public final void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) throws KeeperException, InterruptedException { getProvider().executeContention(new LeaderElection() { @Override @@ -59,7 +59,7 @@ public void action() throws KeeperException, InterruptedException { } @Override - public void createCurrentOnly(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException { + 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); log.debug("ContentionStrategy createCurrentOnly executeContention"); @@ -84,7 +84,7 @@ public void callback() { } @Override - public void update(final String key, final String value) throws KeeperException, InterruptedException { + public final void update(final String key, final String value) throws KeeperException, InterruptedException { LeaderElection election = buildUpdateElection(key, value, null); getProvider().executeContention(election); log.debug("ContentionStrategy update executeContention"); @@ -110,7 +110,7 @@ public void callback() { } @Override - public void deleteOnlyCurrent(final String key) throws KeeperException, InterruptedException { + public final void deleteOnlyCurrent(final String key) throws KeeperException, InterruptedException { LeaderElection election = buildDeleteElection(key, null); getProvider().executeContention(election); log.debug("ContentionStrategy deleteOnlyCurrent executeContention"); @@ -118,7 +118,7 @@ public void deleteOnlyCurrent(final String key) throws KeeperException, Interrup } @Override - public void deleteOnlyCurrent(final String key, final AsyncCallback.VoidCallback callback, final Object ctx) throws KeeperException, InterruptedException { + public final void deleteOnlyCurrent(final String key, final AsyncCallback.VoidCallback callback, final Object ctx) throws KeeperException, InterruptedException { getProvider().executeContention(new LeaderElection() { @Override diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClientTest.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClientTest.java index 3a60bd623e6e6..201c344517130 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClientTest.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseClientTest.java @@ -65,7 +65,7 @@ public void start() throws IOException, InterruptedException { getZooKeeper(testClient); } - protected ZooKeeper getZooKeeper(final IClient client) { + protected final ZooKeeper getZooKeeper(final IClient client) { return ((BaseClient) client).getHolder().getZooKeeper(); } @@ -84,14 +84,14 @@ public void assertDeleteRoot() throws KeeperException, InterruptedException { assertNull(getZooKeeper(testClient).exists(ZookeeperConstants.PATH_SEPARATOR + TestSupport.ROOT, false)); } - protected void createRoot(final IClient client) throws KeeperException, InterruptedException { + protected final void createRoot(final IClient client) throws KeeperException, InterruptedException { ((BaseClient) client).createNamespace(); assertNotNull(getZooKeeper(client).exists(ZookeeperConstants.PATH_SEPARATOR + TestSupport.ROOT, false)); ((BaseClient) client).deleteNamespace(); assertNull(getZooKeeper(client).exists(ZookeeperConstants.PATH_SEPARATOR + TestSupport.ROOT, false)); } - protected void createChild(final IClient client) throws KeeperException, InterruptedException { + protected final void createChild(final IClient client) throws KeeperException, InterruptedException { String key = "a/b/bb"; client.createAllNeedPath(key, "bbb11", CreateMode.PERSISTENT); assertNotNull(getZooKeeper(client).exists(PathUtil.getRealPath(TestSupport.ROOT, key), false)); @@ -99,7 +99,7 @@ protected void createChild(final IClient client) throws KeeperException, Interru assertNull(getZooKeeper(client).exists(PathUtil.getRealPath(TestSupport.ROOT, key), false)); } - protected void deleteBranch(final IClient client) throws KeeperException, InterruptedException { + protected final void deleteBranch(final IClient client) throws KeeperException, InterruptedException { String keyB = "a/b/bb"; String valueB = "bbb11"; client.createAllNeedPath(keyB, valueB, CreateMode.PERSISTENT); @@ -119,7 +119,7 @@ protected void deleteBranch(final IClient client) throws KeeperException, Interr assertNull(getZooKeeper(client).exists(PathUtil.checkPath(TestSupport.ROOT), false)); } - protected void isExisted(final IClient client) throws KeeperException, InterruptedException { + protected final void isExisted(final IClient client) throws KeeperException, InterruptedException { String key = "a/b/bb"; client.createAllNeedPath(key, "", CreateMode.PERSISTENT); assertTrue(isExisted(key, client)); @@ -130,7 +130,7 @@ private boolean isExisted(final String key, final IClient client) throws KeeperE return client.checkExists(key); } - protected void get(final IClient client) throws KeeperException, InterruptedException { + protected final void get(final IClient client) throws KeeperException, InterruptedException { String value = "bbb11"; client.createAllNeedPath("a/b", value, CreateMode.PERSISTENT); String key = "a"; @@ -140,7 +140,7 @@ protected void get(final IClient client) throws KeeperException, InterruptedExce client.deleteCurrentBranch("a/b"); } - protected void asyncGet(final IClient client) throws KeeperException, InterruptedException { + protected final void asyncGet(final IClient client) throws KeeperException, InterruptedException { final CountDownLatch ready = new CountDownLatch(1); String key = "a/b"; String value = "bbb11"; @@ -163,7 +163,7 @@ private String getDirectly(final String key, final IClient client) throws Keeper return new String(client.getData(key)); } - protected void getChildrenKeys(final IClient client) throws KeeperException, InterruptedException { + protected final void getChildrenKeys(final IClient client) throws KeeperException, InterruptedException { String key = "a/b"; String current = "a"; client.createAllNeedPath(key, "", CreateMode.PERSISTENT); @@ -178,7 +178,7 @@ public int compare(final String o1, final String o2) { client.deleteCurrentBranch(key); } - protected void persist(final IClient client) throws KeeperException, InterruptedException { + protected final void persist(final IClient client) throws KeeperException, InterruptedException { String key = "a"; String value = "aa"; String newValue = "aaa"; @@ -199,7 +199,7 @@ private void updateWithCheck(final String key, final String value, final IClient client.update(key, value); } - protected void persistEphemeral(final IClient client) throws KeeperException, InterruptedException { + protected final void persistEphemeral(final IClient client) throws KeeperException, InterruptedException { String key = "a/b/bb"; String value = "b1b"; client.createAllNeedPath(key, value, CreateMode.PERSISTENT); @@ -215,7 +215,7 @@ protected void persistEphemeral(final IClient client) throws KeeperException, In client.deleteCurrentBranch(key); } - protected void delAllChildren(final IClient client) throws KeeperException, InterruptedException { + protected final void delAllChildren(final IClient client) throws KeeperException, InterruptedException { String key = "a/b/bb"; client.createAllNeedPath(key, "bb", CreateMode.PERSISTENT); key = "a/c/cc"; @@ -228,7 +228,7 @@ protected void delAllChildren(final IClient client) throws KeeperException, Inte ((BaseClient) client).deleteNamespace(); } - protected void watch(final IClient client) throws KeeperException, InterruptedException { + protected final void watch(final IClient client) throws KeeperException, InterruptedException { List actual = new ArrayList<>(); final ZookeeperEventListener zookeeperEventListener = buildListener(client, actual); @@ -266,7 +266,7 @@ public void process(final WatchedEvent event) { client.unregisterWatch(zookeeperEventListener.getKey()); } - protected void watchRegister(final IClient client) throws KeeperException, InterruptedException { + protected final void watchRegister(final IClient client) throws KeeperException, InterruptedException { List actual = new ArrayList<>(); final ZookeeperEventListener zookeeperEventListener = buildListener(client, actual); @@ -320,7 +320,7 @@ public void process(final WatchedEvent event) { }; } - protected void close(final IClient client) { + protected final void close(final IClient client) { client.close(); assertThat(getZooKeeper(client).getState(), is(ZooKeeper.States.CLOSED)); } diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseTest.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseTest.java index 48018b026b9b7..7cf32726b3263 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseTest.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/BaseTest.java @@ -22,15 +22,15 @@ public class BaseTest { - protected void createRootOnly(final IClient client) throws KeeperException, InterruptedException { + protected final void createRootOnly(final IClient client) throws KeeperException, InterruptedException { ((BaseClient) client).createNamespace(); } - protected void deleteRoot(final IClient client) throws KeeperException, InterruptedException { + protected final void deleteRoot(final IClient client) throws KeeperException, InterruptedException { ((BaseClient) client).deleteNamespace(); } - protected void sleep(final long tick) { + protected final void sleep(final long tick) { try { Thread.sleep(tick); } catch (final InterruptedException ignore) { diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/DefaultComplexKeysShardingAlgorithm.java b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/DefaultComplexKeysShardingAlgorithm.java index 5e51db9f3d574..e6eb74294d3f5 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/DefaultComplexKeysShardingAlgorithm.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/DefaultComplexKeysShardingAlgorithm.java @@ -22,7 +22,7 @@ import java.util.Collection; -public class DefaultComplexKeysShardingAlgorithm implements ComplexKeysShardingAlgorithm { +public final class DefaultComplexKeysShardingAlgorithm implements ComplexKeysShardingAlgorithm { @Override public Collection doSharding(final Collection availableTargetNames, final Collection shardingValues) { diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/DefaultHintShardingAlgorithm.java b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/DefaultHintShardingAlgorithm.java index 0f9378b8a6776..67b14503d9069 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/DefaultHintShardingAlgorithm.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/DefaultHintShardingAlgorithm.java @@ -22,7 +22,7 @@ import java.util.Collection; -public class DefaultHintShardingAlgorithm implements HintShardingAlgorithm { +public final class DefaultHintShardingAlgorithm implements HintShardingAlgorithm { @Override public Collection doSharding(final Collection availableTargetNames, final ShardingValue shardingValue) { diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractResultSetAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractResultSetAdapter.java index d941614ffc850..0b3e2a7841407 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractResultSetAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractResultSetAdapter.java @@ -60,7 +60,7 @@ public final ResultSetMetaData getMetaData() throws SQLException { } @Override - public int findColumn(final String columnLabel) throws SQLException { + public final int findColumn(final String columnLabel) throws SQLException { return resultSets.get(0).findColumn(columnLabel); } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractShardingPreparedStatementAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractShardingPreparedStatementAdapter.java index f6c4e2da0b2e2..6079b149c2a8c 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractShardingPreparedStatementAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractShardingPreparedStatementAdapter.java @@ -265,7 +265,7 @@ private void recordSetParameter(final String methodName, final Class[] argumentT } } - protected void replaySetParameter(final PreparedStatement preparedStatement, final List parameters) { + protected final void replaySetParameter(final PreparedStatement preparedStatement, final List parameters) { setParameterMethodInvocations.clear(); addParameters(parameters); for (SetParameterMethodInvocation each : setParameterMethodInvocations) { diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractStatementAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractStatementAdapter.java index b7f9252d0f443..b5d65a88e805b 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractStatementAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractStatementAdapter.java @@ -123,12 +123,12 @@ public final int getUpdateCount() throws SQLException { } @Override - public SQLWarning getWarnings() { + public final SQLWarning getWarnings() { return null; } @Override - public void clearWarnings() { + public final void clearWarnings() { } @Override diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java index feb7e3fd2121e..b0f140178cf29 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java @@ -40,52 +40,52 @@ public abstract class AbstractUnsupportedGeneratedKeysResultSet extends AbstractUnsupportedOperationResultSet { @Override - public boolean getBoolean(final int columnIndex) throws SQLException { + public final boolean getBoolean(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getBoolean"); } @Override - public boolean getBoolean(final String columnLabel) throws SQLException { + public final boolean getBoolean(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getBoolean"); } @Override - public Date getDate(final int columnIndex) throws SQLException { + public final Date getDate(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getDate"); } @Override - public Date getDate(final String columnLabel) throws SQLException { + public final Date getDate(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getDate"); } @Override - public Date getDate(final int columnIndex, final Calendar cal) throws SQLException { + public final Date getDate(final int columnIndex, final Calendar cal) throws SQLException { throw new SQLFeatureNotSupportedException("getDate"); } @Override - public Date getDate(final String columnLabel, final Calendar cal) throws SQLException { + public final Date getDate(final String columnLabel, final Calendar cal) throws SQLException { throw new SQLFeatureNotSupportedException("getDate"); } @Override - public Time getTime(final int columnIndex) throws SQLException { + public final Time getTime(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getTime"); } @Override - public Time getTime(final int columnIndex, final Calendar cal) throws SQLException { + public final Time getTime(final int columnIndex, final Calendar cal) throws SQLException { throw new SQLFeatureNotSupportedException("getTime"); } @Override - public Time getTime(final String columnLabel, final Calendar cal) throws SQLException { + public final Time getTime(final String columnLabel, final Calendar cal) throws SQLException { throw new SQLFeatureNotSupportedException("getTime"); } @Override - public Time getTime(final String columnLabel) throws SQLException { + public final Time getTime(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getTime"); } @@ -95,87 +95,87 @@ public Timestamp getTimestamp(final int columnIndex) throws SQLException { } @Override - public Timestamp getTimestamp(final String columnLabel) throws SQLException { + public final Timestamp getTimestamp(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getTimestamp"); } @Override - public Timestamp getTimestamp(final int columnIndex, final Calendar cal) throws SQLException { + public final Timestamp getTimestamp(final int columnIndex, final Calendar cal) throws SQLException { throw new SQLFeatureNotSupportedException("getTimestamp"); } @Override - public Timestamp getTimestamp(final String columnLabel, final Calendar cal) throws SQLException { + public final Timestamp getTimestamp(final String columnLabel, final Calendar cal) throws SQLException { throw new SQLFeatureNotSupportedException("getTimestamp"); } @Override - public InputStream getAsciiStream(final int columnIndex) throws SQLException { + public final InputStream getAsciiStream(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getAsciiStream"); } @Override - public InputStream getAsciiStream(final String columnLabel) throws SQLException { + public final InputStream getAsciiStream(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getAsciiStream"); } @Override - public InputStream getUnicodeStream(final int columnIndex) throws SQLException { + public final InputStream getUnicodeStream(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getUnicodeStream"); } @Override - public InputStream getUnicodeStream(final String columnLabel) throws SQLException { + public final InputStream getUnicodeStream(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getUnicodeStream"); } @Override - public InputStream getBinaryStream(final int columnIndex) throws SQLException { + public final InputStream getBinaryStream(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getBinaryStream"); } @Override - public InputStream getBinaryStream(final String columnLabel) throws SQLException { + public final InputStream getBinaryStream(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getBinaryStream"); } @Override - public SQLWarning getWarnings() throws SQLException { + public final SQLWarning getWarnings() throws SQLException { throw new SQLFeatureNotSupportedException("getWarnings"); } @Override - public void clearWarnings() throws SQLException { + public final void clearWarnings() throws SQLException { throw new SQLFeatureNotSupportedException("clearWarnings"); } @Override - public Reader getCharacterStream(final int columnIndex) throws SQLException { + public final Reader getCharacterStream(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getCharacterStream"); } @Override - public Reader getCharacterStream(final String columnLabel) throws SQLException { + public final Reader getCharacterStream(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getCharacterStream"); } @Override - public void setFetchDirection(final int direction) throws SQLException { + public final void setFetchDirection(final int direction) throws SQLException { throw new SQLFeatureNotSupportedException("setFetchDirection"); } @Override - public int getFetchDirection() throws SQLException { + public final int getFetchDirection() throws SQLException { throw new SQLFeatureNotSupportedException("getFetchDirection"); } @Override - public void setFetchSize(final int rows) throws SQLException { + public final void setFetchSize(final int rows) throws SQLException { throw new SQLFeatureNotSupportedException("setFetchSize"); } @Override - public int getFetchSize() throws SQLException { + public final int getFetchSize() throws SQLException { throw new SQLFeatureNotSupportedException("getFetchSize"); } @@ -190,42 +190,42 @@ public Object getObject(final String columnLabel, final Map> ma } @Override - public Blob getBlob(final int columnIndex) throws SQLException { + public final Blob getBlob(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getBlob"); } @Override - public Blob getBlob(final String columnLabel) throws SQLException { + public final Blob getBlob(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getBlob"); } @Override - public Clob getClob(final int columnIndex) throws SQLException { + public final Clob getClob(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getClob"); } @Override - public Clob getClob(final String columnLabel) throws SQLException { + public final Clob getClob(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getClob"); } @Override - public URL getURL(final int columnIndex) throws SQLException { + public final URL getURL(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getURL"); } @Override - public URL getURL(final String columnLabel) throws SQLException { + public final URL getURL(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getURL"); } @Override - public SQLXML getSQLXML(final int columnIndex) throws SQLException { + public final SQLXML getSQLXML(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getSQLXML"); } @Override - public SQLXML getSQLXML(final String columnLabel) throws SQLException { + public final SQLXML getSQLXML(final String columnLabel) throws SQLException { throw new SQLFeatureNotSupportedException("getSQLXML"); } } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractShardingJDBCDatabaseAndTableTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractShardingJDBCDatabaseAndTableTest.java index b15bafae52389..99c3956607b96 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractShardingJDBCDatabaseAndTableTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractShardingJDBCDatabaseAndTableTest.java @@ -82,11 +82,11 @@ public void initShardingDataSources() throws SQLException { } @Override - protected List getInitDataSetFiles() { + protected final List getInitDataSetFiles() { return Arrays.asList("integrate/dataset/jdbc/jdbc_0.xml", "integrate/dataset/jdbc/jdbc_1.xml"); } - protected ShardingDataSource getShardingDataSource() { + protected final ShardingDataSource getShardingDataSource() { return shardingDataSource; } } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BaseIntegrateTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BaseIntegrateTest.java index 4f5d51e58ec9e..0605b0cfde87f 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BaseIntegrateTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BaseIntegrateTest.java @@ -86,7 +86,7 @@ public BaseIntegrateTest(final String shardingRuleType, final DatabaseTypeEnviro } } - protected String getExpectedDataFile(final String path, final String shardingRuleType, final DatabaseType databaseType, final String expectedDataFile) { + protected final String getExpectedDataFile(final String path, final String shardingRuleType, final DatabaseType databaseType, final String expectedDataFile) { if (null == expectedDataFile) { return null; } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BatchIntegrateTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BatchIntegrateTest.java index 448d3ea5ea540..eaa76b7fbbbbb 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BatchIntegrateTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/BatchIntegrateTest.java @@ -115,7 +115,7 @@ public void clearData() throws SQLException { } } - protected void assertDataSet(final int[] actualUpdateCounts) throws SQLException, IOException, JAXBException { + protected final void assertDataSet(final int[] actualUpdateCounts) throws SQLException, IOException, JAXBException { Collection expectedList = new LinkedList<>(); assertThat(actualUpdateCounts.length, is(getExpectedDataFiles().size())); int count = 0; diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/BaseDDLIntegrateTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/BaseDDLIntegrateTest.java index 6c8104ce01564..7eed86fa4d666 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/BaseDDLIntegrateTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/BaseDDLIntegrateTest.java @@ -94,7 +94,7 @@ public void destroyTables() { } } - protected void assertMetadata(final Connection connection) throws IOException, JAXBException, SQLException { + protected final void assertMetadata(final Connection connection) throws IOException, JAXBException, SQLException { if (null == assertion.getExpectedDataFile()) { log.warn("Have empty expectedDataFile `{}`", super.getSql()); return; @@ -190,7 +190,7 @@ private List getActualIndexes(final Connection connection, final S } } - protected void dropTableIfExisted(final Connection connection) { + protected final void dropTableIfExisted(final Connection connection) { try (PreparedStatement preparedStatement = connection.prepareStatement(String.format("DROP TABLE %s", assertion.getTable()))) { preparedStatement.executeUpdate(); } catch (final SQLException ignored) { diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/BaseDMLIntegrateTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/BaseDMLIntegrateTest.java index 1224e56fdafdd..0fb2209ac4060 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/BaseDMLIntegrateTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/BaseDMLIntegrateTest.java @@ -85,7 +85,7 @@ public void clearData() throws SQLException { } } - protected void assertDataSet(final int actualUpdateCount) throws SQLException, IOException, JAXBException { + protected final void assertDataSet(final int actualUpdateCount) throws SQLException, IOException, JAXBException { DataSet expected; try (FileReader reader = new FileReader(getExpectedDataFile())) { expected = (DataSet) JAXBContext.newInstance(DataSet.class).createUnmarshaller().unmarshal(reader); diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dql/BaseDQLIntegrateTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dql/BaseDQLIntegrateTest.java index 04e352f24f176..fc2b3771ea2c0 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dql/BaseDQLIntegrateTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dql/BaseDQLIntegrateTest.java @@ -105,7 +105,7 @@ private static Map createDataSourceMap(final DatabaseType da return result; } - protected void assertResultSet(final ResultSet resultSet) throws SQLException, JAXBException, IOException { + protected final void assertResultSet(final ResultSet resultSet) throws SQLException, JAXBException, IOException { DataSet expected; try (FileReader reader = new FileReader(getExpectedDataFile())) { expected = (DataSet) JAXBContext.newInstance(DataSet.class).createUnmarshaller().unmarshal(reader); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/DefaultTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/DefaultTransactionEngine.java index e2622c1269495..fd0c8b83f21a5 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/DefaultTransactionEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/DefaultTransactionEngine.java @@ -22,7 +22,7 @@ * * @author zhaojun */ -public class DefaultTransactionEngine extends TransactionEngine { +public final class DefaultTransactionEngine extends TransactionEngine { public DefaultTransactionEngine(final String sql) { super(sql); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/close/ComStmtClosePacket.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/close/ComStmtClosePacket.java index b96f4c09ccc37..490b94aadf15c 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/close/ComStmtClosePacket.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/close/ComStmtClosePacket.java @@ -45,11 +45,11 @@ public ComStmtClosePacket(final int sequenceId, final MySQLPacketPayload payload } @Override - public void write(final MySQLPacketPayload payload) { + public final void write(final MySQLPacketPayload payload) { } @Override - public Optional execute() { + public final Optional execute() { log.debug("COM_STMT_CLOSE received for Sharding-Proxy: {}", statementId); // TODO :yonglun need to clean PreparedStatementRegistry? return Optional.absent(); From a663e6065dac0826300ac8118a25ff547d6ec933 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 14:06:25 +0800 Subject: [PATCH 180/198] checkstyle for DesignForExtension 3 --- .../parser/clause/DistinctClauseParser.java | 6 +-- .../parser/clause/GroupByClauseParser.java | 10 ++--- .../InsertDuplicateKeyUpdateClauseParser.java | 6 +-- .../parser/clause/InsertIntoClauseParser.java | 10 ++--- .../parser/clause/InsertSetClauseParser.java | 6 +-- .../clause/MySQLGroupByClauseParser.java | 5 +++ .../clause/MySQLInsertIntoClauseParser.java | 5 +++ .../clause/OracleGroupByClauseParser.java | 5 +++ ...eInsertDuplicateKeyUpdateClauseParser.java | 40 +++++++++++++++++ .../clause/OracleInsertIntoClauseParser.java | 5 +++ .../clause/OracleInsertSetClauseParser.java | 40 +++++++++++++++++ .../OracleInsertClauseParserFacade.java | 8 ++-- .../PostgreSQLDistinctClauseParser.java | 39 ++++++++++++++++ .../clause/PostgreSQLGroupByClauseParser.java | 44 +++++++++++++++++++ ...LInsertDuplicateKeyUpdateClauseParser.java | 40 +++++++++++++++++ .../PostgreSQLInsertIntoClauseParser.java | 11 +++++ .../PostgreSQLInsertSetClauseParser.java | 40 +++++++++++++++++ .../PostgreSQLInsertClauseParserFacade.java | 8 ++-- .../PostgreSQLSelectClauseParserFacade.java | 8 ++-- .../clause/SQLServerDistinctClauseParser.java | 39 ++++++++++++++++ .../clause/SQLServerGroupByClauseParser.java | 44 +++++++++++++++++++ ...rInsertDuplicateKeyUpdateClauseParser.java | 40 +++++++++++++++++ .../SQLServerInsertIntoClauseParser.java | 11 +++++ .../SQLServerInsertSetClauseParser.java | 40 +++++++++++++++++ .../SQLServerInsertClauseParserFacade.java | 8 ++-- .../SQLServerSelectClauseParserFacade.java | 8 ++-- .../parser/sql/dcl/deny/DenyUserParser.java | 2 +- .../parser/sql/dcl/drop/DropUserParser.java | 2 +- .../parser/sql/dcl/grant/GrantUserParser.java | 2 +- .../keygen/fixture/IncrementKeyGenerator.java | 2 +- .../resultset/GeneratedKeysResultSet.java | 2 +- ...ractUnsupportedGeneratedKeysResultSet.java | 13 +----- ...AbstractUnsupportedOperationResultSet.java | 4 +- .../core/fixture/IncrementKeyGenerator.java | 2 +- .../frontend/common/FrontendHandler.java | 6 +-- src/resources/sharding_checks.xml | 2 +- 36 files changed, 493 insertions(+), 70 deletions(-) create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertDuplicateKeyUpdateClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertSetClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLDistinctClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLGroupByClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertDuplicateKeyUpdateClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertSetClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerDistinctClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerGroupByClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertDuplicateKeyUpdateClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertSetClauseParser.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/DistinctClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/DistinctClauseParser.java index b4e4727d16ca1..9ee26ee4a9e9f 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/DistinctClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/DistinctClauseParser.java @@ -32,7 +32,7 @@ * @author zhangliang */ @RequiredArgsConstructor -public class DistinctClauseParser implements SQLClauseParser { +public abstract class DistinctClauseParser implements SQLClauseParser { private final LexerEngine lexerEngine; @@ -47,7 +47,5 @@ public final void parse() { lexerEngine.unsupportedIfEqual(distinctKeywords.toArray(new Keyword[distinctKeywords.size()])); } - protected Keyword[] getSynonymousKeywordsForDistinct() { - return new Keyword[0]; - } + protected abstract Keyword[] getSynonymousKeywordsForDistinct(); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/GroupByClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/GroupByClauseParser.java index 4ffe8e38db2ea..f4a6b32a543b0 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/GroupByClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/GroupByClauseParser.java @@ -38,7 +38,7 @@ * * @author zhangliang */ -public class GroupByClauseParser implements SQLClauseParser { +public abstract class GroupByClauseParser implements SQLClauseParser { private final LexerEngine lexerEngine; @@ -98,11 +98,7 @@ private void addGroupByItem(final SQLExpression sqlExpression, final SelectState selectStatement.getGroupByItems().add(orderItem); } - protected Keyword[] getUnsupportedKeywordBeforeGroupByItem() { - return new Keyword[0]; - } + protected abstract Keyword[] getUnsupportedKeywordBeforeGroupByItem(); - protected Keyword[] getSkippedKeywordAfterGroupBy() { - return new Keyword[0]; - } + protected abstract Keyword[] getSkippedKeywordAfterGroupBy(); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertDuplicateKeyUpdateClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertDuplicateKeyUpdateClauseParser.java index fadc54877118a..26a9e49d67eab 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertDuplicateKeyUpdateClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertDuplicateKeyUpdateClauseParser.java @@ -34,7 +34,7 @@ * * @author maxiaoguang */ -public class InsertDuplicateKeyUpdateClauseParser implements SQLClauseParser { +public abstract class InsertDuplicateKeyUpdateClauseParser implements SQLClauseParser { private final ShardingRule shardingRule; @@ -78,7 +78,5 @@ public void parse(final InsertStatement insertStatement) { } while (lexerEngine.skipIfEqual(Symbol.COMMA)); } - protected Keyword[] getCustomizedInsertKeywords() { - return new Keyword[0]; - } + protected abstract Keyword[] getCustomizedInsertKeywords(); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertIntoClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertIntoClauseParser.java index 8d5820f7fce78..76566a970ed58 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertIntoClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/InsertIntoClauseParser.java @@ -30,7 +30,7 @@ * @author zhangliang */ @RequiredArgsConstructor -public class InsertIntoClauseParser implements SQLClauseParser { +public abstract class InsertIntoClauseParser implements SQLClauseParser { private final LexerEngine lexerEngine; @@ -49,9 +49,7 @@ public void parse(final InsertStatement insertStatement) { skipBetweenTableAndValues(insertStatement); } - protected Keyword[] getUnsupportedKeywordsBeforeInto() { - return new Keyword[0]; - } + protected abstract Keyword[] getUnsupportedKeywordsBeforeInto(); private void skipBetweenTableAndValues(final InsertStatement insertStatement) { while (lexerEngine.skipIfEqual(getSkippedKeywordsBetweenTableAndValues())) { @@ -62,7 +60,5 @@ private void skipBetweenTableAndValues(final InsertStatement insertStatement) { } } - protected Keyword[] getSkippedKeywordsBetweenTableAndValues() { - return new Keyword[0]; - } + protected abstract Keyword[] getSkippedKeywordsBetweenTableAndValues(); } 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 57685dc8d7f74..dd21f9186c637 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 @@ -51,7 +51,7 @@ * @author zhangliang * @author maxiaoguang */ -public class InsertSetClauseParser implements SQLClauseParser { +public abstract class InsertSetClauseParser implements SQLClauseParser { private final ShardingRule shardingRule; @@ -120,7 +120,5 @@ private void removeUnnecessaryToken(final InsertStatement insertStatement) { } } - protected Keyword[] getCustomizedInsertKeywords() { - return new Keyword[0]; - } + protected abstract Keyword[] getCustomizedInsertKeywords(); } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLGroupByClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLGroupByClauseParser.java index e68a701c935fc..7c024086687fb 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLGroupByClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLGroupByClauseParser.java @@ -34,6 +34,11 @@ public MySQLGroupByClauseParser(final LexerEngine lexerEngine) { super(lexerEngine); } + @Override + protected Keyword[] getUnsupportedKeywordBeforeGroupByItem() { + return new Keyword[0]; + } + @Override protected Keyword[] getSkippedKeywordAfterGroupBy() { return new Keyword[] {DefaultKeyword.WITH, MySQLKeyword.ROLLUP}; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLInsertIntoClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLInsertIntoClauseParser.java index 44996b6a99868..937ab979a493d 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLInsertIntoClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLInsertIntoClauseParser.java @@ -34,6 +34,11 @@ public MySQLInsertIntoClauseParser(final ShardingRule shardingRule, final LexerE super(lexerEngine, new MySQLTableReferencesClauseParser(shardingRule, lexerEngine)); } + @Override + protected Keyword[] getUnsupportedKeywordsBeforeInto() { + return new Keyword[0]; + } + @Override protected Keyword[] getSkippedKeywordsBetweenTableAndValues() { return new Keyword[] {MySQLKeyword.PARTITION}; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleGroupByClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleGroupByClauseParser.java index 9ae22c190972e..e94c2e21385ea 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleGroupByClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleGroupByClauseParser.java @@ -37,4 +37,9 @@ public OracleGroupByClauseParser(final LexerEngine lexerEngine) { protected Keyword[] getUnsupportedKeywordBeforeGroupByItem() { return new Keyword[] {OracleKeyword.ROLLUP, OracleKeyword.CUBE, OracleKeyword.GROUPING}; } + + @Override + protected Keyword[] getSkippedKeywordAfterGroupBy() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertDuplicateKeyUpdateClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertDuplicateKeyUpdateClauseParser.java new file mode 100644 index 0000000000000..ccfe36e0cb162 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertDuplicateKeyUpdateClauseParser.java @@ -0,0 +1,40 @@ +/* + * 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.core.parsing.parser.dialect.oracle.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.InsertDuplicateKeyUpdateClauseParser; +import io.shardingsphere.core.rule.ShardingRule; + +/** + * Insert duplicate key update clause parser for Oracle. + * + * @author maxiaoguang + */ +public final class OracleInsertDuplicateKeyUpdateClauseParser extends InsertDuplicateKeyUpdateClauseParser { + + public OracleInsertDuplicateKeyUpdateClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { + super(shardingRule, lexerEngine); + } + + @Override + protected Keyword[] getCustomizedInsertKeywords() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertIntoClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertIntoClauseParser.java index 81c72b6ce604f..2461905a626ce 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertIntoClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertIntoClauseParser.java @@ -39,4 +39,9 @@ public OracleInsertIntoClauseParser(final ShardingRule shardingRule, final Lexer protected Keyword[] getUnsupportedKeywordsBeforeInto() { return new Keyword[] {DefaultKeyword.ALL, OracleKeyword.FIRST}; } + + @Override + protected Keyword[] getSkippedKeywordsBetweenTableAndValues() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertSetClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertSetClauseParser.java new file mode 100644 index 0000000000000..055131979ab53 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertSetClauseParser.java @@ -0,0 +1,40 @@ +/* + * 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.core.parsing.parser.dialect.oracle.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.InsertSetClauseParser; +import io.shardingsphere.core.rule.ShardingRule; + +/** + * Insert set clause parser for Oracle. + * + * @author zhangliang + */ +public final class OracleInsertSetClauseParser extends InsertSetClauseParser { + + public OracleInsertSetClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { + super(shardingRule, lexerEngine); + } + + @Override + protected Keyword[] getCustomizedInsertKeywords() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleInsertClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleInsertClauseParserFacade.java index 136ea0e8f5666..562ea919b95f6 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleInsertClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleInsertClauseParserFacade.java @@ -19,11 +19,11 @@ import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.parser.clause.InsertColumnsClauseParser; -import io.shardingsphere.core.parsing.parser.clause.InsertDuplicateKeyUpdateClauseParser; -import io.shardingsphere.core.parsing.parser.clause.InsertSetClauseParser; import io.shardingsphere.core.parsing.parser.clause.InsertValuesClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractInsertClauseParserFacade; +import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleInsertDuplicateKeyUpdateClauseParser; import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleInsertIntoClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleInsertSetClauseParser; import io.shardingsphere.core.rule.ShardingRule; /** @@ -34,7 +34,7 @@ public final class OracleInsertClauseParserFacade extends AbstractInsertClauseParserFacade { public OracleInsertClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new OracleInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), - new InsertValuesClauseParser(shardingRule, lexerEngine), new InsertSetClauseParser(shardingRule, lexerEngine), new InsertDuplicateKeyUpdateClauseParser(shardingRule, lexerEngine)); + super(new OracleInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), new InsertValuesClauseParser(shardingRule, lexerEngine), + new OracleInsertSetClauseParser(shardingRule, lexerEngine), new OracleInsertDuplicateKeyUpdateClauseParser(shardingRule, lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLDistinctClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLDistinctClauseParser.java new file mode 100644 index 0000000000000..ca0fc18f12ae6 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLDistinctClauseParser.java @@ -0,0 +1,39 @@ +/* + * 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.core.parsing.parser.dialect.postgresql.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.DistinctClauseParser; + +/** + * Distinct clause parser for PostgreSQL. + * + * @author zhangliang + */ +public final class PostgreSQLDistinctClauseParser extends DistinctClauseParser { + + public PostgreSQLDistinctClauseParser(final LexerEngine lexerEngine) { + super(lexerEngine); + } + + @Override + protected Keyword[] getSynonymousKeywordsForDistinct() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLGroupByClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLGroupByClauseParser.java new file mode 100644 index 0000000000000..ba0a5310d59f7 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLGroupByClauseParser.java @@ -0,0 +1,44 @@ +/* + * 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.core.parsing.parser.dialect.postgresql.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.GroupByClauseParser; + +/** + * Group by clause parser for PostgreSQL. + * + * @author zhangliang + */ +public final class PostgreSQLGroupByClauseParser extends GroupByClauseParser { + + public PostgreSQLGroupByClauseParser(final LexerEngine lexerEngine) { + super(lexerEngine); + } + + @Override + protected Keyword[] getUnsupportedKeywordBeforeGroupByItem() { + return new Keyword[0]; + } + + @Override + protected Keyword[] getSkippedKeywordAfterGroupBy() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertDuplicateKeyUpdateClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertDuplicateKeyUpdateClauseParser.java new file mode 100644 index 0000000000000..7925874eab4b1 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertDuplicateKeyUpdateClauseParser.java @@ -0,0 +1,40 @@ +/* + * 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.core.parsing.parser.dialect.postgresql.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.InsertDuplicateKeyUpdateClauseParser; +import io.shardingsphere.core.rule.ShardingRule; + +/** + * Insert duplicate key update clause parser for SQLServer. + * + * @author maxiaoguang + */ +public final class PostgreSQLInsertDuplicateKeyUpdateClauseParser extends InsertDuplicateKeyUpdateClauseParser { + + public PostgreSQLInsertDuplicateKeyUpdateClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { + super(shardingRule, lexerEngine); + } + + @Override + protected Keyword[] getCustomizedInsertKeywords() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertIntoClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertIntoClauseParser.java index 78e327b4b4e6f..cd4ce0f4b08cf 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertIntoClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertIntoClauseParser.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.parsing.parser.dialect.postgresql.clause; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.clause.InsertIntoClauseParser; import io.shardingsphere.core.rule.ShardingRule; @@ -31,4 +32,14 @@ public final class PostgreSQLInsertIntoClauseParser extends InsertIntoClausePars public PostgreSQLInsertIntoClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(lexerEngine, new PostgreSQLTableReferencesClauseParser(shardingRule, lexerEngine)); } + + @Override + protected Keyword[] getUnsupportedKeywordsBeforeInto() { + return new Keyword[0]; + } + + @Override + protected Keyword[] getSkippedKeywordsBetweenTableAndValues() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertSetClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertSetClauseParser.java new file mode 100644 index 0000000000000..b326f8e36e247 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertSetClauseParser.java @@ -0,0 +1,40 @@ +/* + * 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.core.parsing.parser.dialect.postgresql.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.InsertSetClauseParser; +import io.shardingsphere.core.rule.ShardingRule; + +/** + * Insert set clause parser for PostgreSQL. + * + * @author zhangliang + */ +public final class PostgreSQLInsertSetClauseParser extends InsertSetClauseParser { + + public PostgreSQLInsertSetClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { + super(shardingRule, lexerEngine); + } + + @Override + protected Keyword[] getCustomizedInsertKeywords() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLInsertClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLInsertClauseParserFacade.java index bc04c3e52d42a..05cc2c325fa86 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLInsertClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLInsertClauseParserFacade.java @@ -19,11 +19,11 @@ import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.parser.clause.InsertColumnsClauseParser; -import io.shardingsphere.core.parsing.parser.clause.InsertDuplicateKeyUpdateClauseParser; -import io.shardingsphere.core.parsing.parser.clause.InsertSetClauseParser; import io.shardingsphere.core.parsing.parser.clause.InsertValuesClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractInsertClauseParserFacade; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLInsertDuplicateKeyUpdateClauseParser; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLInsertIntoClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLInsertSetClauseParser; import io.shardingsphere.core.rule.ShardingRule; /** @@ -34,7 +34,7 @@ public final class PostgreSQLInsertClauseParserFacade extends AbstractInsertClauseParserFacade { public PostgreSQLInsertClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new PostgreSQLInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), - new InsertValuesClauseParser(shardingRule, lexerEngine), new InsertSetClauseParser(shardingRule, lexerEngine), new InsertDuplicateKeyUpdateClauseParser(shardingRule, lexerEngine)); + super(new PostgreSQLInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), new InsertValuesClauseParser(shardingRule, lexerEngine), + new PostgreSQLInsertSetClauseParser(shardingRule, lexerEngine), new PostgreSQLInsertDuplicateKeyUpdateClauseParser(shardingRule, lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLSelectClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLSelectClauseParserFacade.java index 7c81407f4da41..ecfdfa56ada64 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLSelectClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLSelectClauseParserFacade.java @@ -19,12 +19,12 @@ import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.parsing.lexer.LexerEngine; -import io.shardingsphere.core.parsing.parser.clause.DistinctClauseParser; -import io.shardingsphere.core.parsing.parser.clause.GroupByClauseParser; import io.shardingsphere.core.parsing.parser.clause.HavingClauseParser; import io.shardingsphere.core.parsing.parser.clause.SelectListClauseParser; import io.shardingsphere.core.parsing.parser.clause.WhereClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractSelectClauseParserFacade; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLDistinctClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLGroupByClauseParser; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLOrderByClauseParser; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLSelectRestClauseParser; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLTableReferencesClauseParser; @@ -38,9 +38,9 @@ public final class PostgreSQLSelectClauseParserFacade extends AbstractSelectClauseParserFacade { public PostgreSQLSelectClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new DistinctClauseParser(lexerEngine), new SelectListClauseParser(shardingRule, lexerEngine), + super(new PostgreSQLDistinctClauseParser(lexerEngine), new SelectListClauseParser(shardingRule, lexerEngine), new PostgreSQLTableReferencesClauseParser(shardingRule, lexerEngine), - new WhereClauseParser(DatabaseType.PostgreSQL, lexerEngine), new GroupByClauseParser(lexerEngine), new HavingClauseParser(lexerEngine), + new WhereClauseParser(DatabaseType.PostgreSQL, lexerEngine), new PostgreSQLGroupByClauseParser(lexerEngine), new HavingClauseParser(lexerEngine), new PostgreSQLOrderByClauseParser(lexerEngine), new PostgreSQLSelectRestClauseParser(lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerDistinctClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerDistinctClauseParser.java new file mode 100644 index 0000000000000..b9e28b8852c62 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerDistinctClauseParser.java @@ -0,0 +1,39 @@ +/* + * 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.core.parsing.parser.dialect.sqlserver.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.DistinctClauseParser; + +/** + * Distinct clause parser for SQLServer. + * + * @author zhangliang + */ +public final class SQLServerDistinctClauseParser extends DistinctClauseParser { + + public SQLServerDistinctClauseParser(final LexerEngine lexerEngine) { + super(lexerEngine); + } + + @Override + protected Keyword[] getSynonymousKeywordsForDistinct() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerGroupByClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerGroupByClauseParser.java new file mode 100644 index 0000000000000..578c5bdea3dfa --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerGroupByClauseParser.java @@ -0,0 +1,44 @@ +/* + * 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.core.parsing.parser.dialect.sqlserver.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.GroupByClauseParser; + +/** + * Group by clause parser for SQLServer. + * + * @author zhangliang + */ +public final class SQLServerGroupByClauseParser extends GroupByClauseParser { + + public SQLServerGroupByClauseParser(final LexerEngine lexerEngine) { + super(lexerEngine); + } + + @Override + protected Keyword[] getUnsupportedKeywordBeforeGroupByItem() { + return new Keyword[0]; + } + + @Override + protected Keyword[] getSkippedKeywordAfterGroupBy() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertDuplicateKeyUpdateClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertDuplicateKeyUpdateClauseParser.java new file mode 100644 index 0000000000000..761e50b57eb00 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertDuplicateKeyUpdateClauseParser.java @@ -0,0 +1,40 @@ +/* + * 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.core.parsing.parser.dialect.sqlserver.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.InsertDuplicateKeyUpdateClauseParser; +import io.shardingsphere.core.rule.ShardingRule; + +/** + * Insert duplicate key update clause parser for PostgreSQL. + * + * @author maxiaoguang + */ +public final class SQLServerInsertDuplicateKeyUpdateClauseParser extends InsertDuplicateKeyUpdateClauseParser { + + public SQLServerInsertDuplicateKeyUpdateClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { + super(shardingRule, lexerEngine); + } + + @Override + protected Keyword[] getCustomizedInsertKeywords() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertIntoClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertIntoClauseParser.java index 9ee12b7a4c44f..0738a6e21d50e 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertIntoClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertIntoClauseParser.java @@ -18,6 +18,7 @@ package io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.clause.InsertIntoClauseParser; import io.shardingsphere.core.rule.ShardingRule; @@ -31,4 +32,14 @@ public final class SQLServerInsertIntoClauseParser extends InsertIntoClauseParse public SQLServerInsertIntoClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(lexerEngine, new SQLServerTableReferencesClauseParser(shardingRule, lexerEngine)); } + + @Override + protected Keyword[] getUnsupportedKeywordsBeforeInto() { + return new Keyword[0]; + } + + @Override + protected Keyword[] getSkippedKeywordsBetweenTableAndValues() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertSetClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertSetClauseParser.java new file mode 100644 index 0000000000000..d4cec92cadcd1 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertSetClauseParser.java @@ -0,0 +1,40 @@ +/* + * 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.core.parsing.parser.dialect.sqlserver.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.InsertSetClauseParser; +import io.shardingsphere.core.rule.ShardingRule; + +/** + * Insert set clause parser for SQLServer. + * + * @author zhangliang + */ +public final class SQLServerInsertSetClauseParser extends InsertSetClauseParser { + + public SQLServerInsertSetClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { + super(shardingRule, lexerEngine); + } + + @Override + protected Keyword[] getCustomizedInsertKeywords() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerInsertClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerInsertClauseParserFacade.java index a1ed3d91c3644..de7f3cb7cca26 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerInsertClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerInsertClauseParserFacade.java @@ -19,11 +19,11 @@ import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.parser.clause.InsertColumnsClauseParser; -import io.shardingsphere.core.parsing.parser.clause.InsertDuplicateKeyUpdateClauseParser; -import io.shardingsphere.core.parsing.parser.clause.InsertSetClauseParser; import io.shardingsphere.core.parsing.parser.clause.InsertValuesClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractInsertClauseParserFacade; +import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerInsertDuplicateKeyUpdateClauseParser; import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerInsertIntoClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerInsertSetClauseParser; import io.shardingsphere.core.rule.ShardingRule; /** @@ -34,7 +34,7 @@ public final class SQLServerInsertClauseParserFacade extends AbstractInsertClauseParserFacade { public SQLServerInsertClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new SQLServerInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), - new InsertValuesClauseParser(shardingRule, lexerEngine), new InsertSetClauseParser(shardingRule, lexerEngine), new InsertDuplicateKeyUpdateClauseParser(shardingRule, lexerEngine)); + super(new SQLServerInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), new InsertValuesClauseParser(shardingRule, lexerEngine), + new SQLServerInsertSetClauseParser(shardingRule, lexerEngine), new SQLServerInsertDuplicateKeyUpdateClauseParser(shardingRule, lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerSelectClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerSelectClauseParserFacade.java index 8744a721e3a5f..62250eec91218 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerSelectClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerSelectClauseParserFacade.java @@ -18,10 +18,10 @@ package io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.facade; import io.shardingsphere.core.parsing.lexer.LexerEngine; -import io.shardingsphere.core.parsing.parser.clause.DistinctClauseParser; -import io.shardingsphere.core.parsing.parser.clause.GroupByClauseParser; import io.shardingsphere.core.parsing.parser.clause.HavingClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractSelectClauseParserFacade; +import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerDistinctClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerGroupByClauseParser; import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerOrderByClauseParser; import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerSelectListClauseParser; import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerSelectRestClauseParser; @@ -37,8 +37,8 @@ public final class SQLServerSelectClauseParserFacade extends AbstractSelectClauseParserFacade { public SQLServerSelectClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new DistinctClauseParser(lexerEngine), new SQLServerSelectListClauseParser(shardingRule, lexerEngine), - new SQLServerTableReferencesClauseParser(shardingRule, lexerEngine), new SQLServerWhereClauseParser(lexerEngine), new GroupByClauseParser(lexerEngine), + super(new SQLServerDistinctClauseParser(lexerEngine), new SQLServerSelectListClauseParser(shardingRule, lexerEngine), + new SQLServerTableReferencesClauseParser(shardingRule, lexerEngine), new SQLServerWhereClauseParser(lexerEngine), new SQLServerGroupByClauseParser(lexerEngine), new HavingClauseParser(lexerEngine), new SQLServerOrderByClauseParser(lexerEngine), new SQLServerSelectRestClauseParser(lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/deny/DenyUserParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/deny/DenyUserParser.java index ff8aaf7f3a4d2..946c639ddbae5 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/deny/DenyUserParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/deny/DenyUserParser.java @@ -29,7 +29,7 @@ * * @author panjuan */ -public class DenyUserParser implements SQLParser { +public final class DenyUserParser implements SQLParser { private final LexerEngine lexerEngine; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/drop/DropUserParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/drop/DropUserParser.java index c88dac0b775a0..d52c2672249d8 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/drop/DropUserParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/drop/DropUserParser.java @@ -35,7 +35,7 @@ public class DropUserParser implements SQLParser { private final LexerEngine lexerEngine; @Override - public DCLStatement parse() { + public final DCLStatement parse() { if (lexerEngine.skipIfEqual(DefaultKeyword.USER) || lexerEngine.skipIfEqual(DefaultKeyword.ROLE) || lexerEngine.skipIfEqual(DefaultKeyword.LOGIN)) { return new DCLStatement(); } else { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/grant/GrantUserParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/grant/GrantUserParser.java index 7aca37b00e1d4..45c8cb6db9715 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/grant/GrantUserParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/grant/GrantUserParser.java @@ -29,7 +29,7 @@ * * @author panjuan */ -public class GrantUserParser implements SQLParser { +public final class GrantUserParser implements SQLParser { private final LexerEngine lexerEngine; diff --git a/sharding-core/src/test/java/io/shardingsphere/core/keygen/fixture/IncrementKeyGenerator.java b/sharding-core/src/test/java/io/shardingsphere/core/keygen/fixture/IncrementKeyGenerator.java index e871ceeed7228..225ddfb7aedfc 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/keygen/fixture/IncrementKeyGenerator.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/keygen/fixture/IncrementKeyGenerator.java @@ -21,7 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger; -public class IncrementKeyGenerator implements KeyGenerator { +public final class IncrementKeyGenerator implements KeyGenerator { private final AtomicInteger count = new AtomicInteger(); diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/GeneratedKeysResultSet.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/GeneratedKeysResultSet.java index f551ff67040a3..c347ada29b505 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/GeneratedKeysResultSet.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/resultset/GeneratedKeysResultSet.java @@ -33,7 +33,7 @@ * @author gaohongtao */ @RequiredArgsConstructor -public class GeneratedKeysResultSet extends AbstractUnsupportedGeneratedKeysResultSet { +public final class GeneratedKeysResultSet extends AbstractUnsupportedGeneratedKeysResultSet { private final Iterator generatedKeys; diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java index b0f140178cf29..736b6e8b951f1 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedGeneratedKeysResultSet.java @@ -30,7 +30,6 @@ import java.sql.Time; import java.sql.Timestamp; import java.util.Calendar; -import java.util.Map; /** * Unsupported {@code ResultSet} methods for generated keys. @@ -90,7 +89,7 @@ public final Time getTime(final String columnLabel) throws SQLException { } @Override - public Timestamp getTimestamp(final int columnIndex) throws SQLException { + public final Timestamp getTimestamp(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getTimestamp"); } @@ -179,16 +178,6 @@ public final int getFetchSize() throws SQLException { throw new SQLFeatureNotSupportedException("getFetchSize"); } - @Override - public Object getObject(final int columnIndex, final Map> map) throws SQLException { - throw new SQLFeatureNotSupportedException("getObject"); - } - - @Override - public Object getObject(final String columnLabel, final Map> map) throws SQLException { - throw new SQLFeatureNotSupportedException("getObject"); - } - @Override public final Blob getBlob(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getBlob"); diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedOperationResultSet.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedOperationResultSet.java index 0a11b1fb4605b..a999782423fb5 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedOperationResultSet.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/unsupported/AbstractUnsupportedOperationResultSet.java @@ -224,12 +224,12 @@ public final T getObject(final String columnLabel, final Class type) thro } @Override - public Object getObject(final String columnLabel, final Map> map) throws SQLException { + public final Object getObject(final String columnLabel, final Map> map) throws SQLException { throw new SQLFeatureNotSupportedException("getObject with map"); } @Override - public Object getObject(final int columnIndex, final Map> map) throws SQLException { + public final Object getObject(final int columnIndex, final Map> map) throws SQLException { throw new SQLFeatureNotSupportedException("getObject with map"); } } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/fixture/IncrementKeyGenerator.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/fixture/IncrementKeyGenerator.java index 54217a1cbea2c..f6eec3372d3c3 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/fixture/IncrementKeyGenerator.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/fixture/IncrementKeyGenerator.java @@ -21,7 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger; -public class IncrementKeyGenerator implements KeyGenerator { +public final class IncrementKeyGenerator implements KeyGenerator { private final AtomicInteger count = new AtomicInteger(); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/FrontendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/FrontendHandler.java index b8381feff3110..bcf08e10851f7 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/FrontendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/frontend/common/FrontendHandler.java @@ -32,7 +32,7 @@ public abstract class FrontendHandler extends ChannelInboundHandlerAdapter { private boolean authorized; @Override - public void channelActive(final ChannelHandlerContext context) { + public final void channelActive(final ChannelHandlerContext context) { ChannelThreadExecutorGroup.getInstance().register(context.channel().id()); handshake(context); } @@ -40,7 +40,7 @@ public void channelActive(final ChannelHandlerContext context) { protected abstract void handshake(ChannelHandlerContext context); @Override - public void channelRead(final ChannelHandlerContext context, final Object message) { + public final void channelRead(final ChannelHandlerContext context, final Object message) { if (!authorized) { auth(context, (ByteBuf) message); authorized = true; @@ -54,7 +54,7 @@ public void channelRead(final ChannelHandlerContext context, final Object messag protected abstract void executeCommand(ChannelHandlerContext context, ByteBuf message); @Override - public void channelInactive(final ChannelHandlerContext context) { + public final void channelInactive(final ChannelHandlerContext context) { context.fireChannelInactive(); ChannelThreadExecutorGroup.getInstance().unregister(context.channel().id()); } diff --git a/src/resources/sharding_checks.xml b/src/resources/sharding_checks.xml index a9c9f75972a5c..e4fcba7d67640 100644 --- a/src/resources/sharding_checks.xml +++ b/src/resources/sharding_checks.xml @@ -180,7 +180,7 @@ - + From a012aa3df9bb810edacea1b4e7967439de369999 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 14:45:35 +0800 Subject: [PATCH 181/198] checkstyle for DesignForExtension 4 --- .../dal/show/LogicTablesMergedResult.java | 2 +- .../merger/dql/common/MemoryMergedResult.java | 14 ++--- .../merger/dql/common/StreamMergedResult.java | 8 +-- .../clause/InsertValuesClauseParser.java | 6 +-- .../parser/clause/OrderByClauseParser.java | 6 +-- .../parser/clause/SelectListClauseParser.java | 14 ++--- .../parser/clause/SelectRestClauseParser.java | 6 +-- .../parser/clause/WhereClauseParser.java | 10 ++-- .../clause/MySQLDistinctClauseParser.java | 2 +- .../clause/MySQLInsertValuesClauseParser.java | 2 +- .../clause/MySQLOrderByClauseParser.java | 39 ++++++++++++++ .../clause/MySQLSelectListClauseParser.java | 52 +++++++++++++++++++ .../mysql/clause/MySQLWhereClauseParser.java | 8 +++ .../facade/MySQLSelectClauseParserFacade.java | 8 +-- .../clause/OracleDistinctClauseParser.java | 2 +- .../OracleInsertValuesClauseParser.java | 40 ++++++++++++++ .../clause/OracleSelectListClauseParser.java | 12 +++++ .../clause/OracleSelectRestClauseParser.java | 39 ++++++++++++++ .../clause/OracleWhereClauseParser.java | 6 +++ .../OracleInsertClauseParserFacade.java | 4 +- .../OracleSelectClauseParserFacade.java | 4 +- .../PostgreSQLInsertValuesClauseParser.java | 40 ++++++++++++++ .../PostgreSQLSelectListClauseParser.java | 52 +++++++++++++++++++ .../clause/PostgreSQLWhereClauseParser.java | 48 +++++++++++++++++ .../PostgreSQLDeleteClauseParserFacade.java | 5 +- .../PostgreSQLInsertClauseParserFacade.java | 7 +-- .../PostgreSQLSelectClauseParserFacade.java | 9 ++-- .../PostgreSQLUpdateClauseParserFacade.java | 5 +- .../SQLServerInsertValuesClauseParser.java | 40 ++++++++++++++ .../SQLServerSelectListClauseParser.java | 6 +++ .../clause/SQLServerWhereClauseParser.java | 6 +++ .../SQLServerInsertClauseParserFacade.java | 7 +-- .../sql/dcl/rename/RenameUserParser.java | 2 +- .../sql/dcl/revoke/RevokeUserParser.java | 2 +- .../OrderDatabaseHintShardingAlgorithm.java | 2 +- .../core/keygen/KeyGeneratorFactoryTest.java | 4 +- .../OrchestrationSpringBootConfiguration.java | 2 +- ...ationMasterSlaveDataSourceFactoryBean.java | 2 +- ...strationShardingDataSourceFactoryBean.java | 2 +- ...erSlaveDataSourceBeanDefinitionParser.java | 2 +- ...hardingDataSourceBeanDefinitionParser.java | 2 +- .../ShardingStrategyBeanDefinitionParser.java | 2 +- ...reciseModuloDatabaseShardingAlgorithm.java | 2 +- .../PreciseModuloTableShardingAlgorithm.java | 2 +- .../RangeModuloDatabaseShardingAlgorithm.java | 2 +- .../RangeModuloTableShardingAlgorithm.java | 2 +- .../OrchestrationMasterSlaveDataSource.java | 2 +- .../OrchestrationShardingDataSource.java | 2 +- .../MasterSlaveConfigurationRepresenter.java | 4 +- .../ProxyConfigurationRepresenter.java | 2 +- .../ShardingConfigurationRepresenter.java | 2 +- .../zookeeper/operation/UpdateOperation.java | 2 +- .../reg/newzk/client/retry/TestCallable.java | 2 +- .../client/retry/TestResultCallable.java | 2 +- .../zookeeper/SyncRetryStrategyTest.java | 11 ++-- .../client/zookeeper/base/TestClient.java | 2 +- .../client/zookeeper/base/TestHolder.java | 2 +- .../yaml/fixture/MultiAlgorithm.java | 2 +- .../yaml/fixture/SingleAlgorithm.java | 2 +- .../spring/boot/SpringBootConfiguration.java | 2 +- ...erSlaveDataSourceBeanDefinitionParser.java | 2 +- ...hardingDataSourceBeanDefinitionParser.java | 2 +- .../ShardingStrategyBeanDefinitionParser.java | 2 +- ...reciseModuloDatabaseShardingAlgorithm.java | 2 +- .../PreciseModuloTableShardingAlgorithm.java | 2 +- .../RangeModuloDatabaseShardingAlgorithm.java | 2 +- .../RangeModuloTableShardingAlgorithm.java | 2 +- .../impl/MemoryTransactionLogDataSource.java | 2 +- .../impl/RdbTransactionLogDataSource.java | 2 +- .../core/jdbc/adapter/WrapperAdapter.java | 2 +- .../datasource/MasterSlaveDataSource.java | 2 +- .../core/datasource/ShardingDataSource.java | 2 +- .../core/statement/ShardingStatement.java | 2 +- .../fixture/PreciseModuloAlgorithm.java | 2 +- .../jdbc/transaction/TransactionEngine.java | 2 +- .../client/response/ResponseHandler.java | 4 +- .../transport/common/codec/PacketCodec.java | 4 +- 77 files changed, 495 insertions(+), 121 deletions(-) create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLOrderByClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLSelectListClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertValuesClauseParser.java create mode 100755 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleSelectRestClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertValuesClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLSelectListClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLWhereClauseParser.java create mode 100644 sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertValuesClauseParser.java diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/LogicTablesMergedResult.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/LogicTablesMergedResult.java index da3aa34eb520d..ab0de00960887 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/LogicTablesMergedResult.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/LogicTablesMergedResult.java @@ -84,7 +84,7 @@ protected void setCellValue(final MemoryQueryResultRow memoryResultSetRow, final } @Override - public boolean next() { + public final boolean next() { if (memoryResultSetRows.hasNext()) { setCurrentResultSetRow(memoryResultSetRows.next()); return true; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/MemoryMergedResult.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/MemoryMergedResult.java index 6493707081627..6ed1b76b7d2fa 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/MemoryMergedResult.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/MemoryMergedResult.java @@ -48,7 +48,7 @@ public abstract class MemoryMergedResult implements MergedResult { private boolean wasNull; @Override - public Object getValue(final int columnIndex, final Class type) throws SQLException { + public final Object getValue(final int columnIndex, final Class type) throws SQLException { if (Blob.class == type || Clob.class == type || Reader.class == type || InputStream.class == type || SQLXML.class == type) { throw new SQLFeatureNotSupportedException(); } @@ -58,7 +58,7 @@ public Object getValue(final int columnIndex, final Class type) throws SQLExc } @Override - public Object getValue(final String columnLabel, final Class type) throws SQLException { + public final Object getValue(final String columnLabel, final Class type) throws SQLException { if (Blob.class == type || Clob.class == type || Reader.class == type || InputStream.class == type || SQLXML.class == type) { throw new SQLFeatureNotSupportedException(); } @@ -68,7 +68,7 @@ public Object getValue(final String columnLabel, final Class type) throws SQL } @Override - public Object getCalendarValue(final int columnIndex, final Class type, final Calendar calendar) { + public final Object getCalendarValue(final int columnIndex, final Class type, final Calendar calendar) { // TODO implement with calendar Object result = currentResultSetRow.getCell(columnIndex); wasNull = null == result; @@ -76,7 +76,7 @@ public Object getCalendarValue(final int columnIndex, final Class type, final } @Override - public Object getCalendarValue(final String columnLabel, final Class type, final Calendar calendar) { + public final Object getCalendarValue(final String columnLabel, final Class type, final Calendar calendar) { // TODO implement with calendar Object result = currentResultSetRow.getCell(labelAndIndexMap.get(columnLabel)); wasNull = null == result; @@ -84,17 +84,17 @@ public Object getCalendarValue(final String columnLabel, final Class type, fi } @Override - public InputStream getInputStream(final int columnIndex, final String type) throws SQLException { + public final InputStream getInputStream(final int columnIndex, final String type) throws SQLException { throw new SQLFeatureNotSupportedException(); } @Override - public InputStream getInputStream(final String columnLabel, final String type) throws SQLException { + public final InputStream getInputStream(final String columnLabel, final String type) throws SQLException { throw new SQLFeatureNotSupportedException(); } @Override - public boolean wasNull() { + public final boolean wasNull() { return wasNull; } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/StreamMergedResult.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/StreamMergedResult.java index 931ab8c89a4ae..572020e76c0e0 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/StreamMergedResult.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dql/common/StreamMergedResult.java @@ -37,7 +37,7 @@ public abstract class StreamMergedResult implements MergedResult { private boolean wasNull; - protected QueryResult getCurrentQueryResult() throws SQLException { + protected final QueryResult getCurrentQueryResult() throws SQLException { if (null == currentQueryResult) { throw new SQLException("Current ResultSet is null, ResultSet perhaps end of next."); } @@ -74,7 +74,7 @@ public Object getCalendarValue(final String columnLabel, final Class type, fi @SuppressWarnings("deprecation") @Override - public InputStream getInputStream(final int columnIndex, final String type) throws SQLException { + public final InputStream getInputStream(final int columnIndex, final String type) throws SQLException { InputStream result = getCurrentQueryResult().getInputStream(columnIndex, type); wasNull = getCurrentQueryResult().wasNull(); return result; @@ -82,14 +82,14 @@ public InputStream getInputStream(final int columnIndex, final String type) thro @SuppressWarnings("deprecation") @Override - public InputStream getInputStream(final String columnLabel, final String type) throws SQLException { + public final InputStream getInputStream(final String columnLabel, final String type) throws SQLException { InputStream result = getCurrentQueryResult().getInputStream(columnLabel, type); wasNull = getCurrentQueryResult().wasNull(); return result; } @Override - public boolean wasNull() { + public final boolean wasNull() { return wasNull; } } 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 c70a286e7f7be..c5768bd7e80ab 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 @@ -50,7 +50,7 @@ * @author maxiaoguang * @author panjuan */ -public class InsertValuesClauseParser implements SQLClauseParser { +public abstract class InsertValuesClauseParser implements SQLClauseParser { private final ShardingRule shardingRule; @@ -78,9 +78,7 @@ public void parse(final InsertStatement insertStatement) { } } - protected Keyword[] getSynonymousKeywordsForValues() { - return new Keyword[0]; - } + protected abstract Keyword[] getSynonymousKeywordsForValues(); /** * Parse insert values. diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/OrderByClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/OrderByClauseParser.java index 1e65c5de13c14..f558a520e91c1 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/OrderByClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/OrderByClauseParser.java @@ -43,7 +43,7 @@ * * @author zhangliang */ -public class OrderByClauseParser implements SQLClauseParser { +public abstract class OrderByClauseParser implements SQLClauseParser { @Getter private final LexerEngine lexerEngine; @@ -100,7 +100,5 @@ private OrderItem parseSelectOrderByItem(final SelectStatement selectStatement) throw new SQLParsingException(lexerEngine); } - protected OrderDirection getNullOrderDirection() { - return OrderDirection.ASC; - } + protected abstract OrderDirection getNullOrderDirection(); } 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 f6a32868faaa5..a94a31cf3c90d 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 @@ -43,7 +43,7 @@ * @author zhangliang */ @Getter -public class SelectListClauseParser implements SQLClauseParser { +public abstract class SelectListClauseParser implements SQLClauseParser { private final ShardingRule shardingRule; @@ -88,17 +88,11 @@ private SelectItem parseSelectItem(final SelectStatement selectStatement) { return result; } - protected Keyword[] getSkippedKeywordsBeforeSelectItem() { - return new Keyword[0]; - } + protected abstract Keyword[] getSkippedKeywordsBeforeSelectItem(); - protected boolean isRowNumberSelectItem() { - return false; - } + protected abstract boolean isRowNumberSelectItem(); - protected SelectItem parseRowNumberSelectItem(final SelectStatement selectStatement) { - throw new UnsupportedOperationException("Cannot support special select item."); - } + protected abstract SelectItem parseRowNumberSelectItem(SelectStatement selectStatement); private boolean isStarSelectItem() { return Symbol.STAR.getLiterals().equals(SQLUtil.getExactlyValue(lexerEngine.getCurrentToken().getLiterals())); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/SelectRestClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/SelectRestClauseParser.java index e87f36fc8fddf..6432397b50b3b 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/SelectRestClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/clause/SelectRestClauseParser.java @@ -32,7 +32,7 @@ * @author zhangliang */ @RequiredArgsConstructor -public class SelectRestClauseParser implements SQLClauseParser { +public abstract class SelectRestClauseParser implements SQLClauseParser { private final LexerEngine lexerEngine; @@ -46,7 +46,5 @@ public final void parse() { lexerEngine.unsupportedIfEqual(unsupportedRestKeywords.toArray(new Keyword[unsupportedRestKeywords.size()])); } - protected Keyword[] getUnsupportedKeywordsRest() { - return new Keyword[0]; - } + protected abstract Keyword[] getUnsupportedKeywordsRest(); } 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 50e47e2b9f726..550dacb89f3be 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 @@ -59,7 +59,7 @@ * @author zhangliang * @author maxiaoguang */ -public class WhereClauseParser implements SQLClauseParser { +public abstract class WhereClauseParser implements SQLClauseParser { private final DatabaseType databaseType; @@ -257,9 +257,7 @@ private boolean isRowNumberCondition(final List items, final SQLExpr return null != columnLabel && isRowNumberCondition(items, columnLabel); } - protected boolean isRowNumberCondition(final List items, final String columnLabel) { - return false; - } + protected abstract boolean isRowNumberCondition(List items, String columnLabel); private void parseRowCountCondition(final SelectStatement selectStatement, final boolean includeRowCount) { SQLExpression sqlExpression = basicExpressionParser.parse(selectStatement); @@ -291,9 +289,7 @@ private void parseOffsetCondition(final SelectStatement selectStatement, final b } } - protected Keyword[] getCustomizedOtherConditionOperators() { - return new Keyword[0]; - } + protected abstract Keyword[] getCustomizedOtherConditionOperators(); private void parseOtherCondition(final SQLStatement sqlStatement) { basicExpressionParser.parse(sqlStatement); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLDistinctClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLDistinctClauseParser.java index d525a292c5ea4..42ea804787c68 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLDistinctClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLDistinctClauseParser.java @@ -27,7 +27,7 @@ * * @author zhangliang */ -public class MySQLDistinctClauseParser extends DistinctClauseParser { +public final class MySQLDistinctClauseParser extends DistinctClauseParser { public MySQLDistinctClauseParser(final LexerEngine lexerEngine) { super(lexerEngine); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLInsertValuesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLInsertValuesClauseParser.java index 547968504233b..ed813ebbfd691 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLInsertValuesClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLInsertValuesClauseParser.java @@ -28,7 +28,7 @@ * * @author zhangliang */ -public class MySQLInsertValuesClauseParser extends InsertValuesClauseParser { +public final class MySQLInsertValuesClauseParser extends InsertValuesClauseParser { public MySQLInsertValuesClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLOrderByClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLOrderByClauseParser.java new file mode 100644 index 0000000000000..ad775870ece94 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLOrderByClauseParser.java @@ -0,0 +1,39 @@ +/* + * 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.core.parsing.parser.dialect.mysql.clause; + +import io.shardingsphere.core.constant.OrderDirection; +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.parser.clause.OrderByClauseParser; + +/** + * Order by clause parser for MySQL. + * + * @author zhangliang + */ +public final class MySQLOrderByClauseParser extends OrderByClauseParser { + + public MySQLOrderByClauseParser(final LexerEngine lexerEngine) { + super(lexerEngine); + } + + @Override + protected OrderDirection getNullOrderDirection() { + return OrderDirection.ASC; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLSelectListClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLSelectListClauseParser.java new file mode 100644 index 0000000000000..5b414930cc86b --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLSelectListClauseParser.java @@ -0,0 +1,52 @@ +/* + * 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.core.parsing.parser.dialect.mysql.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.SelectListClauseParser; +import io.shardingsphere.core.parsing.parser.context.selectitem.SelectItem; +import io.shardingsphere.core.parsing.parser.sql.dql.select.SelectStatement; +import io.shardingsphere.core.rule.ShardingRule; + +/** + * Select list clause parser for MySQL. + * + * @author zhangliang + */ +public final class MySQLSelectListClauseParser extends SelectListClauseParser { + + public MySQLSelectListClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { + super(shardingRule, lexerEngine); + } + + @Override + protected Keyword[] getSkippedKeywordsBeforeSelectItem() { + return new Keyword[0]; + } + + @Override + protected boolean isRowNumberSelectItem() { + return false; + } + + @Override + protected SelectItem parseRowNumberSelectItem(final SelectStatement selectStatement) { + throw new UnsupportedOperationException("Cannot support special select item."); + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLWhereClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLWhereClauseParser.java index 92c829ea20bf9..6cee31c2d2e0c 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLWhereClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/MySQLWhereClauseParser.java @@ -22,6 +22,9 @@ import io.shardingsphere.core.parsing.lexer.dialect.mysql.MySQLKeyword; import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.clause.WhereClauseParser; +import io.shardingsphere.core.parsing.parser.context.selectitem.SelectItem; + +import java.util.List; /** * Where clause parser for MySQL. @@ -34,6 +37,11 @@ public MySQLWhereClauseParser(final LexerEngine lexerEngine) { super(DatabaseType.MySQL, lexerEngine); } + @Override + protected boolean isRowNumberCondition(final List items, final String columnLabel) { + return false; + } + @Override protected Keyword[] getCustomizedOtherConditionOperators() { return new Keyword[] {MySQLKeyword.REGEXP}; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/facade/MySQLSelectClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/facade/MySQLSelectClauseParserFacade.java index a125c8e300ae2..634edc95e29f0 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/facade/MySQLSelectClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/clause/facade/MySQLSelectClauseParserFacade.java @@ -19,11 +19,11 @@ import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.parser.clause.HavingClauseParser; -import io.shardingsphere.core.parsing.parser.clause.OrderByClauseParser; -import io.shardingsphere.core.parsing.parser.clause.SelectListClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractSelectClauseParserFacade; import io.shardingsphere.core.parsing.parser.dialect.mysql.clause.MySQLDistinctClauseParser; import io.shardingsphere.core.parsing.parser.dialect.mysql.clause.MySQLGroupByClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.mysql.clause.MySQLOrderByClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.mysql.clause.MySQLSelectListClauseParser; import io.shardingsphere.core.parsing.parser.dialect.mysql.clause.MySQLSelectRestClauseParser; import io.shardingsphere.core.parsing.parser.dialect.mysql.clause.MySQLTableReferencesClauseParser; import io.shardingsphere.core.parsing.parser.dialect.mysql.clause.MySQLWhereClauseParser; @@ -37,8 +37,8 @@ public final class MySQLSelectClauseParserFacade extends AbstractSelectClauseParserFacade { public MySQLSelectClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new MySQLDistinctClauseParser(lexerEngine), new SelectListClauseParser(shardingRule, lexerEngine), + super(new MySQLDistinctClauseParser(lexerEngine), new MySQLSelectListClauseParser(shardingRule, lexerEngine), new MySQLTableReferencesClauseParser(shardingRule, lexerEngine), new MySQLWhereClauseParser(lexerEngine), new MySQLGroupByClauseParser(lexerEngine), - new HavingClauseParser(lexerEngine), new OrderByClauseParser(lexerEngine), new MySQLSelectRestClauseParser(lexerEngine)); + new HavingClauseParser(lexerEngine), new MySQLOrderByClauseParser(lexerEngine), new MySQLSelectRestClauseParser(lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleDistinctClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleDistinctClauseParser.java index 045f616b148d9..6759b7fdc5b51 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleDistinctClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleDistinctClauseParser.java @@ -27,7 +27,7 @@ * * @author zhangliang */ -public class OracleDistinctClauseParser extends DistinctClauseParser { +public final class OracleDistinctClauseParser extends DistinctClauseParser { public OracleDistinctClauseParser(final LexerEngine lexerEngine) { super(lexerEngine); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertValuesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertValuesClauseParser.java new file mode 100644 index 0000000000000..2d275c4fbc58b --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertValuesClauseParser.java @@ -0,0 +1,40 @@ +/* + * 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.core.parsing.parser.dialect.oracle.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.InsertValuesClauseParser; +import io.shardingsphere.core.rule.ShardingRule; + +/** + * Insert values clause parser for Oracle. + * + * @author zhangliang + */ +public class OracleInsertValuesClauseParser extends InsertValuesClauseParser { + + public OracleInsertValuesClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { + super(shardingRule, lexerEngine); + } + + @Override + protected Keyword[] getSynonymousKeywordsForValues() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleSelectListClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleSelectListClauseParser.java index a0daf7e5d66e0..3241233b6a355 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleSelectListClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleSelectListClauseParser.java @@ -21,6 +21,8 @@ import io.shardingsphere.core.parsing.lexer.dialect.oracle.OracleKeyword; import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.clause.SelectListClauseParser; +import io.shardingsphere.core.parsing.parser.context.selectitem.SelectItem; +import io.shardingsphere.core.parsing.parser.sql.dql.select.SelectStatement; import io.shardingsphere.core.rule.ShardingRule; /** @@ -38,4 +40,14 @@ public OracleSelectListClauseParser(final ShardingRule shardingRule, final Lexer protected Keyword[] getSkippedKeywordsBeforeSelectItem() { return new Keyword[] {OracleKeyword.CONNECT_BY_ROOT}; } + + @Override + protected boolean isRowNumberSelectItem() { + return false; + } + + @Override + protected SelectItem parseRowNumberSelectItem(final SelectStatement selectStatement) { + throw new UnsupportedOperationException("Cannot support special select item."); + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleSelectRestClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleSelectRestClauseParser.java new file mode 100755 index 0000000000000..d7f7bb1cf4248 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleSelectRestClauseParser.java @@ -0,0 +1,39 @@ +/* + * 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.core.parsing.parser.dialect.oracle.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.SelectRestClauseParser; + +/** + * Select rest clause parser for Oracle. + * + * @author zhangliang + */ +public final class OracleSelectRestClauseParser extends SelectRestClauseParser { + + public OracleSelectRestClauseParser(final LexerEngine lexerEngine) { + super(lexerEngine); + } + + @Override + protected Keyword[] getUnsupportedKeywordsRest() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleWhereClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleWhereClauseParser.java index 715428598396a..62661b3c1d860 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleWhereClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleWhereClauseParser.java @@ -20,6 +20,7 @@ import com.google.common.base.Optional; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.clause.WhereClauseParser; import io.shardingsphere.core.parsing.parser.context.selectitem.SelectItem; @@ -47,4 +48,9 @@ protected boolean isRowNumberCondition(final List items, final Strin } return "rownum".equalsIgnoreCase(columnLabel) || columnLabel.equalsIgnoreCase(rowNumberAlias.orNull()); } + + @Override + protected Keyword[] getCustomizedOtherConditionOperators() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleInsertClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleInsertClauseParserFacade.java index 562ea919b95f6..325d71a0e6fcf 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleInsertClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleInsertClauseParserFacade.java @@ -19,11 +19,11 @@ import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.parser.clause.InsertColumnsClauseParser; -import io.shardingsphere.core.parsing.parser.clause.InsertValuesClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractInsertClauseParserFacade; import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleInsertDuplicateKeyUpdateClauseParser; import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleInsertIntoClauseParser; import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleInsertSetClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleInsertValuesClauseParser; import io.shardingsphere.core.rule.ShardingRule; /** @@ -34,7 +34,7 @@ public final class OracleInsertClauseParserFacade extends AbstractInsertClauseParserFacade { public OracleInsertClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new OracleInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), new InsertValuesClauseParser(shardingRule, lexerEngine), + super(new OracleInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), new OracleInsertValuesClauseParser(shardingRule, lexerEngine), new OracleInsertSetClauseParser(shardingRule, lexerEngine), new OracleInsertDuplicateKeyUpdateClauseParser(shardingRule, lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleSelectClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleSelectClauseParserFacade.java index aac24014fc29d..b3ab7eb1e150f 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleSelectClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/facade/OracleSelectClauseParserFacade.java @@ -19,12 +19,12 @@ import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.parser.clause.HavingClauseParser; -import io.shardingsphere.core.parsing.parser.clause.SelectRestClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractSelectClauseParserFacade; import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleDistinctClauseParser; import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleGroupByClauseParser; import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleOrderByClauseParser; import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleSelectListClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleSelectRestClauseParser; import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleTableReferencesClauseParser; import io.shardingsphere.core.parsing.parser.dialect.oracle.clause.OracleWhereClauseParser; import io.shardingsphere.core.rule.ShardingRule; @@ -39,6 +39,6 @@ public final class OracleSelectClauseParserFacade extends AbstractSelectClausePa public OracleSelectClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(new OracleDistinctClauseParser(lexerEngine), new OracleSelectListClauseParser(shardingRule, lexerEngine), new OracleTableReferencesClauseParser(shardingRule, lexerEngine), new OracleWhereClauseParser(lexerEngine), new OracleGroupByClauseParser(lexerEngine), - new HavingClauseParser(lexerEngine), new OracleOrderByClauseParser(lexerEngine), new SelectRestClauseParser(lexerEngine)); + new HavingClauseParser(lexerEngine), new OracleOrderByClauseParser(lexerEngine), new OracleSelectRestClauseParser(lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertValuesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertValuesClauseParser.java new file mode 100644 index 0000000000000..ad288fa7d72ae --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertValuesClauseParser.java @@ -0,0 +1,40 @@ +/* + * 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.core.parsing.parser.dialect.postgresql.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.InsertValuesClauseParser; +import io.shardingsphere.core.rule.ShardingRule; + +/** + * Insert values clause parser for PostgreSQL. + * + * @author zhangliang + */ +public class PostgreSQLInsertValuesClauseParser extends InsertValuesClauseParser { + + public PostgreSQLInsertValuesClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { + super(shardingRule, lexerEngine); + } + + @Override + protected Keyword[] getSynonymousKeywordsForValues() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLSelectListClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLSelectListClauseParser.java new file mode 100644 index 0000000000000..212df85372d74 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLSelectListClauseParser.java @@ -0,0 +1,52 @@ +/* + * 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.core.parsing.parser.dialect.postgresql.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.SelectListClauseParser; +import io.shardingsphere.core.parsing.parser.context.selectitem.SelectItem; +import io.shardingsphere.core.parsing.parser.sql.dql.select.SelectStatement; +import io.shardingsphere.core.rule.ShardingRule; + +/** + * Select list clause parser for PostgreSQL. + * + * @author zhangliang + */ +public final class PostgreSQLSelectListClauseParser extends SelectListClauseParser { + + public PostgreSQLSelectListClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { + super(shardingRule, lexerEngine); + } + + @Override + protected Keyword[] getSkippedKeywordsBeforeSelectItem() { + return new Keyword[0]; + } + + @Override + protected boolean isRowNumberSelectItem() { + return false; + } + + @Override + protected SelectItem parseRowNumberSelectItem(final SelectStatement selectStatement) { + throw new UnsupportedOperationException("Cannot support special select item."); + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLWhereClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLWhereClauseParser.java new file mode 100644 index 0000000000000..2b941611f1299 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLWhereClauseParser.java @@ -0,0 +1,48 @@ +/* + * 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.core.parsing.parser.dialect.postgresql.clause; + +import io.shardingsphere.core.constant.DatabaseType; +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.WhereClauseParser; +import io.shardingsphere.core.parsing.parser.context.selectitem.SelectItem; + +import java.util.List; + +/** + * Where clause parser for PostgreSQL. + * + * @author zhangliang + */ +public final class PostgreSQLWhereClauseParser extends WhereClauseParser { + + public PostgreSQLWhereClauseParser(final LexerEngine lexerEngine) { + super(DatabaseType.PostgreSQL, lexerEngine); + } + + @Override + protected boolean isRowNumberCondition(final List items, final String columnLabel) { + return false; + } + + @Override + protected Keyword[] getCustomizedOtherConditionOperators() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLDeleteClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLDeleteClauseParserFacade.java index 0f2866a46fef1..9c9b55603530b 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLDeleteClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLDeleteClauseParserFacade.java @@ -17,11 +17,10 @@ package io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.facade; -import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.parsing.lexer.LexerEngine; -import io.shardingsphere.core.parsing.parser.clause.WhereClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractDeleteClauseParserFacade; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLTableReferencesClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLWhereClauseParser; import io.shardingsphere.core.rule.ShardingRule; /** @@ -32,6 +31,6 @@ public final class PostgreSQLDeleteClauseParserFacade extends AbstractDeleteClauseParserFacade { public PostgreSQLDeleteClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new PostgreSQLTableReferencesClauseParser(shardingRule, lexerEngine), new WhereClauseParser(DatabaseType.PostgreSQL, lexerEngine)); + super(new PostgreSQLTableReferencesClauseParser(shardingRule, lexerEngine), new PostgreSQLWhereClauseParser(lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLInsertClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLInsertClauseParserFacade.java index 05cc2c325fa86..bb098af2cf4a0 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLInsertClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLInsertClauseParserFacade.java @@ -19,11 +19,11 @@ import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.parser.clause.InsertColumnsClauseParser; -import io.shardingsphere.core.parsing.parser.clause.InsertValuesClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractInsertClauseParserFacade; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLInsertDuplicateKeyUpdateClauseParser; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLInsertIntoClauseParser; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLInsertSetClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLInsertValuesClauseParser; import io.shardingsphere.core.rule.ShardingRule; /** @@ -34,7 +34,8 @@ public final class PostgreSQLInsertClauseParserFacade extends AbstractInsertClauseParserFacade { public PostgreSQLInsertClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new PostgreSQLInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), new InsertValuesClauseParser(shardingRule, lexerEngine), - new PostgreSQLInsertSetClauseParser(shardingRule, lexerEngine), new PostgreSQLInsertDuplicateKeyUpdateClauseParser(shardingRule, lexerEngine)); + super(new PostgreSQLInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), + new PostgreSQLInsertValuesClauseParser(shardingRule, lexerEngine), new PostgreSQLInsertSetClauseParser(shardingRule, lexerEngine), + new PostgreSQLInsertDuplicateKeyUpdateClauseParser(shardingRule, lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLSelectClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLSelectClauseParserFacade.java index ecfdfa56ada64..e3917f6b10708 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLSelectClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLSelectClauseParserFacade.java @@ -17,17 +17,16 @@ package io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.facade; -import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.parser.clause.HavingClauseParser; -import io.shardingsphere.core.parsing.parser.clause.SelectListClauseParser; -import io.shardingsphere.core.parsing.parser.clause.WhereClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractSelectClauseParserFacade; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLDistinctClauseParser; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLGroupByClauseParser; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLOrderByClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLSelectListClauseParser; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLSelectRestClauseParser; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLTableReferencesClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLWhereClauseParser; import io.shardingsphere.core.rule.ShardingRule; /** @@ -38,9 +37,9 @@ public final class PostgreSQLSelectClauseParserFacade extends AbstractSelectClauseParserFacade { public PostgreSQLSelectClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new PostgreSQLDistinctClauseParser(lexerEngine), new SelectListClauseParser(shardingRule, lexerEngine), + super(new PostgreSQLDistinctClauseParser(lexerEngine), new PostgreSQLSelectListClauseParser(shardingRule, lexerEngine), new PostgreSQLTableReferencesClauseParser(shardingRule, lexerEngine), - new WhereClauseParser(DatabaseType.PostgreSQL, lexerEngine), new PostgreSQLGroupByClauseParser(lexerEngine), new HavingClauseParser(lexerEngine), + new PostgreSQLWhereClauseParser(lexerEngine), new PostgreSQLGroupByClauseParser(lexerEngine), new HavingClauseParser(lexerEngine), new PostgreSQLOrderByClauseParser(lexerEngine), new PostgreSQLSelectRestClauseParser(lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLUpdateClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLUpdateClauseParserFacade.java index 779524a2f19f8..3b26736d03f60 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLUpdateClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/facade/PostgreSQLUpdateClauseParserFacade.java @@ -17,12 +17,11 @@ package io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.facade; -import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.parser.clause.UpdateSetItemsClauseParser; -import io.shardingsphere.core.parsing.parser.clause.WhereClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractUpdateClauseParserFacade; import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLTableReferencesClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.postgresql.clause.PostgreSQLWhereClauseParser; import io.shardingsphere.core.rule.ShardingRule; /** @@ -33,6 +32,6 @@ public final class PostgreSQLUpdateClauseParserFacade extends AbstractUpdateClauseParserFacade { public PostgreSQLUpdateClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new PostgreSQLTableReferencesClauseParser(shardingRule, lexerEngine), new UpdateSetItemsClauseParser(lexerEngine), new WhereClauseParser(DatabaseType.PostgreSQL, lexerEngine)); + super(new PostgreSQLTableReferencesClauseParser(shardingRule, lexerEngine), new UpdateSetItemsClauseParser(lexerEngine), new PostgreSQLWhereClauseParser(lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertValuesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertValuesClauseParser.java new file mode 100644 index 0000000000000..1e050c20d9780 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertValuesClauseParser.java @@ -0,0 +1,40 @@ +/* + * 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.core.parsing.parser.dialect.sqlserver.clause; + +import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; +import io.shardingsphere.core.parsing.parser.clause.InsertValuesClauseParser; +import io.shardingsphere.core.rule.ShardingRule; + +/** + * Insert values clause parser for SQLServer. + * + * @author zhangliang + */ +public class SQLServerInsertValuesClauseParser extends InsertValuesClauseParser { + + public SQLServerInsertValuesClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { + super(shardingRule, lexerEngine); + } + + @Override + protected Keyword[] getSynonymousKeywordsForValues() { + return new Keyword[0]; + } +} diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerSelectListClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerSelectListClauseParser.java index 9100d5ee1a58a..1b03f1b537dd3 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerSelectListClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerSelectListClauseParser.java @@ -20,6 +20,7 @@ import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.lexer.dialect.sqlserver.SQLServerKeyword; import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.lexer.token.Symbol; import io.shardingsphere.core.parsing.parser.clause.OrderByClauseParser; import io.shardingsphere.core.parsing.parser.clause.SelectListClauseParser; @@ -42,6 +43,11 @@ public SQLServerSelectListClauseParser(final ShardingRule shardingRule, final Le orderByClauseParser = new SQLServerOrderByClauseParser(lexerEngine); } + @Override + protected Keyword[] getSkippedKeywordsBeforeSelectItem() { + return new Keyword[0]; + } + @Override protected boolean isRowNumberSelectItem() { return getLexerEngine().skipIfEqual(SQLServerKeyword.ROW_NUMBER); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerWhereClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerWhereClauseParser.java index ea67383990b37..8ec78b8e26c5c 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerWhereClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerWhereClauseParser.java @@ -20,6 +20,7 @@ import com.google.common.base.Optional; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.parsing.lexer.LexerEngine; +import io.shardingsphere.core.parsing.lexer.token.Keyword; import io.shardingsphere.core.parsing.parser.clause.WhereClauseParser; import io.shardingsphere.core.parsing.parser.context.selectitem.SelectItem; @@ -47,4 +48,9 @@ protected boolean isRowNumberCondition(final List items, final Strin } return columnLabel.equalsIgnoreCase(rowNumberAlias.orNull()); } + + @Override + protected Keyword[] getCustomizedOtherConditionOperators() { + return new Keyword[0]; + } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerInsertClauseParserFacade.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerInsertClauseParserFacade.java index de7f3cb7cca26..fa891fbd6ff90 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerInsertClauseParserFacade.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/facade/SQLServerInsertClauseParserFacade.java @@ -19,11 +19,11 @@ import io.shardingsphere.core.parsing.lexer.LexerEngine; import io.shardingsphere.core.parsing.parser.clause.InsertColumnsClauseParser; -import io.shardingsphere.core.parsing.parser.clause.InsertValuesClauseParser; import io.shardingsphere.core.parsing.parser.clause.facade.AbstractInsertClauseParserFacade; import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerInsertDuplicateKeyUpdateClauseParser; import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerInsertIntoClauseParser; import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerInsertSetClauseParser; +import io.shardingsphere.core.parsing.parser.dialect.sqlserver.clause.SQLServerInsertValuesClauseParser; import io.shardingsphere.core.rule.ShardingRule; /** @@ -34,7 +34,8 @@ public final class SQLServerInsertClauseParserFacade extends AbstractInsertClauseParserFacade { public SQLServerInsertClauseParserFacade(final ShardingRule shardingRule, final LexerEngine lexerEngine) { - super(new SQLServerInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), new InsertValuesClauseParser(shardingRule, lexerEngine), - new SQLServerInsertSetClauseParser(shardingRule, lexerEngine), new SQLServerInsertDuplicateKeyUpdateClauseParser(shardingRule, lexerEngine)); + super(new SQLServerInsertIntoClauseParser(shardingRule, lexerEngine), new InsertColumnsClauseParser(shardingRule, lexerEngine), + new SQLServerInsertValuesClauseParser(shardingRule, lexerEngine), new SQLServerInsertSetClauseParser(shardingRule, lexerEngine), + new SQLServerInsertDuplicateKeyUpdateClauseParser(shardingRule, lexerEngine)); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/rename/RenameUserParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/rename/RenameUserParser.java index 82f9fda3b6a7e..126eafed4e36a 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/rename/RenameUserParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/rename/RenameUserParser.java @@ -30,7 +30,7 @@ * @author panjuan */ @RequiredArgsConstructor -public class RenameUserParser implements SQLParser { +public final class RenameUserParser implements SQLParser { private final LexerEngine lexerEngine; diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/revoke/RevokeUserParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/revoke/RevokeUserParser.java index 6afcf1bc107c8..85e83a326b5fb 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/revoke/RevokeUserParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/revoke/RevokeUserParser.java @@ -29,7 +29,7 @@ * * @author panjuan */ -public class RevokeUserParser implements SQLParser { +public final class RevokeUserParser implements SQLParser { private final LexerEngine lexerEngine; diff --git a/sharding-core/src/test/java/io/shardingsphere/core/fixture/OrderDatabaseHintShardingAlgorithm.java b/sharding-core/src/test/java/io/shardingsphere/core/fixture/OrderDatabaseHintShardingAlgorithm.java index 8777ccf5a5d36..a6e212ad2910d 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/fixture/OrderDatabaseHintShardingAlgorithm.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/fixture/OrderDatabaseHintShardingAlgorithm.java @@ -24,7 +24,7 @@ import java.util.Collection; import java.util.Collections; -public class OrderDatabaseHintShardingAlgorithm implements HintShardingAlgorithm { +public final class OrderDatabaseHintShardingAlgorithm implements HintShardingAlgorithm { @Override public Collection doSharding(final Collection availableTargetNames, final ShardingValue shardingValue) { diff --git a/sharding-core/src/test/java/io/shardingsphere/core/keygen/KeyGeneratorFactoryTest.java b/sharding-core/src/test/java/io/shardingsphere/core/keygen/KeyGeneratorFactoryTest.java index a38b1376d3c6d..8bb7eceb177fd 100644 --- a/sharding-core/src/test/java/io/shardingsphere/core/keygen/KeyGeneratorFactoryTest.java +++ b/sharding-core/src/test/java/io/shardingsphere/core/keygen/KeyGeneratorFactoryTest.java @@ -43,7 +43,7 @@ public void assertCreateKeyGeneratorFailureWithIllegalAccess() { } @RequiredArgsConstructor - public static class InstantiationKeyGenerator implements KeyGenerator { + public static final class InstantiationKeyGenerator implements KeyGenerator { private final int field; @@ -54,7 +54,7 @@ public Number generateKey() { } @NoArgsConstructor(access = AccessLevel.PRIVATE) - public static class IllegalAccessKeyGenerator implements KeyGenerator { + public static final class IllegalAccessKeyGenerator implements KeyGenerator { @Override public Number generateKey() { diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java index e64bc185b692c..e7fb96c507a39 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/orchestration/spring/boot/OrchestrationSpringBootConfiguration.java @@ -78,7 +78,7 @@ public DataSource dataSource() throws SQLException { } @Override - public void setEnvironment(final Environment environment) { + public final void setEnvironment(final Environment environment) { setDataSourceMap(environment); } diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/datasource/OrchestrationMasterSlaveDataSourceFactoryBean.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/datasource/OrchestrationMasterSlaveDataSourceFactoryBean.java index 73be2ba394096..8fc2e4b868f4c 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/datasource/OrchestrationMasterSlaveDataSourceFactoryBean.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/datasource/OrchestrationMasterSlaveDataSourceFactoryBean.java @@ -36,7 +36,7 @@ * @author zhangliang * @author panjuan */ -public class OrchestrationMasterSlaveDataSourceFactoryBean implements FactoryBean, InitializingBean, DisposableBean { +public final class OrchestrationMasterSlaveDataSourceFactoryBean implements FactoryBean, InitializingBean, DisposableBean { private OrchestrationMasterSlaveDataSource orchestrationMasterSlaveDataSource; diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/datasource/OrchestrationShardingDataSourceFactoryBean.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/datasource/OrchestrationShardingDataSourceFactoryBean.java index d86980b1405e3..963e0cbcd2747 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/datasource/OrchestrationShardingDataSourceFactoryBean.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/datasource/OrchestrationShardingDataSourceFactoryBean.java @@ -35,7 +35,7 @@ * * @author zhangliang */ -public class OrchestrationShardingDataSourceFactoryBean implements FactoryBean, InitializingBean, DisposableBean { +public final class OrchestrationShardingDataSourceFactoryBean implements FactoryBean, InitializingBean, DisposableBean { private OrchestrationShardingDataSource orchestrationShardingDataSource; diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/OrchestrationMasterSlaveDataSourceBeanDefinitionParser.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/OrchestrationMasterSlaveDataSourceBeanDefinitionParser.java index 9af4eda3da0bf..797cb115754e1 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/OrchestrationMasterSlaveDataSourceBeanDefinitionParser.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/OrchestrationMasterSlaveDataSourceBeanDefinitionParser.java @@ -48,7 +48,7 @@ * @author caohao * @author zhangliang */ -public class OrchestrationMasterSlaveDataSourceBeanDefinitionParser extends AbstractOrchestrationBeanDefinitionParser { +public final class OrchestrationMasterSlaveDataSourceBeanDefinitionParser extends AbstractOrchestrationBeanDefinitionParser { @Override protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) { diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/OrchestrationShardingDataSourceBeanDefinitionParser.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/OrchestrationShardingDataSourceBeanDefinitionParser.java index 2152d429a2c06..995017a1b2109 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/OrchestrationShardingDataSourceBeanDefinitionParser.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/OrchestrationShardingDataSourceBeanDefinitionParser.java @@ -47,7 +47,7 @@ * @author caohao * @author zhangliang */ -public class OrchestrationShardingDataSourceBeanDefinitionParser extends AbstractOrchestrationBeanDefinitionParser { +public final class OrchestrationShardingDataSourceBeanDefinitionParser extends AbstractOrchestrationBeanDefinitionParser { @Override protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) { diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/ShardingStrategyBeanDefinitionParser.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/ShardingStrategyBeanDefinitionParser.java index 5523ebea99bca..d9ddf646479bc 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/ShardingStrategyBeanDefinitionParser.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/main/java/io/shardingsphere/jdbc/orchestration/spring/namespace/parser/ShardingStrategyBeanDefinitionParser.java @@ -27,7 +27,7 @@ *® * @author caohao */ -public class ShardingStrategyBeanDefinitionParser extends AbstractBeanDefinitionParser { +public final class ShardingStrategyBeanDefinitionParser extends AbstractBeanDefinitionParser { @Override protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) { diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/PreciseModuloDatabaseShardingAlgorithm.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/PreciseModuloDatabaseShardingAlgorithm.java index 0db78329bf378..fba073419f555 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/PreciseModuloDatabaseShardingAlgorithm.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/PreciseModuloDatabaseShardingAlgorithm.java @@ -22,7 +22,7 @@ import java.util.Collection; -public class PreciseModuloDatabaseShardingAlgorithm implements PreciseShardingAlgorithm { +public final class PreciseModuloDatabaseShardingAlgorithm implements PreciseShardingAlgorithm { @Override public String doSharding(final Collection availableTargetNames, final PreciseShardingValue shardingValue) { diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/PreciseModuloTableShardingAlgorithm.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/PreciseModuloTableShardingAlgorithm.java index 7b15dea133bb4..00cb113be3cb2 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/PreciseModuloTableShardingAlgorithm.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/PreciseModuloTableShardingAlgorithm.java @@ -22,7 +22,7 @@ import java.util.Collection; -public class PreciseModuloTableShardingAlgorithm implements PreciseShardingAlgorithm { +public final class PreciseModuloTableShardingAlgorithm implements PreciseShardingAlgorithm { @Override public String doSharding(final Collection availableTargetNames, final PreciseShardingValue shardingValue) { diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/RangeModuloDatabaseShardingAlgorithm.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/RangeModuloDatabaseShardingAlgorithm.java index 329da016d3c3a..4591ffec5c683 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/RangeModuloDatabaseShardingAlgorithm.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/RangeModuloDatabaseShardingAlgorithm.java @@ -24,7 +24,7 @@ import java.util.Collection; import java.util.LinkedHashSet; -public class RangeModuloDatabaseShardingAlgorithm implements RangeShardingAlgorithm { +public final class RangeModuloDatabaseShardingAlgorithm implements RangeShardingAlgorithm { @Override public Collection doSharding(final Collection availableTargetNames, final RangeShardingValue shardingValue) { diff --git a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/RangeModuloTableShardingAlgorithm.java b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/RangeModuloTableShardingAlgorithm.java index de4df2bc35bec..7459896cce821 100644 --- a/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/RangeModuloTableShardingAlgorithm.java +++ b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/src/test/java/io/shardingsphere/jdbc/orchestration/spring/algorithm/RangeModuloTableShardingAlgorithm.java @@ -24,7 +24,7 @@ import java.util.Collection; import java.util.LinkedHashSet; -public class RangeModuloTableShardingAlgorithm implements RangeShardingAlgorithm { +public final class RangeModuloTableShardingAlgorithm implements RangeShardingAlgorithm { @Override public Collection doSharding(final Collection availableTargetNames, final RangeShardingValue shardingValue) { diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/OrchestrationMasterSlaveDataSource.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/OrchestrationMasterSlaveDataSource.java index fe50cbbb2fe06..8f4b4b7d42f1e 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/OrchestrationMasterSlaveDataSource.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/OrchestrationMasterSlaveDataSource.java @@ -33,7 +33,7 @@ * @author panjuan */ @Slf4j -public class OrchestrationMasterSlaveDataSource extends MasterSlaveDataSource implements AutoCloseable { +public final class OrchestrationMasterSlaveDataSource extends MasterSlaveDataSource implements AutoCloseable { private final OrchestrationFacade orchestrationFacade; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/OrchestrationShardingDataSource.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/OrchestrationShardingDataSource.java index 5791833574de4..a21d15b256bf8 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/OrchestrationShardingDataSource.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/OrchestrationShardingDataSource.java @@ -33,7 +33,7 @@ * @author caohao */ @Slf4j -public class OrchestrationShardingDataSource extends ShardingDataSource { +public final class OrchestrationShardingDataSource extends ShardingDataSource { private final OrchestrationFacade orchestrationFacade; diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/MasterSlaveConfigurationRepresenter.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/MasterSlaveConfigurationRepresenter.java index ff1959ed8da87..6045ffaf009f9 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/MasterSlaveConfigurationRepresenter.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/MasterSlaveConfigurationRepresenter.java @@ -35,7 +35,7 @@ * * @author panjuan */ -public class MasterSlaveConfigurationRepresenter extends Representer { +public final class MasterSlaveConfigurationRepresenter extends Representer { private static Collection eliminatedPropertyNames = new HashSet<>(); @@ -67,6 +67,8 @@ protected Set getProperties(final Class type) { } private class NullRepresent implements Represent { + + @Override public Node representData(final Object data) { return representScalar(Tag.NULL, ""); } diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/ProxyConfigurationRepresenter.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/ProxyConfigurationRepresenter.java index bbe462c7d5e31..2e486a62c53c6 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/ProxyConfigurationRepresenter.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/ProxyConfigurationRepresenter.java @@ -35,7 +35,7 @@ * * @author panjuan */ -public class ProxyConfigurationRepresenter extends Representer { +public final class ProxyConfigurationRepresenter extends Representer { private static Collection eliminatedPropertyNames = new HashSet<>(); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/ShardingConfigurationRepresenter.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/ShardingConfigurationRepresenter.java index bf875a999602d..2e8f124f901c4 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/ShardingConfigurationRepresenter.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/internal/yaml/representer/ShardingConfigurationRepresenter.java @@ -35,7 +35,7 @@ * * @author panjuan */ -public class ShardingConfigurationRepresenter extends Representer { +public final class ShardingConfigurationRepresenter extends Representer { private static Collection eliminatedPropertyNames = new HashSet<>(); diff --git a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/UpdateOperation.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/UpdateOperation.java index 56f646a730304..52b486d16ac44 100644 --- a/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/UpdateOperation.java +++ b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/operation/UpdateOperation.java @@ -26,7 +26,7 @@ * * @author lidongbo */ -public class UpdateOperation extends BaseOperation { +public final class UpdateOperation extends BaseOperation { private final String key; diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/TestCallable.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/TestCallable.java index 9330020a13907..0056ed3576f95 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/TestCallable.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/TestCallable.java @@ -30,7 +30,7 @@ public TestCallable(final IProvider provider, final DelayRetryPolicy delayRetryP } @Override - public void call() throws KeeperException, InterruptedException { + public final void call() throws KeeperException, InterruptedException { if (count < 2) { count++; diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/TestResultCallable.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/TestResultCallable.java index ec5f77c73e014..e96e504b269a2 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/TestResultCallable.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/retry/TestResultCallable.java @@ -30,7 +30,7 @@ public TestResultCallable(final IProvider provider, final DelayRetryPolicy delay } @Override - public void call() throws KeeperException, InterruptedException { + public final void call() throws KeeperException, InterruptedException { if (count < 2) { count++; diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/SyncRetryStrategyTest.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/SyncRetryStrategyTest.java index d43436d0aaaac..9e3d58a33a1e7 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/SyncRetryStrategyTest.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/SyncRetryStrategyTest.java @@ -26,16 +26,17 @@ import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.base.TestSupport; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.section.StrategyType; import io.shardingsphere.jdbc.orchestration.reg.newzk.client.zookeeper.strategy.UsualStrategy; -import java.io.IOException; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; import lombok.extern.slf4j.Slf4j; import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.ZooDefs; import org.junit.Test; +import java.io.IOException; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -44,7 +45,7 @@ import static org.junit.Assert.assertTrue; @Slf4j -public class SyncRetryStrategyTest extends UsualClientTest { +public final class SyncRetryStrategyTest extends UsualClientTest { private IProvider provider; diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestClient.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestClient.java index a06c494e0fdb1..c282df851d385 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestClient.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestClient.java @@ -23,7 +23,7 @@ import java.io.IOException; import java.util.concurrent.TimeUnit; -public class TestClient extends UsualClient { +public final class TestClient extends UsualClient { TestClient(final BaseContext context) { super(context); diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestHolder.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestHolder.java index 0c100858b9433..8dc7f3375a3f7 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestHolder.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/base/TestHolder.java @@ -24,7 +24,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -public class TestHolder extends Holder { +public final class TestHolder extends Holder { private final CountDownLatch connecting = new CountDownLatch(1); diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/fixture/MultiAlgorithm.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/fixture/MultiAlgorithm.java index 166b9a9583073..486fa19842b69 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/fixture/MultiAlgorithm.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/fixture/MultiAlgorithm.java @@ -22,7 +22,7 @@ import java.util.Collection; -public class MultiAlgorithm implements ComplexKeysShardingAlgorithm { +public final class MultiAlgorithm implements ComplexKeysShardingAlgorithm { @Override public Collection doSharding(final Collection availableTargetNames, final Collection shardingValues) { diff --git a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/fixture/SingleAlgorithm.java b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/fixture/SingleAlgorithm.java index 9abdc33b1d622..a1974b2c78461 100644 --- a/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/fixture/SingleAlgorithm.java +++ b/sharding-jdbc-orchestration/src/test/java/io/shardingsphere/jdbc/orchestration/yaml/fixture/SingleAlgorithm.java @@ -22,7 +22,7 @@ import java.util.Collection; -public class SingleAlgorithm implements PreciseShardingAlgorithm { +public final class SingleAlgorithm implements PreciseShardingAlgorithm { @Override public String doSharding(final Collection availableTargetNames, final PreciseShardingValue shardingValue) { diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/spring/boot/SpringBootConfiguration.java b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/spring/boot/SpringBootConfiguration.java index 3ef8ae5dd8ad2..c42114c0819af 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/spring/boot/SpringBootConfiguration.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-boot-starter/src/main/java/io/shardingsphere/jdbc/spring/boot/SpringBootConfiguration.java @@ -69,7 +69,7 @@ public DataSource dataSource() throws SQLException { } @Override - public void setEnvironment(final Environment environment) { + public final void setEnvironment(final Environment environment) { setDataSourceMap(environment); } diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/MasterSlaveDataSourceBeanDefinitionParser.java b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/MasterSlaveDataSourceBeanDefinitionParser.java index 515f6da51446e..850dc5a4d3710 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/MasterSlaveDataSourceBeanDefinitionParser.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/MasterSlaveDataSourceBeanDefinitionParser.java @@ -45,7 +45,7 @@ * * @author zhangliang */ -public class MasterSlaveDataSourceBeanDefinitionParser extends AbstractBeanDefinitionParser { +public final class MasterSlaveDataSourceBeanDefinitionParser extends AbstractBeanDefinitionParser { @Override protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) { diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingDataSourceBeanDefinitionParser.java b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingDataSourceBeanDefinitionParser.java index 3c79dd5aa1a2e..82ed1202dd671 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingDataSourceBeanDefinitionParser.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingDataSourceBeanDefinitionParser.java @@ -45,7 +45,7 @@ * * @author caohao */ -public class ShardingDataSourceBeanDefinitionParser extends AbstractBeanDefinitionParser { +public final class ShardingDataSourceBeanDefinitionParser extends AbstractBeanDefinitionParser { @Override protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) { diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingStrategyBeanDefinitionParser.java b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingStrategyBeanDefinitionParser.java index 774d598eeab94..ed1db84f49a9a 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingStrategyBeanDefinitionParser.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/main/java/io/shardingsphere/jdbc/spring/namespace/parser/ShardingStrategyBeanDefinitionParser.java @@ -27,7 +27,7 @@ *® * @author caohao */ -public class ShardingStrategyBeanDefinitionParser extends AbstractBeanDefinitionParser { +public final class ShardingStrategyBeanDefinitionParser extends AbstractBeanDefinitionParser { @Override protected AbstractBeanDefinition parseInternal(final Element element, final ParserContext parserContext) { diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/PreciseModuloDatabaseShardingAlgorithm.java b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/PreciseModuloDatabaseShardingAlgorithm.java index 2d9620e9bbc79..a209509f4e5fc 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/PreciseModuloDatabaseShardingAlgorithm.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/PreciseModuloDatabaseShardingAlgorithm.java @@ -22,7 +22,7 @@ import java.util.Collection; -public class PreciseModuloDatabaseShardingAlgorithm implements PreciseShardingAlgorithm { +public final class PreciseModuloDatabaseShardingAlgorithm implements PreciseShardingAlgorithm { @Override public String doSharding(final Collection availableTargetNames, final PreciseShardingValue shardingValue) { diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/PreciseModuloTableShardingAlgorithm.java b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/PreciseModuloTableShardingAlgorithm.java index df7d36096e837..4d99eb4ffc065 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/PreciseModuloTableShardingAlgorithm.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/PreciseModuloTableShardingAlgorithm.java @@ -22,7 +22,7 @@ import java.util.Collection; -public class PreciseModuloTableShardingAlgorithm implements PreciseShardingAlgorithm { +public final class PreciseModuloTableShardingAlgorithm implements PreciseShardingAlgorithm { @Override public String doSharding(final Collection availableTargetNames, final PreciseShardingValue shardingValue) { diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/RangeModuloDatabaseShardingAlgorithm.java b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/RangeModuloDatabaseShardingAlgorithm.java index c697639039e2a..b11b727334705 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/RangeModuloDatabaseShardingAlgorithm.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/RangeModuloDatabaseShardingAlgorithm.java @@ -24,7 +24,7 @@ import java.util.Collection; import java.util.LinkedHashSet; -public class RangeModuloDatabaseShardingAlgorithm implements RangeShardingAlgorithm { +public final class RangeModuloDatabaseShardingAlgorithm implements RangeShardingAlgorithm { @Override public Collection doSharding(final Collection availableTargetNames, final RangeShardingValue shardingValue) { diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/RangeModuloTableShardingAlgorithm.java b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/RangeModuloTableShardingAlgorithm.java index a6b6bd9dd696e..e26bd6d9acf1d 100644 --- a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/RangeModuloTableShardingAlgorithm.java +++ b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/src/test/java/io/shardingsphere/jdbc/spring/algorithm/RangeModuloTableShardingAlgorithm.java @@ -24,7 +24,7 @@ import java.util.Collection; import java.util.LinkedHashSet; -public class RangeModuloTableShardingAlgorithm implements RangeShardingAlgorithm { +public final class RangeModuloTableShardingAlgorithm implements RangeShardingAlgorithm { @Override public Collection doSharding(final Collection availableTargetNames, final RangeShardingValue shardingValue) { diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/main/java/io/shardingsphere/transaction/datasource/impl/MemoryTransactionLogDataSource.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/main/java/io/shardingsphere/transaction/datasource/impl/MemoryTransactionLogDataSource.java index f2a34302fd01b..2656102aa667c 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/main/java/io/shardingsphere/transaction/datasource/impl/MemoryTransactionLogDataSource.java +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/main/java/io/shardingsphere/transaction/datasource/impl/MemoryTransactionLogDataSource.java @@ -27,7 +27,7 @@ * * @author caohao */ -public class MemoryTransactionLogDataSource implements TransactionLogDataSource { +public final class MemoryTransactionLogDataSource implements TransactionLogDataSource { @Override public TransactionLogDataSourceType getType() { diff --git a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/main/java/io/shardingsphere/transaction/datasource/impl/RdbTransactionLogDataSource.java b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/main/java/io/shardingsphere/transaction/datasource/impl/RdbTransactionLogDataSource.java index 0744175035962..abf2d01a7e720 100644 --- a/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/main/java/io/shardingsphere/transaction/datasource/impl/RdbTransactionLogDataSource.java +++ b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/src/main/java/io/shardingsphere/transaction/datasource/impl/RdbTransactionLogDataSource.java @@ -29,7 +29,7 @@ * @author caohao */ @RequiredArgsConstructor -public class RdbTransactionLogDataSource implements TransactionLogDataSource { +public final class RdbTransactionLogDataSource implements TransactionLogDataSource { private final DataSource dataSource; diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/WrapperAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/WrapperAdapter.java index 33dd5bd5db712..ded99ca7a87c3 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/WrapperAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/WrapperAdapter.java @@ -75,7 +75,7 @@ public final void replayMethodsInvocation(final Object target) { } } - protected void throwSQLExceptionIfNecessary(final Collection exceptions) throws SQLException { + protected final void throwSQLExceptionIfNecessary(final Collection exceptions) throws SQLException { if (exceptions.isEmpty()) { return; } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/MasterSlaveDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/MasterSlaveDataSource.java index 4a54fce75c31e..ea59f90238659 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/MasterSlaveDataSource.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/MasterSlaveDataSource.java @@ -94,7 +94,7 @@ public void renew(final Map dataSourceMap, final MasterSlave } @Override - public MasterSlaveConnection getConnection() { + public final MasterSlaveConnection getConnection() { return new MasterSlaveConnection(this); } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java index d67ac54bf85b9..180ecadf9943b 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/datasource/ShardingDataSource.java @@ -123,7 +123,7 @@ public void renew(final Map newDataSourceMap, final Sharding } @Override - public ShardingConnection getConnection() { + public final ShardingConnection getConnection() { return new ShardingConnection(shardingContext); } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java index 7d2f101676c9f..3ed4e4559167b 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java @@ -72,7 +72,7 @@ * @author panjuan */ @Getter -public class ShardingStatement extends AbstractStatementAdapter { +public final class ShardingStatement extends AbstractStatementAdapter { private final ShardingConnection connection; diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/fixture/PreciseModuloAlgorithm.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/fixture/PreciseModuloAlgorithm.java index fd922cff7e392..d8d873c8d1164 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/fixture/PreciseModuloAlgorithm.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/fixture/PreciseModuloAlgorithm.java @@ -22,7 +22,7 @@ import java.util.Collection; -public class PreciseModuloAlgorithm implements PreciseShardingAlgorithm { +public final class PreciseModuloAlgorithm implements PreciseShardingAlgorithm { @Override public String doSharding(final Collection availableTargetNames, final PreciseShardingValue shardingValue) { diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/TransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/TransactionEngine.java index 1b54dd265c436..cef4ede6b7f51 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/TransactionEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/TransactionEngine.java @@ -38,7 +38,7 @@ public abstract class TransactionEngine { private final String sql; // TODO :yonglun move to TCLParser - protected Optional parseSQL() { + protected final Optional parseSQL() { switch (sql.toUpperCase()) { case "BEGIN": case "START TRANSACTION": diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java index da260e854603a..eaa1c3558c070 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java @@ -32,7 +32,7 @@ public abstract class ResponseHandler extends ChannelInboundHandlerAdapter { private boolean authorized; @Override - public void channelRead(final ChannelHandlerContext context, final Object message) { + public final void channelRead(final ChannelHandlerContext context, final Object message) { ByteBuf byteBuf = (ByteBuf) message; int header = getHeader(byteBuf); @@ -51,7 +51,7 @@ public void channelRead(final ChannelHandlerContext context, final Object messag protected abstract void executeCommand(ChannelHandlerContext context, ByteBuf byteBuf, int header); @Override - public void channelInactive(final ChannelHandlerContext ctx) throws Exception { + public final void channelInactive(final ChannelHandlerContext ctx) throws Exception { //TODO delete connection map super.channelInactive(ctx); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/common/codec/PacketCodec.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/common/codec/PacketCodec.java index a9a0ed668b6ab..8b013ede2f3fa 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/common/codec/PacketCodec.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/common/codec/PacketCodec.java @@ -35,7 +35,7 @@ public abstract class PacketCodec extends ByteToMessageCodec { @Override - protected void decode(final ChannelHandlerContext context, final ByteBuf in, final List out) { + protected final void decode(final ChannelHandlerContext context, final ByteBuf in, final List out) { int readableBytes = in.readableBytes(); if (!isValidHeader(readableBytes)) { return; @@ -51,7 +51,7 @@ protected void decode(final ChannelHandlerContext context, final ByteBuf in, fin protected abstract void doDecode(ChannelHandlerContext context, ByteBuf in, List out, int readableBytes); @Override - protected void encode(final ChannelHandlerContext context, final T message, final ByteBuf out) { + protected final void encode(final ChannelHandlerContext context, final T message, final ByteBuf out) { doEncode(context, message, out); if (log.isDebugEnabled()) { log.debug("Write to client {} : \n {}", context.channel().id().asShortText(), ByteBufUtil.prettyHexDump(out)); From 9d5a09cece2929eb5fd2e75c89a00d5ddb7db3b7 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 14:54:48 +0800 Subject: [PATCH 182/198] checkstyle for DesignForExtension 5 --- .../dialect/oracle/clause/OracleInsertValuesClauseParser.java | 2 +- .../postgresql/clause/PostgreSQLInsertValuesClauseParser.java | 2 +- .../sqlserver/clause/SQLServerInsertValuesClauseParser.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertValuesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertValuesClauseParser.java index 2d275c4fbc58b..7838114ec813e 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertValuesClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertValuesClauseParser.java @@ -27,7 +27,7 @@ * * @author zhangliang */ -public class OracleInsertValuesClauseParser extends InsertValuesClauseParser { +public final class OracleInsertValuesClauseParser extends InsertValuesClauseParser { public OracleInsertValuesClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertValuesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertValuesClauseParser.java index ad288fa7d72ae..ba4a073629ce7 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertValuesClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertValuesClauseParser.java @@ -27,7 +27,7 @@ * * @author zhangliang */ -public class PostgreSQLInsertValuesClauseParser extends InsertValuesClauseParser { +public final class PostgreSQLInsertValuesClauseParser extends InsertValuesClauseParser { public PostgreSQLInsertValuesClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertValuesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertValuesClauseParser.java index 1e050c20d9780..c252033e8ca39 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertValuesClauseParser.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertValuesClauseParser.java @@ -27,7 +27,7 @@ * * @author zhangliang */ -public class SQLServerInsertValuesClauseParser extends InsertValuesClauseParser { +public final class SQLServerInsertValuesClauseParser extends InsertValuesClauseParser { public SQLServerInsertValuesClauseParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) { super(shardingRule, lexerEngine); From b6651689364f6a00ac506a34ae5a99cbdd00476d Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 15:47:53 +0800 Subject: [PATCH 183/198] Merge remote-tracking branch 'origin/dev' into dev-3.1.0 # Conflicts: # sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java # sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java --- .../core/jdbc/adapter/AbstractConnectionAdapter.java | 10 +++++++--- .../jdbc/core/connection/ShardingConnectionTest.java | 9 +++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index e10e15c880fce..7fd8b9e729b5e 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -19,10 +19,13 @@ import com.google.common.base.Preconditions; import io.shardingsphere.core.constant.TCLType; +import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.hint.HintManagerHolder; import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection; import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager; import io.shardingsphere.core.util.EventBusInstance; +import io.shardingsphere.transaction.api.xa.WeakXaTransactionManager; +import io.shardingsphere.transaction.common.TransactionContext; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration; import io.shardingsphere.transaction.common.event.TransactionEvent; @@ -41,7 +44,7 @@ /** * Adapter for {@code Connection}. - * + * * @author zhangliang */ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOperationConnection { @@ -90,6 +93,7 @@ public final boolean getAutoCommit() { @Override public final void setAutoCommit(final boolean autoCommit) { this.autoCommit = autoCommit; + TransactionContextHolder.set(new TransactionContext(WeakXaTransactionManager.getInstance(), TransactionType.XA, WeakXaTransactionEvent.class)); recordMethodInvocation(Connection.class, "setAutoCommit", new Class[] {boolean.class}, new Object[] {autoCommit}); EventBusInstance.getInstance().post(buildTransactionEvent(TCLType.BEGIN)); } @@ -105,7 +109,7 @@ public final void rollback() { } @Override - public void close() throws SQLException { + public final void close() throws SQLException { closed = true; HintManagerHolder.clear(); MasterVisitedManager.clear(); @@ -160,7 +164,7 @@ public final void setTransactionIsolation(final int level) throws SQLException { // ------- Consist with MySQL driver implementation ------- @Override - public SQLWarning getWarnings() { + public final SQLWarning getWarnings() { return null; } diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java index 2c95f373d18fa..ce93ea95e2a54 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java @@ -20,13 +20,12 @@ import io.shardingsphere.core.api.config.MasterSlaveRuleConfiguration; import io.shardingsphere.core.api.config.ShardingRuleConfiguration; import io.shardingsphere.core.api.config.TableRuleConfiguration; -import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.constant.ConnectionMode; +import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.fixture.TestDataSource; import io.shardingsphere.core.jdbc.core.ShardingContext; import io.shardingsphere.core.jdbc.core.datasource.MasterSlaveDataSource; -import io.shardingsphere.core.metadata.table.ShardingTableMetaData; -import io.shardingsphere.core.metadata.table.TableMetaData; +import io.shardingsphere.core.metadata.ShardingMetaData; import io.shardingsphere.core.rule.ShardingRule; import org.junit.After; import org.junit.Before; @@ -44,6 +43,7 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; public final class ShardingConnectionTest { @@ -74,7 +74,8 @@ public void setUp() { Map dataSourceMap = new HashMap<>(1, 1); dataSourceMap.put(DS_NAME, masterSlaveDataSource); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet()); - ShardingContext shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.H2, null, new ShardingTableMetaData(Collections.emptyMap()), false, ConnectionMode.MEMORY_STRICTLY); + ShardingMetaData shardingMetaData = mock(ShardingMetaData.class); + ShardingContext shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.H2, null, shardingMetaData, ConnectionMode.MEMORY_STRICTLY, false); connection = new ShardingConnection(shardingContext); } From 03003fe4b87d74066c98cf6a7b43a41f0542ae06 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 15:52:42 +0800 Subject: [PATCH 184/198] adjust maven's artifact sequence --- sharding-proxy/pom.xml | 12 ++++---- sharding-transaction/pom.xml | 57 ++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/sharding-proxy/pom.xml b/sharding-proxy/pom.xml index b3c0bd4ae4718..29e5a679ed227 100644 --- a/sharding-proxy/pom.xml +++ b/sharding-proxy/pom.xml @@ -35,6 +35,11 @@ io.netty netty-all + + com.zaxxer + HikariCP-java7 + compile + org.slf4j slf4j-api @@ -45,11 +50,6 @@ logback-classic runtime - - com.zaxxer - HikariCP-java7 - compile - mysql mysql-connector-java @@ -77,7 +77,7 @@ commons-codec - + diff --git a/sharding-transaction/pom.xml b/sharding-transaction/pom.xml index ec81d19823983..f143f07f16307 100644 --- a/sharding-transaction/pom.xml +++ b/sharding-transaction/pom.xml @@ -8,57 +8,58 @@ io.shardingsphere 3.0.0.M3-SNAPSHOT - + sharding-transaction ${project.artifactId} - + - com.google.guava - guava + io.shardingsphere + sharding-core + ${project.parent.version} + - org.projectlombok - lombok + com.google.guava + guava - org.slf4j - slf4j-api + javax.transaction + jta - ch.qos.logback - logback-classic + com.atomikos + transactions - junit - junit + com.atomikos + transactions-jta - org.mockito - mockito-core + com.atomikos + transactions-jdbc - - io.shardingsphere - sharding-core - ${project.parent.version} + org.slf4j + slf4j-api - + - com.atomikos - transactions + org.projectlombok + lombok - com.atomikos - transactions-jta + ch.qos.logback + logback-classic + - com.atomikos - transactions-jdbc + junit + junit - javax.transaction - jta + org.mockito + mockito-core - \ No newline at end of file + From 4779939bd8f0926b7f9494c11a2ee17548a94d47 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 15:54:28 +0800 Subject: [PATCH 185/198] adjust maven's artifact sequence --- sharding-proxy/pom.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sharding-proxy/pom.xml b/sharding-proxy/pom.xml index 207bc03ac7d2b..e77cff2d1ca53 100644 --- a/sharding-proxy/pom.xml +++ b/sharding-proxy/pom.xml @@ -35,21 +35,21 @@ io.netty netty-all + + com.zaxxer + HikariCP-java7 + compile + org.slf4j slf4j-api - + ch.qos.logback logback-classic runtime - - com.zaxxer - HikariCP-java7 - compile - mysql mysql-connector-java @@ -77,7 +77,7 @@ commons-codec - + From 95a27575d5f277deeddfab3cc1bf2ebc2bb4bb94 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 16:08:46 +0800 Subject: [PATCH 186/198] adjust maven's artifact sequence --- sharding-transaction/pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sharding-transaction/pom.xml b/sharding-transaction/pom.xml index f143f07f16307..9198c1504582f 100644 --- a/sharding-transaction/pom.xml +++ b/sharding-transaction/pom.xml @@ -4,11 +4,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - sharding-sphere io.shardingsphere + sharding-sphere 3.0.0.M3-SNAPSHOT - sharding-transaction ${project.artifactId} @@ -18,7 +17,7 @@ sharding-core ${project.parent.version} - + com.google.guava guava From 38686c27a75171d4e4fdcca26e899df916134a64 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 20:03:10 +0800 Subject: [PATCH 187/198] refactor TransactionManager --- .../adapter/AbstractConnectionAdapter.java | 4 +- ...gsphere.transaction.api.TransactionManager | 2 +- .../transaction/api/TransactionManager.java | 6 +-- .../api/base/SagaTransactionManager.java | 20 +++++----- .../LocalTransactionManager.java} | 40 ++++++++----------- .../api/xa/AtomikosTransactionManager.java | 17 ++++---- .../common/TransactionContext.java | 5 +-- .../common/TransactionContextFactory.java | 4 +- 8 files changed, 43 insertions(+), 55 deletions(-) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/api/{xa/WeakXaTransactionManager.java => local/LocalTransactionManager.java} (80%) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index 7fd8b9e729b5e..11e24246da6ed 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -24,7 +24,7 @@ import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection; import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager; import io.shardingsphere.core.util.EventBusInstance; -import io.shardingsphere.transaction.api.xa.WeakXaTransactionManager; +import io.shardingsphere.transaction.api.local.LocalTransactionManager; import io.shardingsphere.transaction.common.TransactionContext; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration; @@ -93,7 +93,7 @@ public final boolean getAutoCommit() { @Override public final void setAutoCommit(final boolean autoCommit) { this.autoCommit = autoCommit; - TransactionContextHolder.set(new TransactionContext(WeakXaTransactionManager.getInstance(), TransactionType.XA, WeakXaTransactionEvent.class)); + TransactionContextHolder.set(new TransactionContext(new LocalTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class)); recordMethodInvocation(Connection.class, "setAutoCommit", new Class[] {boolean.class}, new Object[] {autoCommit}); EventBusInstance.getInstance().post(buildTransactionEvent(TCLType.BEGIN)); } diff --git a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager index c41e2fba94e9e..dd784f3e58903 100644 --- a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager +++ b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager @@ -1 +1 @@ -io.shardingsphere.transaction.api.xa.AtomikosTransactionManager \ No newline at end of file +io.shardingsphere.transaction.api.xa.AtomikosTransactionManager diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java index 8dc49da1ea869..ce6b5850754f4 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java @@ -54,11 +54,7 @@ public interface TransactionManager { /** * Obtain the status of the transaction associated with the current thread. * - * @return The transaction status. - *

- * If no transaction is associated with the current thread, this method returns the Status.NoTransaction value - *

- * + * @return Transaction status. Returns {@code Status.NoTransaction} if no transaction is associated with current thread. * @throws SQLException SQL exception */ int getStatus() throws SQLException; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java index 396d8695b70ef..347cca1c14b60 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java @@ -20,32 +20,30 @@ import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.event.TransactionEvent; -import java.sql.SQLException; +import javax.transaction.Status; /** - * Saga transaction manager for sharding-sphere. + * Saga transaction manager. * * @author zhaojun */ -public class SagaTransactionManager implements TransactionManager { +public final class SagaTransactionManager implements TransactionManager { @Override - public void begin(final TransactionEvent transactionEvent) throws SQLException { - + public void begin(final TransactionEvent transactionEvent) { } @Override - public void commit(final TransactionEvent transactionEvent) throws SQLException { - + public void commit(final TransactionEvent transactionEvent) { } @Override - public void rollback(final TransactionEvent transactionEvent) throws SQLException { - + public void rollback(final TransactionEvent transactionEvent) { } @Override - public int getStatus() throws SQLException { - return 0; + public int getStatus() { + // TODO :zhaojun need confirm, return Status.STATUS_NO_TRANSACTION or zero? + return Status.STATUS_NO_TRANSACTION; } } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java similarity index 80% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java index 140fe217d2982..ba7583a7d130b 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/WeakXaTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java @@ -15,44 +15,37 @@ *

*/ -package io.shardingsphere.transaction.api.xa; +package io.shardingsphere.transaction.api.local; import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.event.TransactionEvent; import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import javax.transaction.Status; import java.sql.Connection; import java.sql.SQLException; import java.util.Collection; import java.util.LinkedList; /** - * Weak XA transaction manager. + * Local transaction manager. * * @author zhaojun */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class WeakXaTransactionManager implements TransactionManager { - - private static final WeakXaTransactionManager TRANSACTION_MANAGER = new WeakXaTransactionManager(); - - /** - * Get singleton instance of {@code WeakXaTransactionManager}. - * - * @return weak XA transaction manager - */ - public static WeakXaTransactionManager getInstance() { - return TRANSACTION_MANAGER; - } +public final class LocalTransactionManager implements TransactionManager { @Override public void begin(final TransactionEvent transactionEvent) throws SQLException { WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent; + Collection exceptions = new LinkedList<>(); for (Connection each : weakXaTransactionEvent.getCachedConnections()) { - each.setAutoCommit(weakXaTransactionEvent.isAutoCommit()); + try { + each.setAutoCommit(weakXaTransactionEvent.isAutoCommit()); + } catch (final SQLException ex) { + exceptions.add(ex); + } } + throwSQLExceptionIfNecessary(exceptions); } @Override @@ -83,11 +76,6 @@ public void rollback(final TransactionEvent transactionEvent) throws SQLExceptio throwSQLExceptionIfNecessary(exceptions); } - @Override - public int getStatus() { - return 0; - } - private void throwSQLExceptionIfNecessary(final Collection exceptions) throws SQLException { if (exceptions.isEmpty()) { return; @@ -98,4 +86,10 @@ private void throwSQLExceptionIfNecessary(final Collection excepti } throw sqlException; } + + @Override + public int getStatus() { + // TODO :zhaojun need confirm, return Status.STATUS_NO_TRANSACTION or zero? + return Status.STATUS_NO_TRANSACTION; + } } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java index bde3f3fa4e16c..decbaecfd46b6 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java @@ -18,6 +18,7 @@ package io.shardingsphere.transaction.api.xa; import com.atomikos.icatch.jta.UserTransactionManager; +import io.shardingsphere.core.exception.ShardingException; import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.event.TransactionEvent; @@ -35,20 +36,20 @@ */ public final class AtomikosTransactionManager implements TransactionManager { - private static UserTransactionManager transactionManager = AtomikosUserTransaction.getInstance(); + private final static UserTransactionManager TRANSACTION_MANAGER = AtomikosUserTransaction.getInstance(); static { try { - transactionManager.init(); + TRANSACTION_MANAGER.init(); } catch (final SystemException ex) { - ex.printStackTrace(); + throw new ShardingException(ex); } } @Override public void begin(final TransactionEvent transactionEvent) throws SQLException { try { - transactionManager.begin(); + TRANSACTION_MANAGER.begin(); } catch (final SystemException | NotSupportedException ex) { throw new SQLException(ex); } @@ -57,8 +58,8 @@ public void begin(final TransactionEvent transactionEvent) throws SQLException { @Override public void commit(final TransactionEvent transactionEvent) throws SQLException { try { - transactionManager.commit(); - } catch (final RollbackException | HeuristicMixedException | SystemException | HeuristicRollbackException ex) { + TRANSACTION_MANAGER.commit(); + } catch (final RollbackException | HeuristicMixedException |HeuristicRollbackException | SystemException ex) { throw new SQLException(ex); } } @@ -66,7 +67,7 @@ public void commit(final TransactionEvent transactionEvent) throws SQLException @Override public void rollback(final TransactionEvent transactionEvent) throws SQLException { try { - transactionManager.rollback(); + TRANSACTION_MANAGER.rollback(); } catch (final SystemException ex) { throw new SQLException(ex); } @@ -75,7 +76,7 @@ public void rollback(final TransactionEvent transactionEvent) throws SQLExceptio @Override public int getStatus() throws SQLException { try { - return transactionManager.getStatus(); + return TRANSACTION_MANAGER.getStatus(); } catch (final SystemException ex) { throw new SQLException(ex); } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java index 58941d29bd2ac..42fa8fa0b91b3 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java @@ -22,12 +22,14 @@ import io.shardingsphere.transaction.common.event.TransactionEvent; import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; import lombok.Getter; +import lombok.NoArgsConstructor; /** * Hold Transaction Context. * * @author zhaojun */ +@NoArgsConstructor @Getter public final class TransactionContext { @@ -36,9 +38,6 @@ public final class TransactionContext { private TransactionType transactionType = TransactionType.XA; private Class transactionEventClazz = WeakXaTransactionEvent.class; - - public TransactionContext() { - } public TransactionContext(final TransactionManager transactionManager, final TransactionType transactionType, final Class clazz) { this.transactionManager = transactionManager; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java index 90a7a3baba612..cd20d5739efe7 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java @@ -21,7 +21,7 @@ import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; import io.shardingsphere.transaction.common.event.XaTransactionEvent; -import io.shardingsphere.transaction.api.xa.WeakXaTransactionManager; +import io.shardingsphere.transaction.api.local.LocalTransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -49,6 +49,6 @@ public static TransactionContext newXAContext(final TransactionManager transacti * @return weak XA transaction context */ public static TransactionContext newWeakXAContext() { - return new TransactionContext(WeakXaTransactionManager.getInstance(), TransactionType.XA, WeakXaTransactionEvent.class); + return new TransactionContext(new LocalTransactionManager(), TransactionType.NONE, WeakXaTransactionEvent.class); } } From b0e04aa183ac250205a1870813c157e6e28216a9 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 20:42:40 +0800 Subject: [PATCH 188/198] refactor TransactionManager --- .../transaction/common/TransactionContextFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java index cd20d5739efe7..a2caacd031c1f 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java @@ -49,6 +49,6 @@ public static TransactionContext newXAContext(final TransactionManager transacti * @return weak XA transaction context */ public static TransactionContext newWeakXAContext() { - return new TransactionContext(new LocalTransactionManager(), TransactionType.NONE, WeakXaTransactionEvent.class); + return new TransactionContext(new LocalTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class); } } From 74aecad8835be2c04ac3ba1e7251b1b9f333f270 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 20:53:57 +0800 Subject: [PATCH 189/198] week xa => local transaction --- .../jdbc/adapter/AbstractConnectionAdapter.java | 12 ++++++------ .../api/local/LocalTransactionManager.java | 16 ++++++++-------- .../transaction/common/TransactionContext.java | 4 ++-- .../common/TransactionContextFactory.java | 10 +++++----- .../config/JDBCTransactionConfiguration.java | 2 +- ...tionEvent.java => LocalTransactionEvent.java} | 6 +++--- .../common/event/TransactionEventFactory.java | 2 +- 7 files changed, 26 insertions(+), 26 deletions(-) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/{WeakXaTransactionEvent.java => LocalTransactionEvent.java} (89%) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index 11e24246da6ed..a3fe85af2e43d 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -30,7 +30,7 @@ import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration; import io.shardingsphere.transaction.common.event.TransactionEvent; import io.shardingsphere.transaction.common.event.TransactionEventFactory; -import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.LocalTransactionEvent; import javax.sql.DataSource; import java.sql.Connection; @@ -93,7 +93,7 @@ public final boolean getAutoCommit() { @Override public final void setAutoCommit(final boolean autoCommit) { this.autoCommit = autoCommit; - TransactionContextHolder.set(new TransactionContext(new LocalTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class)); + TransactionContextHolder.set(new TransactionContext(new LocalTransactionManager(), TransactionType.XA, LocalTransactionEvent.class)); recordMethodInvocation(Connection.class, "setAutoCommit", new Class[] {boolean.class}, new Object[] {autoCommit}); EventBusInstance.getInstance().post(buildTransactionEvent(TCLType.BEGIN)); } @@ -183,10 +183,10 @@ public final void setHoldability(final int holdability) { private TransactionEvent buildTransactionEvent(final TCLType tclType) { TransactionEvent result = TransactionEventFactory.create(tclType); - if (result instanceof WeakXaTransactionEvent) { - WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) result; - weakXaTransactionEvent.setCachedConnections(cachedConnections.values()); - weakXaTransactionEvent.setAutoCommit(autoCommit); + if (result instanceof LocalTransactionEvent) { + LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) result; + localTransactionEvent.setCachedConnections(cachedConnections.values()); + localTransactionEvent.setAutoCommit(autoCommit); } return result; } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java index ba7583a7d130b..67fab70a23c79 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java @@ -19,7 +19,7 @@ import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.event.TransactionEvent; -import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.LocalTransactionEvent; import javax.transaction.Status; import java.sql.Connection; @@ -36,11 +36,11 @@ public final class LocalTransactionManager implements TransactionManager { @Override public void begin(final TransactionEvent transactionEvent) throws SQLException { - WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent; + LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) transactionEvent; Collection exceptions = new LinkedList<>(); - for (Connection each : weakXaTransactionEvent.getCachedConnections()) { + for (Connection each : localTransactionEvent.getCachedConnections()) { try { - each.setAutoCommit(weakXaTransactionEvent.isAutoCommit()); + each.setAutoCommit(localTransactionEvent.isAutoCommit()); } catch (final SQLException ex) { exceptions.add(ex); } @@ -50,9 +50,9 @@ public void begin(final TransactionEvent transactionEvent) throws SQLException { @Override public void commit(final TransactionEvent transactionEvent) throws SQLException { - WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent; + LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) transactionEvent; Collection exceptions = new LinkedList<>(); - for (Connection each : weakXaTransactionEvent.getCachedConnections()) { + for (Connection each : localTransactionEvent.getCachedConnections()) { try { each.commit(); } catch (final SQLException ex) { @@ -64,9 +64,9 @@ public void commit(final TransactionEvent transactionEvent) throws SQLException @Override public void rollback(final TransactionEvent transactionEvent) throws SQLException { - WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent; + LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) transactionEvent; Collection exceptions = new LinkedList<>(); - for (Connection each : weakXaTransactionEvent.getCachedConnections()) { + for (Connection each : localTransactionEvent.getCachedConnections()) { try { each.rollback(); } catch (final SQLException ex) { diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java index 42fa8fa0b91b3..43870fcf89252 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java @@ -20,7 +20,7 @@ import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.event.TransactionEvent; -import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.LocalTransactionEvent; import lombok.Getter; import lombok.NoArgsConstructor; @@ -37,7 +37,7 @@ public final class TransactionContext { private TransactionType transactionType = TransactionType.XA; - private Class transactionEventClazz = WeakXaTransactionEvent.class; + private Class transactionEventClazz = LocalTransactionEvent.class; public TransactionContext(final TransactionManager transactionManager, final TransactionType transactionType, final Class clazz) { this.transactionManager = transactionManager; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java index a2caacd031c1f..0e2fca08e9b61 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java @@ -19,7 +19,7 @@ import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.common.event.WeakXaTransactionEvent; +import io.shardingsphere.transaction.common.event.LocalTransactionEvent; import io.shardingsphere.transaction.common.event.XaTransactionEvent; import io.shardingsphere.transaction.api.local.LocalTransactionManager; import lombok.AccessLevel; @@ -44,11 +44,11 @@ public static TransactionContext newXAContext(final TransactionManager transacti } /** - * Create transaction context of weak XA. + * Create local transaction context. * - * @return weak XA transaction context + * @return local transaction context */ - public static TransactionContext newWeakXAContext() { - return new TransactionContext(new LocalTransactionManager(), TransactionType.XA, WeakXaTransactionEvent.class); + public static TransactionContext newLocalTransactionContext() { + return new TransactionContext(new LocalTransactionManager(), TransactionType.XA, LocalTransactionEvent.class); } } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java index 486b7a6823e88..1dab4dea70bc4 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -49,7 +49,7 @@ public static JDBCTransactionConfiguration getInstance() { protected TransactionManager doXaTransactionConfiguration(final TransactionType transactionType) { Optional transactionManager = doSPIConfiguration(transactionType); TransactionContext transactionContext = transactionManager.isPresent() - ? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newWeakXAContext(); + ? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newLocalTransactionContext(); TransactionContextHolder.set(transactionContext); return transactionContext.getTransactionManager(); } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/LocalTransactionEvent.java similarity index 89% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/LocalTransactionEvent.java index 3933717d5a02f..63cce2ab9390a 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/WeakXaTransactionEvent.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/LocalTransactionEvent.java @@ -27,19 +27,19 @@ import java.util.Collection; /** - * Weak XA transaction event. + * Local transaction event. * * @author zhaojun */ @Getter @Setter -public final class WeakXaTransactionEvent extends TransactionEvent { +public final class LocalTransactionEvent extends TransactionEvent { private Collection cachedConnections; private boolean autoCommit = true; - public WeakXaTransactionEvent(final TCLType tclType) { + public LocalTransactionEvent(final TCLType tclType) { super(tclType); } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java index 133914168c293..09b36fac5026a 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java @@ -40,7 +40,7 @@ public static TransactionEvent create(final TCLType tclType) { switch (TransactionContextHolder.get().getTransactionType()) { case XA: return TransactionContextHolder.get().getTransactionEventClazz().isAssignableFrom(XaTransactionEvent.class) - ? new XaTransactionEvent(tclType, "") : new WeakXaTransactionEvent(tclType); + ? new XaTransactionEvent(tclType, "") : new LocalTransactionEvent(tclType); case BASE: default: return null; From 62e7640ed0a3aa66e00e28838912070e16de072c Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 21:03:36 +0800 Subject: [PATCH 190/198] refactor TransactionType --- .../constant/ShardingPropertiesConstant.java | 2 +- .../core/constant/TransactionType.java | 44 +------------------ 2 files changed, 3 insertions(+), 43 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java index 1f58d01cb1632..75c7534d2d43c 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java @@ -81,7 +81,7 @@ public enum ShardingPropertiesConstant { */ CONNECTION_MODE("connection.mode", ConnectionMode.MEMORY_STRICTLY.name(), String.class), - PROXY_TRANSACTION_MODE("proxy.transaction.mode", TransactionType.NONE.name(), String.class), + PROXY_TRANSACTION_MODE("proxy.transaction.mode", TransactionType.LOCAL.name(), String.class), PROXY_BACKEND_USE_NIO("proxy.backend.use.nio", Boolean.FALSE.toString(), boolean.class), diff --git a/sharding-core/src/main/java/io/shardingsphere/core/constant/TransactionType.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/TransactionType.java index a6ccc77845371..d9ab457f10d17 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/constant/TransactionType.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/constant/TransactionType.java @@ -17,52 +17,12 @@ package io.shardingsphere.core.constant; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - /** - * TransactionType Enum. + * Transaction type. * * @author zhaojun */ -@RequiredArgsConstructor -@Getter public enum TransactionType { - /** - * Default local transaction. - */ - NONE(""), - - /** - * XA distribute transaction provided by RDBMS vendor. - */ - XA("XA"), - - /** - * B.A.S.E distribute transaction. - */ - BASE("BASE"), - - /** - * TCC (Try-Confirm-Cancel) distribute transaction mode. - */ - TCC("TCC"); - - private final String type; - - /** - * Find enum by type value. - * - * @param type property type - * @return value enum, return {@code NONE} if not found - */ - public static TransactionType findByValue(final String type) { - for (TransactionType each : TransactionType.values()) { - if (each.getType().equals(type)) { - return each; - } - } - return NONE; - } + LOCAL, XA, BASE } From e8815ef08d23ae558fc5ed28d22ef9d9653bbf74 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 21:22:01 +0800 Subject: [PATCH 191/198] refactor JDBCTransactionConfiguration & ProxyTransactionConfiguration --- .../common/config/JDBCTransactionConfiguration.java | 6 +++--- .../common/config/ProxyTransactionConfiguration.java | 6 +++--- .../transaction/common/event/TransactionEventFactory.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java index 1dab4dea70bc4..68d3222961e34 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -32,9 +32,9 @@ * @author zhaojun */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class JDBCTransactionConfiguration extends TransactionConfigurationAdapter { +public final class JDBCTransactionConfiguration extends TransactionConfigurationAdapter { - private static final JDBCTransactionConfiguration CONFIG = new JDBCTransactionConfiguration(); + private static final JDBCTransactionConfiguration INSTANCE = new JDBCTransactionConfiguration(); /** * Get singleton instance of {@code JDBCTransactionConfiguration}. @@ -42,7 +42,7 @@ public class JDBCTransactionConfiguration extends TransactionConfigurationAdapte * @return JDBC transaction configuration */ public static JDBCTransactionConfiguration getInstance() { - return CONFIG; + return INSTANCE; } @Override diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java index e63ef806d52bf..c46d73f7262cb 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java @@ -32,9 +32,9 @@ * @author zhaojun */ @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ProxyTransactionConfiguration extends TransactionConfigurationAdapter { +public final class ProxyTransactionConfiguration extends TransactionConfigurationAdapter { - private static final ProxyTransactionConfiguration CONFIG = new ProxyTransactionConfiguration(); + private static final ProxyTransactionConfiguration INSTANCE = new ProxyTransactionConfiguration(); /** * Get singleton instance of {@code ProxyTransactionConfiguration}. @@ -42,7 +42,7 @@ public class ProxyTransactionConfiguration extends TransactionConfigurationAdapt * @return proxy transaction configuration */ public static ProxyTransactionConfiguration getInstance() { - return CONFIG; + return INSTANCE; } @Override diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java index 09b36fac5026a..d5b1b5e238c90 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java @@ -23,7 +23,7 @@ import lombok.NoArgsConstructor; /** - * Create TransactionEvent for current thread. + * Transaction event factory. * * @author zhaojun */ From 56b97f62cfdb3e9b8bca03d6ec58209086de1dbd Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 21:32:55 +0800 Subject: [PATCH 192/198] split local transaction and xa transaction --- .../core/jdbc/adapter/AbstractConnectionAdapter.java | 2 +- .../transaction/common/TransactionContext.java | 2 +- .../transaction/common/TransactionContextFactory.java | 2 +- .../transaction/common/event/TransactionEventFactory.java | 5 +++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index a3fe85af2e43d..6295a307a6b39 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -93,7 +93,7 @@ public final boolean getAutoCommit() { @Override public final void setAutoCommit(final boolean autoCommit) { this.autoCommit = autoCommit; - TransactionContextHolder.set(new TransactionContext(new LocalTransactionManager(), TransactionType.XA, LocalTransactionEvent.class)); + TransactionContextHolder.set(new TransactionContext(new LocalTransactionManager(), TransactionType.LOCAL, LocalTransactionEvent.class)); recordMethodInvocation(Connection.class, "setAutoCommit", new Class[] {boolean.class}, new Object[] {autoCommit}); EventBusInstance.getInstance().post(buildTransactionEvent(TCLType.BEGIN)); } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java index 43870fcf89252..211671ac9d046 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java @@ -35,7 +35,7 @@ public final class TransactionContext { private TransactionManager transactionManager; - private TransactionType transactionType = TransactionType.XA; + private TransactionType transactionType = TransactionType.LOCAL; private Class transactionEventClazz = LocalTransactionEvent.class; diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java index 0e2fca08e9b61..d1a6685a0874d 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java @@ -49,6 +49,6 @@ public static TransactionContext newXAContext(final TransactionManager transacti * @return local transaction context */ public static TransactionContext newLocalTransactionContext() { - return new TransactionContext(new LocalTransactionManager(), TransactionType.XA, LocalTransactionEvent.class); + return new TransactionContext(new LocalTransactionManager(), TransactionType.LOCAL, LocalTransactionEvent.class); } } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java index d5b1b5e238c90..ad696c81a32f6 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/event/TransactionEventFactory.java @@ -38,9 +38,10 @@ public final class TransactionEventFactory { */ public static TransactionEvent create(final TCLType tclType) { switch (TransactionContextHolder.get().getTransactionType()) { + case LOCAL: + return new LocalTransactionEvent(tclType); case XA: - return TransactionContextHolder.get().getTransactionEventClazz().isAssignableFrom(XaTransactionEvent.class) - ? new XaTransactionEvent(tclType, "") : new LocalTransactionEvent(tclType); + return new XaTransactionEvent(tclType, ""); case BASE: default: return null; From 37cff6157e10fed9ed2396ebbf6658e052b84bed Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 21:34:48 +0800 Subject: [PATCH 193/198] remove transactionEventClazz of TransactionContext --- .../core/jdbc/adapter/AbstractConnectionAdapter.java | 2 +- .../transaction/common/TransactionContext.java | 7 +------ .../transaction/common/TransactionContextFactory.java | 6 ++---- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index 6295a307a6b39..ea54e12670bee 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -93,7 +93,7 @@ public final boolean getAutoCommit() { @Override public final void setAutoCommit(final boolean autoCommit) { this.autoCommit = autoCommit; - TransactionContextHolder.set(new TransactionContext(new LocalTransactionManager(), TransactionType.LOCAL, LocalTransactionEvent.class)); + TransactionContextHolder.set(new TransactionContext(new LocalTransactionManager(), TransactionType.LOCAL)); recordMethodInvocation(Connection.class, "setAutoCommit", new Class[] {boolean.class}, new Object[] {autoCommit}); EventBusInstance.getInstance().post(buildTransactionEvent(TCLType.BEGIN)); } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java index 211671ac9d046..eeff7d2188bc9 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java @@ -19,8 +19,6 @@ import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.common.event.TransactionEvent; -import io.shardingsphere.transaction.common.event.LocalTransactionEvent; import lombok.Getter; import lombok.NoArgsConstructor; @@ -37,11 +35,8 @@ public final class TransactionContext { private TransactionType transactionType = TransactionType.LOCAL; - private Class transactionEventClazz = LocalTransactionEvent.class; - - public TransactionContext(final TransactionManager transactionManager, final TransactionType transactionType, final Class clazz) { + public TransactionContext(final TransactionManager transactionManager, final TransactionType transactionType) { this.transactionManager = transactionManager; this.transactionType = transactionType; - this.transactionEventClazz = clazz; } } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java index d1a6685a0874d..91d3e2d51d681 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java @@ -19,8 +19,6 @@ import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.common.event.LocalTransactionEvent; -import io.shardingsphere.transaction.common.event.XaTransactionEvent; import io.shardingsphere.transaction.api.local.LocalTransactionManager; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -40,7 +38,7 @@ public class TransactionContextFactory { * @return XA transaction context */ public static TransactionContext newXAContext(final TransactionManager transactionManager) { - return new TransactionContext(transactionManager, TransactionType.XA, XaTransactionEvent.class); + return new TransactionContext(transactionManager, TransactionType.XA); } /** @@ -49,6 +47,6 @@ public static TransactionContext newXAContext(final TransactionManager transacti * @return local transaction context */ public static TransactionContext newLocalTransactionContext() { - return new TransactionContext(new LocalTransactionManager(), TransactionType.LOCAL, LocalTransactionEvent.class); + return new TransactionContext(new LocalTransactionManager(), TransactionType.LOCAL); } } From 0b12f88908e4ed16a90b54af9bd45c2be38ee9d7 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 23:39:06 +0800 Subject: [PATCH 194/198] add ListenerRegister --- .../adapter/AbstractDataSourceAdapter.java | 3 +- .../core/listener/JDBCListenerRegister.java | 38 +++++++++++++++++++ .../io/shardingsphere/proxy/Bootstrap.java | 2 + .../proxy/config/RuleRegistry.java | 1 - .../proxy/listener/ProxyListenerRegister.java | 38 +++++++++++++++++++ .../config/TransactionConfiguration.java | 6 --- .../TransactionConfigurationAdapter.java | 11 +----- .../common/listener/TransactionListener.java | 14 ++----- 8 files changed, 86 insertions(+), 27 deletions(-) create mode 100644 sharding-jdbc/src/main/java/io/shardingsphere/core/listener/JDBCListenerRegister.java create mode 100644 sharding-proxy/src/main/java/io/shardingsphere/proxy/listener/ProxyListenerRegister.java diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java index ff70ab93fffce..c39b92d0cfd8c 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java @@ -20,6 +20,7 @@ import com.google.common.base.Preconditions; import io.shardingsphere.core.constant.DatabaseType; import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationDataSource; +import io.shardingsphere.core.listener.JDBCListenerRegister; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration; import lombok.Getter; @@ -40,7 +41,7 @@ public abstract class AbstractDataSourceAdapter extends AbstractUnsupportedOpera static { JDBCTransactionConfiguration.getInstance().configTransactionContext(TransactionContextHolder.get().getTransactionType()); - JDBCTransactionConfiguration.getInstance().registerListener(); + JDBCListenerRegister.register(); } @Getter diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/listener/JDBCListenerRegister.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/listener/JDBCListenerRegister.java new file mode 100644 index 0000000000000..0b1de45a7e72d --- /dev/null +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/listener/JDBCListenerRegister.java @@ -0,0 +1,38 @@ +/* + * 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.core.listener; + +import io.shardingsphere.transaction.common.listener.TransactionListener; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * Listener register for JDBC. + * + * @author zhangliang + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class JDBCListenerRegister { + + /** + * Register all listeners. + */ + public static void register() { + new TransactionListener().register(); + } +} diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/Bootstrap.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/Bootstrap.java index 1ada19b7c21bc..2accc50aa3c6a 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/Bootstrap.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/Bootstrap.java @@ -25,6 +25,7 @@ import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusInstance; import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.frontend.ShardingProxy; +import io.shardingsphere.proxy.listener.ProxyListenerRegister; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.yaml.snakeyaml.Yaml; @@ -61,6 +62,7 @@ public final class Bootstrap { * @throws IOException IO exception */ public static void main(final String[] args) throws InterruptedException, IOException { + ProxyListenerRegister.register(); OrchestrationProxyConfiguration localConfig = loadLocalConfiguration(new File(Bootstrap.class.getResource(getConfig(args)).getFile())); int port = getPort(args); if (null == localConfig.getOrchestration()) { diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index a67aedbd18bb4..7fc65a81446ec 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -107,7 +107,6 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE)); transactionManager = ProxyTransactionConfiguration.getInstance().configTransactionContext(transactionType); - ProxyTransactionConfiguration.getInstance().registerListener(); acceptorSize = shardingProperties.getValue(ShardingPropertiesConstant.ACCEPTOR_SIZE); executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); // TODO :jiaqi force off use NIO for backend, this feature is not complete yet diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/listener/ProxyListenerRegister.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/listener/ProxyListenerRegister.java new file mode 100644 index 0000000000000..a48cc9cbbee58 --- /dev/null +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/listener/ProxyListenerRegister.java @@ -0,0 +1,38 @@ +/* + * 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.proxy.listener; + +import io.shardingsphere.transaction.common.listener.TransactionListener; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * Listener register for Proxy. + * + * @author zhangliang + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ProxyListenerRegister { + + /** + * Register all listeners. + */ + public static void register() { + new TransactionListener().register(); + } +} diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java index 76533870eba55..83d38540b7cb7 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java @@ -34,10 +34,4 @@ public interface TransactionConfiguration { * @return transaction manager */ TransactionManager configTransactionContext(TransactionType transactionType); - - /** - * Subscribe transaction event using listener, register into event bus. - */ - void registerListener(); - } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java index 8f661a53fffe8..82fef423e5b97 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java @@ -20,9 +20,7 @@ import com.google.common.base.Optional; import com.google.common.collect.Lists; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.core.util.EventBusInstance; import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.common.listener.TransactionListener; import lombok.extern.slf4j.Slf4j; import java.util.HashMap; @@ -41,7 +39,7 @@ public abstract class TransactionConfigurationAdapter implements TransactionConf private static final Map> SPI_RESOURCE = new HashMap<>(); @Override - public TransactionManager configTransactionContext(final TransactionType transactionType) { + public final TransactionManager configTransactionContext(final TransactionType transactionType) { TransactionManager result = null; switch (transactionType) { case XA: @@ -54,14 +52,9 @@ public TransactionManager configTransactionContext(final TransactionType transac return result; } - @Override - public void registerListener() { - EventBusInstance.getInstance().register(TransactionListener.getInstance()); - } - protected abstract TransactionManager doXaTransactionConfiguration(TransactionType transactionType); - protected Optional doSPIConfiguration(final TransactionType transactionType) { + protected final Optional doSPIConfiguration(final TransactionType transactionType) { if (SPI_RESOURCE.containsKey(transactionType)) { return SPI_RESOURCE.get(transactionType); } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java index 2c19bbd9b9ad3..ffc862bb654a7 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java @@ -19,11 +19,10 @@ import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; +import io.shardingsphere.core.util.EventBusInstance; import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.common.event.TransactionEvent; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; import java.sql.SQLException; @@ -32,18 +31,13 @@ * * @author zhaojun */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class TransactionListener { - private static final TransactionListener INSTANCE = new TransactionListener(); - /** - * Get instance of transaction listener. - * - * @return instance of transaction listener + * Register transaction listener into event bus. */ - public static TransactionListener getInstance() { - return INSTANCE; + public void register() { + EventBusInstance.getInstance().register(this); } /** From d8449fbc5b12fa164566e0bafd0a0d238158593a Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sun, 12 Aug 2018 23:53:40 +0800 Subject: [PATCH 195/198] refactor TransactionConfiguration --- .../adapter/AbstractConnectionAdapter.java | 4 ++-- .../adapter/AbstractDataSourceAdapter.java | 2 +- .../proxy/config/RuleRegistry.java | 2 +- .../config/JDBCTransactionConfiguration.java | 4 ++-- .../config/ProxyTransactionConfiguration.java | 4 ++-- .../config/TransactionConfiguration.java | 4 ++-- .../TransactionConfigurationAdapter.java | 24 ++++++++----------- 7 files changed, 20 insertions(+), 24 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index ea54e12670bee..4f33dc4ef8539 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -67,7 +67,7 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera * @throws SQLException SQL exception */ public final Connection getConnection(final String dataSourceName) throws SQLException { - JDBCTransactionConfiguration.getInstance().configTransactionContext(TransactionContextHolder.get().getTransactionType()); + JDBCTransactionConfiguration.getInstance().getTransactionManager(TransactionContextHolder.get().getTransactionType()); if (cachedConnections.containsKey(dataSourceName)) { return cachedConnections.get(dataSourceName); } @@ -81,7 +81,7 @@ public final Connection getConnection(final String dataSourceName) throws SQLExc protected abstract Map getDataSourceMap(); - protected void removeCache(final Connection connection) { + protected final void removeCache(final Connection connection) { cachedConnections.values().remove(connection); } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java index c39b92d0cfd8c..d6c7018c4fff4 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java @@ -40,7 +40,7 @@ public abstract class AbstractDataSourceAdapter extends AbstractUnsupportedOperationDataSource { static { - JDBCTransactionConfiguration.getInstance().configTransactionContext(TransactionContextHolder.get().getTransactionType()); + JDBCTransactionConfiguration.getInstance().getTransactionManager(TransactionContextHolder.get().getTransactionType()); JDBCListenerRegister.register(); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 7fc65a81446ec..bd529a598490b 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -106,7 +106,7 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE)); - transactionManager = ProxyTransactionConfiguration.getInstance().configTransactionContext(transactionType); + transactionManager = ProxyTransactionConfiguration.getInstance().getTransactionManager(transactionType); acceptorSize = shardingProperties.getValue(ShardingPropertiesConstant.ACCEPTOR_SIZE); executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); // TODO :jiaqi force off use NIO for backend, this feature is not complete yet diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java index 68d3222961e34..2c0d404e4de82 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -46,8 +46,8 @@ public static JDBCTransactionConfiguration getInstance() { } @Override - protected TransactionManager doXaTransactionConfiguration(final TransactionType transactionType) { - Optional transactionManager = doSPIConfiguration(transactionType); + protected TransactionManager getXATransactionManager(final TransactionType transactionType) { + Optional transactionManager = getXATransactionManagerFromSPI(transactionType); TransactionContext transactionContext = transactionManager.isPresent() ? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newLocalTransactionContext(); TransactionContextHolder.set(transactionContext); diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java index c46d73f7262cb..8c535bd50f102 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java @@ -46,8 +46,8 @@ public static ProxyTransactionConfiguration getInstance() { } @Override - protected TransactionManager doXaTransactionConfiguration(final TransactionType transactionType) { - Optional transactionManager = doSPIConfiguration(transactionType); + protected TransactionManager getXATransactionManager(final TransactionType transactionType) { + Optional transactionManager = getXATransactionManagerFromSPI(transactionType); Preconditions.checkState(transactionManager.isPresent(), "there is no XA transaction manager existing, please prepare exactly one(Atomikos or Narayana) using SPI."); TransactionContextHolder.set(TransactionContextFactory.newXAContext(transactionManager.get())); return transactionManager.get(); diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java index 83d38540b7cb7..88ce37309b8a5 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java @@ -28,10 +28,10 @@ public interface TransactionConfiguration { /** - * Config transaction context, then binding to current thread. + * Get transaction manager. * * @param transactionType transaction type * @return transaction manager */ - TransactionManager configTransactionContext(TransactionType transactionType); + TransactionManager getTransactionManager(TransactionType transactionType); } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java index 82fef423e5b97..1969bb18cf157 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java @@ -36,35 +36,31 @@ @Slf4j public abstract class TransactionConfigurationAdapter implements TransactionConfiguration { - private static final Map> SPI_RESOURCE = new HashMap<>(); + private static final Map> SPI_RESOURCES = new HashMap<>(); @Override - public final TransactionManager configTransactionContext(final TransactionType transactionType) { - TransactionManager result = null; + public final TransactionManager getTransactionManager(final TransactionType transactionType) { switch (transactionType) { case XA: - result = doXaTransactionConfiguration(transactionType); - break; - case BASE: - break; + return getXATransactionManager(transactionType); default: + return null; } - return result; } - protected abstract TransactionManager doXaTransactionConfiguration(TransactionType transactionType); + protected abstract TransactionManager getXATransactionManager(TransactionType transactionType); - protected final Optional doSPIConfiguration(final TransactionType transactionType) { - if (SPI_RESOURCE.containsKey(transactionType)) { - return SPI_RESOURCE.get(transactionType); + protected final Optional getXATransactionManagerFromSPI(final TransactionType transactionType) { + if (SPI_RESOURCES.containsKey(transactionType)) { + return SPI_RESOURCES.get(transactionType); } - synchronized (SPI_RESOURCE) { + synchronized (SPI_RESOURCES) { List transactionManagerList = Lists.newArrayList(ServiceLoader.load(TransactionManager.class).iterator()); if (transactionManagerList.size() > 1) { log.info("there is more than one transaction manger existing, chosen first one default."); } Optional transactionManager = transactionManagerList.isEmpty() ? Optional.absent() : Optional.of(transactionManagerList.get(0)); - SPI_RESOURCE.put(transactionType, transactionManager); + SPI_RESOURCES.put(transactionType, transactionManager); return transactionManager; } } From 119a8ae543f3ffbbf0fbdce94d2b7fc708c289c8 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 13 Aug 2018 00:38:39 +0800 Subject: [PATCH 196/198] add XATransactionManagerSPILoader --- .../jdbc/transaction/XaTransactionEngine.java | 5 +- .../proxy/config/RuleRegistry.java | 4 +- ...e.transaction.api.xa.XATransactionManager} | 0 ...r.java => ShardingTransactionManager.java} | 5 +- .../api/base/SagaTransactionManager.java | 4 +- .../api/local/LocalTransactionManager.java | 4 +- .../api/xa/AtomikosTransactionManager.java | 7 +-- .../api/xa/XATransactionManager.java | 28 +++++++++ .../api/xa/XATransactionManagerSPILoader.java | 63 +++++++++++++++++++ .../common/TransactionContext.java | 6 +- .../common/TransactionContextFactory.java | 52 --------------- .../config/JDBCTransactionConfiguration.java | 15 ----- .../config/ProxyTransactionConfiguration.java | 14 ----- .../config/TransactionConfiguration.java | 4 +- .../TransactionConfigurationAdapter.java | 45 +++++-------- .../common/listener/TransactionListener.java | 4 +- 16 files changed, 128 insertions(+), 132 deletions(-) rename sharding-proxy/src/main/resources/META-INF/services/{io.shardingsphere.transaction.api.TransactionManager => io.shardingsphere.transaction.api.xa.XATransactionManager} (100%) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/api/{TransactionManager.java => ShardingTransactionManager.java} (94%) create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/XATransactionManager.java create mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/XATransactionManagerSPILoader.java delete mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java index 3dae64ee20f36..000ec35bfc947 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java @@ -19,9 +19,10 @@ import com.google.common.base.Optional; import io.shardingsphere.core.constant.TCLType; +import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.util.EventBusInstance; import io.shardingsphere.proxy.config.RuleRegistry; -import io.shardingsphere.transaction.common.TransactionContextFactory; +import io.shardingsphere.transaction.common.TransactionContext; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.common.event.XaTransactionEvent; @@ -45,7 +46,7 @@ public XaTransactionEngine(final String sql) { public boolean execute() throws SQLException { Optional tclType = parseSQL(); if (tclType.isPresent() && isInTransaction(tclType.get())) { - TransactionContextHolder.set(TransactionContextFactory.newXAContext(RULE_REGISTRY.getTransactionManager())); + TransactionContextHolder.set(new TransactionContext(RULE_REGISTRY.getTransactionManager(), TransactionType.XA)); EventBusInstance.getInstance().post(new XaTransactionEvent(tclType.get(), getSql())); return true; } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index bd529a598490b..90f6b9088098e 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -33,7 +33,7 @@ import io.shardingsphere.jdbc.orchestration.internal.OrchestrationProxyConfiguration; import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent; import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource; -import io.shardingsphere.transaction.api.TransactionManager; +import io.shardingsphere.transaction.api.ShardingTransactionManager; import io.shardingsphere.transaction.common.config.ProxyTransactionConfiguration; import lombok.AccessLevel; import lombok.Getter; @@ -80,7 +80,7 @@ public final class RuleRegistry { private TransactionType transactionType; - private TransactionManager transactionManager; + private ShardingTransactionManager transactionManager; private ProxyAuthority proxyAuthority; diff --git a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.xa.XATransactionManager similarity index 100% rename from sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.TransactionManager rename to sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.xa.XATransactionManager diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManager.java similarity index 94% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManager.java index ce6b5850754f4..1a729ce98914f 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/TransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManager.java @@ -21,11 +21,12 @@ import java.sql.SQLException; /** - * Transaction manager. + * Sharding transaction manager. * * @author zhaojun + * @author zhangliang */ -public interface TransactionManager { +public interface ShardingTransactionManager { /** * Begin transaction. diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java index 347cca1c14b60..16ec8b1a5aca3 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.java @@ -17,7 +17,7 @@ package io.shardingsphere.transaction.api.base; -import io.shardingsphere.transaction.api.TransactionManager; +import io.shardingsphere.transaction.api.ShardingTransactionManager; import io.shardingsphere.transaction.common.event.TransactionEvent; import javax.transaction.Status; @@ -27,7 +27,7 @@ * * @author zhaojun */ -public final class SagaTransactionManager implements TransactionManager { +public final class SagaTransactionManager implements ShardingTransactionManager { @Override public void begin(final TransactionEvent transactionEvent) { diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java index 67fab70a23c79..b462445d5a131 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java @@ -17,7 +17,7 @@ package io.shardingsphere.transaction.api.local; -import io.shardingsphere.transaction.api.TransactionManager; +import io.shardingsphere.transaction.api.ShardingTransactionManager; import io.shardingsphere.transaction.common.event.TransactionEvent; import io.shardingsphere.transaction.common.event.LocalTransactionEvent; @@ -32,7 +32,7 @@ * * @author zhaojun */ -public final class LocalTransactionManager implements TransactionManager { +public final class LocalTransactionManager implements ShardingTransactionManager { @Override public void begin(final TransactionEvent transactionEvent) throws SQLException { diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java index decbaecfd46b6..7977d51cc4845 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/AtomikosTransactionManager.java @@ -19,7 +19,6 @@ import com.atomikos.icatch.jta.UserTransactionManager; import io.shardingsphere.core.exception.ShardingException; -import io.shardingsphere.transaction.api.TransactionManager; import io.shardingsphere.transaction.common.event.TransactionEvent; import javax.transaction.HeuristicMixedException; @@ -34,9 +33,9 @@ * * @author zhaojun */ -public final class AtomikosTransactionManager implements TransactionManager { +public final class AtomikosTransactionManager implements XATransactionManager { - private final static UserTransactionManager TRANSACTION_MANAGER = AtomikosUserTransaction.getInstance(); + private static final UserTransactionManager TRANSACTION_MANAGER = AtomikosUserTransaction.getInstance(); static { try { @@ -59,7 +58,7 @@ public void begin(final TransactionEvent transactionEvent) throws SQLException { public void commit(final TransactionEvent transactionEvent) throws SQLException { try { TRANSACTION_MANAGER.commit(); - } catch (final RollbackException | HeuristicMixedException |HeuristicRollbackException | SystemException ex) { + } catch (final RollbackException | HeuristicMixedException | HeuristicRollbackException | SystemException ex) { throw new SQLException(ex); } } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/XATransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/XATransactionManager.java new file mode 100644 index 0000000000000..6edc845f82a78 --- /dev/null +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/XATransactionManager.java @@ -0,0 +1,28 @@ +/* + * 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.transaction.api.xa; + +import io.shardingsphere.transaction.api.ShardingTransactionManager; + +/** + * XA transaction manager. + * + * @author zhangliang + */ +public interface XATransactionManager extends ShardingTransactionManager { +} diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/XATransactionManagerSPILoader.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/XATransactionManagerSPILoader.java new file mode 100644 index 0000000000000..fe94ab81b66e2 --- /dev/null +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/XATransactionManagerSPILoader.java @@ -0,0 +1,63 @@ +/* + * 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.transaction.api.xa; + +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; + +import java.util.Iterator; +import java.util.ServiceLoader; + +/** + * XA transaction manager SPI loader. + * + * @author zhangliang + */ +@Getter +@Slf4j +public final class XATransactionManagerSPILoader { + + private static final XATransactionManagerSPILoader INSTANCE = new XATransactionManagerSPILoader(); + + private final XATransactionManager transactionManager; + + private XATransactionManagerSPILoader() { + transactionManager = load(); + } + + private XATransactionManager load() { + Iterator xaTransactionManagers = ServiceLoader.load(XATransactionManager.class).iterator(); + if (!xaTransactionManagers.hasNext()) { + return new AtomikosTransactionManager(); + } + XATransactionManager result = xaTransactionManagers.next(); + if (xaTransactionManagers.hasNext()) { + log.warn("There are more than one transaction mangers existing, chosen first one by default."); + } + return result; + } + + /** + * Get instance of XA transaction manager SPI loader. + * + * @return instance of XA transaction manager SPI loader + */ + public static XATransactionManagerSPILoader getInstance() { + return INSTANCE; + } +} diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java index eeff7d2188bc9..51606268322ae 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java @@ -18,7 +18,7 @@ package io.shardingsphere.transaction.common; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.api.TransactionManager; +import io.shardingsphere.transaction.api.ShardingTransactionManager; import lombok.Getter; import lombok.NoArgsConstructor; @@ -31,11 +31,11 @@ @Getter public final class TransactionContext { - private TransactionManager transactionManager; + private ShardingTransactionManager transactionManager; private TransactionType transactionType = TransactionType.LOCAL; - public TransactionContext(final TransactionManager transactionManager, final TransactionType transactionType) { + public TransactionContext(final ShardingTransactionManager transactionManager, final TransactionType transactionType) { this.transactionManager = transactionManager; this.transactionType = transactionType; } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java deleted file mode 100644 index 91d3e2d51d681..0000000000000 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContextFactory.java +++ /dev/null @@ -1,52 +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.transaction.common; - -import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.api.local.LocalTransactionManager; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -/** - * Transaction context factory. - * - * @author zhaojun - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TransactionContextFactory { - - /** - * Create transaction context of XA. - * - * @param transactionManager transaction manager - * @return XA transaction context - */ - public static TransactionContext newXAContext(final TransactionManager transactionManager) { - return new TransactionContext(transactionManager, TransactionType.XA); - } - - /** - * Create local transaction context. - * - * @return local transaction context - */ - public static TransactionContext newLocalTransactionContext() { - return new TransactionContext(new LocalTransactionManager(), TransactionType.LOCAL); - } -} diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java index 2c0d404e4de82..db524fd7d140c 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java @@ -17,12 +17,6 @@ package io.shardingsphere.transaction.common.config; -import com.google.common.base.Optional; -import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.common.TransactionContext; -import io.shardingsphere.transaction.common.TransactionContextFactory; -import io.shardingsphere.transaction.common.TransactionContextHolder; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -44,13 +38,4 @@ public final class JDBCTransactionConfiguration extends TransactionConfiguration public static JDBCTransactionConfiguration getInstance() { return INSTANCE; } - - @Override - protected TransactionManager getXATransactionManager(final TransactionType transactionType) { - Optional transactionManager = getXATransactionManagerFromSPI(transactionType); - TransactionContext transactionContext = transactionManager.isPresent() - ? TransactionContextFactory.newXAContext(transactionManager.get()) : TransactionContextFactory.newLocalTransactionContext(); - TransactionContextHolder.set(transactionContext); - return transactionContext.getTransactionManager(); - } } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java index 8c535bd50f102..2b10635927556 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java @@ -17,12 +17,6 @@ package io.shardingsphere.transaction.common.config; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.api.TransactionManager; -import io.shardingsphere.transaction.common.TransactionContextFactory; -import io.shardingsphere.transaction.common.TransactionContextHolder; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -44,12 +38,4 @@ public final class ProxyTransactionConfiguration extends TransactionConfiguratio public static ProxyTransactionConfiguration getInstance() { return INSTANCE; } - - @Override - protected TransactionManager getXATransactionManager(final TransactionType transactionType) { - Optional transactionManager = getXATransactionManagerFromSPI(transactionType); - Preconditions.checkState(transactionManager.isPresent(), "there is no XA transaction manager existing, please prepare exactly one(Atomikos or Narayana) using SPI."); - TransactionContextHolder.set(TransactionContextFactory.newXAContext(transactionManager.get())); - return transactionManager.get(); - } } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java index 88ce37309b8a5..4ea8ab3287109 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java @@ -18,7 +18,7 @@ package io.shardingsphere.transaction.common.config; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.api.TransactionManager; +import io.shardingsphere.transaction.api.ShardingTransactionManager; /** * Execute transaction manager configuration. @@ -33,5 +33,5 @@ public interface TransactionConfiguration { * @param transactionType transaction type * @return transaction manager */ - TransactionManager getTransactionManager(TransactionType transactionType); + ShardingTransactionManager getTransactionManager(TransactionType transactionType); } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java index 1969bb18cf157..e096b8d1861b3 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java @@ -17,17 +17,14 @@ package io.shardingsphere.transaction.common.config; -import com.google.common.base.Optional; -import com.google.common.collect.Lists; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.api.TransactionManager; +import io.shardingsphere.transaction.api.ShardingTransactionManager; +import io.shardingsphere.transaction.api.local.LocalTransactionManager; +import io.shardingsphere.transaction.api.xa.XATransactionManagerSPILoader; +import io.shardingsphere.transaction.common.TransactionContext; +import io.shardingsphere.transaction.common.TransactionContextHolder; import lombok.extern.slf4j.Slf4j; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.ServiceLoader; - /** * Abstract transaction manager configuration. * @@ -36,32 +33,20 @@ @Slf4j public abstract class TransactionConfigurationAdapter implements TransactionConfiguration { - private static final Map> SPI_RESOURCES = new HashMap<>(); - @Override - public final TransactionManager getTransactionManager(final TransactionType transactionType) { + public final ShardingTransactionManager getTransactionManager(final TransactionType transactionType) { + ShardingTransactionManager result; switch (transactionType) { + case LOCAL: + result = new LocalTransactionManager(); + break; case XA: - return getXATransactionManager(transactionType); - default: + result = XATransactionManagerSPILoader.getInstance().getTransactionManager(); + break; + default: return null; } - } - - protected abstract TransactionManager getXATransactionManager(TransactionType transactionType); - - protected final Optional getXATransactionManagerFromSPI(final TransactionType transactionType) { - if (SPI_RESOURCES.containsKey(transactionType)) { - return SPI_RESOURCES.get(transactionType); - } - synchronized (SPI_RESOURCES) { - List transactionManagerList = Lists.newArrayList(ServiceLoader.load(TransactionManager.class).iterator()); - if (transactionManagerList.size() > 1) { - log.info("there is more than one transaction manger existing, chosen first one default."); - } - Optional transactionManager = transactionManagerList.isEmpty() ? Optional.absent() : Optional.of(transactionManagerList.get(0)); - SPI_RESOURCES.put(transactionType, transactionManager); - return transactionManager; - } + TransactionContextHolder.set(new TransactionContext(result, transactionType)); + return result; } } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java index ffc862bb654a7..6dfae8075ca18 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/listener/TransactionListener.java @@ -20,7 +20,7 @@ import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; import io.shardingsphere.core.util.EventBusInstance; -import io.shardingsphere.transaction.api.TransactionManager; +import io.shardingsphere.transaction.api.ShardingTransactionManager; import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.common.event.TransactionEvent; @@ -49,7 +49,7 @@ public void register() { @Subscribe @AllowConcurrentEvents public void listen(final TransactionEvent transactionEvent) throws SQLException { - TransactionManager transactionManager = TransactionContextHolder.get().getTransactionManager(); + ShardingTransactionManager transactionManager = TransactionContextHolder.get().getTransactionManager(); switch (transactionEvent.getTclType()) { case BEGIN: transactionManager.begin(transactionEvent); From b3ff9568278da431fe58e2c93a21e69d01e9bb0e Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 13 Aug 2018 00:43:45 +0800 Subject: [PATCH 197/198] add ShardingTransactionManagerFactory --- .../adapter/AbstractConnectionAdapter.java | 6 +-- .../adapter/AbstractDataSourceAdapter.java | 4 +- .../proxy/config/RuleRegistry.java | 4 +- .../ShardingTransactionManagerFactory.java} | 24 +++++++---- .../config/JDBCTransactionConfiguration.java | 41 ------------------- .../config/ProxyTransactionConfiguration.java | 41 ------------------- .../config/TransactionConfiguration.java | 37 ----------------- 7 files changed, 22 insertions(+), 135 deletions(-) rename sharding-transaction/src/main/java/io/shardingsphere/transaction/{common/config/TransactionConfigurationAdapter.java => api/ShardingTransactionManagerFactory.java} (72%) delete mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java delete mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java delete mode 100644 sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index 4f33dc4ef8539..d2586e8d35f19 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -27,10 +27,10 @@ import io.shardingsphere.transaction.api.local.LocalTransactionManager; import io.shardingsphere.transaction.common.TransactionContext; import io.shardingsphere.transaction.common.TransactionContextHolder; -import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration; +import io.shardingsphere.transaction.api.ShardingTransactionManagerFactory; +import io.shardingsphere.transaction.common.event.LocalTransactionEvent; import io.shardingsphere.transaction.common.event.TransactionEvent; import io.shardingsphere.transaction.common.event.TransactionEventFactory; -import io.shardingsphere.transaction.common.event.LocalTransactionEvent; import javax.sql.DataSource; import java.sql.Connection; @@ -67,7 +67,7 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera * @throws SQLException SQL exception */ public final Connection getConnection(final String dataSourceName) throws SQLException { - JDBCTransactionConfiguration.getInstance().getTransactionManager(TransactionContextHolder.get().getTransactionType()); + ShardingTransactionManagerFactory.getTransactionManager(TransactionContextHolder.get().getTransactionType()); if (cachedConnections.containsKey(dataSourceName)) { return cachedConnections.get(dataSourceName); } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java index d6c7018c4fff4..66b2bbdfca07d 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java @@ -22,7 +22,7 @@ import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationDataSource; import io.shardingsphere.core.listener.JDBCListenerRegister; import io.shardingsphere.transaction.common.TransactionContextHolder; -import io.shardingsphere.transaction.common.config.JDBCTransactionConfiguration; +import io.shardingsphere.transaction.api.ShardingTransactionManagerFactory; import lombok.Getter; import javax.sql.DataSource; @@ -40,7 +40,7 @@ public abstract class AbstractDataSourceAdapter extends AbstractUnsupportedOperationDataSource { static { - JDBCTransactionConfiguration.getInstance().getTransactionManager(TransactionContextHolder.get().getTransactionType()); + ShardingTransactionManagerFactory.getTransactionManager(TransactionContextHolder.get().getTransactionType()); JDBCListenerRegister.register(); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 90f6b9088098e..3c0501823565a 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -34,7 +34,7 @@ import io.shardingsphere.jdbc.orchestration.internal.eventbus.ProxyEventBusEvent; import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource; import io.shardingsphere.transaction.api.ShardingTransactionManager; -import io.shardingsphere.transaction.common.config.ProxyTransactionConfiguration; +import io.shardingsphere.transaction.api.ShardingTransactionManagerFactory; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -106,7 +106,7 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE)); - transactionManager = ProxyTransactionConfiguration.getInstance().getTransactionManager(transactionType); + transactionManager = ShardingTransactionManagerFactory.getTransactionManager(transactionType); acceptorSize = shardingProperties.getValue(ShardingPropertiesConstant.ACCEPTOR_SIZE); executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); // TODO :jiaqi force off use NIO for backend, this feature is not complete yet diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManagerFactory.java similarity index 72% rename from sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManagerFactory.java index e096b8d1861b3..5e93c0ec154bd 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfigurationAdapter.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManagerFactory.java @@ -15,26 +15,31 @@ *

*/ -package io.shardingsphere.transaction.common.config; +package io.shardingsphere.transaction.api; import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.api.ShardingTransactionManager; import io.shardingsphere.transaction.api.local.LocalTransactionManager; import io.shardingsphere.transaction.api.xa.XATransactionManagerSPILoader; import io.shardingsphere.transaction.common.TransactionContext; import io.shardingsphere.transaction.common.TransactionContextHolder; -import lombok.extern.slf4j.Slf4j; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; /** - * Abstract transaction manager configuration. + * Sharding transaction manager factory. * - * @author zhaojun + * @author zhangliang */ -@Slf4j -public abstract class TransactionConfigurationAdapter implements TransactionConfiguration { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ShardingTransactionManagerFactory { - @Override - public final ShardingTransactionManager getTransactionManager(final TransactionType transactionType) { + /** + * Get sharding transaction manager. + * + * @param transactionType transaction type + * @return sharding transaction manager + */ + public static ShardingTransactionManager getTransactionManager(final TransactionType transactionType) { ShardingTransactionManager result; switch (transactionType) { case LOCAL: @@ -43,6 +48,7 @@ public final ShardingTransactionManager getTransactionManager(final TransactionT case XA: result = XATransactionManagerSPILoader.getInstance().getTransactionManager(); break; + case BASE: default: return null; } diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java deleted file mode 100644 index db524fd7d140c..0000000000000 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/JDBCTransactionConfiguration.java +++ /dev/null @@ -1,41 +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.transaction.common.config; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -/** - * JDBC transaction configuration. - * - * @author zhaojun - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class JDBCTransactionConfiguration extends TransactionConfigurationAdapter { - - private static final JDBCTransactionConfiguration INSTANCE = new JDBCTransactionConfiguration(); - - /** - * Get singleton instance of {@code JDBCTransactionConfiguration}. - * - * @return JDBC transaction configuration - */ - public static JDBCTransactionConfiguration getInstance() { - return INSTANCE; - } -} diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java deleted file mode 100644 index 2b10635927556..0000000000000 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/ProxyTransactionConfiguration.java +++ /dev/null @@ -1,41 +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.transaction.common.config; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -/** - * Sharding proxy transaction configuration. - * - * @author zhaojun - */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ProxyTransactionConfiguration extends TransactionConfigurationAdapter { - - private static final ProxyTransactionConfiguration INSTANCE = new ProxyTransactionConfiguration(); - - /** - * Get singleton instance of {@code ProxyTransactionConfiguration}. - * - * @return proxy transaction configuration - */ - public static ProxyTransactionConfiguration getInstance() { - return INSTANCE; - } -} diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java deleted file mode 100644 index 4ea8ab3287109..0000000000000 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/config/TransactionConfiguration.java +++ /dev/null @@ -1,37 +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.transaction.common.config; - -import io.shardingsphere.core.constant.TransactionType; -import io.shardingsphere.transaction.api.ShardingTransactionManager; - -/** - * Execute transaction manager configuration. - * - * @author zhaojun - */ -public interface TransactionConfiguration { - - /** - * Get transaction manager. - * - * @param transactionType transaction type - * @return transaction manager - */ - ShardingTransactionManager getTransactionManager(TransactionType transactionType); -} From 46da5d2fe6f7a6b80830cb601191d3c8431373f3 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Mon, 13 Aug 2018 00:48:29 +0800 Subject: [PATCH 198/198] refactor ShardingTransactionManagerFactory --- .../jdbc/adapter/AbstractConnectionAdapter.java | 5 +++-- .../jdbc/adapter/AbstractDataSourceAdapter.java | 7 +++++-- .../shardingsphere/proxy/config/RuleRegistry.java | 5 ++++- .../api/ShardingTransactionManagerFactory.java | 13 +++---------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java index d2586e8d35f19..ce2868a546288 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractConnectionAdapter.java @@ -24,10 +24,10 @@ import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationConnection; import io.shardingsphere.core.routing.router.masterslave.MasterVisitedManager; import io.shardingsphere.core.util.EventBusInstance; +import io.shardingsphere.transaction.api.ShardingTransactionManagerFactory; import io.shardingsphere.transaction.api.local.LocalTransactionManager; import io.shardingsphere.transaction.common.TransactionContext; import io.shardingsphere.transaction.common.TransactionContextHolder; -import io.shardingsphere.transaction.api.ShardingTransactionManagerFactory; import io.shardingsphere.transaction.common.event.LocalTransactionEvent; import io.shardingsphere.transaction.common.event.TransactionEvent; import io.shardingsphere.transaction.common.event.TransactionEventFactory; @@ -67,7 +67,8 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera * @throws SQLException SQL exception */ public final Connection getConnection(final String dataSourceName) throws SQLException { - ShardingTransactionManagerFactory.getTransactionManager(TransactionContextHolder.get().getTransactionType()); + TransactionType transactionType = TransactionContextHolder.get().getTransactionType(); + TransactionContextHolder.set(new TransactionContext(ShardingTransactionManagerFactory.getShardingTransactionManager(transactionType), transactionType)); if (cachedConnections.containsKey(dataSourceName)) { return cachedConnections.get(dataSourceName); } diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java index 66b2bbdfca07d..ce22916fa2fbc 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/adapter/AbstractDataSourceAdapter.java @@ -19,10 +19,12 @@ import com.google.common.base.Preconditions; import io.shardingsphere.core.constant.DatabaseType; +import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationDataSource; import io.shardingsphere.core.listener.JDBCListenerRegister; -import io.shardingsphere.transaction.common.TransactionContextHolder; import io.shardingsphere.transaction.api.ShardingTransactionManagerFactory; +import io.shardingsphere.transaction.common.TransactionContext; +import io.shardingsphere.transaction.common.TransactionContextHolder; import lombok.Getter; import javax.sql.DataSource; @@ -40,7 +42,8 @@ public abstract class AbstractDataSourceAdapter extends AbstractUnsupportedOperationDataSource { static { - ShardingTransactionManagerFactory.getTransactionManager(TransactionContextHolder.get().getTransactionType()); + TransactionType transactionType = TransactionContextHolder.get().getTransactionType(); + TransactionContextHolder.set(new TransactionContext(ShardingTransactionManagerFactory.getShardingTransactionManager(transactionType), transactionType)); JDBCListenerRegister.register(); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java index 3c0501823565a..615c5bb79a184 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/config/RuleRegistry.java @@ -35,6 +35,8 @@ import io.shardingsphere.proxy.backend.jdbc.datasource.JDBCBackendDataSource; import io.shardingsphere.transaction.api.ShardingTransactionManager; import io.shardingsphere.transaction.api.ShardingTransactionManagerFactory; +import io.shardingsphere.transaction.common.TransactionContext; +import io.shardingsphere.transaction.common.TransactionContextHolder; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -106,7 +108,8 @@ public synchronized void init(final OrchestrationProxyConfiguration config) { showSQL = shardingProperties.getValue(ShardingPropertiesConstant.SQL_SHOW); connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); transactionType = TransactionType.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.PROXY_TRANSACTION_MODE)); - transactionManager = ShardingTransactionManagerFactory.getTransactionManager(transactionType); + transactionManager = ShardingTransactionManagerFactory.getShardingTransactionManager(transactionType); + TransactionContextHolder.set(new TransactionContext(transactionManager, transactionType)); acceptorSize = shardingProperties.getValue(ShardingPropertiesConstant.ACCEPTOR_SIZE); executorSize = shardingProperties.getValue(ShardingPropertiesConstant.EXECUTOR_SIZE); // TODO :jiaqi force off use NIO for backend, this feature is not complete yet diff --git a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManagerFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManagerFactory.java index 5e93c0ec154bd..a6ffd2444bd5a 100644 --- a/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManagerFactory.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManagerFactory.java @@ -20,8 +20,6 @@ import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.transaction.api.local.LocalTransactionManager; import io.shardingsphere.transaction.api.xa.XATransactionManagerSPILoader; -import io.shardingsphere.transaction.common.TransactionContext; -import io.shardingsphere.transaction.common.TransactionContextHolder; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -39,20 +37,15 @@ public final class ShardingTransactionManagerFactory { * @param transactionType transaction type * @return sharding transaction manager */ - public static ShardingTransactionManager getTransactionManager(final TransactionType transactionType) { - ShardingTransactionManager result; + public static ShardingTransactionManager getShardingTransactionManager(final TransactionType transactionType) { switch (transactionType) { case LOCAL: - result = new LocalTransactionManager(); - break; + return new LocalTransactionManager(); case XA: - result = XATransactionManagerSPILoader.getInstance().getTransactionManager(); - break; + return XATransactionManagerSPILoader.getInstance().getTransactionManager(); case BASE: default: return null; } - TransactionContextHolder.set(new TransactionContext(result, transactionType)); - return result; } }