未验证 提交 91f74837 编写于 作者: L Liang Zhang 提交者: GitHub

Remove SQLStatementContext.isReadOnly (#7746)

上级 858cee60
......@@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.sql.LogicSQL;
import org.apache.shardingsphere.replication.consensus.constant.ConsensusReplicationOrder;
import org.apache.shardingsphere.replication.consensus.rule.ConsensusReplicationRule;
import org.apache.shardingsphere.replication.consensus.rule.ConsensusReplicationTableRule;
import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil;
import java.util.Collection;
import java.util.Collections;
......@@ -41,12 +42,12 @@ public final class ConsensusReplicationSQLRouter implements SQLRouter<ConsensusR
@Override
public RouteContext createRouteContext(final LogicSQL logicSQL, final ConsensusReplicationRule rule, final ConfigurationProperties props) {
RouteContext result = new RouteContext();
ConsensusReplicationTableRule replicaRoutingRule = rule.getReplicaTableRules().iterator().next();
ConsensusReplicationGroup replicaGroup = new ConsensusReplicationGroup(replicaRoutingRule.getPhysicsTable(), replicaRoutingRule.getReplicaGroupId(), replicaRoutingRule.getReplicaPeers(),
replicaRoutingRule.getDataSourceName());
ConsensusReplicationTableRule tableRule = rule.getReplicaTableRules().iterator().next();
ConsensusReplicationGroup replicaGroup = new ConsensusReplicationGroup(
tableRule.getPhysicsTable(), tableRule.getReplicaGroupId(), tableRule.getReplicaPeers(), tableRule.getDataSourceName());
Map<String, ConsensusReplicationGroup> replicaGroups = Collections.singletonMap(ConsensusReplicationGroup.BLANK_CONSENSUS_REPLICATION_GROUP_KEY, replicaGroup);
result.getRouteStageContexts().put(getTypeClass(),
new ConsensusReplicationRouteStageContext(logicSQL.getSchema().getName(), replicaGroups, logicSQL.getSqlStatementContext().isReadOnly()));
boolean isReadOnly = SQLUtil.isReadOnly(logicSQL.getSqlStatementContext().getSqlStatement());
result.getRouteStageContexts().put(getTypeClass(), new ConsensusReplicationRouteStageContext(logicSQL.getSchema().getName(), replicaGroups, isReadOnly));
return result;
}
......@@ -64,24 +65,24 @@ public final class ConsensusReplicationSQLRouter implements SQLRouter<ConsensusR
routeReplicaGroups(routeMappers, rule, replicaGroups);
}
}
routeContext.getRouteStageContexts().put(getTypeClass(),
new ConsensusReplicationRouteStageContext(logicSQL.getSchema().getName(), replicaGroups, logicSQL.getSqlStatementContext().isReadOnly()));
boolean isReadOnly = SQLUtil.isReadOnly(logicSQL.getSqlStatementContext().getSqlStatement());
routeContext.getRouteStageContexts().put(getTypeClass(), new ConsensusReplicationRouteStageContext(logicSQL.getSchema().getName(), replicaGroups, isReadOnly));
}
private void routeReplicaGroups(final Collection<RouteMapper> routeMappers, final ConsensusReplicationRule rule, final Map<String, ConsensusReplicationGroup> replicaGroups) {
for (RouteMapper each : routeMappers) {
String actualTableName = each.getActualName();
Optional<ConsensusReplicationTableRule> replicaRoutingRuleOptional = rule.findRoutingByTable(actualTableName);
Optional<ConsensusReplicationTableRule> tableRuleOptional = rule.findRoutingByTable(actualTableName);
ConsensusReplicationGroup replicaGroup;
if (replicaRoutingRuleOptional.isPresent()) {
ConsensusReplicationTableRule replicaRoutingRule = replicaRoutingRuleOptional.get();
replicaGroup = new ConsensusReplicationGroup(replicaRoutingRule.getPhysicsTable(), replicaRoutingRule.getReplicaGroupId(), replicaRoutingRule.getReplicaPeers(),
replicaRoutingRule.getDataSourceName());
if (tableRuleOptional.isPresent()) {
ConsensusReplicationTableRule tableRule = tableRuleOptional.get();
replicaGroup = new ConsensusReplicationGroup(
tableRule.getPhysicsTable(), tableRule.getReplicaGroupId(), tableRule.getReplicaPeers(), tableRule.getDataSourceName());
replicaGroups.put(actualTableName, replicaGroup);
} else {
ConsensusReplicationTableRule replicaRoutingRule = rule.getReplicaTableRules().iterator().next();
replicaGroup = new ConsensusReplicationGroup(replicaRoutingRule.getPhysicsTable(), replicaRoutingRule.getReplicaGroupId(), replicaRoutingRule.getReplicaPeers(),
replicaRoutingRule.getDataSourceName());
ConsensusReplicationTableRule tableRule = rule.getReplicaTableRules().iterator().next();
replicaGroup = new ConsensusReplicationGroup(
tableRule.getPhysicsTable(), tableRule.getReplicaGroupId(), tableRule.getReplicaPeers(), tableRule.getDataSourceName());
}
replicaGroups.put(actualTableName, replicaGroup);
}
......
......@@ -19,7 +19,6 @@ package org.apache.shardingsphere.infra.binder.statement;
import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil;
/**
* SQL statement context.
......@@ -41,13 +40,4 @@ public interface SQLStatementContext<T extends SQLStatement> {
* @return tables context
*/
TablesContext getTablesContext();
/**
* Determine whether SQL is read-only.
*
* @return true if read-only, otherwise false
*/
default boolean isReadOnly() {
return SQLUtil.isReadOnly(getSqlStatement());
}
}
......@@ -29,16 +29,7 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.DALStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.DCLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.GrantStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dcl.RevokeStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.AlterTableStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DDLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropIndexStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.DropTableStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.TruncateStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DMLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement;
......@@ -55,7 +46,6 @@ import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQ
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLResetStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLUninstallPluginStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLUseStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.dcl.SQLServerDenyUserStatement;
import java.math.BigDecimal;
import java.math.BigInteger;
......@@ -182,14 +172,14 @@ public final class SQLUtil {
if (sqlStatement instanceof DMLStatement) {
return isReadOnly((DMLStatement) sqlStatement);
}
if (sqlStatement instanceof DALStatement) {
return isReadOnly((DALStatement) sqlStatement);
}
if (sqlStatement instanceof DDLStatement) {
return isReadOnly((DDLStatement) sqlStatement);
return false;
}
if (sqlStatement instanceof DCLStatement) {
return isReadOnly((DCLStatement) sqlStatement);
}
if (sqlStatement instanceof DALStatement) {
return isReadOnly((DALStatement) sqlStatement);
return false;
}
throw new UnsupportedOperationException(String.format("Unsupported SQL Type `%s`", sqlStatement.getClass().getSimpleName()));
}
......@@ -197,35 +187,11 @@ public final class SQLUtil {
private static boolean isReadOnly(final DMLStatement sqlStatement) {
if (sqlStatement instanceof SelectStatement) {
return true;
} else if (sqlStatement instanceof UpdateStatement
| sqlStatement instanceof DeleteStatement
| sqlStatement instanceof InsertStatement) {
return false;
}
throw new UnsupportedOperationException(String.format("Unsupported SQL Type `%s`", sqlStatement.getClass().getSimpleName()));
}
private static boolean isReadOnly(final DDLStatement sqlStatement) {
if (sqlStatement instanceof CreateTableStatement
| sqlStatement instanceof AlterTableStatement
| sqlStatement instanceof DropTableStatement
| sqlStatement instanceof CreateIndexStatement
| sqlStatement instanceof AlterIndexStatement
| sqlStatement instanceof DropIndexStatement
| sqlStatement instanceof TruncateStatement
| sqlStatement instanceof AlterTableStatement) {
return false;
}
return false;
}
private static boolean isReadOnly(final DCLStatement sqlStatement) {
if (sqlStatement instanceof GrantStatement
| sqlStatement instanceof RevokeStatement
| sqlStatement instanceof SQLServerDenyUserStatement) {
if (sqlStatement instanceof UpdateStatement || sqlStatement instanceof DeleteStatement || sqlStatement instanceof InsertStatement) {
return false;
}
return false;
throw new UnsupportedOperationException(String.format("Unsupported SQL Type `%s`", sqlStatement.getClass().getSimpleName()));
}
private static boolean isReadOnly(final DALStatement sqlStatement) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册