This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 291a78d Use generic type for ShardingStatementValidator
new a2c64ce Merge pull request #7461 from terrymanu/dev
291a78d is described below
commit 291a78db3222a7b5da15ab63701deecba6da25d3
Author: terrymanu <[email protected]>
AuthorDate: Tue Sep 15 17:15:58 2020 +0800
Use generic type for ShardingStatementValidator
---
.../sharding/route/engine/ShardingRouteDecorator.java | 12 ++++++------
.../route/engine/validator/ShardingStatementValidator.java | 4 ++--
.../impl/ShardingCreateTableStatementValidator.java | 5 ++---
.../validator/impl/ShardingDeleteStatementValidator.java | 11 +++++------
.../validator/impl/ShardingInsertStatementValidator.java | 9 ++++-----
.../validator/impl/ShardingUpdateStatementValidator.java | 7 +++----
.../shardingsphere/infra/route/context/RouteContext.java | 10 +++++-----
7 files changed, 27 insertions(+), 31 deletions(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingRouteDecorator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingRouteDecorator.java
index 388feee..721a266 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingRouteDecorator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/ShardingRouteDecorator.java
@@ -57,10 +57,10 @@ import java.util.Optional;
*/
public final class ShardingRouteDecorator implements
RouteDecorator<ShardingRule> {
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"rawtypes", "unchecked"})
@Override
public RouteContext decorate(final RouteContext routeContext, final
ShardingSphereMetaData metaData, final ShardingRule shardingRule, final
ConfigurationProperties props) {
- SQLStatementContext sqlStatementContext =
routeContext.getSqlStatementContext();
+ SQLStatementContext<?> sqlStatementContext =
routeContext.getSqlStatementContext();
List<Object> parameters = routeContext.getParameters();
SQLStatement sqlStatement = sqlStatementContext.getSqlStatement();
Optional<ShardingStatementValidator> shardingStatementValidator =
ShardingStatementValidatorFactory.newInstance(sqlStatement);
@@ -77,8 +77,8 @@ public final class ShardingRouteDecorator implements
RouteDecorator<ShardingRule
return new RouteContext(routeContext, routeResult, new
DefaultRouteStageContext(), getTypeClass());
}
- private ShardingConditions getShardingConditions(final List<Object>
parameters, final SQLStatementContext sqlStatementContext,
- final SchemaMetaData
schemaMetaData, final ShardingRule shardingRule) {
+ private ShardingConditions getShardingConditions(final List<Object>
parameters,
+ final
SQLStatementContext<?> sqlStatementContext, final SchemaMetaData
schemaMetaData, final ShardingRule shardingRule) {
if (sqlStatementContext.getSqlStatement() instanceof DMLStatement) {
if (sqlStatementContext instanceof InsertStatementContext) {
return new ShardingConditions(new
InsertClauseShardingConditionEngine(shardingRule,
schemaMetaData).createShardingConditions((InsertStatementContext)
sqlStatementContext, parameters));
@@ -88,14 +88,14 @@ public final class ShardingRouteDecorator implements
RouteDecorator<ShardingRule
return new ShardingConditions(Collections.emptyList());
}
- private boolean isNeedMergeShardingValues(final SQLStatementContext
sqlStatementContext, final ShardingRule shardingRule) {
+ private boolean isNeedMergeShardingValues(final SQLStatementContext<?>
sqlStatementContext, final ShardingRule shardingRule) {
boolean selectContainsSubquery = sqlStatementContext instanceof
SelectStatementContext && ((SelectStatementContext)
sqlStatementContext).isContainsSubquery();
boolean insertSelectContainsSubquery = sqlStatementContext instanceof
InsertStatementContext && null != ((InsertStatementContext)
sqlStatementContext).getInsertSelectContext()
&& ((InsertStatementContext)
sqlStatementContext).getInsertSelectContext().getSelectStatementContext().isContainsSubquery();
return (selectContainsSubquery || insertSelectContainsSubquery) &&
!shardingRule.getShardingLogicTableNames(sqlStatementContext.getTablesContext().getTableNames()).isEmpty();
}
- private void checkSubqueryShardingValues(final SQLStatementContext
sqlStatementContext, final ShardingRule shardingRule, final ShardingConditions
shardingConditions) {
+ private void checkSubqueryShardingValues(final SQLStatementContext<?>
sqlStatementContext, final ShardingRule shardingRule, final ShardingConditions
shardingConditions) {
for (String each :
sqlStatementContext.getTablesContext().getTableNames()) {
Optional<TableRule> tableRule = shardingRule.findTableRule(each);
if (tableRule.isPresent() && isRoutingByHint(shardingRule,
tableRule.get())
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ShardingStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ShardingStatementValidator.java
index b6f731a..de4cb2e 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ShardingStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ShardingStatementValidator.java
@@ -38,12 +38,12 @@ public interface ShardingStatementValidator<T extends
SQLStatement> {
* @param metaData meta data
*/
void preValidate(ShardingRule shardingRule, RouteContext routeContext,
ShardingSphereMetaData metaData);
-
+
/**
* Validate whether sharding operation is supported after route.
*
* @param sqlStatement SQL statement
* @param routeResult route result
*/
- void postValidate(SQLStatement sqlStatement, RouteResult routeResult);
+ void postValidate(T sqlStatement, RouteResult routeResult);
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingCreateTableStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingCreateTableStatementValidator.java
index 4afccfe..5d13437 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingCreateTableStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingCreateTableStatementValidator.java
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.sharding.route.engine.exception.TableExistsExce
import
org.apache.shardingsphere.sharding.route.engine.validator.ShardingStatementValidator;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.binder.statement.ddl.CreateTableStatementContext;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.MySQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.ddl.MySQLCreateTableStatement;
@@ -46,9 +45,9 @@ public final class ShardingCreateTableStatementValidator
implements ShardingStat
}
@Override
- public void postValidate(final SQLStatement sqlStatement, final
RouteResult routeResult) {
+ public void postValidate(final CreateTableStatement sqlStatement, final
RouteResult routeResult) {
}
-
+
private boolean containsNotExistClause(final CreateTableStatement
sqlStatement) {
return (sqlStatement instanceof MySQLStatement &&
((MySQLCreateTableStatement) sqlStatement).isNotExisted())
|| (sqlStatement instanceof PostgreSQLStatement &&
((PostgreSQLCreateTableStatement) sqlStatement).isNotExisted());
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingDeleteStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingDeleteStatementValidator.java
index 5297e89..221db99 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingDeleteStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingDeleteStatementValidator.java
@@ -25,25 +25,24 @@ import
org.apache.shardingsphere.sharding.route.engine.validator.ShardingStateme
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.sql.parser.binder.type.TableAvailable;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement;
/**
* Sharding delete statement validator.
*/
public final class ShardingDeleteStatementValidator implements
ShardingStatementValidator<DeleteStatement> {
-
+
@Override
public void preValidate(final ShardingRule shardingRule, final
RouteContext routeContext, final ShardingSphereMetaData metaData) {
- SQLStatementContext sqlStatementContext =
routeContext.getSqlStatementContext();
+ SQLStatementContext<?> sqlStatementContext =
routeContext.getSqlStatementContext();
if (1 != ((TableAvailable) sqlStatementContext).getAllTables().size())
{
throw new ShardingSphereException("Cannot support Multiple-Table
for '%s'.", sqlStatementContext.getSqlStatement());
}
}
-
+
@Override
- public void postValidate(final SQLStatement sqlStatement, final
RouteResult routeResult) {
- if (((DeleteStatement) sqlStatement).getLimit().isPresent() &&
routeResult.getRouteUnits().size() > 1) {
+ public void postValidate(final DeleteStatement sqlStatement, final
RouteResult routeResult) {
+ if (sqlStatement.getLimit().isPresent() &&
routeResult.getRouteUnits().size() > 1) {
throw new ShardingSphereException("DELETE ... LIMIT can not
support sharding route to multiple data nodes.");
}
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingInsertStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingInsertStatementValidator.java
index f386815..19e3cd0 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingInsertStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingInsertStatementValidator.java
@@ -31,7 +31,6 @@ import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.assignment.As
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.OnDuplicateKeyColumnsSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.subquery.SubquerySegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
import java.util.Collection;
@@ -44,7 +43,7 @@ public final class ShardingInsertStatementValidator
implements ShardingStatement
@Override
public void preValidate(final ShardingRule shardingRule, final
RouteContext routeContext, final ShardingSphereMetaData metaData) {
- SQLStatementContext sqlStatementContext =
routeContext.getSqlStatementContext();
+ SQLStatementContext<?> sqlStatementContext =
routeContext.getSqlStatementContext();
if (null == ((InsertStatementContext)
sqlStatementContext).getInsertSelectContext() && 1 != ((TableAvailable)
sqlStatementContext).getTablesContext().getTables().size()) {
throw new ShardingSphereException("Cannot support Multiple-Table
for '%s'.", sqlStatementContext.getSqlStatement());
}
@@ -64,11 +63,11 @@ public final class ShardingInsertStatementValidator
implements ShardingStatement
throw new ShardingSphereException("The table inserted and the
table selected must be the same or bind tables.");
}
}
-
+
@Override
- public void postValidate(final SQLStatement sqlStatement, final
RouteResult routeResult) {
+ public void postValidate(final InsertStatement sqlStatement, final
RouteResult routeResult) {
}
-
+
private boolean isUpdateShardingKey(final ShardingRule shardingRule, final
OnDuplicateKeyColumnsSegment onDuplicateKeyColumnsSegment, final String
tableName) {
for (AssignmentSegment each :
onDuplicateKeyColumnsSegment.getColumns()) {
if
(shardingRule.isShardingColumn(each.getColumn().getIdentifier().getValue(),
tableName)) {
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingUpdateStatementValidator.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingUpdateStatementValidator.java
index 08b4b5a..2bf9dac 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingUpdateStatementValidator.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/impl/ShardingUpdateStatementValidator.java
@@ -34,7 +34,6 @@ import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.ListExpr
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.LiteralExpressionSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.expr.simple.ParameterMarkerExpressionSegment;
import
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.WhereSegment;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement;
import java.util.List;
@@ -47,7 +46,7 @@ public final class ShardingUpdateStatementValidator
implements ShardingStatement
@Override
public void preValidate(final ShardingRule shardingRule, final
RouteContext routeContext, final ShardingSphereMetaData metaData) {
- SQLStatementContext sqlStatementContext =
routeContext.getSqlStatementContext();
+ SQLStatementContext<?> sqlStatementContext =
routeContext.getSqlStatementContext();
if (1 != ((TableAvailable) sqlStatementContext).getAllTables().size())
{
throw new ShardingSphereException("Cannot support Multiple-Table
for '%s'.", sqlStatementContext.getSqlStatement());
}
@@ -71,8 +70,8 @@ public final class ShardingUpdateStatementValidator
implements ShardingStatement
}
@Override
- public void postValidate(final SQLStatement sqlStatement, final
RouteResult routeResult) {
- if (((UpdateStatement) sqlStatement).getLimit().isPresent() &&
routeResult.getRouteUnits().size() > 1) {
+ public void postValidate(final UpdateStatement sqlStatement, final
RouteResult routeResult) {
+ if (sqlStatement.getLimit().isPresent() &&
routeResult.getRouteUnits().size() > 1) {
throw new ShardingSphereException("UPDATE ... LIMIT can not
support sharding route to multiple data nodes.");
}
}
diff --git
a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/context/RouteContext.java
b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/context/RouteContext.java
index 417ad0c..9e00efe 100644
---
a/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/context/RouteContext.java
+++
b/shardingsphere-infra/shardingsphere-infra-route/src/main/java/org/apache/shardingsphere/infra/route/context/RouteContext.java
@@ -42,8 +42,8 @@ public final class RouteContext {
private final Map<Class<? extends ShardingSphereRule>, RouteStageContext>
routeStageContexts = new LinkedHashMap<>();
public RouteContext(final RouteContext parent, final RouteResult
routeResult, final RouteStageContext nextRouteStageContext, final Class<?
extends ShardingSphereRule> ruleType) {
- this(parent.getSqlStatementContext(), parent.getParameters(),
routeResult);
- addBeforeRouteStageContexts(parent.getRouteStageContexts());
+ this(parent.sqlStatementContext, parent.parameters, routeResult);
+ addBeforeRouteStageContexts(parent.routeStageContexts);
addNextRouteStageContext(ruleType, nextRouteStageContext);
}
@@ -53,7 +53,7 @@ public final class RouteContext {
* @param beforeRouteStageContexts before route stage contexts
*/
public void addBeforeRouteStageContexts(final Map<Class<? extends
ShardingSphereRule>, RouteStageContext> beforeRouteStageContexts) {
- getRouteStageContexts().putAll(beforeRouteStageContexts);
+ routeStageContexts.putAll(beforeRouteStageContexts);
}
/**
@@ -63,7 +63,7 @@ public final class RouteContext {
* @param nextRouteStageContext next route stage contexts
*/
public void addNextRouteStageContext(final Class<? extends
ShardingSphereRule> ruleType, final RouteStageContext nextRouteStageContext) {
- getRouteStageContexts().put(ruleType, nextRouteStageContext);
+ routeStageContexts.put(ruleType, nextRouteStageContext);
}
/**
@@ -73,6 +73,6 @@ public final class RouteContext {
* @return route stage context
*/
public RouteStageContext getRouteStageContext(final Class<? extends
ShardingSphereRule> ruleType) {
- return getRouteStageContexts().get(ruleType);
+ return routeStageContexts.get(ruleType);
}
}