Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
91f74837
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
91f74837
编写于
10月 12, 2020
作者:
L
Liang Zhang
提交者:
GitHub
10月 12, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove SQLStatementContext.isReadOnly (#7746)
上级
858cee60
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
66 deletion
+23
-66
shardingsphere-features/shardingsphere-consensus-replication/shardingsphere-consensus-replication-route/src/main/java/org/apache/shardingsphere/replication/consensus/route/engine/ConsensusReplicationSQLRouter.java
...consensus/route/engine/ConsensusReplicationSQLRouter.java
+16
-15
shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementContext.java
...ingsphere/infra/binder/statement/SQLStatementContext.java
+0
-10
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtil.java
...he/shardingsphere/sql/parser/sql/common/util/SQLUtil.java
+7
-41
未找到文件。
shardingsphere-features/shardingsphere-consensus-replication/shardingsphere-consensus-replication-route/src/main/java/org/apache/shardingsphere/replication/consensus/route/engine/ConsensusReplicationSQLRouter.java
浏览文件 @
91f74837
...
...
@@ -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
replicaRouting
Rule
=
rule
.
getReplicaTableRules
().
iterator
().
next
();
ConsensusReplicationGroup
replicaGroup
=
new
ConsensusReplicationGroup
(
replicaRoutingRule
.
getPhysicsTable
(),
replicaRoutingRule
.
getReplicaGroupId
(),
replicaRoutingRule
.
getReplicaPeers
(),
replicaRouting
Rule
.
getDataSourceName
());
ConsensusReplicationTableRule
table
Rule
=
rule
.
getReplicaTableRules
().
iterator
().
next
();
ConsensusReplicationGroup
replicaGroup
=
new
ConsensusReplicationGroup
(
tableRule
.
getPhysicsTable
(),
tableRule
.
getReplicaGroupId
(),
tableRule
.
getReplicaPeers
(),
table
Rule
.
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
>
replicaRouting
RuleOptional
=
rule
.
findRoutingByTable
(
actualTableName
);
Optional
<
ConsensusReplicationTableRule
>
table
RuleOptional
=
rule
.
findRoutingByTable
(
actualTableName
);
ConsensusReplicationGroup
replicaGroup
;
if
(
replicaRouting
RuleOptional
.
isPresent
())
{
ConsensusReplicationTableRule
replicaRoutingRule
=
replicaRouting
RuleOptional
.
get
();
replicaGroup
=
new
ConsensusReplicationGroup
(
replicaRoutingRule
.
getPhysicsTable
(),
replicaRoutingRule
.
getReplicaGroupId
(),
replicaRoutingRule
.
getReplicaPeers
(),
replicaRouting
Rule
.
getDataSourceName
());
if
(
table
RuleOptional
.
isPresent
())
{
ConsensusReplicationTableRule
tableRule
=
table
RuleOptional
.
get
();
replicaGroup
=
new
ConsensusReplicationGroup
(
tableRule
.
getPhysicsTable
(),
tableRule
.
getReplicaGroupId
(),
tableRule
.
getReplicaPeers
(),
table
Rule
.
getDataSourceName
());
replicaGroups
.
put
(
actualTableName
,
replicaGroup
);
}
else
{
ConsensusReplicationTableRule
replicaRouting
Rule
=
rule
.
getReplicaTableRules
().
iterator
().
next
();
replicaGroup
=
new
ConsensusReplicationGroup
(
replicaRoutingRule
.
getPhysicsTable
(),
replicaRoutingRule
.
getReplicaGroupId
(),
replicaRoutingRule
.
getReplicaPeers
(),
replicaRouting
Rule
.
getDataSourceName
());
ConsensusReplicationTableRule
table
Rule
=
rule
.
getReplicaTableRules
().
iterator
().
next
();
replicaGroup
=
new
ConsensusReplicationGroup
(
tableRule
.
getPhysicsTable
(),
tableRule
.
getReplicaGroupId
(),
tableRule
.
getReplicaPeers
(),
table
Rule
.
getDataSourceName
());
}
replicaGroups
.
put
(
actualTableName
,
replicaGroup
);
}
...
...
shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/SQLStatementContext.java
浏览文件 @
91f74837
...
...
@@ -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
());
}
}
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/util/SQLUtil.java
浏览文件 @
91f74837
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录