Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
9d3dab10
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 搜索 >>
未验证
提交
9d3dab10
编写于
9月 09, 2020
作者:
L
Liang Zhang
提交者:
GitHub
9月 09, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename ProxyContext (#7335)
* Rename ProxySchemaContexts.getAllSchemaNames * Rename ProxyContext
上级
572be6ae
变更
61
隐藏空白更改
内联
并排
Showing
61 changed file
with
207 addition
and
204 deletion
+207
-204
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dal/common/SingleLocalDataMergedResult.java
...harding/merge/dal/common/SingleLocalDataMergedResult.java
+1
-0
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
...end/communication/DatabaseCommunicationEngineFactory.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
...d/communication/jdbc/JDBCDatabaseCommunicationEngine.java
+9
-9
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnection.java
...kend/communication/jdbc/connection/BackendConnection.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManager.java
...munication/jdbc/connection/BackendTransactionManager.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/engine/jdbc/JDBCExecuteEngine.java
...unication/jdbc/execute/engine/jdbc/JDBCExecuteEngine.java
+4
-4
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/engine/jdbc/ProxySQLExecutorCallback.java
...on/jdbc/execute/engine/jdbc/ProxySQLExecutorCallback.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/PreparedStatementExecutorWrapper.java
...cation/jdbc/wrapper/PreparedStatementExecutorWrapper.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/StatementExecutorWrapper.java
.../communication/jdbc/wrapper/StatementExecutorWrapper.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/executor/BackendExecutorContext.java
...sphere/proxy/backend/executor/BackendExecutorContext.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/ProxyContext.java
...che/shardingsphere/proxy/backend/schema/ProxyContext.java
+16
-16
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/datasource/impl/JDBCBackendDataSource.java
...backend/schema/datasource/impl/JDBCBackendDataSource.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandler.java
...ere/proxy/backend/text/admin/BroadcastBackendHandler.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandler.java
...ingsphere/proxy/backend/text/admin/RDLBackendHandler.java
+5
-5
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/ShowDatabasesBackendHandler.java
...proxy/backend/text/admin/ShowDatabasesBackendHandler.java
+4
-5
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/ShowTablesBackendHandler.java
...re/proxy/backend/text/admin/ShowTablesBackendHandler.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/UnicastBackendHandler.java
...phere/proxy/backend/text/admin/UnicastBackendHandler.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/UseDatabaseBackendHandler.java
...e/proxy/backend/text/admin/UseDatabaseBackendHandler.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/query/QueryBackendHandler.java
...gsphere/proxy/backend/text/query/QueryBackendHandler.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandler.java
...d/text/sctl/explain/ShardingCTLExplainBackendHandler.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/internal/executor/HintShowTableStatusExecutor.java
...l/hint/internal/executor/HintShowTableStatusExecutor.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java
.../proxy/backend/TextProtocolBackendHandlerFactoryTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/DatabaseCommunicationEngineFactoryTest.java
...nication/jdbc/DatabaseCommunicationEngineFactoryTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
.../communication/jdbc/connection/BackendConnectionTest.java
+9
-9
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManagerTest.java
...cation/jdbc/connection/BackendTransactionManagerTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java
...munication/jdbc/datasource/JDBCBackendDataSourceTest.java
+9
-9
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/schema/ProxyContextTest.java
...shardingsphere/proxy/backend/schema/ProxyContextTest.java
+4
-4
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandlerTest.java
...proxy/backend/text/admin/BroadcastBackendHandlerTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandlerTest.java
...phere/proxy/backend/text/admin/RDLBackendHandlerTest.java
+6
-6
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/ShowDatabasesBackendHandlerTest.java
...y/backend/text/admin/ShowDatabasesBackendHandlerTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/ShowTablesBackendHandlerTest.java
...roxy/backend/text/admin/ShowTablesBackendHandlerTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/UnicastBackendHandlerTest.java
...e/proxy/backend/text/admin/UnicastBackendHandlerTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/UseDatabaseBackendHandlerTest.java
...oxy/backend/text/admin/UseDatabaseBackendHandlerTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
...xt/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
...end/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/set/ShardingCTLSetBackendHandlerTest.java
...ckend/text/sctl/set/ShardingCTLSetBackendHandlerTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/init/impl/AbstractBootstrapInitializer.java
...gsphere/proxy/init/impl/AbstractBootstrapInitializer.java
+4
-4
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/executor/UserExecutorGroup.java
...dingsphere/proxy/frontend/executor/UserExecutorGroup.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
...e/proxy/frontend/netty/FrontendChannelInboundHandler.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/ServerHandlerInitializer.java
...sphere/proxy/frontend/netty/ServerHandlerInitializer.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationEngine.java
.../proxy/frontend/mysql/auth/MySQLAuthenticationEngine.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandler.java
...proxy/frontend/mysql/auth/MySQLAuthenticationHandler.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
...oxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/initdb/MySQLComInitDbExecutor.java
...nd/mysql/command/admin/initdb/MySQLComInitDbExecutor.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
...and/query/binary/execute/MySQLComStmtExecuteExecutor.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
...and/query/binary/prepare/MySQLComStmtPrepareExecutor.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
...query/text/fieldlist/MySQLComFieldListPacketExecutor.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
...command/query/text/query/MySQLComQueryPacketExecutor.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
...gsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
+5
-5
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationEngineTest.java
...xy/frontend/mysql/auth/MySQLAuthenticationEngineTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
...y/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
+5
-5
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
...ontend/mysql/command/MySQLCommandExecutorFactoryTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
...query/binary/execute/MySQLComStmtExecuteExecutorTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java
...ntend/postgresql/auth/PostgreSQLAuthenticationEngine.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationHandler.java
...tend/postgresql/auth/PostgreSQLAuthenticationHandler.java
+6
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java
...nd/postgresql/command/PostgreSQLCommandExecuteEngine.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutor.java
.../command/query/binary/bind/PostgreSQLComBindExecutor.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/parse/PostgreSQLComParseExecutor.java
...ommand/query/binary/parse/PostgreSQLComParseExecutor.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutor.java
...gresql/command/query/text/PostgreSQLComQueryExecutor.java
+2
-2
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
...d/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
+3
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutorTest.java
...mand/query/binary/bind/PostgreSQLComBindExecutorTest.java
+3
-3
未找到文件。
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-merge/src/main/java/org/apache/shardingsphere/sharding/merge/dal/common/SingleLocalDataMergedResult.java
浏览文件 @
9d3dab10
...
...
@@ -39,6 +39,7 @@ public final class SingleLocalDataMergedResult implements MergedResult {
this
.
values
=
values
.
iterator
();
}
@Override
public
boolean
next
()
{
if
(
values
.
hasNext
())
{
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
浏览文件 @
9d3dab10
...
...
@@ -25,7 +25,7 @@ import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.Bac
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.engine.jdbc.JDBCExecuteEngine
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.wrapper.PreparedStatementExecutorWrapper
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.wrapper.StatementExecutorWrapper
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
import
java.util.List
;
...
...
@@ -56,7 +56,7 @@ public final class DatabaseCommunicationEngineFactory {
* @return instance of text protocol backend handler
*/
public
DatabaseCommunicationEngine
newTextProtocolInstance
(
final
SQLStatement
sqlStatement
,
final
String
sql
,
final
BackendConnection
backendConnection
)
{
SchemaContext
schema
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
SchemaContext
schema
=
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
return
new
JDBCDatabaseCommunicationEngine
(
sql
,
backendConnection
,
new
JDBCExecuteEngine
(
backendConnection
,
new
StatementExecutorWrapper
(
schema
,
sqlStatement
)));
}
...
...
@@ -70,7 +70,7 @@ public final class DatabaseCommunicationEngineFactory {
* @return instance of text protocol backend handler
*/
public
DatabaseCommunicationEngine
newBinaryProtocolInstance
(
final
SQLStatement
sqlStatement
,
final
String
sql
,
final
List
<
Object
>
parameters
,
final
BackendConnection
backendConnection
)
{
SchemaContext
schema
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
SchemaContext
schema
=
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
return
new
JDBCDatabaseCommunicationEngine
(
sql
,
backendConnection
,
new
JDBCExecuteEngine
(
backendConnection
,
new
PreparedStatementExecutorWrapper
(
schema
,
sqlStatement
,
parameters
)));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
浏览文件 @
9d3dab10
...
...
@@ -43,7 +43,7 @@ import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.sharding.route.engine.exception.TableExistsException
;
import
org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData
;
import
org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext
;
...
...
@@ -79,7 +79,7 @@ public final class JDBCDatabaseCommunicationEngine implements DatabaseCommunicat
this
.
sql
=
sql
;
connection
=
backendConnection
;
executeEngine
=
sqlExecuteEngine
;
schema
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
schema
=
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
}
@Override
...
...
@@ -95,8 +95,8 @@ public final class JDBCDatabaseCommunicationEngine implements DatabaseCommunicat
}
private
void
logSQL
(
final
ExecutionContext
executionContext
)
{
if
(
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getProps
().<
Boolean
>
getValue
(
ConfigurationPropertyKey
.
SQL_SHOW
))
{
SQLLogger
.
logSQL
(
sql
,
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getProps
().<
Boolean
>
getValue
(
ConfigurationPropertyKey
.
SQL_SIMPLE
),
executionContext
);
if
(
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getProps
().<
Boolean
>
getValue
(
ConfigurationPropertyKey
.
SQL_SHOW
))
{
SQLLogger
.
logSQL
(
sql
,
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getProps
().<
Boolean
>
getValue
(
ConfigurationPropertyKey
.
SQL_SIMPLE
),
executionContext
);
}
}
...
...
@@ -131,7 +131,7 @@ public final class JDBCDatabaseCommunicationEngine implements DatabaseCommunicat
}
Optional
<
MetaDataRefreshStrategy
>
refreshStrategy
=
MetaDataRefreshStrategyFactory
.
newInstance
(
sqlStatementContext
);
if
(
refreshStrategy
.
isPresent
())
{
refreshStrategy
.
get
().
refreshMetaData
(
schema
.
getSchema
().
getMetaData
(),
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getDatabaseType
(),
refreshStrategy
.
get
().
refreshMetaData
(
schema
.
getSchema
().
getMetaData
(),
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getDatabaseType
(),
schema
.
getSchema
().
getDataSources
(),
sqlStatementContext
,
this
::
loadTableMetaData
);
ShardingSphereEventBus
.
getInstance
().
post
(
new
MetaDataPersistEvent
(
schema
.
getName
(),
schema
.
getSchema
().
getMetaData
().
getSchema
()));
}
...
...
@@ -139,8 +139,8 @@ public final class JDBCDatabaseCommunicationEngine implements DatabaseCommunicat
private
Optional
<
TableMetaData
>
loadTableMetaData
(
final
String
tableName
)
throws
SQLException
{
RuleSchemaMetaDataLoader
loader
=
new
RuleSchemaMetaDataLoader
(
schema
.
getSchema
().
getRules
());
return
loader
.
load
(
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getDatabaseType
(),
schema
.
getSchema
().
getDataSources
(),
tableName
,
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getProps
());
return
loader
.
load
(
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getDatabaseType
(),
schema
.
getSchema
().
getDataSources
(),
tableName
,
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getProps
());
}
private
BackendResponse
merge
(
final
SQLStatementContext
<?>
sqlStatementContext
)
throws
SQLException
{
...
...
@@ -164,8 +164,8 @@ public final class JDBCDatabaseCommunicationEngine implements DatabaseCommunicat
}
private
MergedResult
mergeQuery
(
final
SQLStatementContext
<?>
sqlStatementContext
,
final
List
<
QueryResult
>
queryResults
)
throws
SQLException
{
MergeEngine
mergeEngine
=
new
MergeEngine
(
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getDatabaseType
(),
schema
.
getSchema
().
getMetaData
().
getSchema
().
getConfiguredSchemaMetaData
(),
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getProps
(),
schema
.
getSchema
().
getRules
());
MergeEngine
mergeEngine
=
new
MergeEngine
(
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getDatabaseType
(),
schema
.
getSchema
().
getMetaData
().
getSchema
().
getConfiguredSchemaMetaData
(),
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getProps
(),
schema
.
getSchema
().
getRules
());
return
mergeEngine
.
merge
(
queryResults
,
sqlStatementContext
);
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnection.java
浏览文件 @
9d3dab10
...
...
@@ -33,7 +33,7 @@ import org.apache.shardingsphere.infra.executor.sql.ConnectionMode;
import
org.apache.shardingsphere.infra.executor.sql.resourced.jdbc.connection.JDBCExecutionConnection
;
import
org.apache.shardingsphere.infra.executor.sql.resourced.jdbc.group.StatementOption
;
import
org.apache.shardingsphere.masterslave.route.engine.impl.MasterVisitedManager
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.transaction.core.TransactionType
;
import
java.sql.Connection
;
...
...
@@ -188,7 +188,7 @@ public final class BackendConnection implements JDBCExecutionConnection, AutoClo
}
private
List
<
Connection
>
getConnectionFromUnderlying
(
final
String
dataSourceName
,
final
int
connectionSize
,
final
ConnectionMode
connectionMode
)
throws
SQLException
{
return
Proxy
SchemaContexts
.
getInstance
().
getBackendDataSource
().
getConnections
(
schema
,
dataSourceName
,
connectionSize
,
connectionMode
);
return
Proxy
Context
.
getInstance
().
getBackendDataSource
().
getConnections
(
schema
,
dataSourceName
,
connectionSize
,
connectionMode
);
}
@Override
...
...
@@ -220,7 +220,7 @@ public final class BackendConnection implements JDBCExecutionConnection, AutoClo
}
private
void
setFetchSize
(
final
Statement
statement
)
throws
SQLException
{
DatabaseType
databaseType
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getDatabaseType
();
DatabaseType
databaseType
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getDatabaseType
();
if
(
databaseType
instanceof
MySQLDatabaseType
)
{
statement
.
setFetchSize
(
MYSQL_MEMORY_FETCH_ONE_ROW_A_TIME
);
}
else
if
(
databaseType
instanceof
PostgreSQLDatabaseType
)
{
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManager.java
浏览文件 @
9d3dab10
...
...
@@ -17,7 +17,7 @@
package
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine
;
import
org.apache.shardingsphere.transaction.core.TransactionType
;
import
org.apache.shardingsphere.transaction.spi.ShardingTransactionManager
;
...
...
@@ -41,7 +41,7 @@ public final class BackendTransactionManager implements TransactionManager {
connection
=
backendConnection
;
transactionType
=
connection
.
getTransactionType
();
localTransactionManager
=
new
LocalTransactionManager
(
backendConnection
);
ShardingTransactionManagerEngine
engine
=
Proxy
SchemaContexts
.
getInstance
().
getTransactionContexts
().
getEngines
().
get
(
connection
.
getSchema
());
ShardingTransactionManagerEngine
engine
=
Proxy
Context
.
getInstance
().
getTransactionContexts
().
getEngines
().
get
(
connection
.
getSchema
());
shardingTransactionManager
=
null
==
engine
?
null
:
engine
.
getTransactionManager
(
transactionType
);
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/engine/jdbc/JDBCExecuteEngine.java
浏览文件 @
9d3dab10
...
...
@@ -43,7 +43,7 @@ import org.apache.shardingsphere.proxy.backend.executor.BackendExecutorContext;
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.DeleteStatement
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.InsertStatement
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.UpdateStatement
;
...
...
@@ -100,14 +100,14 @@ public final class JDBCExecuteEngine implements SQLExecuteEngine {
}
private
Collection
<
ExecuteResult
>
execute
(
final
ExecutionContext
executionContext
,
final
boolean
isReturnGeneratedKeys
,
final
boolean
isExceptionThrown
)
throws
SQLException
{
int
maxConnectionsSizePerQuery
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getProps
().<
Integer
>
getValue
(
ConfigurationPropertyKey
.
MAX_CONNECTIONS_SIZE_PER_QUERY
);
int
maxConnectionsSizePerQuery
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getProps
().<
Integer
>
getValue
(
ConfigurationPropertyKey
.
MAX_CONNECTIONS_SIZE_PER_QUERY
);
return
ExecutorConstant
.
MANAGED_RESOURCE
?
executeWithManagedResource
(
executionContext
,
maxConnectionsSizePerQuery
,
isReturnGeneratedKeys
,
isExceptionThrown
)
:
executeWithUnmanagedResource
(
executionContext
,
maxConnectionsSizePerQuery
);
}
private
Collection
<
ExecuteResult
>
executeWithManagedResource
(
final
ExecutionContext
executionContext
,
final
int
maxConnectionsSizePerQuery
,
final
boolean
isReturnGeneratedKeys
,
final
boolean
isExceptionThrown
)
throws
SQLException
{
DatabaseType
databaseType
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getDatabaseType
();
DatabaseType
databaseType
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getDatabaseType
();
return
sqlExecutor
.
execute
(
generateInputGroups
(
executionContext
.
getExecutionUnits
(),
maxConnectionsSizePerQuery
,
isReturnGeneratedKeys
),
new
ProxySQLExecutorCallback
(
databaseType
,
executionContext
.
getSqlStatementContext
(),
backendConnection
,
jdbcExecutorWrapper
,
isExceptionThrown
,
isReturnGeneratedKeys
,
true
),
new
ProxySQLExecutorCallback
(
databaseType
,
executionContext
.
getSqlStatementContext
(),
backendConnection
,
jdbcExecutorWrapper
,
isExceptionThrown
,
isReturnGeneratedKeys
,
false
));
...
...
@@ -121,7 +121,7 @@ public final class JDBCExecuteEngine implements SQLExecuteEngine {
}
private
Collection
<
ExecuteResult
>
executeWithUnmanagedResource
(
final
ExecutionContext
executionContext
,
final
int
maxConnectionsSizePerQuery
)
throws
SQLException
{
Collection
<
ShardingSphereRule
>
rules
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()).
getSchema
().
getRules
();
Collection
<
ShardingSphereRule
>
rules
=
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()).
getSchema
().
getRules
();
Collection
<
InputGroup
<
RawSQLExecuteUnit
>>
inputGroups
=
new
RawExecuteGroupEngine
(
maxConnectionsSizePerQuery
,
rules
).
generate
(
executionContext
.
getExecutionUnits
());
// TODO handle query header
return
rawExecutor
.
execute
(
inputGroups
,
new
RawSQLExecutorCallback
());
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/engine/jdbc/ProxySQLExecutorCallback.java
浏览文件 @
9d3dab10
...
...
@@ -30,7 +30,7 @@ import org.apache.shardingsphere.infra.executor.sql.resourced.jdbc.queryresult.S
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.wrapper.JDBCExecutorWrapper
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryHeaderBuilder
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.sql.parser.binder.segment.select.projection.ProjectionsContext
;
import
org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext
;
import
org.apache.shardingsphere.sql.parser.binder.statement.dml.SelectStatementContext
;
...
...
@@ -99,7 +99,7 @@ public final class ProxySQLExecutorCallback extends DefaultSQLExecutorCallback<E
private
List
<
QueryHeader
>
getQueryHeaders
(
final
ProjectionsContext
projectionsContext
,
final
ResultSetMetaData
resultSetMetaData
)
throws
SQLException
{
List
<
QueryHeader
>
result
=
new
LinkedList
<>();
for
(
int
columnIndex
=
1
;
columnIndex
<=
projectionsContext
.
getExpandProjections
().
size
();
columnIndex
++)
{
result
.
add
(
QueryHeaderBuilder
.
build
(
projectionsContext
,
resultSetMetaData
,
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()),
columnIndex
));
result
.
add
(
QueryHeaderBuilder
.
build
(
projectionsContext
,
resultSetMetaData
,
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()),
columnIndex
));
}
return
result
;
}
...
...
@@ -107,7 +107,7 @@ public final class ProxySQLExecutorCallback extends DefaultSQLExecutorCallback<E
private
List
<
QueryHeader
>
getQueryHeaders
(
final
ResultSetMetaData
resultSetMetaData
)
throws
SQLException
{
List
<
QueryHeader
>
result
=
new
LinkedList
<>();
for
(
int
columnIndex
=
1
;
columnIndex
<=
resultSetMetaData
.
getColumnCount
();
columnIndex
++)
{
result
.
add
(
QueryHeaderBuilder
.
build
(
resultSetMetaData
,
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()),
columnIndex
));
result
.
add
(
QueryHeaderBuilder
.
build
(
resultSetMetaData
,
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()),
columnIndex
));
}
return
result
;
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/PreparedStatementExecutorWrapper.java
浏览文件 @
9d3dab10
...
...
@@ -32,7 +32,7 @@ import org.apache.shardingsphere.infra.route.DataNodeRouter;
import
org.apache.shardingsphere.infra.route.context.RouteContext
;
import
org.apache.shardingsphere.infra.rule.ShardingSphereRule
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.sql.parser.binder.statement.CommonSQLStatementContext
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
...
...
@@ -49,7 +49,7 @@ import java.util.List;
@RequiredArgsConstructor
public
final
class
PreparedStatementExecutorWrapper
implements
JDBCExecutorWrapper
{
private
static
final
Proxy
SchemaContexts
PROXY_SCHEMA_CONTEXTS
=
ProxySchemaContexts
.
getInstance
();
private
static
final
Proxy
Context
PROXY_SCHEMA_CONTEXTS
=
ProxyContext
.
getInstance
();
private
final
SchemaContext
schema
;
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/wrapper/StatementExecutorWrapper.java
浏览文件 @
9d3dab10
...
...
@@ -31,7 +31,7 @@ import org.apache.shardingsphere.infra.route.DataNodeRouter;
import
org.apache.shardingsphere.infra.route.context.RouteContext
;
import
org.apache.shardingsphere.infra.rule.ShardingSphereRule
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.sql.parser.binder.statement.CommonSQLStatementContext
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
...
...
@@ -46,7 +46,7 @@ import java.util.Collections;
@RequiredArgsConstructor
public
final
class
StatementExecutorWrapper
implements
JDBCExecutorWrapper
{
private
static
final
Proxy
SchemaContexts
PROXY_SCHEMA_CONTEXTS
=
ProxySchemaContexts
.
getInstance
();
private
static
final
Proxy
Context
PROXY_SCHEMA_CONTEXTS
=
ProxyContext
.
getInstance
();
private
final
SchemaContext
schema
;
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/executor/BackendExecutorContext.java
浏览文件 @
9d3dab10
...
...
@@ -22,7 +22,7 @@ import lombok.Getter;
import
lombok.NoArgsConstructor
;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey
;
import
org.apache.shardingsphere.infra.executor.kernel.ExecutorKernel
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
/**
* Backend executor context.
...
...
@@ -34,7 +34,7 @@ public final class BackendExecutorContext {
private
static
final
BackendExecutorContext
INSTANCE
=
new
BackendExecutorContext
();
private
final
ExecutorKernel
executorKernel
=
new
ExecutorKernel
(
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getProps
().<
Integer
>
getValue
(
ConfigurationPropertyKey
.
EXECUTOR_SIZE
));
new
ExecutorKernel
(
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getProps
().<
Integer
>
getValue
(
ConfigurationPropertyKey
.
EXECUTOR_SIZE
));
/**
* Get executor context instance.
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/Proxy
SchemaContexts
.java
→
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/Proxy
Context
.java
浏览文件 @
9d3dab10
...
...
@@ -27,19 +27,19 @@ import org.apache.shardingsphere.transaction.context.TransactionContexts;
import
org.apache.shardingsphere.transaction.context.impl.StandardTransactionContexts
;
import
javax.sql.DataSource
;
import
java.util.
Linked
List
;
import
java.util.
Array
List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.Optional
;
/**
* Proxy
schema contexts
.
* Proxy
context
.
*/
@Getter
public
final
class
Proxy
SchemaContexts
{
public
final
class
Proxy
Context
{
private
static
final
Proxy
SchemaContexts
INSTANCE
=
new
ProxySchemaContexts
();
private
static
final
Proxy
Context
INSTANCE
=
new
ProxyContext
();
private
final
JDBCBackendDataSource
backendDataSource
;
...
...
@@ -47,7 +47,7 @@ public final class ProxySchemaContexts {
private
TransactionContexts
transactionContexts
;
private
Proxy
SchemaContexts
()
{
private
Proxy
Context
()
{
backendDataSource
=
new
JDBCBackendDataSource
();
schemaContexts
=
new
StandardSchemaContexts
();
transactionContexts
=
new
StandardTransactionContexts
();
...
...
@@ -58,7 +58,7 @@ public final class ProxySchemaContexts {
*
* @return instance of ShardingSphere schemas.
*/
public
static
Proxy
SchemaContexts
getInstance
()
{
public
static
Proxy
Context
getInstance
()
{
return
INSTANCE
;
}
...
...
@@ -76,30 +76,30 @@ public final class ProxySchemaContexts {
/**
* Check schema exists.
*
* @param schema
schema
* @param schema
Name schema name
* @return schema exists or not
*/
public
boolean
schemaExists
(
final
String
schema
)
{
return
null
!=
schemaContexts
&&
schemaContexts
.
getSchemaContexts
().
containsKey
(
schema
);
public
boolean
schemaExists
(
final
String
schema
Name
)
{
return
schemaContexts
.
getSchemaContexts
().
containsKey
(
schemaName
);
}
/**
* Get
ShardingSphere schema
.
* Get
schema context
.
*
* @param schemaName schema name
* @return
ShardingSphere schema
* @return
schema context
*/
public
SchemaContext
getSchema
(
final
String
schemaName
)
{
return
Strings
.
isNullOrEmpty
(
schemaName
)
?
null
:
schemaContexts
.
getSchemaContexts
().
get
(
schemaName
);
}
/**
* Get schema names.
* Get
all
schema names.
*
* @return schema names
* @return
all
schema names
*/
public
List
<
String
>
getSchemaNames
()
{
return
new
Linked
List
<>(
schemaContexts
.
getSchemaContexts
().
keySet
());
public
List
<
String
>
get
All
SchemaNames
()
{
return
new
Array
List
<>(
schemaContexts
.
getSchemaContexts
().
keySet
());
}
/**
...
...
@@ -108,7 +108,7 @@ public final class ProxySchemaContexts {
* @return data source sample
*/
public
Optional
<
DataSource
>
getDataSourceSample
()
{
List
<
String
>
schemaNames
=
getSchemaNames
();
List
<
String
>
schemaNames
=
get
All
SchemaNames
();
if
(
schemaNames
.
isEmpty
())
{
return
Optional
.
empty
();
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/datasource/impl/JDBCBackendDataSource.java
浏览文件 @
9d3dab10
...
...
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.proxy.backend.schema.datasource.impl;
import
com.google.common.base.Preconditions
;
import
org.apache.shardingsphere.infra.executor.sql.ConnectionMode
;
import
org.apache.shardingsphere.proxy.backend.schema.datasource.BackendDataSource
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.transaction.core.TransactionType
;
import
org.apache.shardingsphere.transaction.spi.ShardingTransactionManager
;
...
...
@@ -76,7 +76,7 @@ public final class JDBCBackendDataSource implements BackendDataSource {
@SuppressWarnings
(
"SynchronizationOnLocalVariableOrMethodParameter"
)
public
List
<
Connection
>
getConnections
(
final
String
schemaName
,
final
String
dataSourceName
,
final
int
connectionSize
,
final
ConnectionMode
connectionMode
,
final
TransactionType
transactionType
)
throws
SQLException
{
DataSource
dataSource
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getSchemaContexts
().
get
(
schemaName
).
getSchema
().
getDataSources
().
get
(
dataSourceName
);
DataSource
dataSource
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getSchemaContexts
().
get
(
schemaName
).
getSchema
().
getDataSources
().
get
(
dataSourceName
);
Preconditions
.
checkNotNull
(
dataSource
,
"Can not get connection from datasource %s."
,
dataSourceName
);
if
(
1
==
connectionSize
)
{
return
Collections
.
singletonList
(
createConnection
(
schemaName
,
dataSourceName
,
dataSource
,
transactionType
));
...
...
@@ -106,7 +106,7 @@ public final class JDBCBackendDataSource implements BackendDataSource {
}
private
Connection
createConnection
(
final
String
schemaName
,
final
String
dataSourceName
,
final
DataSource
dataSource
,
final
TransactionType
transactionType
)
throws
SQLException
{
ShardingTransactionManager
shardingTransactionManager
=
Proxy
SchemaContexts
.
getInstance
().
getTransactionContexts
().
getEngines
().
get
(
schemaName
).
getTransactionManager
(
transactionType
);
ShardingTransactionManager
shardingTransactionManager
=
Proxy
Context
.
getInstance
().
getTransactionContexts
().
getEngines
().
get
(
schemaName
).
getTransactionManager
(
transactionType
);
return
isInShardingTransaction
(
shardingTransactionManager
)
?
shardingTransactionManager
.
getConnection
(
dataSourceName
)
:
dataSource
.
getConnection
();
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandler.java
浏览文件 @
9d3dab10
...
...
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
...
...
@@ -49,7 +49,7 @@ public final class BroadcastBackendHandler implements TextProtocolBackendHandler
public
BackendResponse
execute
()
{
Collection
<
BackendResponse
>
responses
=
new
LinkedList
<>();
String
originalSchema
=
backendConnection
.
getSchema
();
for
(
String
each
:
Proxy
SchemaContexts
.
getInstance
().
get
SchemaNames
())
{
for
(
String
each
:
Proxy
Context
.
getInstance
().
getAll
SchemaNames
())
{
backendConnection
.
setCurrentSchema
(
each
);
responses
.
add
(
databaseCommunicationEngineFactory
.
newTextProtocolInstance
(
sqlStatement
,
sql
,
backendConnection
).
execute
());
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandler.java
浏览文件 @
9d3dab10
...
...
@@ -33,7 +33,7 @@ import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.proxy.config.util.DataSourceParameterConverter
;
import
org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter
;
...
...
@@ -76,7 +76,7 @@ public final class RDLBackendHandler implements TextProtocolBackendHandler {
}
private
BackendResponse
execute
(
final
CreateDatabaseStatementContext
context
)
{
if
(
Proxy
SchemaContexts
.
getInstance
().
get
SchemaNames
().
contains
(
context
.
getSqlStatement
().
getDatabaseName
()))
{
if
(
Proxy
Context
.
getInstance
().
getAll
SchemaNames
().
contains
(
context
.
getSqlStatement
().
getDatabaseName
()))
{
return
new
ErrorResponse
(
new
DBCreateExistsException
(
context
.
getSqlStatement
().
getDatabaseName
()));
}
// TODO Need to get the executed feedback from registry center for returning.
...
...
@@ -87,7 +87,7 @@ public final class RDLBackendHandler implements TextProtocolBackendHandler {
}
private
BackendResponse
execute
(
final
DropDatabaseStatementContext
context
)
{
if
(!
Proxy
SchemaContexts
.
getInstance
().
get
SchemaNames
().
contains
(
context
.
getSqlStatement
().
getDatabaseName
()))
{
if
(!
Proxy
Context
.
getInstance
().
getAll
SchemaNames
().
contains
(
context
.
getSqlStatement
().
getDatabaseName
()))
{
return
new
ErrorResponse
(
new
DBCreateExistsException
(
context
.
getSqlStatement
().
getDatabaseName
()));
}
// TODO Need to get the executed feedback from registry center for returning.
...
...
@@ -119,7 +119,7 @@ public final class RDLBackendHandler implements TextProtocolBackendHandler {
}
private
SQLStatementContext
<?>
getSQLStatementContext
()
{
DatabaseType
databaseType
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getDatabaseType
();
DatabaseType
databaseType
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getDatabaseType
();
if
(
sqlStatement
instanceof
CreateDataSourcesStatement
)
{
return
new
CreateDataSourcesStatementContext
((
CreateDataSourcesStatement
)
sqlStatement
,
databaseType
);
}
...
...
@@ -146,7 +146,7 @@ public final class RDLBackendHandler implements TextProtocolBackendHandler {
}
private
boolean
isRegistryCenterExisted
()
{
return
!(
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
()
instanceof
StandardSchemaContexts
);
return
!(
Proxy
Context
.
getInstance
().
getSchemaContexts
()
instanceof
StandardSchemaContexts
);
}
@Override
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/ShowDatabasesBackendHandler.java
浏览文件 @
9d3dab10
...
...
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.Bac
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.sharding.merge.dal.common.SingleLocalDataMergedResult
;
...
...
@@ -44,16 +44,15 @@ public final class ShowDatabasesBackendHandler implements TextProtocolBackendHan
private
MergedResult
mergedResult
;
@SuppressWarnings
(
"unchecked"
)
@Override
public
BackendResponse
execute
()
{
mergedResult
=
new
SingleLocalDataMergedResult
(
getSchemaNames
());
return
new
QueryResponse
(
Collections
.
singletonList
(
new
QueryHeader
(
"information_schema"
,
"SCHEMATA"
,
"Database"
,
"SCHEMA_NAME"
,
100
,
Types
.
VARCHAR
,
0
,
false
,
false
,
false
,
false
)));
}
private
Collection
getSchemaNames
()
{
Collection
<
String
>
result
=
new
LinkedList
<>(
ProxySchemaContexts
.
getInstance
().
get
SchemaNames
());
Collection
<
String
>
authorizedSchemas
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getAuthentication
().
getUsers
().
get
(
backendConnection
.
getUsername
()).
getAuthorizedSchemas
();
private
Collection
<
Object
>
getSchemaNames
()
{
Collection
<
Object
>
result
=
new
LinkedList
<>(
ProxyContext
.
getInstance
().
getAll
SchemaNames
());
Collection
<
String
>
authorizedSchemas
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getAuthentication
().
getUsers
().
get
(
backendConnection
.
getUsername
()).
getAuthorizedSchemas
();
if
(!
authorizedSchemas
.
isEmpty
())
{
result
.
retainAll
(
authorizedSchemas
);
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/ShowTablesBackendHandler.java
浏览文件 @
9d3dab10
...
...
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
...
...
@@ -54,7 +54,7 @@ public final class ShowTablesBackendHandler implements TextProtocolBackendHandle
@Override
public
BackendResponse
execute
()
{
SchemaContext
context
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
SchemaContext
context
=
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
if
(
null
==
context
)
{
return
new
ErrorResponse
(
new
NoDatabaseSelectedException
());
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/UnicastBackendHandler.java
浏览文件 @
9d3dab10
...
...
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedExcep
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
...
...
@@ -52,7 +52,7 @@ public final class UnicastBackendHandler implements TextProtocolBackendHandler {
@Override
public
BackendResponse
execute
()
{
if
(
null
==
backendConnection
.
getSchema
())
{
Map
<
String
,
SchemaContext
>
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getSchemaContexts
();
Map
<
String
,
SchemaContext
>
schemaContexts
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getSchemaContexts
();
if
(
schemaContexts
.
isEmpty
())
{
return
new
ErrorResponse
(
new
NoDatabaseSelectedException
());
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/UseDatabaseBackendHandler.java
浏览文件 @
9d3dab10
...
...
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLUseStatement
;
import
org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil
;
...
...
@@ -44,7 +44,7 @@ public final class UseDatabaseBackendHandler implements TextProtocolBackendHandl
@Override
public
BackendResponse
execute
()
{
String
schema
=
SQLUtil
.
getExactlyValue
(
useStatement
.
getSchema
());
if
(
Proxy
SchemaContexts
.
getInstance
().
schemaExists
(
schema
)
&&
isAuthorizedSchema
(
schema
))
{
if
(
Proxy
Context
.
getInstance
().
schemaExists
(
schema
)
&&
isAuthorizedSchema
(
schema
))
{
backendConnection
.
setCurrentSchema
(
schema
);
return
new
UpdateResponse
();
}
...
...
@@ -53,7 +53,7 @@ public final class UseDatabaseBackendHandler implements TextProtocolBackendHandl
}
private
boolean
isAuthorizedSchema
(
final
String
schema
)
{
Collection
<
String
>
authorizedSchemas
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getAuthentication
().
getUsers
().
get
(
backendConnection
.
getUsername
()).
getAuthorizedSchemas
();
Collection
<
String
>
authorizedSchemas
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getAuthentication
().
getUsers
().
get
(
backendConnection
.
getUsername
()).
getAuthorizedSchemas
();
return
authorizedSchemas
.
isEmpty
()
||
authorizedSchemas
.
contains
(
schema
);
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/query/QueryBackendHandler.java
浏览文件 @
9d3dab10
...
...
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
...
...
@@ -54,7 +54,7 @@ public final class QueryBackendHandler implements TextProtocolBackendHandler {
@Override
public
BackendResponse
execute
()
{
SchemaContext
context
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
SchemaContext
context
=
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
if
(
null
==
context
)
{
return
new
ErrorResponse
(
new
NoDatabaseSelectedException
());
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandler.java
浏览文件 @
9d3dab10
...
...
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.proxy.backend.text.sctl.exception.InvalidShardingCTLFormatException
;
...
...
@@ -57,7 +57,7 @@ public final class ShardingCTLExplainBackendHandler implements TextProtocolBacke
if
(!
explainStatement
.
isPresent
())
{
return
new
ErrorResponse
(
new
InvalidShardingCTLFormatException
(
sql
));
}
SchemaContext
schema
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
SchemaContext
schema
=
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
StatementExecutorWrapper
statementExecutorWrapper
=
new
StatementExecutorWrapper
(
schema
,
schema
.
getRuntimeContext
().
getSqlParserEngine
().
parse
(
explainStatement
.
get
().
getSql
(),
false
));
executionUnits
=
statementExecutorWrapper
.
generateExecutionContext
(
explainStatement
.
get
().
getSql
()).
getExecutionUnits
().
iterator
();
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/internal/executor/HintShowTableStatusExecutor.java
浏览文件 @
9d3dab10
...
...
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.executor.sql.raw.execute.result.query.Que
import
org.apache.shardingsphere.infra.hint.HintManager
;
import
org.apache.shardingsphere.infra.merge.result.MergedResult
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.sctl.hint.internal.command.HintShowTableStatusCommand
;
import
org.apache.shardingsphere.proxy.backend.text.sctl.hint.internal.result.HintShowTableStatusResult
;
import
org.apache.shardingsphere.sharding.merge.dal.common.MultipleLocalDataMergedResult
;
...
...
@@ -57,7 +57,7 @@ public final class HintShowTableStatusExecutor extends AbstractHintQueryExecutor
protected
MergedResult
createMergedResult
()
{
Map
<
String
,
HintShowTableStatusResult
>
results
=
new
HashMap
<>();
Collection
<
String
>
tableNames
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()).
getSchema
().
getMetaData
().
getSchema
().
getConfiguredSchemaMetaData
().
getAllTableNames
();
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()).
getSchema
().
getMetaData
().
getSchema
().
getConfiguredSchemaMetaData
().
getAllTableNames
();
for
(
String
each
:
tableNames
)
{
if
(
HintManager
.
isDatabaseShardingOnly
())
{
fillShardingValues
(
results
,
each
,
HintManager
.
getDatabaseShardingValues
(),
Collections
.
emptyList
());
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java
浏览文件 @
9d3dab10
...
...
@@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
import
org.apache.shardingsphere.infra.database.type.DatabaseTypes
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.ConnectionStateHandler
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandlerFactory
;
import
org.apache.shardingsphere.proxy.backend.text.admin.BroadcastBackendHandler
;
...
...
@@ -69,9 +69,9 @@ public final class TextProtocolBackendHandlerFactoryTest {
@SneakyThrows
(
ReflectiveOperationException
.
class
)
private
void
setTransactionContexts
()
{
Field
transactionContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"transactionContexts"
);
Field
transactionContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"transactionContexts"
);
transactionContexts
.
setAccessible
(
true
);
transactionContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
createSchemaContext
());
transactionContexts
.
set
(
Proxy
Context
.
getInstance
(),
createSchemaContext
());
}
private
TransactionContexts
createSchemaContext
()
{
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/DatabaseCommunicationEngineFactoryTest.java
浏览文件 @
9d3dab10
...
...
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine
;
import
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -50,9 +50,9 @@ public final class DatabaseCommunicationEngineFactoryTest {
@Before
@SneakyThrows
(
ReflectiveOperationException
.
class
)
public
void
setUp
()
{
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
BackendConnection
backendConnection
=
mock
(
BackendConnection
.
class
);
when
(
backendConnection
.
getSchema
()).
thenReturn
(
"schema"
);
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
浏览文件 @
9d3dab10
...
...
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.context.schema.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType
;
import
org.apache.shardingsphere.infra.exception.ShardingSphereException
;
import
org.apache.shardingsphere.infra.executor.sql.ConnectionMode
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.schema.datasource.impl.JDBCBackendDataSource
;
import
org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine
;
import
org.apache.shardingsphere.transaction.context.TransactionContexts
;
...
...
@@ -86,9 +86,9 @@ public final class BackendConnectionTest {
@SneakyThrows
(
ReflectiveOperationException
.
class
)
private
void
setSchemaContexts
()
{
Field
field
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
field
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
field
.
setAccessible
(
true
);
field
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
field
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
createSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
}
...
...
@@ -105,9 +105,9 @@ public final class BackendConnectionTest {
@SneakyThrows
(
ReflectiveOperationException
.
class
)
private
void
setTransactionContexts
()
{
Field
field
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"transactionContexts"
);
Field
field
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"transactionContexts"
);
field
.
setAccessible
(
true
);
field
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
createTransactionContexts
());
field
.
set
(
Proxy
Context
.
getInstance
(),
createTransactionContexts
());
}
private
TransactionContexts
createTransactionContexts
()
{
...
...
@@ -121,9 +121,9 @@ public final class BackendConnectionTest {
@SneakyThrows
(
ReflectiveOperationException
.
class
)
private
void
setBackendDataSource
()
{
Field
field
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"backendDataSource"
);
Field
field
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"backendDataSource"
);
field
.
setAccessible
(
true
);
field
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
backendDataSource
);
field
.
set
(
Proxy
Context
.
getInstance
(),
backendDataSource
);
}
@Test
...
...
@@ -292,10 +292,10 @@ public final class BackendConnectionTest {
@SneakyThrows
(
ReflectiveOperationException
.
class
)
@After
public
void
clean
()
{
Field
field
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"backendDataSource"
);
Field
field
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"backendDataSource"
);
field
.
setAccessible
(
true
);
Class
<?>
clazz
=
field
.
getType
();
Object
datasource
=
clazz
.
getDeclaredConstructors
()[
0
].
newInstance
();
field
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
datasource
);
field
.
set
(
Proxy
Context
.
getInstance
(),
datasource
);
}
}
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManagerTest.java
浏览文件 @
9d3dab10
...
...
@@ -18,7 +18,7 @@
package
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection
;
import
lombok.SneakyThrows
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine
;
import
org.apache.shardingsphere.transaction.context.TransactionContexts
;
import
org.apache.shardingsphere.transaction.core.TransactionType
;
...
...
@@ -64,9 +64,9 @@ public final class BackendTransactionManagerTest {
@SneakyThrows
(
ReflectiveOperationException
.
class
)
private
void
setTransactionContexts
()
{
Field
transactionContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"transactionContexts"
);
Field
transactionContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"transactionContexts"
);
transactionContexts
.
setAccessible
(
true
);
transactionContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
getTransactionContexts
());
transactionContexts
.
set
(
Proxy
Context
.
getInstance
(),
getTransactionContexts
());
}
private
TransactionContexts
getTransactionContexts
()
{
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java
浏览文件 @
9d3dab10
...
...
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.context.schema.ShardingSphereSchema;
import
org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType
;
import
org.apache.shardingsphere.infra.executor.sql.ConnectionMode
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.fixture.CallTimeRecordDataSource
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine
;
import
org.apache.shardingsphere.transaction.context.TransactionContexts
;
import
org.junit.Before
;
...
...
@@ -70,9 +70,9 @@ public final class JDBCBackendDataSourceTest {
@SneakyThrows
(
ReflectiveOperationException
.
class
)
private
void
setSchemaContexts
()
{
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
createSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
}
...
...
@@ -89,9 +89,9 @@ public final class JDBCBackendDataSourceTest {
@SneakyThrows
(
ReflectiveOperationException
.
class
)
private
void
setTransactionContexts
()
{
Field
transactionContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"transactionContexts"
);
Field
transactionContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"transactionContexts"
);
transactionContexts
.
setAccessible
(
true
);
transactionContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
createTransactionContexts
());
transactionContexts
.
set
(
Proxy
Context
.
getInstance
(),
createTransactionContexts
());
}
private
TransactionContexts
createTransactionContexts
()
{
...
...
@@ -111,19 +111,19 @@ public final class JDBCBackendDataSourceTest {
@Test
public
void
assertGetConnectionFixedOne
()
throws
SQLException
{
Connection
actual
=
Proxy
SchemaContexts
.
getInstance
().
getBackendDataSource
().
getConnection
(
"schema"
,
"ds_1"
);
Connection
actual
=
Proxy
Context
.
getInstance
().
getBackendDataSource
().
getConnection
(
"schema"
,
"ds_1"
);
assertThat
(
actual
,
instanceOf
(
Connection
.
class
));
}
@Test
public
void
assertGetConnectionsSucceed
()
throws
SQLException
{
List
<
Connection
>
actual
=
Proxy
SchemaContexts
.
getInstance
().
getBackendDataSource
().
getConnections
(
"schema"
,
"ds_1"
,
5
,
ConnectionMode
.
MEMORY_STRICTLY
);
List
<
Connection
>
actual
=
Proxy
Context
.
getInstance
().
getBackendDataSource
().
getConnections
(
"schema"
,
"ds_1"
,
5
,
ConnectionMode
.
MEMORY_STRICTLY
);
assertThat
(
actual
.
size
(),
is
(
5
));
}
@Test
(
expected
=
SQLException
.
class
)
public
void
assertGetConnectionsFailed
()
throws
SQLException
{
Proxy
SchemaContexts
.
getInstance
().
getBackendDataSource
().
getConnections
(
"schema"
,
"ds_1"
,
6
,
ConnectionMode
.
MEMORY_STRICTLY
);
Proxy
Context
.
getInstance
().
getBackendDataSource
().
getConnections
(
"schema"
,
"ds_1"
,
6
,
ConnectionMode
.
MEMORY_STRICTLY
);
}
@Test
...
...
@@ -156,7 +156,7 @@ public final class JDBCBackendDataSourceTest {
@Override
public
List
<
Connection
>
call
()
throws
SQLException
{
return
Proxy
SchemaContexts
.
getInstance
().
getBackendDataSource
().
getConnections
(
"schema"
,
datasourceName
,
connectionSize
,
connectionMode
);
return
Proxy
Context
.
getInstance
().
getBackendDataSource
().
getConnections
(
"schema"
,
datasourceName
,
connectionSize
,
connectionMode
);
}
}
}
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/schema/Proxy
SchemaContexts
Test.java
→
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/schema/Proxy
Context
Test.java
浏览文件 @
9d3dab10
...
...
@@ -40,18 +40,18 @@ import static org.junit.Assert.assertThat;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
final
class
Proxy
SchemaContexts
Test
{
public
final
class
Proxy
Context
Test
{
@Test
public
void
assertGetDataSourceSample
()
throws
NoSuchFieldException
,
IllegalAccessException
{
Map
<
String
,
DataSource
>
mockDataSourceMap
=
new
HashMap
<>(
2
,
1
);
mockDataSourceMap
.
put
(
"ds_1"
,
new
MockedDataSource
());
mockDataSourceMap
.
put
(
"ds_2"
,
new
MockedDataSource
());
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(
mockDataSourceMap
),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
Optional
<
DataSource
>
actual
=
Proxy
SchemaContexts
.
getInstance
().
getDataSourceSample
();
Optional
<
DataSource
>
actual
=
Proxy
Context
.
getInstance
().
getDataSourceSample
();
assertThat
(
actual
,
is
(
Optional
.
of
(
mockDataSourceMap
.
get
(
"ds_1"
))));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/BroadcastBackendHandlerTest.java
浏览文件 @
9d3dab10
...
...
@@ -29,7 +29,7 @@ import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.Bac
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -68,9 +68,9 @@ public final class BroadcastBackendHandlerTest {
@Before
@SneakyThrows
(
ReflectiveOperationException
.
class
)
public
void
setUp
()
{
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
when
(
backendConnection
.
getSchema
()).
thenReturn
(
"schema_0"
);
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandlerTest.java
浏览文件 @
9d3dab10
...
...
@@ -29,7 +29,7 @@ import org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateDataSourcesStatement
;
import
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateShardingRuleStatement
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateDatabaseStatement
;
...
...
@@ -53,9 +53,9 @@ public final class RDLBackendHandlerTest {
@Before
@SneakyThrows
(
ReflectiveOperationException
.
class
)
public
void
setUp
()
{
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
}
...
...
@@ -127,14 +127,14 @@ public final class RDLBackendHandlerTest {
@SneakyThrows
(
ReflectiveOperationException
.
class
)
private
void
setGovernanceSchemaContexts
(
final
boolean
isGovernance
)
{
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
if
(
isGovernance
)
{
SchemaContexts
mockedSchemaContexts
=
mock
(
SchemaContexts
.
class
);
when
(
mockedSchemaContexts
.
getSchemaContexts
()).
thenReturn
(
Collections
.
singletonMap
(
"schema"
,
mock
(
SchemaContext
.
class
)));
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
mockedSchemaContexts
);
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
mockedSchemaContexts
);
}
else
{
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
new
StandardSchemaContexts
());
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
());
}
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/ShowDatabasesBackendHandlerTest.java
浏览文件 @
9d3dab10
...
...
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
@@ -58,9 +58,9 @@ public final class ShowDatabasesBackendHandlerTest {
BackendConnection
backendConnection
=
mock
(
BackendConnection
.
class
);
when
(
backendConnection
.
getUsername
()).
thenReturn
(
"root"
);
showDatabasesBackendHandler
=
new
ShowDatabasesBackendHandler
(
backendConnection
);
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
getAuthentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/ShowTablesBackendHandlerTest.java
浏览文件 @
9d3dab10
...
...
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -58,9 +58,9 @@ public class ShowTablesBackendHandlerTest {
tablesBackendHandler
=
new
ShowTablesBackendHandler
(
"show tables"
,
mock
(
SQLStatement
.
class
),
backendConnection
);
Map
<
String
,
SchemaContext
>
schemaContextMap
=
getSchemaContextMap
();
when
(
backendConnection
.
getSchema
()).
thenReturn
(
"schema_0"
);
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
schemaContextMap
,
getAuthentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/UnicastBackendHandlerTest.java
浏览文件 @
9d3dab10
...
...
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicati
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
import
org.apache.shardingsphere.transaction.core.TransactionType
;
import
org.junit.Before
;
...
...
@@ -62,9 +62,9 @@ public final class UnicastBackendHandlerTest {
@Before
@SneakyThrows
(
ReflectiveOperationException
.
class
)
public
void
setUp
()
{
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
setUnderlyingHandler
(
new
UpdateResponse
());
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/UseDatabaseBackendHandlerTest.java
浏览文件 @
9d3dab10
...
...
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.Bac
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.sql.parser.sql.dialect.statement.mysql.dal.MySQLUseStatement
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -59,9 +59,9 @@ public final class UseDatabaseBackendHandlerTest {
public
void
setUp
()
{
backendConnection
=
mock
(
BackendConnection
.
class
);
when
(
backendConnection
.
getUsername
()).
thenReturn
(
"root"
);
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
getAuthentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
浏览文件 @
9d3dab10
...
...
@@ -9,7 +9,7 @@ import org.apache.shardingsphere.infra.context.runtime.RuntimeContext;
import
org.apache.shardingsphere.infra.context.schema.ShardingSphereSchema
;
import
org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine
;
import
org.apache.shardingsphere.sql.parser.engine.StandardSQLParserEngine
;
import
org.junit.Before
;
...
...
@@ -54,9 +54,9 @@ public final class ShardingCTLExplainBackendHandlerTest {
BackendConnection
connection
=
mock
(
BackendConnection
.
class
);
when
(
connection
.
getSchema
()).
thenReturn
(
"schema"
);
handler
=
new
ShardingCTLExplainBackendHandler
(
"sctl:explain select 1"
,
connection
);
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/hint/ShardingCTLHintBackendHandlerTest.java
浏览文件 @
9d3dab10
...
...
@@ -35,7 +35,7 @@ import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.sctl.exception.InvalidShardingCTLFormatException
;
import
org.apache.shardingsphere.proxy.backend.text.sctl.exception.UnsupportedShardingCTLTypeException
;
import
org.apache.shardingsphere.proxy.backend.text.sctl.hint.internal.HintManagerHolder
;
...
...
@@ -172,9 +172,9 @@ public final class ShardingCTLHintBackendHandlerTest {
public
void
assertShowTableStatus
()
throws
SQLException
{
clearThreadLocal
();
when
(
backendConnection
.
getSchema
()).
thenReturn
(
"schema"
);
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
String
sql
=
"sctl:hint show table status"
;
ShardingCTLHintBackendHandler
defaultShardingCTLHintBackendHandler
=
new
ShardingCTLHintBackendHandler
(
sql
,
backendConnection
);
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/set/ShardingCTLSetBackendHandlerTest.java
浏览文件 @
9d3dab10
...
...
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.Bac
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.transaction.core.TransactionType
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -49,9 +49,9 @@ public final class ShardingCTLSetBackendHandlerTest {
@Before
@SneakyThrows
(
ReflectiveOperationException
.
class
)
public
void
setUp
()
{
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/init/impl/AbstractBootstrapInitializer.java
浏览文件 @
9d3dab10
...
...
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.context.SchemaContext;
import
org.apache.shardingsphere.infra.context.SchemaContexts
;
import
org.apache.shardingsphere.infra.context.SchemaContextsBuilder
;
import
org.apache.shardingsphere.proxy.backend.schema.ProxyDataSourceContext
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.config.ProxyConfiguration
;
import
org.apache.shardingsphere.proxy.config.YamlProxyConfiguration
;
import
org.apache.shardingsphere.proxy.db.DatabaseServerInfo
;
...
...
@@ -53,7 +53,7 @@ public abstract class AbstractBootstrapInitializer implements BootstrapInitializ
ProxyConfiguration
proxyConfig
=
getProxyConfiguration
(
yamlConfig
);
SchemaContexts
schemaContexts
=
decorateSchemaContexts
(
createSchemaContexts
(
proxyConfig
));
TransactionContexts
transactionContexts
=
decorateTransactionContexts
(
createTransactionContexts
(
schemaContexts
));
Proxy
SchemaContexts
.
getInstance
().
init
(
schemaContexts
,
transactionContexts
);
Proxy
Context
.
getInstance
().
init
(
schemaContexts
,
transactionContexts
);
initOpenTracing
();
setDatabaseServerInfo
();
new
ShardingSphereProxy
().
start
(
port
);
...
...
@@ -77,13 +77,13 @@ public abstract class AbstractBootstrapInitializer implements BootstrapInitializ
}
private
void
initOpenTracing
()
{
if
(
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getProps
().<
Boolean
>
getValue
(
ConfigurationPropertyKey
.
PROXY_OPENTRACING_ENABLED
))
{
if
(
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getProps
().<
Boolean
>
getValue
(
ConfigurationPropertyKey
.
PROXY_OPENTRACING_ENABLED
))
{
OpenTracingTracer
.
init
();
}
}
private
void
setDatabaseServerInfo
()
{
Optional
<
DataSource
>
dataSourceSample
=
Proxy
SchemaContexts
.
getInstance
().
getDataSourceSample
();
Optional
<
DataSource
>
dataSourceSample
=
Proxy
Context
.
getInstance
().
getDataSourceSample
();
if
(
dataSourceSample
.
isPresent
())
{
DatabaseServerInfo
databaseServerInfo
=
new
DatabaseServerInfo
(
dataSourceSample
.
get
());
log
.
info
(
databaseServerInfo
.
toString
());
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/executor/UserExecutorGroup.java
浏览文件 @
9d3dab10
...
...
@@ -21,14 +21,14 @@ import com.google.common.util.concurrent.ListeningExecutorService;
import
lombok.Getter
;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey
;
import
org.apache.shardingsphere.infra.executor.kernel.impl.ShardingSphereExecutorService
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
/**
* User executor group.
*/
public
final
class
UserExecutorGroup
{
private
static
final
Proxy
SchemaContexts
PROXY_SCHEMA_CONTEXTS
=
ProxySchemaContexts
.
getInstance
();
private
static
final
Proxy
Context
PROXY_SCHEMA_CONTEXTS
=
ProxyContext
.
getInstance
();
private
static
final
String
NAME_FORMAT
=
"Command-%d"
;
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/FrontendChannelInboundHandler.java
浏览文件 @
9d3dab10
...
...
@@ -24,7 +24,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.db.protocol.payload.PacketPayload
;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask
;
import
org.apache.shardingsphere.proxy.frontend.auth.AuthenticationResult
;
import
org.apache.shardingsphere.proxy.frontend.executor.ChannelThreadExecutorGroup
;
...
...
@@ -49,8 +49,8 @@ public final class FrontendChannelInboundHandler extends ChannelInboundHandlerAd
public
FrontendChannelInboundHandler
(
final
DatabaseProtocolFrontendEngine
databaseProtocolFrontendEngine
)
{
this
.
databaseProtocolFrontendEngine
=
databaseProtocolFrontendEngine
;
TransactionType
transactionType
=
TransactionType
.
valueOf
(
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getProps
().
getValue
(
ConfigurationPropertyKey
.
PROXY_TRANSACTION_TYPE
));
boolean
supportHint
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getProps
().<
Boolean
>
getValue
(
ConfigurationPropertyKey
.
PROXY_HINT_ENABLED
);
TransactionType
transactionType
=
TransactionType
.
valueOf
(
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getProps
().
getValue
(
ConfigurationPropertyKey
.
PROXY_TRANSACTION_TYPE
));
boolean
supportHint
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getProps
().<
Boolean
>
getValue
(
ConfigurationPropertyKey
.
PROXY_HINT_ENABLED
);
backendConnection
=
new
BackendConnection
(
transactionType
,
supportHint
);
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/netty/ServerHandlerInitializer.java
浏览文件 @
9d3dab10
...
...
@@ -24,7 +24,7 @@ import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.db.protocol.codec.PacketCodec
;
import
org.apache.shardingsphere.infra.database.type.DatabaseType
;
import
org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.protocol.DatabaseProtocolFrontendEngineFactory
;
import
org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine
;
...
...
@@ -37,8 +37,8 @@ public final class ServerHandlerInitializer extends ChannelInitializer<SocketCha
@Override
protected
void
initChannel
(
final
SocketChannel
socketChannel
)
{
// TODO Consider loading from configuration.
DatabaseType
databaseType
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getSchemaContexts
().
isEmpty
()
?
new
MySQLDatabaseType
()
:
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getDatabaseType
();
DatabaseType
databaseType
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getSchemaContexts
().
isEmpty
()
?
new
MySQLDatabaseType
()
:
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getDatabaseType
();
DatabaseProtocolFrontendEngine
databaseProtocolFrontendEngine
=
DatabaseProtocolFrontendEngineFactory
.
newInstance
(
databaseType
);
ChannelPipeline
pipeline
=
socketChannel
.
pipeline
();
pipeline
.
addLast
(
new
PacketCodec
(
databaseProtocolFrontendEngine
.
getCodecEngine
()));
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationEngine.java
浏览文件 @
9d3dab10
...
...
@@ -31,7 +31,7 @@ import org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLHandsha
import
org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLHandshakeResponse41Packet
;
import
org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload
;
import
org.apache.shardingsphere.db.protocol.payload.PacketPayload
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.connection.ConnectionIdGenerator
;
import
org.apache.shardingsphere.proxy.frontend.auth.AuthenticationResultBuilder
;
import
org.apache.shardingsphere.proxy.frontend.auth.AuthenticationEngine
;
...
...
@@ -83,7 +83,7 @@ public final class MySQLAuthenticationEngine implements AuthenticationEngine {
MySQLHandshakeResponse41Packet
packet
=
new
MySQLHandshakeResponse41Packet
((
MySQLPacketPayload
)
payload
);
authResponse
=
packet
.
getAuthResponse
();
sequenceId
=
packet
.
getSequenceId
();
if
(!
Strings
.
isNullOrEmpty
(
packet
.
getDatabase
())
&&
!
Proxy
SchemaContexts
.
getInstance
().
schemaExists
(
packet
.
getDatabase
()))
{
if
(!
Strings
.
isNullOrEmpty
(
packet
.
getDatabase
())
&&
!
Proxy
Context
.
getInstance
().
schemaExists
(
packet
.
getDatabase
()))
{
context
.
writeAndFlush
(
new
MySQLErrPacket
(++
sequenceId
,
MySQLServerErrorCode
.
ER_BAD_DB_ERROR
,
packet
.
getDatabase
()));
return
AuthenticationResultBuilder
.
continued
();
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandler.java
浏览文件 @
9d3dab10
...
...
@@ -24,7 +24,7 @@ import org.apache.commons.collections4.CollectionUtils;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerErrorCode
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.handshake.MySQLAuthPluginData
;
import
org.apache.shardingsphere.infra.auth.ProxyUser
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
java.util.Arrays
;
import
java.util.Collection
;
...
...
@@ -37,7 +37,7 @@ import java.util.Optional;
@Getter
public
final
class
MySQLAuthenticationHandler
{
private
static
final
Proxy
SchemaContexts
PROXY_SCHEMA_CONTEXTS
=
ProxySchemaContexts
.
getInstance
();
private
static
final
Proxy
Context
PROXY_SCHEMA_CONTEXTS
=
ProxyContext
.
getInstance
();
private
final
MySQLAuthPluginData
authPluginData
=
new
MySQLAuthPluginData
();
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
浏览文件 @
9d3dab10
...
...
@@ -31,7 +31,7 @@ import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import
org.apache.shardingsphere.db.protocol.payload.PacketPayload
;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor
;
import
org.apache.shardingsphere.proxy.frontend.command.CommandExecuteEngine
;
...
...
@@ -78,7 +78,7 @@ public final class MySQLCommandExecuteEngine implements CommandExecuteEngine {
return
;
}
int
count
=
0
;
int
flushThreshold
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getProps
().<
Integer
>
getValue
(
ConfigurationPropertyKey
.
PROXY_FRONTEND_FLUSH_THRESHOLD
);
int
flushThreshold
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getProps
().<
Integer
>
getValue
(
ConfigurationPropertyKey
.
PROXY_FRONTEND_FLUSH_THRESHOLD
);
int
currentSequenceId
=
0
;
while
(
queryCommandExecutor
.
next
())
{
count
++;
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/admin/initdb/MySQLComInitDbExecutor.java
浏览文件 @
9d3dab10
...
...
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket
;
import
org.apache.shardingsphere.db.protocol.packet.DatabasePacket
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor
;
import
org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtil
;
...
...
@@ -44,7 +44,7 @@ public final class MySQLComInitDbExecutor implements CommandExecutor {
@Override
public
Collection
<
DatabasePacket
<?>>
execute
()
{
String
schema
=
SQLUtil
.
getExactlyValue
(
packet
.
getSchema
());
if
(
Proxy
SchemaContexts
.
getInstance
().
schemaExists
(
schema
)
&&
isAuthorizedSchema
(
schema
))
{
if
(
Proxy
Context
.
getInstance
().
schemaExists
(
schema
)
&&
isAuthorizedSchema
(
schema
))
{
backendConnection
.
setCurrentSchema
(
packet
.
getSchema
());
return
Collections
.
singletonList
(
new
MySQLOKPacket
(
1
));
}
...
...
@@ -52,7 +52,7 @@ public final class MySQLComInitDbExecutor implements CommandExecutor {
}
private
boolean
isAuthorizedSchema
(
final
String
schema
)
{
Collection
<
String
>
authorizedSchemas
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getAuthentication
().
getUsers
().
get
(
backendConnection
.
getUsername
()).
getAuthorizedSchemas
();
Collection
<
String
>
authorizedSchemas
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getAuthentication
().
getUsers
().
get
(
backendConnection
.
getUsername
()).
getAuthorizedSchemas
();
return
authorizedSchemas
.
isEmpty
()
||
authorizedSchemas
.
contains
(
schema
);
}
}
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
浏览文件 @
9d3dab10
...
...
@@ -38,7 +38,7 @@ import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor
;
import
org.apache.shardingsphere.proxy.frontend.mysql.MySQLErrPacketFactory
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
...
...
@@ -70,14 +70,14 @@ public final class MySQLComStmtExecuteExecutor implements QueryCommandExecutor {
public
MySQLComStmtExecuteExecutor
(
final
MySQLComStmtExecutePacket
comStmtExecutePacket
,
final
BackendConnection
backendConnection
)
{
SQLStatement
sqlStatement
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()).
getRuntimeContext
().
getSqlParserEngine
().
parse
(
comStmtExecutePacket
.
getSql
(),
true
);
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()).
getRuntimeContext
().
getSqlParserEngine
().
parse
(
comStmtExecutePacket
.
getSql
(),
true
);
databaseCommunicationEngine
=
DatabaseCommunicationEngineFactory
.
getInstance
().
newBinaryProtocolInstance
(
sqlStatement
,
comStmtExecutePacket
.
getSql
(),
comStmtExecutePacket
.
getParameters
(),
backendConnection
);
}
@Override
public
Collection
<
DatabasePacket
<?>>
execute
()
{
if
(
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
isCircuitBreak
())
{
if
(
Proxy
Context
.
getInstance
().
getSchemaContexts
().
isCircuitBreak
())
{
return
Collections
.
singletonList
(
new
MySQLErrPacket
(
1
,
CommonErrorCode
.
CIRCUIT_BREAK_MODE
));
}
BackendResponse
backendResponse
=
getBackendResponse
();
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
浏览文件 @
9d3dab10
...
...
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket
import
org.apache.shardingsphere.db.protocol.packet.DatabasePacket
;
import
org.apache.shardingsphere.infra.context.SchemaContext
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement
;
...
...
@@ -49,7 +49,7 @@ public final class MySQLComStmtPrepareExecutor implements CommandExecutor {
public
MySQLComStmtPrepareExecutor
(
final
MySQLComStmtPreparePacket
packet
,
final
BackendConnection
backendConnection
)
{
this
.
packet
=
packet
;
schema
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
schema
=
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
}
private
int
getColumnsCount
(
final
SQLStatement
sqlStatement
)
{
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java
浏览文件 @
9d3dab10
...
...
@@ -27,7 +27,7 @@ import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicati
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor
;
import
org.apache.shardingsphere.proxy.frontend.mysql.MySQLErrPacketFactory
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
...
...
@@ -55,7 +55,7 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor {
schemaName
=
backendConnection
.
getSchema
();
String
sql
=
getShowColumnsSQL
();
SQLStatement
sqlStatement
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()).
getRuntimeContext
().
getSqlParserEngine
().
parse
(
sql
,
false
);
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
()).
getRuntimeContext
().
getSqlParserEngine
().
parse
(
sql
,
false
);
databaseCommunicationEngine
=
DatabaseCommunicationEngineFactory
.
getInstance
().
newTextProtocolInstance
(
sqlStatement
,
sql
,
backendConnection
);
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
浏览文件 @
9d3dab10
...
...
@@ -37,7 +37,7 @@ import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandlerFactory
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor
;
...
...
@@ -73,7 +73,7 @@ public final class MySQLComQueryPacketExecutor implements QueryCommandExecutor {
@Override
public
Collection
<
DatabasePacket
<?>>
execute
()
{
if
(
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
isCircuitBreak
())
{
if
(
Proxy
Context
.
getInstance
().
getSchemaContexts
().
isCircuitBreak
())
{
return
Collections
.
singletonList
(
new
MySQLErrPacket
(
1
,
CommonErrorCode
.
CIRCUIT_BREAK_MODE
));
}
BackendResponse
backendResponse
=
getBackendResponse
();
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLFrontendEngineTest.java
浏览文件 @
9d3dab10
...
...
@@ -34,7 +34,7 @@ import org.apache.shardingsphere.infra.context.impl.StandardSchemaContexts;
import
org.apache.shardingsphere.infra.context.runtime.RuntimeContext
;
import
org.apache.shardingsphere.infra.context.schema.ShardingSphereSchema
;
import
org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.connection.ConnectionIdGenerator
;
import
org.apache.shardingsphere.proxy.frontend.auth.AuthenticationResult
;
import
org.apache.shardingsphere.proxy.frontend.mysql.auth.MySQLAuthenticationEngine
;
...
...
@@ -147,7 +147,7 @@ public final class MySQLFrontendEngineTest {
private
void
setAuthentication
(
final
ProxyUser
proxyUser
)
{
Authentication
authentication
=
new
Authentication
();
authentication
.
getUsers
().
put
(
"root"
,
proxyUser
);
initProxy
SchemaContexts
(
authentication
);
initProxy
Context
(
authentication
);
}
@SneakyThrows
(
ReflectiveOperationException
.
class
)
...
...
@@ -158,10 +158,10 @@ public final class MySQLFrontendEngineTest {
}
@SneakyThrows
(
ReflectiveOperationException
.
class
)
private
void
initProxy
SchemaContexts
(
final
Authentication
authentication
)
{
Field
field
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
private
void
initProxy
Context
(
final
Authentication
authentication
)
{
Field
field
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
field
.
setAccessible
(
true
);
field
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
getSchemaContexts
(
authentication
));
field
.
set
(
Proxy
Context
.
getInstance
(),
getSchemaContexts
(
authentication
));
}
private
SchemaContexts
getSchemaContexts
(
final
Authentication
authentication
)
{
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationEngineTest.java
浏览文件 @
9d3dab10
...
...
@@ -32,7 +32,7 @@ import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties
import
org.apache.shardingsphere.infra.context.SchemaContext
;
import
org.apache.shardingsphere.infra.context.impl.StandardSchemaContexts
;
import
org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.auth.AuthenticationResultBuilder
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -137,9 +137,9 @@ public final class MySQLAuthenticationEngineTest {
}
private
void
setSchemas
()
throws
NoSuchFieldException
,
IllegalAccessException
{
Field
field
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
field
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
field
.
setAccessible
(
true
);
field
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
field
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
Collections
.
singletonMap
(
"sharding_db"
,
mock
(
SchemaContext
.
class
)),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/auth/MySQLAuthenticationHandlerTest.java
浏览文件 @
9d3dab10
...
...
@@ -30,7 +30,7 @@ import org.apache.shardingsphere.infra.context.impl.StandardSchemaContexts;
import
org.apache.shardingsphere.infra.context.runtime.RuntimeContext
;
import
org.apache.shardingsphere.infra.context.schema.ShardingSphereSchema
;
import
org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -110,14 +110,14 @@ public final class MySQLAuthenticationHandlerTest {
private
void
setAuthentication
(
final
ProxyUser
proxyUser
)
{
Authentication
authentication
=
new
Authentication
();
authentication
.
getUsers
().
put
(
"root"
,
proxyUser
);
initProxy
SchemaContexts
(
authentication
);
initProxy
Context
(
authentication
);
}
@SneakyThrows
private
void
initProxy
SchemaContexts
(
final
Authentication
authentication
)
{
Field
field
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
private
void
initProxy
Context
(
final
Authentication
authentication
)
{
Field
field
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
field
.
setAccessible
(
true
);
field
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
getSchemaContexts
(
authentication
));
field
.
set
(
Proxy
Context
.
getInstance
(),
getSchemaContexts
(
authentication
));
}
private
SchemaContexts
getSchemaContexts
(
final
Authentication
authentication
)
{
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecutorFactoryTest.java
浏览文件 @
9d3dab10
...
...
@@ -35,7 +35,7 @@ import org.apache.shardingsphere.infra.context.runtime.RuntimeContext;
import
org.apache.shardingsphere.infra.context.schema.ShardingSphereSchema
;
import
org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.mysql.command.admin.initdb.MySQLComInitDbExecutor
;
import
org.apache.shardingsphere.proxy.frontend.mysql.command.admin.ping.MySQLComPingExecutor
;
import
org.apache.shardingsphere.proxy.frontend.mysql.command.admin.quit.MySQLComQuitExecutor
;
...
...
@@ -66,9 +66,9 @@ public final class MySQLCommandExecutorFactoryTest {
@Test
@SneakyThrows
(
ReflectiveOperationException
.
class
)
public
void
assertNewInstance
()
{
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
BackendConnection
backendConnection
=
mock
(
BackendConnection
.
class
);
when
(
backendConnection
.
getSchema
()).
thenReturn
(
"schema"
);
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
浏览文件 @
9d3dab10
...
...
@@ -30,7 +30,7 @@ import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.Bac
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -61,9 +61,9 @@ public final class MySQLComStmtExecuteExecutorTest {
@Before
public
void
setUp
()
throws
ReflectiveOperationException
{
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngine.java
浏览文件 @
9d3dab10
...
...
@@ -32,7 +32,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.Postgre
import
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLRandomGenerator
;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLSSLNegativePacket
;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.connection.ConnectionIdGenerator
;
import
org.apache.shardingsphere.proxy.frontend.auth.AuthenticationResultBuilder
;
import
org.apache.shardingsphere.proxy.frontend.auth.AuthenticationEngine
;
...
...
@@ -84,7 +84,7 @@ public final class PostgreSQLAuthenticationEngine implements AuthenticationEngin
PostgreSQLComStartupPacket
comStartupPacket
=
new
PostgreSQLComStartupPacket
(
payload
);
startupMessageReceived
.
set
(
true
);
String
databaseName
=
comStartupPacket
.
getParametersMap
().
get
(
DATABASE_NAME_KEYWORD
);
if
(!
Strings
.
isNullOrEmpty
(
databaseName
)
&&
!
Proxy
SchemaContexts
.
getInstance
().
schemaExists
(
databaseName
))
{
if
(!
Strings
.
isNullOrEmpty
(
databaseName
)
&&
!
Proxy
Context
.
getInstance
().
schemaExists
(
databaseName
))
{
PostgreSQLErrorResponsePacket
responsePacket
=
createErrorPacket
(
PostgreSQLErrorCode
.
INVALID_CATALOG_NAME
,
String
.
format
(
"database \"%s\" does not exist"
,
databaseName
));
context
.
writeAndFlush
(
responsePacket
);
context
.
close
();
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationHandler.java
浏览文件 @
9d3dab10
...
...
@@ -18,13 +18,15 @@
package
org.apache.shardingsphere.proxy.frontend.postgresql.auth
;
import
com.google.common.base.Strings
;
import
lombok.AccessLevel
;
import
lombok.NoArgsConstructor
;
import
org.apache.commons.codec.binary.Hex
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLErrorCode
;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLPasswordMessagePacket
;
import
org.apache.shardingsphere.infra.auth.ProxyUser
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
java.security.MessageDigest
;
import
java.util.Collection
;
...
...
@@ -33,7 +35,8 @@ import java.util.Map;
/**
* Authentication handler for PostgreSQL.
*/
public
class
PostgreSQLAuthenticationHandler
{
@NoArgsConstructor
(
access
=
AccessLevel
.
PRIVATE
)
public
final
class
PostgreSQLAuthenticationHandler
{
/**
* Login.
...
...
@@ -46,7 +49,7 @@ public class PostgreSQLAuthenticationHandler {
*/
public
static
PostgreSQLLoginResult
loginWithMd5Password
(
final
String
username
,
final
String
databaseName
,
final
byte
[]
md5Salt
,
final
PostgreSQLPasswordMessagePacket
passwordMessagePacket
)
{
ProxyUser
proxyUser
=
null
;
for
(
Map
.
Entry
<
String
,
ProxyUser
>
entry
:
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getAuthentication
().
getUsers
().
entrySet
())
{
for
(
Map
.
Entry
<
String
,
ProxyUser
>
entry
:
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getAuthentication
().
getUsers
().
entrySet
())
{
if
(
entry
.
getKey
().
equals
(
username
))
{
proxyUser
=
entry
.
getValue
();
break
;
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java
浏览文件 @
9d3dab10
...
...
@@ -33,7 +33,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQ
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor
;
import
org.apache.shardingsphere.proxy.frontend.command.CommandExecuteEngine
;
...
...
@@ -87,7 +87,7 @@ public final class PostgreSQLCommandExecuteEngine implements CommandExecuteEngin
return
;
}
int
count
=
0
;
int
proxyFrontendFlushThreshold
=
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
getProps
().<
Integer
>
getValue
(
ConfigurationPropertyKey
.
PROXY_FRONTEND_FLUSH_THRESHOLD
);
int
proxyFrontendFlushThreshold
=
Proxy
Context
.
getInstance
().
getSchemaContexts
().
getProps
().<
Integer
>
getValue
(
ConfigurationPropertyKey
.
PROXY_FRONTEND_FLUSH_THRESHOLD
);
while
(
queryCommandExecutor
.
next
())
{
count
++;
while
(!
context
.
channel
().
isWritable
()
&&
context
.
channel
().
isActive
())
{
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutor.java
浏览文件 @
9d3dab10
...
...
@@ -40,7 +40,7 @@ import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor
;
import
org.apache.shardingsphere.proxy.frontend.postgresql.PostgreSQLErrPacketFactory
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
...
...
@@ -74,7 +74,7 @@ public final class PostgreSQLComBindExecutor implements QueryCommandExecutor {
public
PostgreSQLComBindExecutor
(
final
PostgreSQLComBindPacket
packet
,
final
BackendConnection
backendConnection
)
{
this
.
packet
=
packet
;
SchemaContext
schemaContext
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
SchemaContext
schemaContext
=
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
if
(
null
!=
packet
.
getSql
()
&&
null
!=
schemaContext
)
{
SQLStatement
sqlStatement
=
schemaContext
.
getRuntimeContext
().
getSqlParserEngine
().
parse
(
packet
.
getSql
(),
true
);
databaseCommunicationEngine
=
...
...
@@ -86,7 +86,7 @@ public final class PostgreSQLComBindExecutor implements QueryCommandExecutor {
@Override
public
Collection
<
DatabasePacket
<?>>
execute
()
{
if
(
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
isCircuitBreak
())
{
if
(
Proxy
Context
.
getInstance
().
getSchemaContexts
().
isCircuitBreak
())
{
return
Collections
.
singletonList
(
new
PostgreSQLErrorResponsePacket
());
}
List
<
DatabasePacket
<?>>
result
=
new
LinkedList
<>();
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/parse/PostgreSQLComParseExecutor.java
浏览文件 @
9d3dab10
...
...
@@ -24,7 +24,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.bin
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.parse.PostgreSQLParseCompletePacket
;
import
org.apache.shardingsphere.infra.context.SchemaContext
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor
;
import
org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement
;
...
...
@@ -44,7 +44,7 @@ public final class PostgreSQLComParseExecutor implements CommandExecutor {
public
PostgreSQLComParseExecutor
(
final
PostgreSQLComParsePacket
packet
,
final
BackendConnection
backendConnection
)
{
this
.
packet
=
packet
;
schema
=
Proxy
SchemaContexts
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
schema
=
Proxy
Context
.
getInstance
().
getSchema
(
backendConnection
.
getSchema
());
binaryStatementRegistry
=
BinaryStatementRegistry
.
getInstance
().
get
(
backendConnection
.
getConnectionId
());
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutor.java
浏览文件 @
9d3dab10
...
...
@@ -34,7 +34,7 @@ import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler
;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandlerFactory
;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor
;
...
...
@@ -70,7 +70,7 @@ public final class PostgreSQLComQueryExecutor implements QueryCommandExecutor {
@Override
public
Collection
<
DatabasePacket
<?>>
execute
()
{
if
(
Proxy
SchemaContexts
.
getInstance
().
getSchemaContexts
().
isCircuitBreak
())
{
if
(
Proxy
Context
.
getInstance
().
getSchemaContexts
().
isCircuitBreak
())
{
return
Collections
.
singletonList
(
new
PostgreSQLErrorResponsePacket
());
}
BackendResponse
backendResponse
=
getBackendResponse
();
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
浏览文件 @
9d3dab10
...
...
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.Postgre
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload
;
import
org.apache.shardingsphere.infra.auth.ProxyUser
;
import
org.apache.shardingsphere.infra.context.impl.StandardSchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.apache.shardingsphere.proxy.frontend.auth.AuthenticationResult
;
import
org.apache.shardingsphere.transaction.context.TransactionContexts
;
import
org.junit.Test
;
...
...
@@ -123,10 +123,10 @@ public final class PostgreSQLAuthenticationEngineTest {
payload
.
writeInt4
(
4
+
md5Digest
.
length
()
+
1
);
payload
.
writeStringNul
(
md5Digest
);
Proxy
SchemaContexts
proxySchemaContexts
=
ProxySchemaContexts
.
getInstance
();
Proxy
Context
proxyContext
=
ProxyContext
.
getInstance
();
StandardSchemaContexts
standardSchemaContexts
=
new
StandardSchemaContexts
();
standardSchemaContexts
.
getAuthentication
().
getUsers
().
put
(
username
,
new
ProxyUser
(
password
,
null
));
proxy
SchemaContexts
.
init
(
standardSchemaContexts
,
mock
(
TransactionContexts
.
class
));
proxy
Context
.
init
(
standardSchemaContexts
,
mock
(
TransactionContexts
.
class
));
actual
=
engine
.
auth
(
channelHandlerContext
,
payload
);
assertThat
(
actual
.
isFinished
(),
is
(
password
.
equals
(
inputPassword
)));
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutorTest.java
浏览文件 @
9d3dab10
...
...
@@ -28,7 +28,7 @@ import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
SchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.schema.Proxy
Context
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
...
...
@@ -58,9 +58,9 @@ public final class PostgreSQLComBindExecutorTest {
@Test
@SneakyThrows
public
void
assertExecuteHasError
()
{
Field
schemaContexts
=
Proxy
SchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
Field
schemaContexts
=
Proxy
Context
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
schemaContexts
.
set
(
Proxy
SchemaContexts
.
getInstance
(),
schemaContexts
.
set
(
Proxy
Context
.
getInstance
(),
new
StandardSchemaContexts
(
getSchemaContextMap
(),
new
Authentication
(),
new
ConfigurationProperties
(
new
Properties
()),
new
MySQLDatabaseType
()));
BackendConnection
connection
=
mock
(
BackendConnection
.
class
);
when
(
connection
.
getSchema
()).
thenReturn
(
"schema"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录