+ * 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.sql;
+
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.parsing.lexer.dialect.mysql.MySQLKeyword;
+import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
+import io.shardingsphere.core.parsing.lexer.token.Keyword;
+import io.shardingsphere.core.parsing.parser.sql.ddl.create.index.AbstractCreateIndexParser;
+import io.shardingsphere.core.rule.ShardingRule;
+
+/**
+ * Create parser for MySQL.
+ *
+ * @author zhangliang
+ * @author panjuan
+ */
+public final class MySQLCreateIndexParser extends AbstractCreateIndexParser {
+
+ public MySQLCreateIndexParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ super(shardingRule, lexerEngine);
+ }
+
+ @Override
+ protected Keyword[] getSkippedKeywordsBetweenCreateAndKeyword() {
+ return new Keyword[] {DefaultKeyword.TEMPORARY};
+ }
+
+ @Override
+ protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() {
+ return new Keyword[] {DefaultKeyword.UNIQUE, DefaultKeyword.FULLTEXT, MySQLKeyword.SPATIAL};
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateTableParser.java
similarity index 85%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateTableParser.java
index 1de830addfea7..1ed5e513ee4a1 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLCreateTableParser.java
@@ -21,17 +21,18 @@
import io.shardingsphere.core.parsing.lexer.dialect.mysql.MySQLKeyword;
import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
import io.shardingsphere.core.parsing.lexer.token.Keyword;
-import io.shardingsphere.core.parsing.parser.sql.ddl.create.AbstractCreateParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.create.table.AbstractCreateTableParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Create parser for MySQL.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class MySQLCreateParser extends AbstractCreateParser {
+public final class MySQLCreateTableParser extends AbstractCreateTableParser {
- public MySQLCreateParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public MySQLCreateTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
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
new file mode 100644
index 0000000000000..3e8971c16fe23
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDropIndexParser.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package io.shardingsphere.core.parsing.parser.dialect.mysql.sql;
+
+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.parser.sql.ddl.drop.index.AbstractDropIndexParser;
+import io.shardingsphere.core.rule.ShardingRule;
+
+/**
+ * Drop parser for MySQL.
+ *
+ * @author zhangliang
+ * @author panjuan
+ */
+public final class MySQLDropIndexParser extends AbstractDropIndexParser {
+
+ public MySQLDropIndexParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ super(shardingRule, lexerEngine);
+ }
+
+ @Override
+ protected Keyword[] getSkippedKeywordsBetweenDropAndTable() {
+ return new Keyword[] {DefaultKeyword.TEMPORARY};
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDropParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDropTableParser.java
similarity index 82%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDropParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDropTableParser.java
index 2b8687e2917c7..1df1f6f1cff6d 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDropParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLDropTableParser.java
@@ -20,17 +20,18 @@
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.parser.sql.ddl.drop.AbstractDropParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.drop.table.AbstractDropTableParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Drop parser for MySQL.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class MySQLDropParser extends AbstractDropParser {
+public final class MySQLDropTableParser extends AbstractDropTableParser {
- public MySQLDropParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public MySQLDropTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLTruncateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLTruncateTableParser.java
similarity index 75%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLTruncateParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLTruncateTableParser.java
index f644309f05b95..0a8ce40e58fa7 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLTruncateParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/mysql/sql/MySQLTruncateTableParser.java
@@ -18,17 +18,18 @@
package io.shardingsphere.core.parsing.parser.dialect.mysql.sql;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
-import io.shardingsphere.core.parsing.parser.sql.ddl.truncate.AbstractTruncateParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.truncate.table.AbstractTruncateTableParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Truncate parser for MySQL.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class MySQLTruncateParser extends AbstractTruncateParser {
+public final class MySQLTruncateTableParser extends AbstractTruncateTableParser {
- public MySQLTruncateParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public MySQLTruncateTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleAlterParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleAlterTableParser.java
similarity index 76%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleAlterParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleAlterTableParser.java
index c7fc6e2312db5..e80663d0d835b 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleAlterParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleAlterTableParser.java
@@ -18,17 +18,18 @@
package io.shardingsphere.core.parsing.parser.dialect.oracle.sql;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
-import io.shardingsphere.core.parsing.parser.sql.ddl.alter.AbstractAlterParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.alter.table.AbstractAlterTableParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Alter parser for Oracle.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class OracleAlterParser extends AbstractAlterParser {
+public final class OracleAlterTableParser extends AbstractAlterTableParser {
- public OracleAlterParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public OracleAlterTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
}
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
new file mode 100644
index 0000000000000..7ccfc07e781f4
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateIndexParser.java
@@ -0,0 +1,47 @@
+/*
+ * 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.sql;
+
+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.parser.sql.ddl.create.index.AbstractCreateIndexParser;
+import io.shardingsphere.core.rule.ShardingRule;
+
+/**
+ * Create parser for Oracle.
+ *
+ * @author zhangliang
+ * @author panjuan
+ */
+public final class OracleCreateIndexParser extends AbstractCreateIndexParser {
+
+ public OracleCreateIndexParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ super(shardingRule, lexerEngine);
+ }
+
+ @Override
+ protected Keyword[] getSkippedKeywordsBetweenCreateAndKeyword() {
+ return new Keyword[] {DefaultKeyword.GLOBAL, DefaultKeyword.TEMPORARY};
+ }
+
+ @Override
+ protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() {
+ return new Keyword[] {DefaultKeyword.UNIQUE, DefaultKeyword.BITMAP};
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateTableParser.java
similarity index 83%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateTableParser.java
index 5da430af804cd..0985718f234cb 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleCreateTableParser.java
@@ -20,17 +20,18 @@
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.parser.sql.ddl.create.AbstractCreateParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.create.table.AbstractCreateTableParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Create parser for Oracle.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class OracleCreateParser extends AbstractCreateParser {
+public final class OracleCreateTableParser extends AbstractCreateTableParser {
- public OracleCreateParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public OracleCreateTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
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
new file mode 100644
index 0000000000000..42a2f36e15d6c
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropIndexParser.java
@@ -0,0 +1,35 @@
+/*
+ * 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.sql;
+
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.parsing.parser.sql.ddl.drop.index.AbstractDropIndexParser;
+import io.shardingsphere.core.rule.ShardingRule;
+
+/**
+ * Drop parser for Oracle.
+ *
+ * @author zhangliang
+ * @author panjuan
+ */
+public final class OracleDropIndexParser extends AbstractDropIndexParser {
+
+ public OracleDropIndexParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ super(shardingRule, lexerEngine);
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropTableParser.java
similarity index 79%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropTableParser.java
index b6d3f0aeb902f..08fb1c4caafa6 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleDropTableParser.java
@@ -19,17 +19,18 @@
import io.shardingsphere.core.parsing.lexer.LexerEngine;
import io.shardingsphere.core.parsing.lexer.token.Keyword;
-import io.shardingsphere.core.parsing.parser.sql.ddl.drop.AbstractDropParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.drop.table.AbstractDropTableParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Drop parser for Oracle.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class OracleDropParser extends AbstractDropParser {
+public final class OracleDropTableParser extends AbstractDropTableParser {
- public OracleDropParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public OracleDropTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleTruncateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleTruncateTableParser.java
similarity index 75%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleTruncateParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleTruncateTableParser.java
index 7dc24dd60c490..00ffacb34d5f7 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleTruncateParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/oracle/sql/OracleTruncateTableParser.java
@@ -18,17 +18,18 @@
package io.shardingsphere.core.parsing.parser.dialect.oracle.sql;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
-import io.shardingsphere.core.parsing.parser.sql.ddl.truncate.AbstractTruncateParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.truncate.table.AbstractTruncateTableParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Truncate parser for Oracle.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class OracleTruncateParser extends AbstractTruncateParser {
+public final class OracleTruncateTableParser extends AbstractTruncateTableParser {
- public OracleTruncateParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public OracleTruncateTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLAlterParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLAlterTableParser.java
similarity index 81%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLAlterParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLAlterTableParser.java
index 616a7d06599d4..d92ead70b8bc8 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLAlterParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLAlterTableParser.java
@@ -21,17 +21,18 @@
import io.shardingsphere.core.parsing.lexer.dialect.postgresql.PostgreSQLKeyword;
import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
import io.shardingsphere.core.parsing.lexer.token.Keyword;
-import io.shardingsphere.core.parsing.parser.sql.ddl.alter.AbstractAlterParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.alter.table.AbstractAlterTableParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Alter parser for PostgreSQL.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class PostgreSQLAlterParser extends AbstractAlterParser {
+public final class PostgreSQLAlterTableParser extends AbstractAlterTableParser {
- public PostgreSQLAlterParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public PostgreSQLAlterTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLCreateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLCreateIndexParser.java
similarity index 79%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLCreateParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLCreateIndexParser.java
index 83837096449fb..81ec1df47e8ab 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLCreateParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLCreateIndexParser.java
@@ -21,17 +21,18 @@
import io.shardingsphere.core.parsing.lexer.dialect.postgresql.PostgreSQLKeyword;
import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
import io.shardingsphere.core.parsing.lexer.token.Keyword;
-import io.shardingsphere.core.parsing.parser.sql.ddl.create.AbstractCreateParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.create.index.AbstractCreateIndexParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Create parser for PostgreSQL.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class PostgreSQLCreateParser extends AbstractCreateParser {
+public final class PostgreSQLCreateIndexParser extends AbstractCreateIndexParser {
- public PostgreSQLCreateParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public PostgreSQLCreateIndexParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
@@ -45,11 +46,6 @@ protected Keyword[] getSkippedKeywordsBetweenCreateAndKeyword() {
return new Keyword[] {DefaultKeyword.GLOBAL, DefaultKeyword.LOCAL, DefaultKeyword.TEMPORARY, DefaultKeyword.TEMP, PostgreSQLKeyword.UNLOGGED};
}
- @Override
- protected Keyword[] getSkippedKeywordsBetweenCreateTableAndTableName() {
- return new Keyword[] {DefaultKeyword.IF, DefaultKeyword.NOT, DefaultKeyword.EXISTS};
- }
-
@Override
protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() {
return new Keyword[] {DefaultKeyword.UNIQUE};
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
new file mode 100644
index 0000000000000..700a6e484d4f7
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLCreateTableParser.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package io.shardingsphere.core.parsing.parser.dialect.postgresql.sql;
+
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.parsing.lexer.dialect.postgresql.PostgreSQLKeyword;
+import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
+import io.shardingsphere.core.parsing.lexer.token.Keyword;
+import io.shardingsphere.core.parsing.parser.sql.ddl.create.table.AbstractCreateTableParser;
+import io.shardingsphere.core.rule.ShardingRule;
+
+/**
+ * Create parser for PostgreSQL.
+ *
+ * @author zhangliang
+ * @author panjuan
+ */
+public final class PostgreSQLCreateTableParser extends AbstractCreateTableParser {
+
+ public PostgreSQLCreateTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ super(shardingRule, lexerEngine);
+ }
+
+ @Override
+ protected Keyword[] getSkippedKeywordsBetweenCreateAndKeyword() {
+ return new Keyword[] {DefaultKeyword.GLOBAL, DefaultKeyword.LOCAL, DefaultKeyword.TEMPORARY, DefaultKeyword.TEMP, PostgreSQLKeyword.UNLOGGED};
+ }
+
+ @Override
+ protected Keyword[] getSkippedKeywordsBetweenCreateTableAndTableName() {
+ return new Keyword[] {DefaultKeyword.IF, DefaultKeyword.NOT, DefaultKeyword.EXISTS};
+ }
+
+ @Override
+ protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() {
+ return new Keyword[] {DefaultKeyword.UNIQUE};
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropIndexParser.java
similarity index 75%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropIndexParser.java
index db1404746948a..489dcca85c099 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropIndexParser.java
@@ -20,26 +20,23 @@
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.parser.sql.ddl.drop.AbstractDropParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.drop.index.AbstractDropIndexParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Drop parser for PostgreSQL.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class PostgreSQLDropParser extends AbstractDropParser {
+public final class PostgreSQLDropIndexParser extends AbstractDropIndexParser {
- public PostgreSQLDropParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public PostgreSQLDropIndexParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
- protected Keyword[] getSkippedKeywordsBetweenDropIndexAndIndexName() {
- return new Keyword[] {DefaultKeyword.IF, DefaultKeyword.EXISTS};
- }
-
@Override
- protected Keyword[] getSkippedKeywordsBetweenDropTableAndTableName() {
+ protected Keyword[] getSkippedKeywordsBetweenDropIndexAndIndexName() {
return new Keyword[] {DefaultKeyword.IF, DefaultKeyword.EXISTS};
}
}
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
new file mode 100644
index 0000000000000..984cc84317f00
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLDropTableParser.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package io.shardingsphere.core.parsing.parser.dialect.postgresql.sql;
+
+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.parser.sql.ddl.drop.table.AbstractDropTableParser;
+import io.shardingsphere.core.rule.ShardingRule;
+
+/**
+ * Drop parser for PostgreSQL.
+ *
+ * @author zhangliang
+ * @author panjuan
+ */
+public final class PostgreSQLDropTableParser extends AbstractDropTableParser {
+
+ public PostgreSQLDropTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ super(shardingRule, lexerEngine);
+ }
+
+ @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/PostgreSQLTruncateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLTruncateTableParser.java
similarity index 79%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLTruncateParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLTruncateTableParser.java
index e134ff4a5badc..60059308978e3 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLTruncateParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/postgresql/sql/PostgreSQLTruncateTableParser.java
@@ -20,17 +20,18 @@
import io.shardingsphere.core.parsing.lexer.LexerEngine;
import io.shardingsphere.core.parsing.lexer.dialect.postgresql.PostgreSQLKeyword;
import io.shardingsphere.core.parsing.lexer.token.Keyword;
-import io.shardingsphere.core.parsing.parser.sql.ddl.truncate.AbstractTruncateParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.truncate.table.AbstractTruncateTableParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Truncate parser for PostgreSQL.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class PostgreSQLTruncateParser extends AbstractTruncateParser {
+public final class PostgreSQLTruncateTableParser extends AbstractTruncateTableParser {
- public PostgreSQLTruncateParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public PostgreSQLTruncateTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerAlterParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerAlterTableParser.java
similarity index 75%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerAlterParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerAlterTableParser.java
index 87e205332d454..961b0d4227395 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerAlterParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerAlterTableParser.java
@@ -18,17 +18,18 @@
package io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
-import io.shardingsphere.core.parsing.parser.sql.ddl.alter.AbstractAlterParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.alter.table.AbstractAlterTableParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Alter parser for SQLServer.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class SQLServerAlterParser extends AbstractAlterParser {
+public final class SQLServerAlterTableParser extends AbstractAlterTableParser {
- public SQLServerAlterParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public SQLServerAlterTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
}
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
new file mode 100644
index 0000000000000..a6074dad18392
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateIndexParser.java
@@ -0,0 +1,47 @@
+/*
+ * 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.sql;
+
+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.parser.sql.ddl.create.index.AbstractCreateIndexParser;
+import io.shardingsphere.core.rule.ShardingRule;
+
+/**
+ * Create parser for SQLServer.
+ *
+ * @author zhangliang
+ * @author panjuan
+ */
+public final class SQLServerCreateIndexParser extends AbstractCreateIndexParser {
+
+ public SQLServerCreateIndexParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ super(shardingRule, lexerEngine);
+ }
+
+ @Override
+ protected Keyword[] getSkippedKeywordsBetweenCreateAndKeyword() {
+ return new Keyword[] {};
+ }
+
+ @Override
+ protected Keyword[] getSkippedKeywordsBetweenCreateIndexAndKeyword() {
+ return new Keyword[] {DefaultKeyword.UNIQUE, DefaultKeyword.FULLTEXT};
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateTableParser.java
similarity index 83%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateTableParser.java
index aad87117561ab..d65ccdb351176 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerCreateTableParser.java
@@ -20,17 +20,18 @@
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.parser.sql.ddl.create.AbstractCreateParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.create.table.AbstractCreateTableParser;
import io.shardingsphere.core.rule.ShardingRule;
/**
* Create parser for SQLServer.
*
* @author zhangliang
+ * @author panjuan
*/
-public final class SQLServerCreateParser extends AbstractCreateParser {
+public final class SQLServerCreateTableParser extends AbstractCreateTableParser {
- public SQLServerCreateParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public SQLServerCreateTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
super(shardingRule, lexerEngine);
}
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
new file mode 100644
index 0000000000000..75c79fa735869
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/dialect/sqlserver/sql/SQLServerDropIndexParser.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package io.shardingsphere.core.parsing.parser.sql.dcl.alter;
+
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
+import io.shardingsphere.core.parsing.parser.exception.SQLParsingException;
+import io.shardingsphere.core.parsing.parser.sql.SQLParser;
+import io.shardingsphere.core.parsing.parser.sql.dcl.DCLStatement;
+import lombok.RequiredArgsConstructor;
+
+/**
+ * Alter user parser.
+ *
+ * @author panjuan
+ */
+@RequiredArgsConstructor
+public class AlterUserParser implements SQLParser {
+
+ private final LexerEngine lexerEngine;
+
+ @Override
+ public DCLStatement parse() {
+ if (lexerEngine.skipIfEqual(DefaultKeyword.USER) || lexerEngine.skipIfEqual(DefaultKeyword.ROLE) || lexerEngine.skipIfEqual(DefaultKeyword.LOGIN)) {
+ return new DCLStatement();
+ } else {
+ throw new SQLParsingException("Can't support other ALTER grammar unless ALTER USER, ALTER ROLE, ALTER LOGIN.");
+ }
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/alter/AlterUserParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/alter/AlterUserParserFactory.java
new file mode 100644
index 0000000000000..b49e2eb318afc
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/alter/AlterUserParserFactory.java
@@ -0,0 +1,45 @@
+/*
+ * 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.dcl.alter;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.rule.ShardingRule;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Alter user parser factory.
+ *
+ * @author panjuan
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class AlterUserParserFactory {
+
+ /**
+ * Alter user parser instance.
+ *
+ * @param dbType database type
+ * @param shardingRule databases and tables sharding rule
+ * @param lexerEngine lexical analysis engine.
+ * @return alter user parser instance
+ */
+ public static AlterUserParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ return new AlterUserParser(lexerEngine);
+ }
+}
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
new file mode 100644
index 0000000000000..68d2da0ff4654
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/create/CreateUserParser.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package io.shardingsphere.core.parsing.parser.sql.dcl.create;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.rule.ShardingRule;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Create user parser factory.
+ *
+ * @author panjuan
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class CreateUserParserFactory {
+
+ /**
+ * Create user parser instance.
+ *
+ * @param dbType database type
+ * @param shardingRule databases and tables sharding rule
+ * @param lexerEngine lexical analysis engine.
+ * @return create user parser instance
+ */
+ public static CreateUserParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ return new CreateUserParser(lexerEngine);
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/deny/DenyUserParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/deny/DenyUserParser.java
new file mode 100644
index 0000000000000..ff8aaf7f3a4d2
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/deny/DenyUserParser.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 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.dcl.deny;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.rule.ShardingRule;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Deny user parser factory.
+ *
+ * @author panjuan
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DenyUserParserFactory {
+
+ /**
+ * Deny user parser instance.
+ *
+ * @param dbType database type
+ * @param shardingRule databases and tables sharding rule
+ * @param lexerEngine lexical analysis engine.
+ * @return deny user parser instance
+ */
+ public static DenyUserParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ switch (dbType) {
+ case SQLServer:
+ return new DenyUserParser(shardingRule, lexerEngine);
+ default:
+ throw new UnsupportedOperationException(String.format("Cannot support database [%s].", dbType));
+ }
+ }
+}
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
new file mode 100644
index 0000000000000..c88dac0b775a0
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/drop/DropUserParser.java
@@ -0,0 +1,45 @@
+/*
+ * 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.dcl.drop;
+
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
+import io.shardingsphere.core.parsing.parser.exception.SQLParsingException;
+import io.shardingsphere.core.parsing.parser.sql.SQLParser;
+import io.shardingsphere.core.parsing.parser.sql.dcl.DCLStatement;
+import lombok.RequiredArgsConstructor;
+
+/**
+ * Drop user parser.
+ *
+ * @author panjuan
+ */
+@RequiredArgsConstructor
+public class DropUserParser implements SQLParser {
+
+ private final LexerEngine lexerEngine;
+
+ @Override
+ public DCLStatement parse() {
+ if (lexerEngine.skipIfEqual(DefaultKeyword.USER) || lexerEngine.skipIfEqual(DefaultKeyword.ROLE) || lexerEngine.skipIfEqual(DefaultKeyword.LOGIN)) {
+ return new DCLStatement();
+ } else {
+ throw new SQLParsingException("Can't support other DROP grammar unless DROP USER, DROP ROLE, DROP LOGIN.");
+ }
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/drop/DropUserParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/drop/DropUserParserFactory.java
new file mode 100644
index 0000000000000..fef63bec50d72
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/drop/DropUserParserFactory.java
@@ -0,0 +1,45 @@
+/*
+ * 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.dcl.drop;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.rule.ShardingRule;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Drop user parser factory.
+ *
+ * @author panjuan
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DropUserParserFactory {
+
+ /**
+ * Drop user parser instance.
+ *
+ * @param dbType database type
+ * @param shardingRule databases and tables sharding rule
+ * @param lexerEngine lexical analysis engine.
+ * @return drop user parser instance
+ */
+ public static DropUserParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ return new DropUserParser(lexerEngine);
+ }
+}
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
new file mode 100644
index 0000000000000..7aca37b00e1d4
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/grant/GrantUserParser.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package io.shardingsphere.core.parsing.parser.sql.dcl.grant;
+
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
+import io.shardingsphere.core.parsing.parser.clause.TableReferencesClauseParser;
+import io.shardingsphere.core.parsing.parser.sql.SQLParser;
+import io.shardingsphere.core.parsing.parser.sql.dcl.DCLStatement;
+import io.shardingsphere.core.rule.ShardingRule;
+
+/**
+ * Grant user parser.
+ *
+ * @author panjuan
+ */
+public class GrantUserParser implements SQLParser {
+
+ private final LexerEngine lexerEngine;
+
+ private final TableReferencesClauseParser tableReferencesClauseParser;
+
+ public GrantUserParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ this.lexerEngine = lexerEngine;
+ tableReferencesClauseParser = new TableReferencesClauseParser(shardingRule, lexerEngine);
+ }
+
+ @Override
+ public DCLStatement parse() {
+ DCLStatement result = new DCLStatement();
+ lexerEngine.skipUntil(DefaultKeyword.ON);
+ if (!lexerEngine.isEnd()) {
+ lexerEngine.nextToken();
+ tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
+ }
+ return result;
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/grant/GrantUserParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/grant/GrantUserParserFactory.java
new file mode 100644
index 0000000000000..9d5ee0172be00
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/grant/GrantUserParserFactory.java
@@ -0,0 +1,45 @@
+/*
+ * 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.dcl.grant;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.rule.ShardingRule;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Grant user parser factory.
+ *
+ * @author panjuan
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class GrantUserParserFactory {
+
+ /**
+ * Grant user parser instance.
+ *
+ * @param dbType database type
+ * @param shardingRule databases and tables sharding rule
+ * @param lexerEngine lexical analysis engine.
+ * @return grant user parser instance
+ */
+ public static GrantUserParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ return new GrantUserParser(shardingRule, lexerEngine);
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/rename/RenameUserParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/rename/RenameUserParser.java
new file mode 100644
index 0000000000000..82f9fda3b6a7e
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/rename/RenameUserParser.java
@@ -0,0 +1,45 @@
+/*
+ * 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.dcl.rename;
+
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
+import io.shardingsphere.core.parsing.parser.exception.SQLParsingException;
+import io.shardingsphere.core.parsing.parser.sql.SQLParser;
+import io.shardingsphere.core.parsing.parser.sql.dcl.DCLStatement;
+import lombok.RequiredArgsConstructor;
+
+/**
+ * Rename user parser.
+ *
+ * @author panjuan
+ */
+@RequiredArgsConstructor
+public class RenameUserParser implements SQLParser {
+
+ private final LexerEngine lexerEngine;
+
+ @Override
+ public DCLStatement parse() {
+ if (lexerEngine.skipIfEqual(DefaultKeyword.USER)) {
+ return new DCLStatement();
+ } else {
+ throw new SQLParsingException("Can't support other CREATE grammar unless RENAME USER.");
+ }
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/rename/RenameUserParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/rename/RenameUserParserFactory.java
new file mode 100644
index 0000000000000..bed71acb80af7
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/rename/RenameUserParserFactory.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.core.parsing.parser.sql.dcl.rename;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.rule.ShardingRule;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Rename user parser factory.
+ *
+ * @author panjuan
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class RenameUserParserFactory {
+
+ /**
+ * Rename user parser instance.
+ *
+ * @param dbType database type
+ * @param shardingRule databases and tables sharding rule
+ * @param lexerEngine lexical analysis engine.
+ * @return rename user parser instance
+ */
+ public static RenameUserParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ switch (dbType) {
+ case H2:
+ case MySQL:
+ return new RenameUserParser(lexerEngine);
+ default:
+ throw new UnsupportedOperationException(String.format("Cannot support database [%s].", dbType));
+ }
+ }
+}
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
new file mode 100644
index 0000000000000..6afcf1bc107c8
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/dcl/revoke/RevokeUserParser.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 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.dcl.revoke;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.rule.ShardingRule;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Revoke user parser factory.
+ *
+ * @author panjuan
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class RevokeUserParserFactory {
+
+ /**
+ * Revoke user parser instance.
+ *
+ * @param dbType database type
+ * @param shardingRule databases and tables sharding rule
+ * @param lexerEngine lexical analysis engine.
+ * @return revoke user parser instance
+ */
+ public static RevokeUserParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ return new RevokeUserParser(shardingRule, lexerEngine);
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/AbstractAlterParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java
similarity index 88%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/AbstractAlterParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java
index e013c7543b0d6..d0695e3068f89 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/AbstractAlterParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AbstractAlterTableParser.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.core.parsing.parser.sql.ddl.alter;
+package io.shardingsphere.core.parsing.parser.sql.ddl.alter.table;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
@@ -31,9 +31,10 @@
* Alter parser.
*
* @author zhangliang
+ * @author panjuan
*/
@Getter(AccessLevel.PROTECTED)
-public abstract class AbstractAlterParser implements SQLParser {
+public abstract class AbstractAlterTableParser implements SQLParser {
private final ShardingRule shardingRule;
@@ -41,7 +42,7 @@ public abstract class AbstractAlterParser implements SQLParser {
private final TableReferencesClauseParser tableReferencesClauseParser;
- public AbstractAlterParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public AbstractAlterTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
this.shardingRule = shardingRule;
this.lexerEngine = lexerEngine;
tableReferencesClauseParser = new TableReferencesClauseParser(shardingRule, lexerEngine);
@@ -49,7 +50,6 @@ public AbstractAlterParser(final ShardingRule shardingRule, final LexerEngine le
@Override
public DDLStatement parse() {
- lexerEngine.nextToken();
lexerEngine.unsupportedIfNotSkip(DefaultKeyword.TABLE);
lexerEngine.skipAll(getSkippedKeywordsBetweenAlterTableAndTableName());
DDLStatement result = new DDLStatement();
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/AlterParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AlterTableParserFactory.java
similarity index 71%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/AlterParserFactory.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AlterTableParserFactory.java
index 7218bac5a34cd..e4d1522960ca0 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/AlterParserFactory.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/alter/table/AlterTableParserFactory.java
@@ -15,14 +15,14 @@
*
*/
-package io.shardingsphere.core.parsing.parser.sql.ddl.alter;
+package io.shardingsphere.core.parsing.parser.sql.ddl.alter.table;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
-import io.shardingsphere.core.parsing.parser.dialect.mysql.sql.MySQLAlterParser;
-import io.shardingsphere.core.parsing.parser.dialect.oracle.sql.OracleAlterParser;
-import io.shardingsphere.core.parsing.parser.dialect.postgresql.sql.PostgreSQLAlterParser;
-import io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql.SQLServerAlterParser;
+import io.shardingsphere.core.parsing.parser.dialect.mysql.sql.MySQLAlterTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.oracle.sql.OracleAlterTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.postgresql.sql.PostgreSQLAlterTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql.SQLServerAlterTableParser;
import io.shardingsphere.core.rule.ShardingRule;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -31,9 +31,10 @@
* Alter parser factory.
*
* @author zhangliang
+ * @author panjuan
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class AlterParserFactory {
+public final class AlterTableParserFactory {
/**
* Create alter parser instance.
@@ -43,17 +44,17 @@ public final class AlterParserFactory {
* @param lexerEngine lexical analysis engine.
* @return alter parser instance
*/
- public static AbstractAlterParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public static AbstractAlterTableParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
switch (dbType) {
case H2:
case MySQL:
- return new MySQLAlterParser(shardingRule, lexerEngine);
+ return new MySQLAlterTableParser(shardingRule, lexerEngine);
case Oracle:
- return new OracleAlterParser(shardingRule, lexerEngine);
+ return new OracleAlterTableParser(shardingRule, lexerEngine);
case SQLServer:
- return new SQLServerAlterParser(shardingRule, lexerEngine);
+ return new SQLServerAlterTableParser(shardingRule, lexerEngine);
case PostgreSQL:
- return new PostgreSQLAlterParser(shardingRule, lexerEngine);
+ return new PostgreSQLAlterTableParser(shardingRule, lexerEngine);
default:
throw new UnsupportedOperationException(String.format("Cannot support database [%s].", dbType));
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/AbstractCreateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/index/AbstractCreateIndexParser.java
similarity index 85%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/AbstractCreateParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/index/AbstractCreateIndexParser.java
index 2d1ac9389ff11..ffc8d80499718 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/AbstractCreateParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/index/AbstractCreateIndexParser.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.core.parsing.parser.sql.ddl.create;
+package io.shardingsphere.core.parsing.parser.sql.ddl.create.index;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
@@ -34,9 +34,10 @@
* Create parser.
*
* @author zhangliang
+ * @author panjuan
*/
@Getter(AccessLevel.PROTECTED)
-public abstract class AbstractCreateParser implements SQLParser {
+public abstract class AbstractCreateIndexParser implements SQLParser {
private final ShardingRule shardingRule;
@@ -44,7 +45,7 @@ public abstract class AbstractCreateParser implements SQLParser {
private final TableReferencesClauseParser tableReferencesClauseParser;
- public AbstractCreateParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public AbstractCreateIndexParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
this.shardingRule = shardingRule;
this.lexerEngine = lexerEngine;
tableReferencesClauseParser = new TableReferencesClauseParser(shardingRule, lexerEngine);
@@ -52,17 +53,14 @@ public AbstractCreateParser(final ShardingRule shardingRule, final LexerEngine l
@Override
public DDLStatement parse() {
- lexerEngine.nextToken();
lexerEngine.skipAll(getSkippedKeywordsBetweenCreateIndexAndKeyword());
lexerEngine.skipAll(getSkippedKeywordsBetweenCreateAndKeyword());
DDLStatement result = new DDLStatement();
if (lexerEngine.skipIfEqual(DefaultKeyword.INDEX)) {
lexerEngine.skipAll(getSkippedKeywordsBetweenCreateIndexAndIndexName());
parseIndex(result);
- } else if (lexerEngine.skipIfEqual(DefaultKeyword.TABLE)) {
- lexerEngine.skipAll(getSkippedKeywordsBetweenCreateTableAndTableName());
} else {
- throw new SQLParsingException("Can't support other CREATE grammar unless CREATE TABLE, CREATE INDEX.");
+ throw new SQLParsingException("Can't support other CREATE grammar unless CREATE INDEX.");
}
tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
return result;
@@ -85,6 +83,4 @@ private void parseIndex(final DDLStatement ddlStatement) {
String tableName = lexerEngine.getCurrentToken().getLiterals();
ddlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, tableName));
}
-
- protected abstract Keyword[] getSkippedKeywordsBetweenCreateTableAndTableName();
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/CreateParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/index/CreateIndexParserFactory.java
similarity index 71%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/CreateParserFactory.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/index/CreateIndexParserFactory.java
index 343f1a79265d9..6940783ee070a 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/CreateParserFactory.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/index/CreateIndexParserFactory.java
@@ -15,14 +15,14 @@
*
*/
-package io.shardingsphere.core.parsing.parser.sql.ddl.create;
+package io.shardingsphere.core.parsing.parser.sql.ddl.create.index;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
-import io.shardingsphere.core.parsing.parser.dialect.mysql.sql.MySQLCreateParser;
-import io.shardingsphere.core.parsing.parser.dialect.oracle.sql.OracleCreateParser;
-import io.shardingsphere.core.parsing.parser.dialect.postgresql.sql.PostgreSQLCreateParser;
-import io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql.SQLServerCreateParser;
+import io.shardingsphere.core.parsing.parser.dialect.mysql.sql.MySQLCreateIndexParser;
+import io.shardingsphere.core.parsing.parser.dialect.oracle.sql.OracleCreateIndexParser;
+import io.shardingsphere.core.parsing.parser.dialect.postgresql.sql.PostgreSQLCreateIndexParser;
+import io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql.SQLServerCreateIndexParser;
import io.shardingsphere.core.rule.ShardingRule;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -31,9 +31,10 @@
* Create parser factory.
*
* @author zhangliang
+ * @author panjuan
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class CreateParserFactory {
+public final class CreateIndexParserFactory {
/**
* Create create parser instance.
@@ -43,17 +44,17 @@ public final class CreateParserFactory {
* @param lexerEngine lexical analysis engine.
* @return create parser instance
*/
- public static AbstractCreateParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public static AbstractCreateIndexParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
switch (dbType) {
case H2:
case MySQL:
- return new MySQLCreateParser(shardingRule, lexerEngine);
+ return new MySQLCreateIndexParser(shardingRule, lexerEngine);
case Oracle:
- return new OracleCreateParser(shardingRule, lexerEngine);
+ return new OracleCreateIndexParser(shardingRule, lexerEngine);
case SQLServer:
- return new SQLServerCreateParser(shardingRule, lexerEngine);
+ return new SQLServerCreateIndexParser(shardingRule, lexerEngine);
case PostgreSQL:
- return new PostgreSQLCreateParser(shardingRule, lexerEngine);
+ return new PostgreSQLCreateIndexParser(shardingRule, lexerEngine);
default:
throw new UnsupportedOperationException(String.format("Cannot support database [%s].", dbType));
}
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
new file mode 100644
index 0000000000000..f9e5d76ae9d6a
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/create/table/AbstractCreateTableParser.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package io.shardingsphere.core.parsing.parser.sql.ddl.create.table;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.parsing.parser.dialect.mysql.sql.MySQLCreateTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.oracle.sql.OracleCreateTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.postgresql.sql.PostgreSQLCreateTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql.SQLServerCreateTableParser;
+import io.shardingsphere.core.rule.ShardingRule;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Create parser factory.
+ *
+ * @author zhangliang
+ * @author panjuan
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class CreateTableParserFactory {
+
+ /**
+ * Create create parser instance.
+ *
+ * @param dbType database type
+ * @param shardingRule databases and tables sharding rule
+ * @param lexerEngine lexical analysis engine.
+ * @return create parser instance
+ */
+ public static AbstractCreateTableParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ switch (dbType) {
+ case H2:
+ case MySQL:
+ return new MySQLCreateTableParser(shardingRule, lexerEngine);
+ case Oracle:
+ return new OracleCreateTableParser(shardingRule, lexerEngine);
+ case SQLServer:
+ return new SQLServerCreateTableParser(shardingRule, lexerEngine);
+ case PostgreSQL:
+ return new PostgreSQLCreateTableParser(shardingRule, lexerEngine);
+ default:
+ throw new UnsupportedOperationException(String.format("Cannot support database [%s].", dbType));
+ }
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/AbstractDropParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/index/AbstractDropIndexParser.java
similarity index 83%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/AbstractDropParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/index/AbstractDropIndexParser.java
index 4f6cdde03aa1d..12fcab6c58b6a 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/AbstractDropParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/index/AbstractDropIndexParser.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.core.parsing.parser.sql.ddl.drop;
+package io.shardingsphere.core.parsing.parser.sql.ddl.drop.index;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
@@ -34,9 +34,10 @@
* Drop parser.
*
* @author zhangliang
+ * @author panjuan
*/
@Getter(AccessLevel.PROTECTED)
-public abstract class AbstractDropParser implements SQLParser {
+public abstract class AbstractDropIndexParser implements SQLParser {
private final ShardingRule shardingRule;
@@ -44,7 +45,7 @@ public abstract class AbstractDropParser implements SQLParser {
private final TableReferencesClauseParser tableReferencesClauseParser;
- public AbstractDropParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public AbstractDropIndexParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
this.shardingRule = shardingRule;
this.lexerEngine = lexerEngine;
tableReferencesClauseParser = new TableReferencesClauseParser(shardingRule, lexerEngine);
@@ -52,17 +53,13 @@ public AbstractDropParser(final ShardingRule shardingRule, final LexerEngine lex
@Override
public DDLStatement parse() {
- lexerEngine.nextToken();
lexerEngine.skipAll(getSkippedKeywordsBetweenDropAndTable());
DDLStatement result = new DDLStatement();
if (lexerEngine.skipIfEqual(DefaultKeyword.INDEX)) {
lexerEngine.skipAll(getSkippedKeywordsBetweenDropIndexAndIndexName());
parseIndex(result);
- } else if (lexerEngine.skipIfEqual(DefaultKeyword.TABLE)) {
- lexerEngine.skipAll(getSkippedKeywordsBetweenDropTableAndTableName());
- tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
} else {
- throw new SQLParsingException("Can't support other DROP grammar unless DROP TABLE, DROP INDEX.");
+ throw new SQLParsingException("Can't support other DROP grammar unless DROP INDEX.");
}
return result;
}
@@ -87,6 +84,4 @@ private void parseIndex(final DDLStatement ddlStatement) {
ddlStatement.getSqlTokens().add(new IndexToken(beginPosition, literals, ""));
}
}
-
- protected abstract Keyword[] getSkippedKeywordsBetweenDropTableAndTableName();
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/DropParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/index/DropIndexParserFactory.java
similarity index 72%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/DropParserFactory.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/index/DropIndexParserFactory.java
index 7dd99087c52cd..a537cce1fe7ad 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/DropParserFactory.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/index/DropIndexParserFactory.java
@@ -15,14 +15,14 @@
*
*/
-package io.shardingsphere.core.parsing.parser.sql.ddl.drop;
+package io.shardingsphere.core.parsing.parser.sql.ddl.drop.index;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
-import io.shardingsphere.core.parsing.parser.dialect.mysql.sql.MySQLDropParser;
-import io.shardingsphere.core.parsing.parser.dialect.oracle.sql.OracleDropParser;
-import io.shardingsphere.core.parsing.parser.dialect.postgresql.sql.PostgreSQLDropParser;
-import io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql.SQLServerDropParser;
+import io.shardingsphere.core.parsing.parser.dialect.mysql.sql.MySQLDropIndexParser;
+import io.shardingsphere.core.parsing.parser.dialect.oracle.sql.OracleDropIndexParser;
+import io.shardingsphere.core.parsing.parser.dialect.postgresql.sql.PostgreSQLDropIndexParser;
+import io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql.SQLServerDropIndexParser;
import io.shardingsphere.core.rule.ShardingRule;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -31,9 +31,10 @@
* Drop parser factory.
*
* @author zhangliang
+ * @author panjuan
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DropParserFactory {
+public final class DropIndexParserFactory {
/**
* Create drop parser instance.
@@ -43,17 +44,17 @@ public final class DropParserFactory {
* @param lexerEngine lexical analysis engine.
* @return drop parser instance
*/
- public static AbstractDropParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public static AbstractDropIndexParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
switch (dbType) {
case H2:
case MySQL:
- return new MySQLDropParser(shardingRule, lexerEngine);
+ return new MySQLDropIndexParser(shardingRule, lexerEngine);
case Oracle:
- return new OracleDropParser(shardingRule, lexerEngine);
+ return new OracleDropIndexParser(shardingRule, lexerEngine);
case SQLServer:
- return new SQLServerDropParser(shardingRule, lexerEngine);
+ return new SQLServerDropIndexParser(shardingRule, lexerEngine);
case PostgreSQL:
- return new PostgreSQLDropParser(shardingRule, lexerEngine);
+ return new PostgreSQLDropIndexParser(shardingRule, lexerEngine);
default:
throw new UnsupportedOperationException(String.format("Cannot support database [%s].", dbType));
}
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
new file mode 100644
index 0000000000000..f7518b8f013ba
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/AbstractDropTableParser.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2016-2018 shardingsphere.io.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package io.shardingsphere.core.parsing.parser.sql.ddl.drop.table;
+
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
+import io.shardingsphere.core.parsing.lexer.token.Keyword;
+import io.shardingsphere.core.parsing.parser.clause.TableReferencesClauseParser;
+import io.shardingsphere.core.parsing.parser.exception.SQLParsingException;
+import io.shardingsphere.core.parsing.parser.sql.SQLParser;
+import io.shardingsphere.core.parsing.parser.sql.ddl.DDLStatement;
+import io.shardingsphere.core.rule.ShardingRule;
+import lombok.AccessLevel;
+import lombok.Getter;
+
+/**
+ * Drop parser.
+ *
+ * @author zhangliang
+ * @author panjuan
+ */
+@Getter(AccessLevel.PROTECTED)
+public abstract class AbstractDropTableParser implements SQLParser {
+
+ private final ShardingRule shardingRule;
+
+ private final LexerEngine lexerEngine;
+
+ private final TableReferencesClauseParser tableReferencesClauseParser;
+
+ public AbstractDropTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ this.shardingRule = shardingRule;
+ this.lexerEngine = lexerEngine;
+ tableReferencesClauseParser = new TableReferencesClauseParser(shardingRule, lexerEngine);
+ }
+
+ @Override
+ public DDLStatement parse() {
+ lexerEngine.skipAll(getSkippedKeywordsBetweenDropAndTable());
+ DDLStatement result = new DDLStatement();
+ if (lexerEngine.skipIfEqual(DefaultKeyword.TABLE)) {
+ lexerEngine.skipAll(getSkippedKeywordsBetweenDropTableAndTableName());
+ tableReferencesClauseParser.parseSingleTableWithoutAlias(result);
+ } else {
+ throw new SQLParsingException("Can't support other DROP grammar unless DROP TABLE.");
+ }
+ return result;
+ }
+
+ protected Keyword[] getSkippedKeywordsBetweenDropAndTable() {
+ return new Keyword[0];
+ }
+
+ protected abstract Keyword[] getSkippedKeywordsBetweenDropTableAndTableName();
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/DropTableParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/DropTableParserFactory.java
new file mode 100644
index 0000000000000..de796f6197486
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/drop/table/DropTableParserFactory.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.sql.ddl.drop.table;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.parsing.lexer.LexerEngine;
+import io.shardingsphere.core.parsing.parser.dialect.mysql.sql.MySQLDropTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.oracle.sql.OracleDropTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.postgresql.sql.PostgreSQLDropTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql.SQLServerDropTableParser;
+import io.shardingsphere.core.rule.ShardingRule;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Drop parser factory.
+ *
+ * @author zhangliang
+ * @author panjuan
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DropTableParserFactory {
+
+ /**
+ * Create drop parser instance.
+ *
+ * @param dbType database type
+ * @param shardingRule databases and tables sharding rule
+ * @param lexerEngine lexical analysis engine.
+ * @return drop parser instance
+ */
+ public static AbstractDropTableParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ switch (dbType) {
+ case H2:
+ case MySQL:
+ return new MySQLDropTableParser(shardingRule, lexerEngine);
+ case Oracle:
+ return new OracleDropTableParser(shardingRule, lexerEngine);
+ case SQLServer:
+ return new SQLServerDropTableParser(shardingRule, lexerEngine);
+ case PostgreSQL:
+ return new PostgreSQLDropTableParser(shardingRule, lexerEngine);
+ default:
+ throw new UnsupportedOperationException(String.format("Cannot support database [%s].", dbType));
+ }
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/AbstractTruncateParser.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/table/AbstractTruncateTableParser.java
similarity index 88%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/AbstractTruncateParser.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/table/AbstractTruncateTableParser.java
index 7fed06783e13c..4c1bf99d417b6 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/AbstractTruncateParser.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/table/AbstractTruncateTableParser.java
@@ -15,7 +15,7 @@
*
*/
-package io.shardingsphere.core.parsing.parser.sql.ddl.truncate;
+package io.shardingsphere.core.parsing.parser.sql.ddl.truncate.table;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
import io.shardingsphere.core.parsing.lexer.token.DefaultKeyword;
@@ -31,9 +31,10 @@
* Truncate parser.
*
* @author zhangliang
+ * @author panjuan
*/
@Getter(AccessLevel.PROTECTED)
-public abstract class AbstractTruncateParser implements SQLParser {
+public abstract class AbstractTruncateTableParser implements SQLParser {
private final ShardingRule shardingRule;
@@ -41,7 +42,7 @@ public abstract class AbstractTruncateParser implements SQLParser {
private final TableReferencesClauseParser tableReferencesClauseParser;
- public AbstractTruncateParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public AbstractTruncateTableParser(final ShardingRule shardingRule, final LexerEngine lexerEngine) {
this.shardingRule = shardingRule;
this.lexerEngine = lexerEngine;
tableReferencesClauseParser = new TableReferencesClauseParser(shardingRule, lexerEngine);
@@ -49,7 +50,6 @@ public AbstractTruncateParser(final ShardingRule shardingRule, final LexerEngine
@Override
public DDLStatement parse() {
- lexerEngine.nextToken();
lexerEngine.skipIfEqual(DefaultKeyword.TABLE);
lexerEngine.skipAll(getSkippedKeywordsBetweenTruncateTableAndTableName());
DDLStatement result = new DDLStatement();
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/TruncateParserFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/table/TruncateTableParserFactory.java
similarity index 71%
rename from sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/TruncateParserFactory.java
rename to sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/table/TruncateTableParserFactory.java
index 2fd2686e1f191..4c18889cddb71 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/TruncateParserFactory.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/parsing/parser/sql/ddl/truncate/table/TruncateTableParserFactory.java
@@ -15,14 +15,14 @@
*
*/
-package io.shardingsphere.core.parsing.parser.sql.ddl.truncate;
+package io.shardingsphere.core.parsing.parser.sql.ddl.truncate.table;
import io.shardingsphere.core.constant.DatabaseType;
import io.shardingsphere.core.parsing.lexer.LexerEngine;
-import io.shardingsphere.core.parsing.parser.dialect.mysql.sql.MySQLTruncateParser;
-import io.shardingsphere.core.parsing.parser.dialect.oracle.sql.OracleTruncateParser;
-import io.shardingsphere.core.parsing.parser.dialect.postgresql.sql.PostgreSQLTruncateParser;
-import io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql.SQLServerTruncateParser;
+import io.shardingsphere.core.parsing.parser.dialect.mysql.sql.MySQLTruncateTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.oracle.sql.OracleTruncateTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.postgresql.sql.PostgreSQLTruncateTableParser;
+import io.shardingsphere.core.parsing.parser.dialect.sqlserver.sql.SQLServerTruncateTableParser;
import io.shardingsphere.core.rule.ShardingRule;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@@ -31,9 +31,10 @@
* Truncate parser factory.
*
* @author zhangliang
+ * @author panjuan
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class TruncateParserFactory {
+public final class TruncateTableParserFactory {
/**
* Create truncate parser instance.
@@ -43,17 +44,17 @@ public final class TruncateParserFactory {
* @param lexerEngine lexical analysis engine.
* @return truncate parser instance
*/
- public static AbstractTruncateParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
+ public static AbstractTruncateTableParser newInstance(final DatabaseType dbType, final ShardingRule shardingRule, final LexerEngine lexerEngine) {
switch (dbType) {
case H2:
case MySQL:
- return new MySQLTruncateParser(shardingRule, lexerEngine);
+ return new MySQLTruncateTableParser(shardingRule, lexerEngine);
case Oracle:
- return new OracleTruncateParser(shardingRule, lexerEngine);
+ return new OracleTruncateTableParser(shardingRule, lexerEngine);
case SQLServer:
- return new SQLServerTruncateParser(shardingRule, lexerEngine);
+ return new SQLServerTruncateTableParser(shardingRule, lexerEngine);
case PostgreSQL:
- return new PostgreSQLTruncateParser(shardingRule, lexerEngine);
+ return new PostgreSQLTruncateTableParser(shardingRule, lexerEngine);
default:
throw new UnsupportedOperationException(String.format("Cannot support database [%s].", dbType));
}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourceProperty.java b/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourceProperty.java
new file mode 100644
index 0000000000000..ce2f7463652a2
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourceProperty.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.core.property;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+/**
+ * Data source property.
+ *
+ * @author panjuan
+ */
+@RequiredArgsConstructor
+@Getter
+public class DataSourceProperty {
+
+ private final String hostName;
+
+ private final Integer port;
+
+ private final String schemeName;
+
+ private final DatabaseType databaseType;
+
+ /**
+ * Judge whether two of data source properties point at the same instance.
+ *
+ * @param dataSourceProperty data source property.
+ * @return pointing at the same instance or not.
+ */
+ public boolean isPointAtSameInstance(final DataSourceProperty dataSourceProperty) {
+ return getHostName().equals(dataSourceProperty.getHostName()) && getPort().equals(dataSourceProperty.getPort())
+ && getDatabaseType().equals(dataSourceProperty.getDatabaseType());
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourcePropertyFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourcePropertyFactory.java
new file mode 100644
index 0000000000000..18acfbe627272
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourcePropertyFactory.java
@@ -0,0 +1,59 @@
+/*
+ * 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.property;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.property.dialect.H2DataSourcePropertyParser;
+import io.shardingsphere.core.property.dialect.MySQLDataSourcePropertyParser;
+import io.shardingsphere.core.property.dialect.OracleDataSourcePropertyParser;
+import io.shardingsphere.core.property.dialect.PostgreSQLDataSourcePropertyParser;
+import io.shardingsphere.core.property.dialect.SQLServerDataSourcePropertyParser;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+/**
+ * Data source property factory.
+ *
+ * @author panjuan
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DataSourcePropertyFactory {
+
+ /**
+ * Create data source property parser.
+ *
+ * @param databaseType data base type.
+ * @return data source property parser.
+ */
+ public static DataSourcePropertyParser createDataSourcePropertyParser(final DatabaseType databaseType) {
+ switch (databaseType) {
+ case H2:
+ return new H2DataSourcePropertyParser();
+ case MySQL:
+ return new MySQLDataSourcePropertyParser();
+ case Oracle:
+ return new OracleDataSourcePropertyParser();
+ case PostgreSQL:
+ return new PostgreSQLDataSourcePropertyParser();
+ case SQLServer:
+ return new SQLServerDataSourcePropertyParser();
+ default:
+ throw new UnsupportedOperationException(String.format("Cannot support database [%s].", databaseType));
+ }
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourcePropertyManager.java b/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourcePropertyManager.java
new file mode 100644
index 0000000000000..9b374b60fae2b
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourcePropertyManager.java
@@ -0,0 +1,83 @@
+/*
+ * 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.property;
+
+import io.shardingsphere.core.constant.DatabaseType;
+
+import javax.sql.DataSource;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Data source property manager.
+ *
+ * @author panjuan
+ */
+public class DataSourcePropertyManager {
+
+ private final Map dataSourcePropertyMap;
+
+ public DataSourcePropertyManager(final Map dataSourceMap, final DatabaseType databaseType) {
+ dataSourcePropertyMap = initDataSourcePropertyMap(dataSourceMap, databaseType);
+ }
+
+ private Map initDataSourcePropertyMap(final Map dataSourceMap,
+ final DatabaseType databaseType) {
+ Map result = new LinkedHashMap<>();
+ for (Map.Entry each : dataSourceMap.entrySet()) {
+ result.put(each.getKey(), DataSourcePropertyFactory.createDataSourcePropertyParser(databaseType).parseDataSource(each.getValue()));
+ }
+ return result;
+ }
+
+ /**
+ * Get all instance data source names.
+ *
+ * @return instance data source name list
+ */
+ public List getAllInstanceDataSourceNames() {
+ List result = new LinkedList<>();
+ for (Map.Entry each : dataSourcePropertyMap.entrySet()) {
+ if (!isExisted(each.getKey(), result)) {
+ result.add(each.getKey());
+ }
+ }
+ return result;
+ }
+
+ private boolean isExisted(final String dataSourceName, final List existedDataSourceNames) {
+ for (String each : existedDataSourceNames) {
+ if (dataSourcePropertyMap.get(each).isPointAtSameInstance(dataSourcePropertyMap.get(dataSourceName))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get actual schema name.
+ *
+ * @param actualDataSourceName actual data source name
+ * @return actual schema name
+ */
+ public String getActualSchemaName(final String actualDataSourceName) {
+ return dataSourcePropertyMap.get(actualDataSourceName).getSchemeName();
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourcePropertyParser.java b/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourcePropertyParser.java
new file mode 100644
index 0000000000000..b9c6499891426
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/property/DataSourcePropertyParser.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.
+ *
+ * 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.property.dialect;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.exception.ShardingException;
+import io.shardingsphere.core.property.DataSourceProperty;
+import io.shardingsphere.core.property.DataSourcePropertyParser;
+
+import java.net.URI;
+
+/**
+ * H2 data source property parser.
+ *
+ * @author panjuan
+ */
+public final class H2DataSourcePropertyParser extends DataSourcePropertyParser {
+
+ private static final Integer DEFAULT_PORT = -1;
+
+ private static final String DEFAULT_HOST = "localhost";
+
+ @Override
+ protected DataSourceProperty parseJDBCUrl(final String url) {
+ String cleanUrl = url.substring(5);
+ if (cleanUrl.contains("h2:~")) {
+ cleanUrl = cleanUrl.split(";")[0];
+ cleanUrl = cleanUrl.replace(":", "://").replace("~", DEFAULT_HOST);
+ } else if (cleanUrl.contains("h2:mem")) {
+ cleanUrl = cleanUrl.split(";")[0];
+ String[] parts = cleanUrl.split(":");
+ if (3 == parts.length) {
+ cleanUrl = parts[0] + "://" + parts[1] + "/" + parts[2];
+ }
+ } else {
+ throw new ShardingException("The URL of JDBC is not supported.");
+ }
+ URI uri = URI.create(cleanUrl);
+ if (null == uri.getHost()) {
+ throw new ShardingException("The URL of JDBC is not supported.");
+ }
+ return new DataSourceProperty(uri.getHost(), -1 == uri.getPort() ? DEFAULT_PORT : uri.getPort(),
+ uri.getPath().isEmpty() ? "" : uri.getPath().substring(1), DatabaseType.H2);
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/property/dialect/MySQLDataSourcePropertyParser.java b/sharding-core/src/main/java/io/shardingsphere/core/property/dialect/MySQLDataSourcePropertyParser.java
new file mode 100644
index 0000000000000..9589fb20c0a2e
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/property/dialect/MySQLDataSourcePropertyParser.java
@@ -0,0 +1,46 @@
+/*
+ * 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.property.dialect;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.exception.ShardingException;
+import io.shardingsphere.core.property.DataSourceProperty;
+import io.shardingsphere.core.property.DataSourcePropertyParser;
+
+import java.net.URI;
+
+/**
+ * MySQL data source property parser.
+ *
+ * @author panjuan
+ */
+public final class MySQLDataSourcePropertyParser extends DataSourcePropertyParser {
+
+ private static final Integer DEFAULT_PORT = 3306;
+
+ @Override
+ protected DataSourceProperty parseJDBCUrl(final String url) {
+ String cleanUrl = url.substring(5);
+ URI uri = URI.create(cleanUrl);
+ if (null == uri.getHost()) {
+ throw new ShardingException("The URL of JDBC is not supported.");
+ }
+ return new DataSourceProperty(uri.getHost(), -1 == uri.getPort() ? DEFAULT_PORT : uri.getPort(),
+ uri.getPath().isEmpty() ? "" : uri.getPath().substring(1), DatabaseType.MySQL);
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/property/dialect/OracleDataSourcePropertyParser.java b/sharding-core/src/main/java/io/shardingsphere/core/property/dialect/OracleDataSourcePropertyParser.java
new file mode 100644
index 0000000000000..06913db5610ac
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/property/dialect/OracleDataSourcePropertyParser.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.
+ *
+ * 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.property.dialect;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.exception.ShardingException;
+import io.shardingsphere.core.property.DataSourceProperty;
+import io.shardingsphere.core.property.DataSourcePropertyParser;
+
+import java.net.URI;
+
+/**
+ * PostgreSQL data source property parser.
+ *
+ * @author panjuan
+ */
+public final class PostgreSQLDataSourcePropertyParser extends DataSourcePropertyParser {
+
+ private static final Integer DEFAULT_PORT = 5432;
+
+ @Override
+ protected DataSourceProperty parseJDBCUrl(final String url) {
+ String cleanUrl = url.substring(5);
+ URI uri = URI.create(cleanUrl);
+ if (null == uri.getHost()) {
+ throw new ShardingException("The URL of JDBC is not supported.");
+ }
+ return new DataSourceProperty(uri.getHost(), -1 == uri.getPort() ? DEFAULT_PORT : uri.getPort(),
+ uri.getPath().isEmpty() ? "" : uri.getPath().substring(1), DatabaseType.PostgreSQL);
+ }
+}
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/property/dialect/SQLServerDataSourcePropertyParser.java b/sharding-core/src/main/java/io/shardingsphere/core/property/dialect/SQLServerDataSourcePropertyParser.java
new file mode 100644
index 0000000000000..3b6d37ab1cd60
--- /dev/null
+++ b/sharding-core/src/main/java/io/shardingsphere/core/property/dialect/SQLServerDataSourcePropertyParser.java
@@ -0,0 +1,47 @@
+/*
+ * 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.property.dialect;
+
+import io.shardingsphere.core.constant.DatabaseType;
+import io.shardingsphere.core.exception.ShardingException;
+import io.shardingsphere.core.property.DataSourceProperty;
+import io.shardingsphere.core.property.DataSourcePropertyParser;
+
+import java.net.URI;
+
+/**
+ * SQLServer data source property parser.
+ *
+ * @author panjuan
+ */
+public final class SQLServerDataSourcePropertyParser extends DataSourcePropertyParser {
+
+ private static final Integer DEFAULT_PORT = 1433;
+
+ @Override
+ protected DataSourceProperty parseJDBCUrl(final String url) {
+ String cleanUrl = url.substring(5);
+ cleanUrl = cleanUrl.replace("microsoft:", "").replace(";DatabaseName=", "/");
+ URI uri = URI.create(cleanUrl);
+ if (null == uri.getHost()) {
+ throw new ShardingException("The URL of JDBC is not supported.");
+ }
+ return new DataSourceProperty(uri.getHost(), -1 == uri.getPort() ? DEFAULT_PORT : uri.getPort(),
+ uri.getPath().isEmpty() ? "" : uri.getPath().substring(1), DatabaseType.SQLServer);
+ }
+}
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 6fe8c6bafb589..f2bd40d09e471 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
@@ -23,6 +23,7 @@
import io.shardingsphere.core.exception.ShardingException;
import io.shardingsphere.core.optimizer.condition.ShardingCondition;
import io.shardingsphere.core.optimizer.insert.InsertShardingCondition;
+import io.shardingsphere.core.property.DataSourcePropertyManager;
import io.shardingsphere.core.rewrite.placeholder.IndexPlaceholder;
import io.shardingsphere.core.rewrite.placeholder.InsertValuesPlaceholder;
import io.shardingsphere.core.rewrite.placeholder.SchemaPlaceholder;
@@ -42,7 +43,7 @@
/**
* SQL builder.
- *
+ *
* @author gaohongtao
* @author zhangliang
* @author maxiaoguang
@@ -92,9 +93,11 @@ public void appendPlaceholder(final ShardingPlaceholder shardingPlaceholder) {
* @param tableUnit table unit
* @param logicAndActualTableMap logic and actual map
* @param shardingRule sharding rule
+ * @param dataSourcePropertyManager data source property manager
* @return SQL unit
*/
- public SQLUnit toSQL(final TableUnit tableUnit, final Map logicAndActualTableMap, final ShardingRule shardingRule) {
+ public SQLUnit toSQL(final TableUnit tableUnit, final Map logicAndActualTableMap,
+ final ShardingRule shardingRule, final DataSourcePropertyManager dataSourcePropertyManager) {
List