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 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. 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! 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/RELEASE-NOTES.md b/RELEASE-NOTES.md index bc1e861db43da..d0377a569a19f 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -6,112 +6,155 @@ ### 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 #862](https://github.com/sharding-sphere/sharding-sphere/issues/862) Support data orchestration in cloud side -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 +#### 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 -1. [ISSUE #701](https://github.com/sharding-sphere/sharding-sphere/issues/701) Support caching parsing results of SQL to improve performance -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 #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. +#### 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) 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 `$->{..}` 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 -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 #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 #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` +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 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 -### 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 ### 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 ### 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 ### 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 2a77985a1fed3..0f13a0cc00c2c 100644 --- a/RELEASE-NOTES_ZH.md +++ b/RELEASE-NOTES_ZH.md @@ -6,112 +6,154 @@ ### 新功能 +#### 内核 + 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 #980](https://github.com/sharding-sphere/sharding-sphere/issues/980) 支持DCL语句 -1. [ISSUE #936](https://github.com/sharding-sphere/sharding-sphere/issues/936) 支持Proxy使用注册中心 +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 #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 #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 #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的方式在命名空间中注入分片算法对象 -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属性 ### 缺陷修正 -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 #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 #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` +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中使用`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 -### 功能提升 +### 新功能 + +#### 内核 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 ### 功能提升 -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 ### 功能提升 -1. [ISSUE #489](https://github.com/sharding-sphere/sharding-sphere/issues/489) SpringName使用RuntimeBeanReference防止创建InnerBean +#### 内核 + +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 ### 里程碑 -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 diff --git a/pom.xml b/pom.xml index f003acfabb4e5..d5fc5c543a407 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.M3-SNAPSHOT pom ${project.artifactId} @@ -16,6 +16,7 @@ sharding-opentracing sharding-proxy sharding-sql-test + sharding-transaction diff --git a/sharding-core/pom.xml b/sharding-core/pom.xml index be5b84acfbd10..806cd04176731 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.M3-SNAPSHOT sharding-core ${project.artifactId} 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/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java b/sharding-core/src/main/java/io/shardingsphere/core/constant/ShardingPropertiesConstant.java index d421c3593643e..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 @@ -42,16 +42,27 @@ 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. * *

* 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(Runtime.getRuntime().availableProcessors()), int.class), + EXECUTOR_SIZE("executor.size", String.valueOf(0), int.class), /** * Connection mode of connected to databases. @@ -70,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 } 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..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 @@ -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,11 +59,14 @@ 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); } 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/LogicTablesMergedResult.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/LogicTablesMergedResult.java new file mode 100644 index 0000000000000..ab0de00960887 --- /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 final 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/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/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..3f326a0470be2 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTableStatusMergedResult.java @@ -0,0 +1,61 @@ +/* + * 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 io.shardingsphere.core.merger.QueryResult; +import io.shardingsphere.core.metadata.table.ShardingTableMetaData; +import io.shardingsphere.core.rule.ShardingRule; + +import java.sql.SQLException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Merged result for show table status. + * + * @author zhangliang + */ +public final class ShowTableStatusMergedResult extends LogicTablesMergedResult { + + private static final Map LABEL_AND_INDEX_MAP = new HashMap<>(17, 1); + + 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, 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); } } 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/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/metadata/ShardingMetaData.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java index 54a0701ac4a6e..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 @@ -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 final 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-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/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/TableMetaDataInitializer.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/table/executor/TableMetaDataInitializer.java index 7b2099ff354d5..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; @@ -39,13 +40,14 @@ */ 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 ShardingDataSourceMetaData shardingDataSourceMetaData, final ListeningExecutorService executorService, final TableMetaDataConnectionManager connectionManager) { + this.connectionManager = connectionManager; + tableMetaDataLoader = new TableMetaDataLoader(shardingDataSourceMetaData, executorService, connectionManager); } /** @@ -86,8 +88,8 @@ private Map loadDefaultTables(final ShardingRule sharding private Collection getAllTableNames(final String dataSourceName) throws SQLException { Collection result = new LinkedList<>(); - try (Connection connection = executorAdapter.getConnection(dataSourceName); - ResultSet resultSet = connection.getMetaData().getTables(null, null, null, null)) { + try (Connection connection = connectionManager.getConnection(dataSourceName); + 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 55529d3ee60f0..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,12 +21,12 @@ 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.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; @@ -37,6 +37,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; @@ -48,9 +50,11 @@ @RequiredArgsConstructor public final class TableMetaDataLoader { + private final ShardingDataSourceMetaData shardingDataSourceMetaData; + private final ListeningExecutorService executorService; - private final TableMetaDataConnectionManager executorAdapter; + private final TableMetaDataConnectionManager connectionManager; /** * Load table meta data. @@ -60,38 +64,57 @@ public final class TableMetaDataLoader { * @return table meta data */ public TableMetaData load(final String logicTableName, final ShardingRule shardingRule) { - return load(shardingRule.getTableRuleByLogicTableName(logicTableName), shardingRule.getShardingDataSourceNames()); - } - - private TableMetaData load(final TableRule tableRule, final ShardingDataSourceNames shardingDataSourceNames) { - List actualTableMetaDataList = loadActualTableMetaDataList(tableRule.getActualDataNodes(), shardingDataSourceNames); - checkUniformed(tableRule.getLogicTable(), actualTableMetaDataList); + List actualTableMetaDataList = load(shardingRule.getTableRuleByLogicTableName(logicTableName).getDataNodeGroups(), shardingRule.getShardingDataSourceNames()); + checkUniformed(logicTableName, actualTableMetaDataList); return actualTableMetaDataList.iterator().next(); } - private TableMetaData load(final DataNode dataNode) throws SQLException { - if (executorAdapter.isAutoClose()) { - try (Connection connection = executorAdapter.getConnection(dataNode.getDataSourceName())) { - return load(connection, dataNode); + private List load(final Map> dataNodeGroups, final ShardingDataSourceNames shardingDataSourceNames) { + List>> futures = new LinkedList<>(); + 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(dataSourceName, catalog, actualTableNames); + } + })); + } + List result = new LinkedList<>(); + try { + for (Collection each : Futures.allAsList(futures).get()) { + result.addAll(each); } + return result; + } catch (final InterruptedException | ExecutionException ex) { + throw new ShardingException(ex); } - return load(executorAdapter.getConnection(dataNode.getDataSourceName()), dataNode); } - 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 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, 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"); @@ -101,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")); } @@ -111,24 +134,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/parsing/lexer/dialect/mysql/MySQLKeyword.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/lexer/dialect/mysql/MySQLKeyword.java index fa4a73189fa58..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 @@ -98,5 +98,10 @@ public enum MySQLKeyword implements Keyword { STRAIGHT_JOIN, REGEXP, INDEXES, - KEYS + KEYS, + STATUS, + GENERATED, + ALWAYS, + BTREE, + HASH } 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/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/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/constant/DerivedColumn.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java new file mode 100644 index 0000000000000..50408632b6633 --- /dev/null +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/constant/DerivedColumn.java @@ -0,0 +1,62 @@ +/* + * 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.RequiredArgsConstructor; + +/** + * Derived column alias. + * + * @author zhangliang + */ +@RequiredArgsConstructor(access = AccessLevel.PRIVATE) +public enum DerivedColumn { + + 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 final String pattern; + + /** + * Get alias of derived column. + * + * @param derivedColumnCount derived column count + * @return alias of derived column + */ + public String getDerivedColumnAlias(final int derivedColumnCount) { + return String.format(pattern + "%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) { + 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/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/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/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/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/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/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/mysql/sql/MySQLShowParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLShowParser.java index fb5e3fa7a8b1e..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 @@ -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; @@ -56,43 +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 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; + } } 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-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/PacketHeader.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/statement/ShowTableStatusStatement.java similarity index 66% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/PacketHeader.java rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/statement/ShowTableStatusStatement.java index e59b7f11e12c6..98f6a021fbf90 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/constant/PacketHeader.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/statement/ShowTableStatusStatement.java @@ -15,25 +15,14 @@ *

*/ -package io.shardingsphere.proxy.transport.mysql.constant; +package io.shardingsphere.core.parsing.parser.dialect.mysql.statement; -import lombok.Getter; -import lombok.RequiredArgsConstructor; +import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement; /** - * Generic Packet Header. + * Show table status statement. * - * @author linjiaqi + * @author zhangliang */ -@RequiredArgsConstructor -@Getter -public enum PacketHeader { - - OK(0x00), - - EOF(0xfe), - - ERR(0xff); - - private final int value; +public final class ShowTableStatusStatement extends DALStatement { } 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/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/OracleInsertValuesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/clause/OracleInsertValuesClauseParser.java new file mode 100644 index 0000000000000..7838114ec813e --- /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 final 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 136ea0e8f5666..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.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.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), new InsertSetClauseParser(shardingRule, lexerEngine), new InsertDuplicateKeyUpdateClauseParser(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/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/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/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/PostgreSQLInsertValuesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/clause/PostgreSQLInsertValuesClauseParser.java new file mode 100644 index 0000000000000..ba4a073629ce7 --- /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 final 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 bc04c3e52d42a..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.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.parsing.parser.dialect.postgresql.clause.PostgreSQLInsertValuesClauseParser; import io.shardingsphere.core.rule.ShardingRule; /** @@ -35,6 +35,7 @@ public final class PostgreSQLInsertClauseParserFacade extends AbstractInsertClau 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)); + 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 7c81407f4da41..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.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.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 DistinctClauseParser(lexerEngine), new SelectListClauseParser(shardingRule, lexerEngine), + super(new PostgreSQLDistinctClauseParser(lexerEngine), new PostgreSQLSelectListClauseParser(shardingRule, lexerEngine), new PostgreSQLTableReferencesClauseParser(shardingRule, lexerEngine), - new WhereClauseParser(DatabaseType.PostgreSQL, lexerEngine), new GroupByClauseParser(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/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/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/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/SQLServerInsertValuesClauseParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/clause/SQLServerInsertValuesClauseParser.java new file mode 100644 index 0000000000000..c252033e8ca39 --- /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 final 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 a1ed3d91c3644..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.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.parsing.parser.dialect.sqlserver.clause.SQLServerInsertValuesClauseParser; import io.shardingsphere.core.rule.ShardingRule; /** @@ -35,6 +35,7 @@ public final class SQLServerInsertClauseParserFacade extends AbstractInsertClaus 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)); + 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/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/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/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/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/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/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/alter/table/AbstractAlterTableParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java index d0695e3068f89..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 @@ -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(); @@ -57,7 +57,5 @@ public 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 f9e5d76ae9d6a..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 @@ -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. * @@ -50,16 +54,21 @@ public AbstractCreateTableParser(final ShardingRule shardingRule, final LexerEng } @Override - public DDLStatement parse() { + public final 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,53 @@ 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 = lexerEngine.getCurrentToken().getLiterals(); + statement.getColumnNames().add(result); + return result; + } + + private void parseColumnDefinition(final String columnName, final CreateTableStatement statement) { + parseDataType(statement); + 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); + } + } + } + + private void parseDataType(final CreateTableStatement statement) { + lexerEngine.nextToken(); + statement.getColumnTypes().add(lexerEngine.getCurrentToken().getLiterals()); + lexerEngine.skipParentheses(statement); + } + + protected abstract Keyword[] getSkippedKeywordsBeforeTableConstraint(); + + private void parseTableConstraint(final CreateTableStatement statement) { + Collection columnNames = new LinkedList<>(); + do { + 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); + lexerEngine.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/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 f7518b8f013ba..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,9 +50,9 @@ public AbstractDropTableParser(final ShardingRule shardingRule, final LexerEngin } @Override - public DDLStatement parse() { + public final DDLStatement parse() { lexerEngine.skipAll(getSkippedKeywordsBetweenDropAndTable()); - DDLStatement result = new DDLStatement(); + DropTableStatement result = new DropTableStatement(); if (lexerEngine.skipIfEqual(DefaultKeyword.TABLE)) { lexerEngine.skipAll(getSkippedKeywordsBetweenDropTableAndTableName()); tableReferencesClauseParser.parseSingleTableWithoutAlias(result); @@ -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-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/AuthType.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/DropTableStatement.java similarity index 61% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/AuthType.java rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/DropTableStatement.java index 3d64dbe50c6f0..10fbdea41da21 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/constant/AuthType.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/DropTableStatement.java @@ -15,36 +15,14 @@ *

*/ -package io.shardingsphere.proxy.backend.constant; +package io.shardingsphere.core.parsing.parser.sql.ddl.drop.table; + +import io.shardingsphere.core.parsing.parser.sql.ddl.DDLStatement; /** - * Auth Type. - * - * @author linjiaqi + * Drop table statement. + * + * @author zhangliang */ -public enum AuthType { - - /** - * Database UN_AUTH. - * - */ - UN_AUTH, - - /** - * Database AUTHING. - * - */ - AUTHING, - - /** - * Database AUTH_SUCCESS. - * - */ - AUTH_SUCCESS, - - /** - * Database AUTH_FAILED. - * - */ - AUTH_FAILED +public final class DropTableStatement extends DDLStatement { } 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/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-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-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..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 @@ -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.AVG_COUNT_ALIAS.getDerivedColumnAlias(derivedColumnOffset); AggregationSelectItem countItem = new AggregationSelectItem(AggregationType.COUNT, avgItem.getInnerExpression(), Optional.of(countAlias)); - String sumAlias = String.format(DERIVED_SUM_ALIAS, 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); @@ -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.ORDER_BY_ALIAS.getDerivedColumnAlias(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.GROUP_BY_ALIAS.getDerivedColumnAlias(derivedColumnOffset++); each.setAlias(Optional.of(alias)); itemsToken.getItems().add(each.getQualifiedName().get() + " AS " + alias + " "); } 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/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. * 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-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-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-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(); } /** 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/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/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/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-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-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/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()); } } 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/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-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 ed872f102741d..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 @@ -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,8 +32,9 @@ AllStatementParserTests.class, AllSQLTests.class, SQLJudgeEngineTest.class, - OrderItemTest.class, + OrderItemTest.class, + 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/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..27e618209506b --- /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.CoreMatchers.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/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/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")); + } +} 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/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 *"); } 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-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-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-jdbc-orchestration-spring/pom.xml b/sharding-jdbc-orchestration-spring/pom.xml index 6f16c4d089108..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-SNAPSHOT + 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 b22894a9bdea4..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-SNAPSHOT + 3.0.0.M3-SNAPSHOT sharding-jdbc-orchestration-spring-boot-starter 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-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-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/pom.xml b/sharding-jdbc-orchestration-spring/sharding-jdbc-orchestration-spring-namespace/pom.xml index 25265aef3aa6e..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-SNAPSHOT + 3.0.0.M3-SNAPSHOT sharding-jdbc-orchestration-spring-namespace 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/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/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/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-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/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-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-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-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/pom.xml b/sharding-jdbc-orchestration/pom.xml index 5067a4d7ffe04..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-SNAPSHOT + 3.0.0.M3-SNAPSHOT 4.0.0 sharding-jdbc-orchestration ${project.artifactId} - 3.0.0.M2-SNAPSHOT + 3.0.0.M3-SNAPSHOT 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/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/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/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/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/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..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 @@ -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,21 @@ public interface IClient extends IAction, IGroupAction { void useExecStrategy(StrategyType strategyType); /** - * Create transaction. + * Get execution strategy. * - * @return ZKTransaction + * @return execution strategy + */ + IExecStrategy getExecStrategy(); + + /** + * Create zookeeper transaction. + * + * @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 e13fc41f7df23..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,31 +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 { private final Map children = new ConcurrentHashMap<>(); - + 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) { @@ -56,32 +54,9 @@ 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) { - this.children.put(node.nodeKey, node); - node.setPath(PathUtil.getRealPath(path, node.getKey())); + void attachChild(final PathNode node) { + children.put(node.nodeKey, node); + node.setPath(PathUtil.getRealPath(path, node.getNodeKey())); } PathNode set(final PathResolve pathResolve, final String value) { @@ -90,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 10f54af0627c0..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 @@ -23,44 +23,43 @@ 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.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 +67,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; + // TODO consider whether to use a new client alternative to the current this.client = client; - // todo It looks unpleasant - this.provider = ((UsualClient) client).getStrategy().getProvider(); + provider = client.getExecStrategy().getProvider(); } /** @@ -82,30 +81,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().getKey()); - final List children = provider.getChildren(PathUtil.checkPath(rootNode.get().getKey())); + 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 +115,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 +135,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 +146,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 +164,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,18 +182,19 @@ public void run() { public void stopRefresh() { cacheService.shutdown(); executorStart = false; - log.debug("stopRefresh"); + log.debug("stop refresh"); } /** * 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(); - log.debug("PathTree Watch event:{}", event.toString()); + log.debug("PathTree Watch event: {}", event.toString()); switch (event.getType()) { case NodeCreated: case NodeDataChanged: @@ -220,15 +220,15 @@ public void watch(final ZookeeperEventListener zookeeperEventListener) { if (closed) { return; } - final String key = zookeeperEventListener.getKey(); - log.debug("PathTree Watch:{}", key); - client.registerWatch(rootNode.get().getKey(), zookeeperEventListener); + 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 +239,6 @@ private void processNodeChange(final String path) { } } - /** - * Get root node. - * - * @return root node - */ - public PathNode getRootNode() { - return rootNode.get(); - } - /** * Get node value. * @@ -258,7 +249,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 +263,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 +273,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 +301,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 +309,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 +336,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 +356,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..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 @@ -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,23 +112,23 @@ 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); - return getStrategy().getData(key); + log.debug("getData cache not hit: {}", 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()) { - log.debug("getChildren cache hit:{}", keys); + 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)); + log.debug("getChildren cache not hit: {}", keys); + return getExecStrategy().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..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 @@ -42,7 +42,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -/* +/** * Usually use client. * * @author lidongbo @@ -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); @@ -61,7 +61,7 @@ protected UsualClient(final BaseContext context) { @Override public void close() { - this.strategies.clear(); + strategies.clear(); super.close(); } @@ -69,86 +69,86 @@ 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 public void createCurrentOnly(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException { - this.createNamespace(); + createNamespace(); if (getRootNode().equals(key)) { return; } - strategy.createCurrentOnly(key, value, createMode); + execStrategy.createCurrentOnly(key, value, createMode); } @Override public void createAllNeedPath(final String key, final String value, final CreateMode createMode) throws KeeperException, InterruptedException { - this.createNamespace(); + createNamespace(); 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,29 +166,29 @@ 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()); + log.debug("deleteAllChildren delete root: {}", getRootNode()); } } @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()); + log.debug("deleteCurrentBranch delete root: {}", getRootNode()); } } @Override public BaseTransaction transaction() { - return strategy.transaction(); + return execStrategy.transaction(); } } 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..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 @@ -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) { @@ -123,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); @@ -131,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"); } @@ -171,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) { @@ -181,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/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..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 @@ -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,22 +44,15 @@ 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 final 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) { + public final 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..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 @@ -21,12 +21,12 @@ 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 */ -public class DeleteCurrentOperation extends BaseOperation { +public final class DeleteCurrentOperation extends BaseOperation { private final String key; @@ -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..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 @@ -21,12 +21,12 @@ 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 */ -public class UpdateOperation extends BaseOperation { +public final class UpdateOperation extends BaseOperation { private final String key; @@ -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..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 @@ -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,55 +58,48 @@ 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 { + 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); + 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 - 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; @@ -112,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); + 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); + 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); } @@ -150,11 +146,11 @@ private void executeContention(final String nodeBeCompete, final LeaderElection } @Override - public void resetConnection() { + public final 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..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 @@ -22,7 +22,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.zookeeper.KeeperException; -/* +/** * Client task. * * @author lidongbo @@ -37,13 +37,13 @@ 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; @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/section/Connection.java b/sharding-jdbc-orchestration/src/main/java/io/shardingsphere/jdbc/orchestration/reg/newzk/client/zookeeper/section/Connection.java index 896a563d8c959..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,17 +17,20 @@ 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; import java.util.concurrent.ConcurrentHashMap; -/* +/** * Zookeeper connection check. * * @author lidongbo */ -public class Connection { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +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..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,17 +17,20 @@ 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; -/* +/** * Build public watcher. * * @author lidongbo */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) @Slf4j -public class WatcherCreator { +public final class WatcherCreator { /** * Get string type data. @@ -42,7 +45,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..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 @@ -31,13 +31,13 @@ import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; -/* +/** * Async retry strategy. * * @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 6963b9baf1ad1..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 @@ -21,29 +21,27 @@ 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 { + 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 8f39f50d7cd2d..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 @@ -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 */ @@ -46,20 +46,20 @@ 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 { - LeaderElection election = new LeaderElection() { + public final void getData(final String key, final AsyncCallback.DataCallback callback, final Object ctx) throws KeeperException, InterruptedException { + getProvider().executeContention(new LeaderElection() { + @Override public void action() throws KeeperException, InterruptedException { getProvider().getData(getProvider().getRealPath(key), callback, ctx); - log.debug("ContentionStrategy getData action:{}", key); + log.debug("ContentionStrategy getData action: {}", key); } - }; - getProvider().executeContention(election); + }); log.debug("ContentionStrategy getData executeContention"); } @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"); @@ -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(); } } @@ -83,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"); @@ -92,15 +93,16 @@ 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); - 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(); } } @@ -108,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"); @@ -116,18 +118,20 @@ 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 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 +139,7 @@ public void action() throws KeeperException, InterruptedException { @Override public void callback() { - if (contentionCallback != null) { + if (null != contentionCallback) { contentionCallback.processResult(); } } @@ -152,15 +156,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 +173,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 +181,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 +196,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 +208,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 +225,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 +244,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/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/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 f9ee5ed67d8d1..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,25 +26,26 @@ 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 static junit.framework.TestCase.assertFalse; +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; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @Slf4j -public class SyncRetryStrategyTest extends UsualClientTest { +public final class SyncRetryStrategyTest extends UsualClientTest { private IProvider provider; @@ -53,7 +54,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; } 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-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..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,16 +23,16 @@ 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); } @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(); } 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/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-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-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-plugin/pom.xml b/sharding-jdbc-plugin/pom.xml index ad19ebcbbe870..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-SNAPSHOT + 3.0.0.M3-SNAPSHOT pom - 3.0.0.M2-SNAPSHOT + 3.0.0.M3-SNAPSHOT 4.12 1.6.6 1.7 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/pom.xml b/sharding-jdbc-spring/pom.xml index 233cb061c502c..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-SNAPSHOT + 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 c34c7a7053db6..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-SNAPSHOT + 3.0.0.M3-SNAPSHOT sharding-jdbc-spring-boot-starter 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-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-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-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-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 diff --git a/sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml b/sharding-jdbc-spring/sharding-jdbc-spring-namespace/pom.xml index ceccaabeceabc..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-SNAPSHOT + 3.0.0.M3-SNAPSHOT sharding-jdbc-spring-namespace 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/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-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/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-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-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-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 @@ + 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 @@ + diff --git a/sharding-jdbc-transaction-parent/pom.xml b/sharding-jdbc-transaction-parent/pom.xml index 0af233cee31df..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-SNAPSHOT + 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 55d0d0568efaa..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-SNAPSHOT + 3.0.0.M3-SNAPSHOT sharding-jdbc-transaction-async-job ${project.artifactId} 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-storage/pom.xml b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction-storage/pom.xml index 9bc391997ea8a..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-SNAPSHOT + 3.0.0.M3-SNAPSHOT sharding-jdbc-transaction-storage ${project.artifactId} 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-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/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-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/pom.xml b/sharding-jdbc-transaction-parent/sharding-jdbc-transaction/pom.xml index b604b82c937a3..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-SNAPSHOT + 3.0.0.M3-SNAPSHOT sharding-jdbc-transaction ${project.artifactId} 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/pom.xml b/sharding-jdbc/pom.xml index faa93cefd5368..70d34ed310ffd 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.M3-SNAPSHOT sharding-jdbc ${project.artifactId} @@ -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/executor/ExecutorEngine.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/ExecutorEngine.java index 2e066f42257e4..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 @@ -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,16 +33,13 @@ 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.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; @@ -57,7 +52,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()); @@ -66,8 +61,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); } @@ -88,11 +88,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,64 +104,34 @@ 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; - 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; } - } - - 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()); + for (AbstractExecutionEvent each : events) { + each.setEventExecutionType(EventExecutionType.EXECUTE_SUCCESS); + EventBusInstance.getInstance().post(each); } return result; } 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..f3877e5d482d9 --- /dev/null +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/ConnectionStrictlyExecutorEngine.java @@ -0,0 +1,105 @@ +/* + * 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; + } +} 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..61587bd65df56 --- /dev/null +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/connection/MemoryQueryResult.java @@ -0,0 +1,134 @@ +/* + * 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 + * @author panjuan + */ +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"); + } +} 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..529ecdbefa9f3 --- /dev/null +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/MemoryStrictlyExecutorEngine.java @@ -0,0 +1,87 @@ +/* + * 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); + Collection> restFutures = asyncExecute(sqlType, Lists.newArrayList(iterator), executeCallback); + return getResultList(firstOutput, restFutures); + } + + private Collection> 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 getResultList(final T firstOutput, final Collection> restResultFutures) throws ExecutionException, InterruptedException { + List result = new LinkedList<>(); + result.add(firstOutput); + for (ListenableFuture each : restResultFutures) { + result.add(each.get()); + } + return result; + } +} + diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/merger/JDBCQueryResult.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java similarity index 97% rename from sharding-jdbc/src/main/java/io/shardingsphere/core/merger/JDBCQueryResult.java rename to sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java index 2685b19079c2e..43332c85e1d89 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/merger/JDBCQueryResult.java +++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/executor/type/memory/StreamQueryResult.java @@ -15,8 +15,9 @@ *

*/ -package io.shardingsphere.core.merger; +package io.shardingsphere.core.executor.type.memory; +import io.shardingsphere.core.merger.QueryResult; import lombok.RequiredArgsConstructor; import java.io.InputStream; @@ -34,12 +35,13 @@ import java.util.Calendar; /** - * Query result form database for JDBC. + * Query result for stream loading. * * @author zhangliang + * @author panjuan */ @RequiredArgsConstructor -public final class JDBCQueryResult implements QueryResult { +public final class StreamQueryResult implements QueryResult { private final ResultSet resultSet; 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..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 @@ -19,13 +19,18 @@ 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.transaction.event.TransactionEvent; -import io.shardingsphere.core.transaction.event.TransactionEventFactory; -import io.shardingsphere.core.transaction.event.WeakXaTransactionEvent; 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.common.event.LocalTransactionEvent; +import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.common.event.TransactionEventFactory; import javax.sql.DataSource; import java.sql.Connection; @@ -39,7 +44,7 @@ /** * Adapter for {@code Connection}. - * + * * @author zhangliang */ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOperationConnection { @@ -62,6 +67,8 @@ public abstract class AbstractConnectionAdapter extends AbstractUnsupportedOpera * @throws SQLException SQL exception */ public final Connection getConnection(final String dataSourceName) throws SQLException { + TransactionType transactionType = TransactionContextHolder.get().getTransactionType(); + TransactionContextHolder.set(new TransactionContext(ShardingTransactionManagerFactory.getShardingTransactionManager(transactionType), transactionType)); if (cachedConnections.containsKey(dataSourceName)) { return cachedConnections.get(dataSourceName); } @@ -75,7 +82,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); } @@ -87,6 +94,7 @@ public final boolean getAutoCommit() { @Override public final void setAutoCommit(final boolean autoCommit) { this.autoCommit = autoCommit; + 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)); } @@ -102,10 +110,11 @@ public final void rollback() { } @Override - public void close() throws SQLException { + public final void close() throws SQLException { closed = true; HintManagerHolder.clear(); MasterVisitedManager.clear(); + TransactionContextHolder.clear(); Collection exceptions = new LinkedList<>(); for (Connection each : cachedConnections.values()) { try { @@ -156,7 +165,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; } @@ -175,10 +184,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); - weakXaTransactionEvent.setAutoCommit(autoCommit); + if (result instanceof LocalTransactionEvent) { + LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) result; + localTransactionEvent.setCachedConnections(cachedConnections.values()); + localTransactionEvent.setAutoCommit(autoCommit); } return result; } 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..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,8 +19,12 @@ import com.google.common.base.Preconditions; import io.shardingsphere.core.constant.DatabaseType; -import io.shardingsphere.core.jdbc.core.transaction.TransactionLoader; +import io.shardingsphere.core.constant.TransactionType; import io.shardingsphere.core.jdbc.unsupported.AbstractUnsupportedOperationDataSource; +import io.shardingsphere.core.listener.JDBCListenerRegister; +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; @@ -38,7 +42,9 @@ public abstract class AbstractDataSourceAdapter extends AbstractUnsupportedOperationDataSource { static { - TransactionLoader.load(); + TransactionType transactionType = TransactionContextHolder.get().getTransactionType(); + TransactionContextHolder.set(new TransactionContext(ShardingTransactionManagerFactory.getShardingTransactionManager(transactionType), transactionType)); + JDBCListenerRegister.register(); } @Getter @@ -50,7 +56,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); } 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..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 @@ -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,11 +56,11 @@ 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 - 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/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/ShardingContext.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/ShardingContext.java index cf7c16191e7e8..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 @@ -17,22 +17,16 @@ package io.shardingsphere.core.jdbc.core; +import io.shardingsphere.core.constant.ConnectionMode; import io.shardingsphere.core.constant.DatabaseType; -import io.shardingsphere.core.exception.ShardingException; 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. @@ -52,33 +46,9 @@ public final class ShardingContext { private final ExecutorEngine executorEngine; - private final boolean showSQL; - private final ShardingMetaData metaData; - public ShardingContext(final Map dataSourceMap, final ShardingRule shardingRule, - final DatabaseType databaseType, final ExecutorEngine executorEngine, final ShardingTableMetaData shardingTableMetaData, final boolean showSQL) { - this.dataSourceMap = dataSourceMap; - this.shardingRule = shardingRule; - this.databaseType = databaseType; - this.executorEngine = executorEngine; - this.showSQL = showSQL; - metaData = new ShardingMetaData(new ShardingDataSourceMetaData(getDataSourceURLs(dataSourceMap), shardingRule, databaseType), shardingTableMetaData); - } + private final ConnectionMode connectionMode; - 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); - } - } + private final boolean showSQL; } 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 8c535618ff91a..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 @@ -20,20 +20,24 @@ 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.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; 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.metadata.table.ShardingTableMetaData; -import io.shardingsphere.core.metadata.table.executor.TableMetaDataInitializer; +import io.shardingsphere.core.jdbc.metadata.JDBCTableMetaDataConnectionManager; +import io.shardingsphere.core.metadata.ShardingMetaData; import io.shardingsphere.core.rule.MasterSlaveRule; import io.shardingsphere.core.rule.ShardingRule; import lombok.Getter; import javax.sql.DataSource; +import java.sql.Connection; import java.sql.SQLException; import java.util.Collection; import java.util.LinkedHashMap; @@ -47,6 +51,7 @@ * * @author zhangliang * @author zhaojun + * @author panjuan */ public class ShardingDataSource extends AbstractDataSourceAdapter implements AutoCloseable { @@ -68,11 +73,28 @@ 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)); + ConnectionMode connectionMode = ConnectionMode.valueOf(shardingProperties.getValue(ShardingPropertiesConstant.CONNECTION_MODE)); + executorEngine = ConnectionMode.MEMORY_STRICTLY == connectionMode ? new MemoryStrictlyExecutorEngine(executorSize) : new ConnectionStrictlyExecutorEngine(executorSize); + 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, shardingTableMetaData, showSQL); + shardingContext = new ShardingContext(dataSourceMap, shardingRule, getDatabaseType(), executorEngine, shardingMetaData, connectionMode, showSQL); + } + + 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); + } } /** @@ -86,20 +108,22 @@ 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) { + 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 = new ExecutorEngine(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); + 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 - public ShardingConnection getConnection() { + public final ShardingConnection getConnection() { return new ShardingConnection(shardingContext); } 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/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/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..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 @@ -20,9 +20,12 @@ import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.Iterators; +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; +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; @@ -30,8 +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.merger.JDBCQueryResult; +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; @@ -60,8 +62,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; /** @@ -136,12 +140,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(); @@ -150,6 +150,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 (ConnectionMode.MEMORY_STRICTLY == connection.getShardingContext().getConnectionMode()) { + result.add(new StreamQueryResult(each)); + } else { + result.add(new MemoryQueryResult(each)); + } + } + return result; + } + @Override public int executeUpdate() throws SQLException { routedStatements.clear(); @@ -177,10 +189,33 @@ public boolean execute() throws SQLException { } private Collection route() throws SQLException { - Collection result = new LinkedList<>(); sqlRoute(); + if (ConnectionMode.MEMORY_STRICTLY == connection.getShardingContext().getConnectionMode()) { + 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 +223,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() { @@ -211,11 +245,12 @@ 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(); - TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( - connection.getShardingContext().getExecutorEngine().getExecutorService(), new ShardingConnectionTableMetaDataConnectionManager(logicTableName, connection)); + 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())); } } @@ -265,7 +300,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; } @@ -313,7 +349,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 StreamQueryResult(resultSet)); } if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) { MergeEngine mergeEngine = MergeEngineFactory.newInstance( 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..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 @@ -18,7 +18,10 @@ package io.shardingsphere.core.jdbc.core.statement; import com.google.common.base.Optional; +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; import io.shardingsphere.core.executor.type.statement.StatementExecutor; import io.shardingsphere.core.executor.type.statement.StatementUnit; import io.shardingsphere.core.jdbc.adapter.AbstractStatementAdapter; @@ -26,8 +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.merger.JDBCQueryResult; +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; @@ -49,13 +51,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. @@ -64,9 +69,10 @@ * @author caohao * @author zhangliang * @author zhaojun + * @author panjuan */ @Getter -public class ShardingStatement extends AbstractStatementAdapter { +public final class ShardingStatement extends AbstractStatementAdapter { private final ShardingConnection connection; @@ -108,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; @@ -122,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 (ConnectionMode.MEMORY_STRICTLY == connection.getShardingContext().getConnectionMode()) { + result.add(new StreamQueryResult(each)); + } else { + result.add(new MemoryQueryResult(each)); + } + } + return result; + } + @Override public int executeUpdate(final String sql) throws SQLException { try { @@ -209,14 +223,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 (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()); + } + + private Collection getStatementUnitsForConnectionStrictly() throws SQLException { + Collection result = new LinkedList<>(); + Map connectionMap = new LinkedHashMap<>(); for (SQLExecutionUnit each : routeResult.getExecutionUnits()) { - Statement statement = connection.getConnection(each.getDataSource()).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); + 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); - 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 Collection getStatementUnitsForMemoryStrictly() throws SQLException { + Collection result = new LinkedList<>(); + for (SQLExecutionUnit each : routeResult.getExecutionUnits()) { + String dataSourceName = each.getDataSource(); + Statement statement = connection.getConnection(dataSourceName).createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); + replayMethodsInvocation(statement); + result.add(new StatementUnit(each, statement)); + routedStatements.add(statement); + } + return result; } private void clearPrevious() throws SQLException { @@ -245,11 +283,12 @@ 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(); - TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( - connection.getShardingContext().getExecutorEngine().getExecutorService(), new ShardingConnectionTableMetaDataConnectionManager(logicTableName, connection)); + 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())); } } @@ -287,7 +326,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 StreamQueryResult(resultSet)); } if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) { MergeEngine mergeEngine = MergeEngineFactory.newInstance( diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/TransactionLoader.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/TransactionLoader.java deleted file mode 100644 index c5e0d89beef52..0000000000000 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/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.core.jdbc.core.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.core.util.EventBusInstance; -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: - } - EventBusInstance.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); - } -} 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-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..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. @@ -40,192 +39,182 @@ 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"); } @Override - public Timestamp getTimestamp(final int columnIndex) throws SQLException { + public final Timestamp getTimestamp(final int columnIndex) throws SQLException { throw new SQLFeatureNotSupportedException("getTimestamp"); } @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"); } @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 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/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/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-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/common/base/AbstractSQLTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java index ceca41f7bc67b..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) { @@ -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; } @@ -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/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/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/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); 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"); 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..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 @@ -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"); @@ -318,8 +308,6 @@ public void assertExecuteForMultiplePreparedStatementsFailureWithDML() 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"); @@ -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"); 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"); 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-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/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/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/core/connection/ShardingConnectionTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/jdbc/core/connection/ShardingConnectionTest.java index 5f8354f98d45c..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,12 +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.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; @@ -40,8 +40,10 @@ 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.assertSame; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; public final class ShardingConnectionTest { @@ -72,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); + ShardingMetaData shardingMetaData = mock(ShardingMetaData.class); + ShardingContext shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.H2, null, shardingMetaData, ConnectionMode.MEMORY_STRICTLY, false); connection = new ShardingConnection(shardingContext); } @@ -86,7 +89,7 @@ public void clear() { @Test public void assertGetConnectionFromCache() throws SQLException { - assertSame(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-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/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/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/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/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 6fc1db79e1346..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 @@ -97,7 +97,7 @@ public static void initDatabasesAndTables() { } @AfterClass - public static void destroyDatabasesAndTables(){ + public static void destroyDatabasesAndTables() { dropDatabases(); } @@ -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/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/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/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/ddl/BaseDDLIntegrateTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/ddl/BaseDDLIntegrateTest.java index 330183c13d1fd..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 @@ -72,7 +72,7 @@ public static void initDatabases() { } @AfterClass - public static void destroyDatabasesAndTables(){ + public static void destroyDatabasesAndTables() { dropDatabases(); } @@ -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/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/dml/BaseDMLIntegrateTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/dbtest/engine/dml/BaseDMLIntegrateTest.java index 4bd329cdd49e3..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 @@ -67,7 +67,7 @@ public static void initDatabasesAndTables() { } @AfterClass - public static void destroyDatabasesAndTables(){ + public static void destroyDatabasesAndTables() { dropDatabases(); } @@ -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/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-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-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-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/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) { 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-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 deleted file mode 100644 index 401ecdb6b83d1..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_avg.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - 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 deleted file mode 100644 index 5076e53c7db99..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_with_avg.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 deleted file mode 100644 index 9bcbb53b85eee..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_group_by_without_grouped_column.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - 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 deleted file mode 100644 index d1bef7a93e65f..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 deleted file mode 100644 index d1bef7a93e65f..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_order_by_with_date.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 deleted file mode 100644 index 4342bb10faa03..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/db/select_with_expression.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 deleted file mode 100644 index 68ef4ca247351..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - 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 deleted file mode 100644 index a3948f0d84a86..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - 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 deleted file mode 100644 index 3005656eb6725..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_without_grouped_column.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - 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 deleted file mode 100644 index 0d99717a60553..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_pagination_with_row_number_and_limit.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - 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 deleted file mode 100644 index 75104707db64e..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/dbtbl_with_masterslave/select_with_expression.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 deleted file mode 100644 index 6c135954eef86..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_avg.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - 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 deleted file mode 100644 index 53fa098cf0b1f..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_with_avg.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - 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 deleted file mode 100644 index 3005656eb6725..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_group_by_without_grouped_column.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - 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 deleted file mode 100644 index 5fe27842bcd30..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_desc_and_index_asc.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 deleted file mode 100644 index 5fe27842bcd30..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_order_by_with_date.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 deleted file mode 100644 index 6c6fc3e759ad2..0000000000000 --- a/sharding-jdbc/src/test/resources/asserts/cases/dql/dataset/tbl/select_with_expression.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - 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/masterslave/mysql/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/masterslave/mysql/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/masterslave/mysql/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/masterslave/mysql/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/masterslave/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/masterslave/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/integrate/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 new file mode 100644 index 0000000000000..07200bcec11cd --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_desc_and_index_asc.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/integrate/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 new file mode 100644 index 0000000000000..07200bcec11cd --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/db/select_order_by_with_date.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 59% 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 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/integrate/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_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/masterslave/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/masterslave/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/integrate/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 new file mode 100644 index 0000000000000..9b6b22ab882c7 --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_avg.xml @@ -0,0 +1,6 @@ + + + + + + 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/integrate/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 new file mode 100644 index 0000000000000..e8f8a0260655f --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_with_avg.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + 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/integrate/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 new file mode 100644 index 0000000000000..f8f37eb485f3f --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_group_by_without_grouped_column.xml @@ -0,0 +1,7 @@ + + + + + + + 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/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/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/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/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/tbl/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 59% 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/dbtbl_with_masterslave/select_pagination_with_row_number_and_limit.xml index a84f46a14a9b3..d1de128735a24 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/integrate/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_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/integrate/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 new file mode 100644 index 0000000000000..5e75601385ce5 --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/dbtbl_with_masterslave/select_with_expression.xml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/integrate/cases/dql/dataset/masterslave/mysql/select_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/mysql/select_avg.xml new file mode 100644 index 0000000000000..290cc8b0f3ab9 --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/mysql/select_avg.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/sharding-jdbc/src/test/resources/integrate/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 new file mode 100644 index 0000000000000..a7f7c6e274bf9 --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/mysql/select_group_by_with_avg.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + 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/integrate/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 new file mode 100644 index 0000000000000..26b1167c7d6e9 --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_group_by_without_grouped_column.xml @@ -0,0 +1,7 @@ + + + + + + + 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_sharding_route_with_broadcast_table.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_sharding_route_with_broadcast_table.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/dbtbl_with_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 83% 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/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/integrate/cases/dql/dataset/masterslave/select_order_by_with_date.xml @@ -5,6 +5,5 @@ - 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/dbtbl_with_masterslave/select_order_by_desc_and_index_asc.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_sharding_route_with_broadcast_table.xml similarity index 83% 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/masterslave/select_sharding_route_with_broadcast_table.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/integrate/cases/dql/dataset/masterslave/select_sharding_route_with_broadcast_table.xml @@ -5,6 +5,5 @@ - 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/integrate/cases/dql/dataset/masterslave/select_with_expression.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_expression.xml new file mode 100644 index 0000000000000..7aeb183d0b9f5 --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/masterslave/select_with_expression.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/integrate/cases/dql/dataset/tbl/select_avg.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_avg.xml new file mode 100644 index 0000000000000..0d54113846a80 --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_avg.xml @@ -0,0 +1,6 @@ + + + + + + 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/integrate/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 new file mode 100644 index 0000000000000..c95e5e8ac5bec --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_with_avg.xml @@ -0,0 +1,8 @@ + + + + + + + + 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/integrate/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 new file mode 100644 index 0000000000000..f8f37eb485f3f --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_group_by_without_grouped_column.xml @@ -0,0 +1,7 @@ + + + + + + + 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/integrate/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 new file mode 100644 index 0000000000000..36739c810117d --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_desc_and_index_asc.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/integrate/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 new file mode 100644 index 0000000000000..36739c810117d --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_order_by_with_date.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/integrate/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 new file mode 100644 index 0000000000000..a2c10abce6831 --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_pagination_with_row_number_and_limit.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + 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/integrate/cases/dql/dataset/tbl/select_with_expression.xml b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_expression.xml new file mode 100644 index 0000000000000..40644b52f7e84 --- /dev/null +++ b/sharding-jdbc/src/test/resources/integrate/cases/dql/dataset/tbl/select_with_expression.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + 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 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 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 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/pom.xml b/sharding-opentracing/pom.xml index 6ea46b144ff41..711dfb61232e5 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.M3-SNAPSHOT sharding-opentracing ${project.artifactId} 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-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..813a44896544b 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; @@ -33,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; @@ -87,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); + ShardingMetaData shardingMetaData = mock(ShardingMetaData.class); + 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 23ed731edbf55..2df27f5a9ee5f 100644 --- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java +++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/SqlRoutingEventListenerTest.java @@ -26,11 +26,13 @@ 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; 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; @@ -81,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); + ShardingMetaData shardingMetaData = mock(ShardingMetaData.class); + shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, shardingMetaData, ConnectionMode.MEMORY_STRICTLY, true); } private DataSource mockDataSource() throws SQLException { 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/pom.xml b/sharding-proxy/pom.xml index 40e7e9ec6a9a4..83374851d21a9 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.M3-SNAPSHOT sharding-proxy ${project.artifactId} @@ -24,7 +24,7 @@ io.shardingsphere - sharding-jdbc-transaction + sharding-transaction ${project.version} @@ -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 - + @@ -102,7 +102,7 @@ com.spotify docker-maven-plugin - shardingsphere/sharding-proxy:3.0.0.M2-SNAPSHOT + 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 fceed07920c33..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.M1.tar.gz / -RUN mv /sharding-proxy-3.0.0.M1 /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/Bootstrap.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/Bootstrap.java index 52d90233e566b..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,9 @@ 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; import org.yaml.snakeyaml.constructor.Constructor; @@ -32,7 +35,6 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; -import java.net.MalformedURLException; /** * Sharding-Proxy Bootstrap. @@ -41,6 +43,7 @@ * @author wangkai * @author panjuan */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class Bootstrap { private static final int DEFAULT_PORT = 3307; @@ -59,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()) { @@ -101,12 +105,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/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(); } 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/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/JDBCBackendHandler.java index 723fc981d2253..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 @@ -23,10 +23,12 @@ 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; 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 +38,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; /** @@ -86,7 +91,8 @@ 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(); - TableMetaDataLoader tableMetaDataLoader = new TableMetaDataLoader( + // TODO refresh table meta data by SQL parse result + 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())); } @@ -103,11 +109,24 @@ 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 (!DerivedColumn.isDerivedColumn(each.getName())) { + 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(); 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..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,15 @@ 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 659c3605b87a6..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 @@ -50,6 +50,17 @@ 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("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; } } 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..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 @@ -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,17 @@ 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 = asyncExecuteWithXA(isReturnGeneratedKeys, sqlExecutionUnits); + } else { + futureList = asyncExecuteWithoutXA(isReturnGeneratedKeys, sqlExecutionUnits); + } Collection firstExecuteResponseUnits = syncExecute(isReturnGeneratedKeys, firstEntry.getKey(), firstEntry.getValue()); return getExecuteQueryResponse(firstExecuteResponseUnits, futureList); } - private List>> asyncExecute(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); @@ -86,6 +93,27 @@ public Collection call() throws SQLException { return result; } + private List>> asyncExecuteWithoutXA(final boolean isReturnGeneratedKeys, final Map> sqlUnitGroups) { + List>> result = new LinkedList<>(); + for (Entry> entry : sqlUnitGroups.entrySet()) { + 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<>(); + Map sqlUnitStatementMap = createSQLUnitStatement(dataSourceName, sqlUnits, isReturnGeneratedKeys); + for (Entry each : sqlUnitStatementMap.entrySet()) { + result.add(executeWithoutMetadata(each.getValue(), each.getKey().getSql(), isReturnGeneratedKeys)); + } + return result; + } + })); + } + return result; + } + private Map createSQLUnitStatement(final String dataSourceName, final Collection sqlUnits, final boolean isReturnGeneratedKeys) throws SQLException { Map result = new HashMap<>(sqlUnits.size(), 1); Connection connection = getBackendConnection().getConnection(dataSourceName); 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..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 @@ -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,21 +63,43 @@ 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 = asyncExecuteWithXA(isReturnGeneratedKeys, Lists.newArrayList(executionUnits)); + } else { + 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> asyncExecute(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(); 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> asyncExecuteWithoutXA(final boolean isReturnGeneratedKeys, final Collection sqlExecutionUnits) { + List> result = new LinkedList<>(); + for (SQLExecutionUnit each : sqlExecutionUnits) { + final SQLExecutionUnit sqlExecutionUnit = each; result.add(getExecutorService().submit(new Callable() { @Override public ExecuteResponseUnit call() throws SQLException { + String actualSQL = sqlExecutionUnit.getSqlUnit().getSql(); + Statement statement = getJdbcExecutorWrapper().createStatement(getBackendConnection().getConnection(sqlExecutionUnit.getDataSource()), actualSQL, isReturnGeneratedKeys); return executeWithoutMetadata(statement, actualSQL, isReturnGeneratedKeys); } })); 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/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/jdbc/transaction/XaTransactionEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/jdbc/transaction/XaTransactionEngine.java index eabcdd9d6aebf..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,11 +19,12 @@ 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.core.constant.TransactionType; import io.shardingsphere.core.util.EventBusInstance; import io.shardingsphere.proxy.config.RuleRegistry; +import io.shardingsphere.transaction.common.TransactionContext; +import io.shardingsphere.transaction.common.TransactionContextHolder; +import io.shardingsphere.transaction.common.event.XaTransactionEvent; import javax.transaction.Status; import java.sql.SQLException; @@ -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(new TransactionContext(RULE_REGISTRY.getTransactionManager(), RULE_REGISTRY.getTransactionType(), XaTransactionEvent.class)); + 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/backend/netty/CommandResponsePacketsHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/CommandResponsePacketsHandler.java deleted file mode 100644 index 4dc6d6a41170e..0000000000000 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/CommandResponsePacketsHandler.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; - -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload; - -/** - * SQL execute backend handler. - * - * @author wangkai - * @author linjiaqi - */ -public abstract class CommandResponsePacketsHandler extends ChannelInboundHandlerAdapter { - - protected abstract void auth(ChannelHandlerContext context, MySQLPacketPayload payload); - - protected abstract void eofPacket(ChannelHandlerContext context, MySQLPacketPayload payload); - - protected abstract void okPacket(ChannelHandlerContext context, MySQLPacketPayload payload); - - protected abstract void errPacket(ChannelHandlerContext context, MySQLPacketPayload payload); - - protected abstract void commonPacket(ChannelHandlerContext context, MySQLPacketPayload payload); -} 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..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 @@ -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; @@ -33,8 +32,12 @@ 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.mysql.MySQLQueryResult; +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.response.mysql.MySQLQueryResult; import io.shardingsphere.proxy.config.ProxyTableMetaDataConnectionManager; import io.shardingsphere.proxy.config.RuleRegistry; import io.shardingsphere.proxy.runtime.ChannelRegistry; @@ -44,9 +47,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.BackendExecutorContext; -import io.shardingsphere.proxy.util.MySQLResultCache; -import io.shardingsphere.proxy.util.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,14 +120,13 @@ 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); - - List packets = Lists.newArrayListWithCapacity(queryResults.size()); + FutureRegistry.getInstance().delete(connectionId); + List packets = new ArrayList<>(queryResults.size()); for (QueryResult each : queryResults) { MySQLQueryResult queryResult = (MySQLQueryResult) each; if (0 == currentSequenceId) { @@ -138,22 +137,19 @@ 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; } - 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()); } - 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); @@ -170,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); } @@ -201,14 +200,18 @@ private CommandResponsePackets mergeDQLorDAL(final SQLStatement sqlStatement, fi return packets.get(0); } + // 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( + RULE_REGISTRY.getMetaData().getDataSource(), 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()) { - for (Entry> entry : channelMap.entrySet()) { - for (Channel each : entry.getValue()) { - ShardingProxyClient.getInstance().getPoolMap().get(entry.getKey()).release(each); - } - } + channelRelease(); return false; } return true; @@ -222,4 +225,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); + } + } + } } 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/client/BackendNettyClient.java similarity index 69% 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/client/BackendNettyClient.java index d604da46bc9cc..98132f50d5621 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/client/BackendNettyClient.java @@ -15,9 +15,8 @@ *

*/ -package io.shardingsphere.proxy.backend.netty; +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,28 +31,28 @@ import io.netty.channel.pool.FixedChannelPool; import io.netty.channel.pool.SimpleChannelPool; import io.netty.channel.socket.nio.NioSocketChannel; -import io.shardingsphere.core.rule.DataSourceParameter; +import io.shardingsphere.core.metadata.datasource.DataSourceMetaData; 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.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(); @@ -63,31 +62,28 @@ public final class ShardingProxyClient { private static final int CONNECTION_TIMEOUT_SECONDS = RULE_REGISTRY.getBackendNIOConfig().getConnectionTimeoutSeconds(); - private final Map dataSourceConfigMap = Maps.newHashMap(); - private EventLoopGroup workerGroup; @Getter private ChannelPoolMap poolMap; /** - * Start Sharding-Proxy. + * Get instance of backend connection client for netty. + * + * @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()) { - 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)); - } - final Bootstrap bootstrap = new Bootstrap(); + public void start() throws InterruptedException { + Bootstrap bootstrap = new Bootstrap(); + // TODO :jiaqi where to init workerGroup? if (workerGroup instanceof EpollEventLoopGroup) { groupsEpoll(bootstrap); } else { @@ -97,10 +93,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(); } } @@ -128,13 +124,15 @@ 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); - 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 BackendNettyClientChannelPoolHandler(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++) { @@ -149,13 +147,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/client/BackendNettyClientChannelInitializer.java similarity index 74% 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/client/BackendNettyClientChannelInitializer.java index 3e7b009240eab..25be3ca2c6df2 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/client/BackendNettyClientChannelInitializer.java @@ -15,31 +15,32 @@ *

*/ -package io.shardingsphere.proxy.backend.netty; +package io.shardingsphere.proxy.backend.netty.client; import io.netty.channel.Channel; 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; /** - * 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; + 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(ResponseHandlerFactory.newInstance(DatabaseType.MySQL, dataSourceName)); } } 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/BackendNettyClientChannelPoolHandler.java similarity index 80% 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/BackendNettyClientChannelPoolHandler.java index 90880b8237347..f00a9bb06ce4c 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/BackendNettyClientChannelPoolHandler.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.pool.ChannelPoolHandler; @@ -23,15 +23,16 @@ import lombok.extern.slf4j.Slf4j; /** - * NettyChannelPoolHandler. + * Channel pool handler of backend netty client. * * @author wangkai * @author linjiaqi */ @RequiredArgsConstructor @Slf4j -public class NettyChannelPoolHandler implements ChannelPoolHandler { - private final DataSourceConfig dataSourceConfig; +public final class BackendNettyClientChannelPoolHandler implements ChannelPoolHandler { + + private final String dataSourceName; @Override public void channelReleased(final Channel channel) { @@ -46,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 ClientHandlerInitializer(dataSourceConfig)); + channel.pipeline().addLast(new BackendNettyClientChannelInitializer(dataSourceName)); } } 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 new file mode 100644 index 0000000000000..eaa1c3558c070 --- /dev/null +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandler.java @@ -0,0 +1,58 @@ +/* + * 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; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; + +/** + * SQL executed response handler. + * + * @author wangkai + * @author linjiaqi + */ +public abstract class ResponseHandler extends ChannelInboundHandlerAdapter { + + private boolean authorized; + + @Override + public final void channelRead(final ChannelHandlerContext context, final Object message) { + ByteBuf byteBuf = (ByteBuf) message; + int header = getHeader(byteBuf); + + if (!authorized) { + auth(context, byteBuf); + authorized = true; + } else { + executeCommand(context, byteBuf, header); + } + } + + protected abstract int getHeader(ByteBuf byteBuf); + + protected abstract void auth(ChannelHandlerContext context, ByteBuf byteBuf); + + protected abstract void executeCommand(ChannelHandlerContext context, ByteBuf byteBuf, int header); + + @Override + 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/backend/netty/NettyBackendHandlerFactory.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/ResponseHandlerFactory.java similarity index 56% 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/response/ResponseHandlerFactory.java index ed045acad6f54..4e527bc5cf397 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/response/ResponseHandlerFactory.java @@ -15,29 +15,32 @@ *

*/ -package io.shardingsphere.proxy.backend.netty; +package io.shardingsphere.proxy.backend.netty.client.response; import io.shardingsphere.core.constant.DatabaseType; -import io.shardingsphere.proxy.backend.netty.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 */ -public final class NettyBackendHandlerFactory { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ResponseHandlerFactory { /** - * Create backend handler instance. + * Create new instance of response handler factory for using netty connect backend. * * @param databaseType database type - * @param dataSourceConfig dataSourceConfig - * @return backend handler instance + * @param dataSourceName data source name + * @return new instance of response handler factory for using netty connect backend */ - public static CommandResponsePacketsHandler createBackendHandlerInstance(final DatabaseType databaseType, final DataSourceConfig dataSourceConfig) { + public static ResponseHandler newInstance(final DatabaseType databaseType, final String dataSourceName) { switch (databaseType) { case MySQL: - return new MySQLBackendHandler(dataSourceConfig); + 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/mysql/MySQLQueryResult.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/client/response/mysql/MySQLQueryResult.java similarity index 91% 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/response/mysql/MySQLQueryResult.java index a36c6e5160b59..3812034623d5a 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/response/mysql/MySQLQueryResult.java @@ -15,7 +15,7 @@ *

*/ -package io.shardingsphere.proxy.backend.netty.mysql; +package io.shardingsphere.proxy.backend.netty.client.response.mysql; import com.google.common.collect.Lists; import io.shardingsphere.core.merger.QueryResult; @@ -45,6 +45,7 @@ */ @Slf4j public final class MySQLQueryResult implements QueryResult { + @Getter private final CommandResponsePackets commandResponsePackets; @@ -87,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); @@ -115,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); @@ -133,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); 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/response/mysql/MySQLResponseHandler.java similarity index 60% 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/response/mysql/MySQLResponseHandler.java index c94403c0b052c..b4448faa63cbe 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/response/mysql/MySQLResponseHandler.java @@ -15,17 +15,18 @@ *

*/ -package io.shardingsphere.proxy.backend.netty.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.proxy.backend.constant.AuthType; -import io.shardingsphere.proxy.backend.netty.CommandResponsePacketsHandler; -import io.shardingsphere.proxy.backend.netty.DataSourceConfig; +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.ResponseHandler; +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; 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; @@ -35,110 +36,123 @@ 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 lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; 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 final DataSourceConfig dataSourceConfig; + private final DataSourceParameter dataSourceParameter; - private final Map resultMap = Maps.newHashMap(); + private final DataSourceMetaData dataSourceMetaData; - private AuthType authType = AuthType.UN_AUTH; + private final Map resultMap; + + public MySQLResponseHandler(final String dataSourceName) { + dataSourceParameter = RuleRegistry.getInstance().getDataSourceConfigurationMap().get(dataSourceName); + dataSourceMetaData = RuleRegistry.getInstance().getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); + resultMap = new HashMap<>(); + } @Override - public void channelRead(final ChannelHandlerContext context, final Object message) { - MySQLPacketPayload payload = new MySQLPacketPayload((ByteBuf) message); + protected int getHeader(final ByteBuf byteBuf) { + MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf); payload.getByteBuf().markReaderIndex(); payload.readInt1(); - int header = payload.readInt1(); + int result = payload.readInt1(); payload.getByteBuf().resetReaderIndex(); - if (AuthType.UN_AUTH == authType) { - auth(context, payload); - authType = AuthType.AUTHING; - } else if (AuthType.AUTHING == authType) { - if (PacketHeader.OK.getValue() == 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 (PacketHeader.EOF.getValue() == header) { - eofPacket(context, payload); - } else if (PacketHeader.OK.getValue() == header) { - okPacket(context, payload); - } else if (PacketHeader.ERR.getValue() == header) { - errPacket(context, payload); - } else { - commonPacket(context, payload); - } - } + return result; } @Override - protected void auth(final ChannelHandlerContext context, final MySQLPacketPayload payload) { - try { + protected void auth(final ChannelHandlerContext context, final ByteBuf byteBuf) { + try (MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf)) { 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( + (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()); ChannelRegistry.getInstance().putConnectionId(context.channel().id().asShortText(), handshakePacket.getConnectionId()); context.writeAndFlush(handshakeResponse41Packet); - } finally { - payload.close(); + } + } + + 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); } } @Override - protected void okPacket(final ChannelHandlerContext context, final MySQLPacketPayload payload) { + protected void executeCommand(final ChannelHandlerContext context, final ByteBuf byteBuf, final int header) { + switch (header) { + case EofPacket.HEADER: + eofPacket(context, byteBuf); + break; + case OKPacket.HEADER: + okPacket(context, byteBuf); + break; + case ErrPacket.HEADER: + errPacket(context, byteBuf); + break; + default: + commandPacket(context, byteBuf); + } + } + + private 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) { + private 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) { + 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); if (mysqlQueryResult.isColumnFinished()) { mysqlQueryResult.setRowFinished(new EofPacket(payload)); resultMap.remove(connectionId); @@ -149,11 +163,18 @@ protected void eofPacket(final ChannelHandlerContext context, final MySQLPacketP } } - @Override - protected void commonPacket(final ChannelHandlerContext context, final MySQLPacketPayload payload) { + 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)); + } + } + + private void commandPacket(final ChannelHandlerContext context, final ByteBuf byteBuf) { int connectionId = ChannelRegistry.getInstance().getConnectionId(context.channel().id().asShortText()); MySQLQueryResult mysqlQueryResult = resultMap.get(connectionId); - if (mysqlQueryResult == null) { + MySQLPacketPayload payload = new MySQLPacketPayload(byteBuf); + if (null == mysqlQueryResult) { mysqlQueryResult = new MySQLQueryResult(payload); resultMap.put(connectionId, mysqlQueryResult); } else if (mysqlQueryResult.needColumnDefinition()) { @@ -162,36 +183,4 @@ protected void commonPacket(final ChannelHandlerContext context, final MySQLPack mysqlQueryResult.addTextResultSetRow(new TextResultSetRowPacket(payload, mysqlQueryResult.getColumnCount())); } } - - @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"); - 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 (MySQLResultCache.getInstance().getFuture(connectionId) != null) { - MySQLResultCache.getInstance().getFuture(connectionId).setResponse(resultMap.get(connectionId)); - } - } } 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 88% 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..477b359cd7028 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 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; +import java.util.concurrent.TimeUnit; + +/** + * Synchronized future for get multiple netty returns. + * + * @author wangkai + * @author linjiaqi + */ +@Slf4j +public final 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 = new ArrayList<>(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/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; - } } 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..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 @@ -26,18 +26,17 @@ 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; 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.jdbc.datasource.JDBCBackendDataSource; -import io.shardingsphere.proxy.util.ProxyTransactionLoader; +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; @@ -75,13 +74,15 @@ public final class RuleRegistry { private ConnectionMode connectionMode; + private int acceptorSize; + private int executorSize; private BackendNIOConfiguration backendNIOConfig; private TransactionType transactionType; - private TransactionManager transactionManager; + private ShardingTransactionManager transactionManager; private ProxyAuthority proxyAuthority; @@ -107,11 +108,13 @@ 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 = ProxyTransactionLoader.load(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 boolean useNIO = false; -// boolean proxyBackendUseNio = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_USE_NIO); + // boolean proxyBackendUseNio = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_USE_NIO); int databaseConnectionCount = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_MAX_CONNECTIONS); int connectionTimeoutSeconds = shardingProperties.getValue(ShardingPropertiesConstant.PROXY_BACKEND_CONNECTION_TIMEOUT_SECONDS); backendNIOConfig = new BackendNIOConfiguration(useNIO, databaseConnectionCount, connectionTimeoutSeconds); @@ -132,10 +135,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(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) { @@ -148,7 +149,7 @@ private static Map getDataSourceURLs(final Map - * 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 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; - -/** - * Frontend executor context. - * - * @author zhangyonglun - */ -public final class FrontendExecutorContext { - - private static final FrontendExecutorContext INSTANCE = new FrontendExecutorContext(); - - @Getter - private final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(RuleRegistry.getInstance().getExecutorSize())); - - /** - * Get frontend executor context instance. - * - * @return instance of frontend executor context - */ - public static FrontendExecutorContext getInstance() { - return INSTANCE; - } -} 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..2fd74e729c247 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.netty.ShardingProxyClient; +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. @@ -48,14 +46,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 EventLoopGroup userGroup; + public ShardingProxy() { RULE_REGISTRY.initShardingMetaData(backendExecutorContext.getExecutorService()); } @@ -65,12 +63,11 @@ 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()) { - ShardingProxyClient.getInstance().start(); + BackendNettyClient.getInstance().start(); } ServerBootstrap bootstrap = new ServerBootstrap(); bossGroup = createEventLoopGroup(); @@ -82,12 +79,12 @@ 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(); - frontendExecutorContext.getExecutorService().shutdown(); backendExecutorContext.getExecutorService().shutdown(); if (RULE_REGISTRY.getBackendNIOConfig().isUseNIO()) { - ShardingProxyClient.getInstance().stop(); + BackendNettyClient.getInstance().stop(); } } } @@ -101,7 +98,8 @@ private EventLoopGroup createEventLoopGroup() { } private void groupsEpoll(final ServerBootstrap bootstrap) { - workerGroup = new EpollEventLoopGroup(RULE_REGISTRY.getExecutorSize()); + workerGroup = new EpollEventLoopGroup(RULE_REGISTRY.getAcceptorSize()); + userGroup = new EpollEventLoopGroup(RULE_REGISTRY.getAcceptorSize()); bootstrap.group(bossGroup, workerGroup) .channel(EpollServerSocketChannel.class) .option(EpollChannelOption.SO_BACKLOG, 128) @@ -109,11 +107,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.getExecutorSize()); + workerGroup = new NioEventLoopGroup(RULE_REGISTRY.getAcceptorSize()); + userGroup = new NioEventLoopGroup(RULE_REGISTRY.getAcceptorSize()); bootstrap.group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 128) @@ -122,6 +121,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/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/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 109c9c6e9d155..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.FrontendExecutorContext; 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) - : FrontendExecutorContext.getInstance().getExecutorService(); + 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 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-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)); 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..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.M1"; + 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/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); 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/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(); 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); } 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(); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/ProxyTransactionLoader.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/ProxyTransactionLoader.java deleted file mode 100644 index d3dbf8a432e42..0000000000000 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/util/ProxyTransactionLoader.java +++ /dev/null @@ -1,63 +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.util; - -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 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: - } - EventBusInstance.getInstance().register(TransactionListener.getInstance()); - return result; - } - - // TODO :zhaojun 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-proxy/src/main/resources/META-INF/services/io.shardingsphere.core.transaction.spi.TransactionManager b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.core.transaction.spi.TransactionManager deleted file mode 100644 index bfa7798479eba..0000000000000 --- a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.core.transaction.spi.TransactionManager +++ /dev/null @@ -1 +0,0 @@ -io.shardingsphere.transaction.xa.AtomikosTransactionManager \ No newline at end of file diff --git a/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.xa.XATransactionManager b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.xa.XATransactionManager new file mode 100644 index 0000000000000..dd784f3e58903 --- /dev/null +++ b/sharding-proxy/src/main/resources/META-INF/services/io.shardingsphere.transaction.api.xa.XATransactionManager @@ -0,0 +1 @@ +io.shardingsphere.transaction.api.xa.AtomikosTransactionManager diff --git a/sharding-proxy/src/main/resources/conf/config.yaml b/sharding-proxy/src/main/resources/conf/config.yaml index 4c0f1905bee9c..de0a79397de87 100644 --- a/sharding-proxy/src/main/resources/conf/config.yaml +++ b/sharding-proxy/src/main/resources/conf/config.yaml @@ -61,7 +61,8 @@ # # 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 -# executor.size: 16 # The default value is available processors count. +# acceptor.size: 16 # The default value is available processors count * 2. +# executor.size: 16 # Infinite by default. # sql.show: false # #orchestration: @@ -74,4 +75,4 @@ # #proxyAuthority: # username: root -# password: root +# password: root \ No newline at end of file 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..5206ab54849b9 100644 --- a/sharding-proxy/src/main/resources/conf/config_master_slave.yaml +++ b/sharding-proxy/src/main/resources/conf/config_master_slave.yaml @@ -40,7 +40,8 @@ # # 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 -# executor.size: 16 # The default value is available processors count. +# acceptor.size: 16 # The default value is available processors count * 2. +# executor.size: 16 # Infinite by default. # sql.show: false #orchestration: diff --git a/sharding-proxy/src/main/resources/jta.properties b/sharding-proxy/src/main/resources/conf/jta.properties similarity index 100% rename from sharding-proxy/src/main/resources/jta.properties rename to sharding-proxy/src/main/resources/conf/jta.properties diff --git a/sharding-proxy/src/main/resources/logback.xml b/sharding-proxy/src/main/resources/logback.xml index 409fd9272c5d7..35eedd49dc958 100644 --- a/sharding-proxy/src/main/resources/logback.xml +++ b/sharding-proxy/src/main/resources/logback.xml @@ -9,7 +9,7 @@ - + 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 { } 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; 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 diff --git a/sharding-sql-test/pom.xml b/sharding-sql-test/pom.xml index 3e6fd308a3d30..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-SNAPSHOT + 3.0.0.M3-SNAPSHOT sharding-sql-test ${project.artifactId} 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 @@ + + + + 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 @@ - + diff --git a/sharding-transaction/pom.xml b/sharding-transaction/pom.xml new file mode 100644 index 0000000000000..9198c1504582f --- /dev/null +++ b/sharding-transaction/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + io.shardingsphere + sharding-sphere + 3.0.0.M3-SNAPSHOT + + sharding-transaction + ${project.artifactId} + + + + io.shardingsphere + sharding-core + ${project.parent.version} + + + + com.google.guava + guava + + + javax.transaction + jta + + + com.atomikos + transactions + + + com.atomikos + transactions-jta + + + com.atomikos + transactions-jdbc + + + org.slf4j + slf4j-api + + + + org.projectlombok + lombok + + + ch.qos.logback + logback-classic + + + + junit + junit + + + org.mockito + mockito-core + + + diff --git a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManager.java similarity index 80% rename from sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManager.java index f47639a4fd800..1a729ce98914f 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/transaction/spi/TransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManager.java @@ -15,18 +15,18 @@ *

*/ -package io.shardingsphere.core.transaction.spi; - -import io.shardingsphere.core.transaction.event.TransactionEvent; +package io.shardingsphere.transaction.api; +import io.shardingsphere.transaction.common.event.TransactionEvent; import java.sql.SQLException; /** - * Transaction manager. + * Sharding transaction manager. * * @author zhaojun + * @author zhangliang */ -public interface TransactionManager { +public interface ShardingTransactionManager { /** * Begin transaction. @@ -55,11 +55,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/ShardingTransactionManagerFactory.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManagerFactory.java new file mode 100644 index 0000000000000..a6ffd2444bd5a --- /dev/null +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/ShardingTransactionManagerFactory.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; + +import io.shardingsphere.core.constant.TransactionType; +import io.shardingsphere.transaction.api.local.LocalTransactionManager; +import io.shardingsphere.transaction.api.xa.XATransactionManagerSPILoader; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * Sharding transaction manager factory. + * + * @author zhangliang + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ShardingTransactionManagerFactory { + + /** + * Get sharding transaction manager. + * + * @param transactionType transaction type + * @return sharding transaction manager + */ + public static ShardingTransactionManager getShardingTransactionManager(final TransactionType transactionType) { + switch (transactionType) { + case LOCAL: + return new LocalTransactionManager(); + case XA: + return XATransactionManagerSPILoader.getInstance().getTransactionManager(); + case BASE: + default: + return null; + } + } +} 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..16ec8b1a5aca3 --- /dev/null +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/base/SagaTransactionManager.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.transaction.api.base; + +import io.shardingsphere.transaction.api.ShardingTransactionManager; +import io.shardingsphere.transaction.common.event.TransactionEvent; + +import javax.transaction.Status; + +/** + * Saga transaction manager. + * + * @author zhaojun + */ +public final class SagaTransactionManager implements ShardingTransactionManager { + + @Override + public void begin(final TransactionEvent transactionEvent) { + } + + @Override + public void commit(final TransactionEvent transactionEvent) { + } + + @Override + public void rollback(final TransactionEvent transactionEvent) { + } + + @Override + public int getStatus() { + // TODO :zhaojun need confirm, return Status.STATUS_NO_TRANSACTION or zero? + return Status.STATUS_NO_TRANSACTION; + } +} 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/api/local/LocalTransactionManager.java similarity index 60% 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/api/local/LocalTransactionManager.java index 52bde5e99f3a9..b462445d5a131 100644 --- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/transaction/WeakXaTransactionManager.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/local/LocalTransactionManager.java @@ -15,37 +15,44 @@ *

*/ -package io.shardingsphere.core.jdbc.core.transaction; +package io.shardingsphere.transaction.api.local; -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.api.ShardingTransactionManager; +import io.shardingsphere.transaction.common.event.TransactionEvent; +import io.shardingsphere.transaction.common.event.LocalTransactionEvent; +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 */ -public final class WeakXaTransactionManager implements TransactionManager { +public final class LocalTransactionManager implements ShardingTransactionManager { @Override public void begin(final TransactionEvent transactionEvent) throws SQLException { - WeakXaTransactionEvent weakXaTransactionEvent = (WeakXaTransactionEvent) transactionEvent; - for (Connection each : weakXaTransactionEvent.getCachedConnections().values()) { - each.setAutoCommit(weakXaTransactionEvent.isAutoCommit()); + LocalTransactionEvent localTransactionEvent = (LocalTransactionEvent) transactionEvent; + Collection exceptions = new LinkedList<>(); + for (Connection each : localTransactionEvent.getCachedConnections()) { + try { + each.setAutoCommit(localTransactionEvent.isAutoCommit()); + } catch (final SQLException ex) { + exceptions.add(ex); + } } + throwSQLExceptionIfNecessary(exceptions); } @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().values()) { + for (Connection each : localTransactionEvent.getCachedConnections()) { try { each.commit(); } catch (final SQLException ex) { @@ -57,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().values()) { + for (Connection each : localTransactionEvent.getCachedConnections()) { try { each.rollback(); } catch (final SQLException ex) { @@ -69,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; @@ -84,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-jdbc-transaction-parent/sharding-jdbc-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 74% 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/api/xa/AtomikosTransactionManager.java index 12d5ab2cf0333..7977d51cc4845 100644 --- 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/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.core.transaction.event.TransactionEvent; -import io.shardingsphere.core.transaction.spi.TransactionManager; +import io.shardingsphere.core.exception.ShardingException; +import io.shardingsphere.transaction.common.event.TransactionEvent; import javax.transaction.HeuristicMixedException; import javax.transaction.HeuristicRollbackException; @@ -33,22 +33,22 @@ * * @author zhaojun */ -public final class AtomikosTransactionManager implements TransactionManager { +public final class AtomikosTransactionManager implements XATransactionManager { - private static UserTransactionManager transactionManager = AtomikosUserTransaction.getInstance(); + private static final 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 +57,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 +66,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 +75,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-jdbc-transaction-parent/sharding-jdbc-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 65% 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/api/xa/AtomikosUserTransaction.java index bd05b40e2ee29..137c89ad32787 100644 --- 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/api/xa/AtomikosUserTransaction.java @@ -15,33 +15,28 @@ *

*/ -package io.shardingsphere.transaction.xa; +package io.shardingsphere.transaction.api.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; } } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/DataSourceConfig.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/XATransactionManager.java similarity index 60% rename from sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/DataSourceConfig.java rename to sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/XATransactionManager.java index 3a98e89e55e47..6edc845f82a78 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/netty/DataSourceConfig.java +++ b/sharding-transaction/src/main/java/io/shardingsphere/transaction/api/xa/XATransactionManager.java @@ -15,27 +15,14 @@ *

*/ -package io.shardingsphere.proxy.backend.netty; +package io.shardingsphere.transaction.api.xa; -import lombok.Getter; -import lombok.RequiredArgsConstructor; +import io.shardingsphere.transaction.api.ShardingTransactionManager; /** - * DataSourceConfig. + * XA transaction manager. * - * @author linjiaqi + * @author zhangliang */ -@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; +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-core/src/main/java/io/shardingsphere/core/transaction/TransactionContext.java b/sharding-transaction/src/main/java/io/shardingsphere/transaction/common/TransactionContext.java similarity index 56% 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..51606268322ae 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,34 +15,28 @@ *

*/ -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.api.ShardingTransactionManager; import lombok.Getter; +import lombok.NoArgsConstructor; /** * Hold Transaction Context. * * @author zhaojun */ +@NoArgsConstructor @Getter public final class TransactionContext { - private TransactionManager transactionManager; + private ShardingTransactionManager transactionManager; - private TransactionType transactionType = TransactionType.XA; + private TransactionType transactionType = TransactionType.LOCAL; - private Class transactionEventClazz = WeakXaTransactionEvent.class; - - public TransactionContext() { - } - - public TransactionContext(final TransactionManager transactionManager, final TransactionType transactionType, final Class clazz) { + public TransactionContext(final ShardingTransactionManager transactionManager, final TransactionType transactionType) { this.transactionManager = transactionManager; this.transactionType = transactionType; - this.transactionEventClazz = clazz; } } 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 87% 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..d14285f1f4400 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. @@ -25,6 +25,7 @@ public final class TransactionContextHolder { private static final ThreadLocal CONTEXT = new ThreadLocal() { + @Override protected TransactionContext initialValue() { return new TransactionContext(); @@ -48,4 +49,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(); + } } 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/LocalTransactionEvent.java similarity index 79% 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/LocalTransactionEvent.java index e002128cc9df9..63cce2ab9390a 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/LocalTransactionEvent.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; @@ -24,22 +24,22 @@ import lombok.Setter; import java.sql.Connection; -import java.util.Map; +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 Map cachedConnections; + private Collection cachedConnections; private boolean autoCommit = true; - public WeakXaTransactionEvent(final TCLType tclType) { + public LocalTransactionEvent(final TCLType tclType) { super(tclType); } 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 75% 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..ad696c81a32f6 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,15 +15,15 @@ *

*/ -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; /** - * Create TransactionEvent for current thread. + * Transaction event factory. * * @author zhaojun */ @@ -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 WeakXaTransactionEvent(tclType); + return new XaTransactionEvent(tclType, ""); case BASE: default: return null; 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 68% 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..6dfae8075ca18 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,15 +15,14 @@ *

*/ -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 lombok.AccessLevel; -import lombok.NoArgsConstructor; +import io.shardingsphere.core.util.EventBusInstance; +import io.shardingsphere.transaction.api.ShardingTransactionManager; +import io.shardingsphere.transaction.common.TransactionContextHolder; +import io.shardingsphere.transaction.common.event.TransactionEvent; 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); } /** @@ -55,7 +49,7 @@ public static TransactionListener getInstance() { @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); diff --git a/src/resources/sharding_checks.xml b/src/resources/sharding_checks.xml index 90f0c09fa663c..e4fcba7d67640 100644 --- a/src/resources/sharding_checks.xml +++ b/src/resources/sharding_checks.xml @@ -180,8 +180,10 @@ - + + +