Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
46be46ae
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 搜索 >>
未验证
提交
46be46ae
编写于
5月 14, 2020
作者:
J
Juan Pan(Trista)
提交者:
GitHub
5月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add SchemaContextsBuilder (#5606)
上级
fe5bce52
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
138 addition
and
15 deletion
+138
-15
sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/context/SchemaContextsBuilder.java
...shardingjdbc/jdbc/core/context/SchemaContextsBuilder.java
+129
-0
sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/ShardingSphereDataSource.java
...ngjdbc/jdbc/core/datasource/ShardingSphereDataSource.java
+5
-0
shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/context/ShardingSphereSchema.java
...phere/underlying/common/context/ShardingSphereSchema.java
+2
-5
shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/context/runtime/RuntimeExecutorKernel.java
...erlying/common/context/runtime/RuntimeExecutorKernel.java
+0
-9
shardingsphere-underlying/shardingsphere-executor/src/main/java/org/apache/shardingsphere/underlying/executor/kernel/ExecutorKernel.java
...dingsphere/underlying/executor/kernel/ExecutorKernel.java
+2
-1
未找到文件。
sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/context/SchemaContextsBuilder.java
0 → 100644
浏览文件 @
46be46ae
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.shardingjdbc.jdbc.core.context
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.shardingsphere.sharding.core.log.ConfigurationLogger
;
import
org.apache.shardingsphere.underlying.common.auth.Authentication
;
import
org.apache.shardingsphere.underlying.common.config.DatabaseAccessConfiguration
;
import
org.apache.shardingsphere.underlying.common.config.RuleConfiguration
;
import
org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties
;
import
org.apache.shardingsphere.underlying.common.config.properties.ConfigurationPropertyKey
;
import
org.apache.shardingsphere.underlying.common.context.SchemaContext
;
import
org.apache.shardingsphere.underlying.common.context.SchemaContexts
;
import
org.apache.shardingsphere.underlying.common.context.ShardingSphereSchema
;
import
org.apache.shardingsphere.underlying.common.context.runtime.CachedDatabaseMetaData
;
import
org.apache.shardingsphere.underlying.common.context.runtime.RuntimeContext
;
import
org.apache.shardingsphere.underlying.common.database.type.DatabaseType
;
import
org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData
;
import
org.apache.shardingsphere.underlying.common.metadata.datasource.DataSourceMetas
;
import
org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaData
;
import
org.apache.shardingsphere.underlying.common.metadata.schema.RuleSchemaMetaDataLoader
;
import
org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule
;
import
org.apache.shardingsphere.underlying.common.rule.ShardingSphereRulesBuilder
;
import
org.apache.shardingsphere.underlying.executor.kernel.ExecutorKernel
;
import
javax.sql.DataSource
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
java.sql.SQLException
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Properties
;
@Slf4j
(
topic
=
"ShardingSphere-metadata"
)
public
final
class
SchemaContextsBuilder
{
private
final
Map
<
String
,
DataSource
>
dataSources
;
private
final
DatabaseType
databaseType
;
private
final
Collection
<
RuleConfiguration
>
configurations
;
private
final
Collection
<
ShardingSphereRule
>
rules
;
private
final
ConfigurationProperties
properties
;
private
final
ExecutorKernel
executorKernel
;
private
final
CachedDatabaseMetaData
cachedDatabaseMetaData
;
private
final
ShardingSphereMetaData
metaData
;
public
SchemaContextsBuilder
(
final
Map
<
String
,
DataSource
>
dataSources
,
final
DatabaseType
databaseType
,
final
Collection
<
RuleConfiguration
>
configurations
,
final
Properties
props
)
throws
SQLException
{
this
.
dataSources
=
dataSources
;
this
.
databaseType
=
databaseType
;
this
.
configurations
=
configurations
;
rules
=
ShardingSphereRulesBuilder
.
build
(
configurations
,
dataSources
.
keySet
());
properties
=
new
ConfigurationProperties
(
null
==
props
?
new
Properties
()
:
props
);
executorKernel
=
new
ExecutorKernel
(
properties
.<
Integer
>
getValue
(
ConfigurationPropertyKey
.
EXECUTOR_SIZE
));
cachedDatabaseMetaData
=
createCachedDatabaseMetaData
(
dataSources
);
metaData
=
createMetaData
(
dataSources
,
databaseType
);
log
(
configurations
,
props
);
}
/**
* Build.
*
* @return SchemaContexts
*/
public
SchemaContexts
build
()
{
return
new
SchemaContexts
(
Collections
.
singleton
(
createSchemaContext
()),
properties
,
new
Authentication
());
}
private
SchemaContext
createSchemaContext
()
{
return
new
SchemaContext
(
new
ShardingSphereSchema
(
databaseType
,
configurations
,
rules
,
dataSources
,
metaData
),
new
RuntimeContext
(
cachedDatabaseMetaData
,
executorKernel
));
}
private
CachedDatabaseMetaData
createCachedDatabaseMetaData
(
final
Map
<
String
,
DataSource
>
dataSourceMap
)
throws
SQLException
{
try
(
Connection
connection
=
dataSourceMap
.
values
().
iterator
().
next
().
getConnection
())
{
return
new
CachedDatabaseMetaData
(
connection
.
getMetaData
());
}
}
private
ShardingSphereMetaData
createMetaData
(
final
Map
<
String
,
DataSource
>
dataSourceMap
,
final
DatabaseType
databaseType
)
throws
SQLException
{
long
start
=
System
.
currentTimeMillis
();
DataSourceMetas
dataSourceMetas
=
new
DataSourceMetas
(
databaseType
,
getDatabaseAccessConfigurationMap
(
dataSourceMap
));
RuleSchemaMetaData
ruleSchemaMetaData
=
new
RuleSchemaMetaDataLoader
(
rules
).
load
(
databaseType
,
dataSourceMap
,
properties
,
executorKernel
.
getExecutorService
().
getExecutorService
());
ShardingSphereMetaData
result
=
new
ShardingSphereMetaData
(
dataSourceMetas
,
ruleSchemaMetaData
);
log
.
info
(
"Meta data load finished, cost {} milliseconds."
,
System
.
currentTimeMillis
()
-
start
);
return
result
;
}
private
Map
<
String
,
DatabaseAccessConfiguration
>
getDatabaseAccessConfigurationMap
(
final
Map
<
String
,
DataSource
>
dataSourceMap
)
throws
SQLException
{
Map
<
String
,
DatabaseAccessConfiguration
>
result
=
new
LinkedHashMap
<>(
dataSourceMap
.
size
(),
1
);
for
(
Entry
<
String
,
DataSource
>
entry
:
dataSourceMap
.
entrySet
())
{
DataSource
dataSource
=
entry
.
getValue
();
try
(
Connection
connection
=
dataSource
.
getConnection
())
{
DatabaseMetaData
metaData
=
connection
.
getMetaData
();
result
.
put
(
entry
.
getKey
(),
new
DatabaseAccessConfiguration
(
metaData
.
getURL
(),
metaData
.
getUserName
(),
null
));
}
}
return
result
;
}
private
void
log
(
final
Collection
<
RuleConfiguration
>
configurations
,
final
Properties
props
)
{
ConfigurationLogger
.
log
(
configurations
);
ConfigurationLogger
.
log
(
props
);
}
}
sharding-jdbc/sharding-jdbc-core/src/main/java/org/apache/shardingsphere/shardingjdbc/jdbc/core/datasource/ShardingSphereDataSource.java
浏览文件 @
46be46ae
...
...
@@ -22,9 +22,11 @@ import lombok.Getter;
import
lombok.Setter
;
import
org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.ShardingSphereConnection
;
import
org.apache.shardingsphere.shardingjdbc.jdbc.core.context.RuntimeContext
;
import
org.apache.shardingsphere.shardingjdbc.jdbc.core.context.SchemaContextsBuilder
;
import
org.apache.shardingsphere.shardingjdbc.jdbc.unsupported.AbstractUnsupportedOperationDataSource
;
import
org.apache.shardingsphere.transaction.core.TransactionTypeHolder
;
import
org.apache.shardingsphere.underlying.common.config.RuleConfiguration
;
import
org.apache.shardingsphere.underlying.common.context.SchemaContexts
;
import
org.apache.shardingsphere.underlying.common.database.type.DatabaseType
;
import
org.apache.shardingsphere.underlying.common.database.type.DatabaseTypes
;
...
...
@@ -50,6 +52,8 @@ public final class ShardingSphereDataSource extends AbstractUnsupportedOperation
private
final
RuntimeContext
runtimeContext
;
private
final
SchemaContexts
schemaContexts
;
@Setter
private
PrintWriter
logWriter
=
new
PrintWriter
(
System
.
out
);
...
...
@@ -57,6 +61,7 @@ public final class ShardingSphereDataSource extends AbstractUnsupportedOperation
this
.
dataSourceMap
=
dataSourceMap
;
databaseType
=
createDatabaseType
();
runtimeContext
=
new
RuntimeContext
(
dataSourceMap
,
databaseType
,
configurations
,
props
);
schemaContexts
=
new
SchemaContextsBuilder
(
dataSourceMap
,
databaseType
,
configurations
,
props
).
build
();
}
private
DatabaseType
createDatabaseType
()
throws
SQLException
{
...
...
shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/context/ShardingSphereSchema.java
浏览文件 @
46be46ae
...
...
@@ -17,12 +17,10 @@
package
org.apache.shardingsphere.underlying.common.context
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.underlying.common.config.RuleConfiguration
;
import
org.apache.shardingsphere.underlying.common.database.type.DatabaseType
;
import
org.apache.shardingsphere.underlying.common.metadata.ShardingSphereMetaData
;
import
org.apache.shardingsphere.underlying.common.rule.ShardingSphereRule
;
import
org.apache.shardingsphere.underlying.common.rule.ShardingSphereRulesBuilder
;
import
javax.sql.DataSource
;
import
java.util.Collection
;
...
...
@@ -30,7 +28,6 @@ import java.util.LinkedHashMap;
import
java.util.LinkedList
;
import
java.util.Map
;
@RequiredArgsConstructor
public
final
class
ShardingSphereSchema
{
private
final
DatabaseType
databaseType
;
...
...
@@ -43,11 +40,11 @@ public final class ShardingSphereSchema {
private
ShardingSphereMetaData
metaData
;
public
ShardingSphereSchema
(
final
DatabaseType
databaseType
,
final
Collection
<
RuleConfiguration
>
configurations
,
public
ShardingSphereSchema
(
final
DatabaseType
databaseType
,
final
Collection
<
RuleConfiguration
>
configurations
,
final
Collection
<
ShardingSphereRule
>
rules
,
final
Map
<
String
,
DataSource
>
dataSourceMap
,
final
ShardingSphereMetaData
shardingSphereMetaData
)
{
this
.
databaseType
=
databaseType
;
this
.
configurations
.
addAll
(
configurations
);
rules
=
ShardingSphereRulesBuilder
.
build
(
configurations
,
dataSourceMap
.
keySet
())
;
this
.
rules
=
rules
;
this
.
dataSources
.
putAll
(
dataSourceMap
);
metaData
=
shardingSphereMetaData
;
}
...
...
shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/context/runtime/RuntimeExecutorKernel.java
浏览文件 @
46be46ae
...
...
@@ -17,14 +17,5 @@
package
org.apache.shardingsphere.underlying.common.context.runtime
;
import
org.apache.shardingsphere.underlying.common.config.properties.ConfigurationProperties
;
public
interface
RuntimeExecutorKernel
{
/**
* Refresh executor kernel.
*
* @param properties properties
*/
void
refresh
(
ConfigurationProperties
properties
);
}
shardingsphere-underlying/shardingsphere-executor/src/main/java/org/apache/shardingsphere/underlying/executor/kernel/ExecutorKernel.java
浏览文件 @
46be46ae
...
...
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.underlying.executor.kernel;
import
com.google.common.collect.Lists
;
import
com.google.common.util.concurrent.ListenableFuture
;
import
lombok.Getter
;
import
org.apache.shardingsphere.underlying.common.context.runtime.RuntimeExecutorKernel
;
import
org.apache.shardingsphere.underlying.common.exception.ShardingSphereException
;
import
org.apache.shardingsphere.underlying.executor.kernel.impl.ShardingSphereExecutorService
;
...
...
@@ -35,7 +36,7 @@ import java.util.concurrent.ExecutionException;
/**
* Executor kernel.
*/
public
final
class
ExecutorKernel
implements
AutoCloseable
{
public
final
class
ExecutorKernel
implements
AutoCloseable
,
RuntimeExecutorKernel
{
@Getter
private
final
ShardingSphereExecutorService
executorService
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录