Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
da283c2f
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 搜索 >>
未验证
提交
da283c2f
编写于
6月 03, 2020
作者:
X
xiaoyu
提交者:
GitHub
6月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix oracle bug. (#5908)
上级
5f07d25c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
20 addition
and
15 deletion
+20
-15
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/column/ColumnMetaDataLoader.java
...l/parser/binder/metadata/column/ColumnMetaDataLoader.java
+7
-7
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/index/IndexMetaDataLoader.java
...sql/parser/binder/metadata/index/IndexMetaDataLoader.java
+3
-2
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/schema/SchemaMetaDataLoader.java
...l/parser/binder/metadata/schema/SchemaMetaDataLoader.java
+4
-4
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/table/TableMetaDataLoader.java
...sql/parser/binder/metadata/table/TableMetaDataLoader.java
+1
-1
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/util/JdbcUtil.java
...rdingsphere/sql/parser/binder/metadata/util/JdbcUtil.java
+5
-1
未找到文件。
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/column/ColumnMetaDataLoader.java
浏览文件 @
da283c2f
...
...
@@ -53,17 +53,17 @@ public final class ColumnMetaDataLoader {
* @throws SQLException SQL exception
*/
public
static
Collection
<
ColumnMetaData
>
load
(
final
Connection
connection
,
final
String
table
,
final
String
databaseType
)
throws
SQLException
{
if
(!
isTableExist
(
connection
,
connection
.
getCatalog
(),
table
))
{
if
(!
isTableExist
(
connection
,
connection
.
getCatalog
(),
table
,
databaseType
))
{
return
Collections
.
emptyList
();
}
Collection
<
ColumnMetaData
>
result
=
new
LinkedList
<>();
Collection
<
String
>
primaryKeys
=
loadPrimaryKeys
(
connection
,
table
);
Collection
<
String
>
primaryKeys
=
loadPrimaryKeys
(
connection
,
table
,
databaseType
);
List
<
String
>
columnNames
=
new
ArrayList
<>();
List
<
Integer
>
columnTypes
=
new
ArrayList
<>();
List
<
String
>
columnTypeNames
=
new
ArrayList
<>();
List
<
Boolean
>
isPrimaryKeys
=
new
ArrayList
<>();
List
<
Boolean
>
isCaseSensitives
=
new
ArrayList
<>();
try
(
ResultSet
resultSet
=
connection
.
getMetaData
().
getColumns
(
connection
.
getCatalog
(),
JdbcUtil
.
getSchema
(
connection
),
table
,
"%"
))
{
try
(
ResultSet
resultSet
=
connection
.
getMetaData
().
getColumns
(
connection
.
getCatalog
(),
JdbcUtil
.
getSchema
(
connection
,
databaseType
),
table
,
"%"
))
{
while
(
resultSet
.
next
())
{
String
columnName
=
resultSet
.
getString
(
COLUMN_NAME
);
columnTypes
.
add
(
resultSet
.
getInt
(
DATA_TYPE
));
...
...
@@ -104,15 +104,15 @@ public final class ColumnMetaDataLoader {
return
"SELECT * FROM "
+
delimiterLeft
+
table
+
delimiterRight
+
" WHERE 1 != 1"
;
}
private
static
boolean
isTableExist
(
final
Connection
connection
,
final
String
catalog
,
final
String
table
)
throws
SQLException
{
try
(
ResultSet
resultSet
=
connection
.
getMetaData
().
getTables
(
catalog
,
JdbcUtil
.
getSchema
(
connection
),
table
,
null
))
{
private
static
boolean
isTableExist
(
final
Connection
connection
,
final
String
catalog
,
final
String
table
,
final
String
databaseType
)
throws
SQLException
{
try
(
ResultSet
resultSet
=
connection
.
getMetaData
().
getTables
(
catalog
,
JdbcUtil
.
getSchema
(
connection
,
databaseType
),
table
,
null
))
{
return
resultSet
.
next
();
}
}
private
static
Collection
<
String
>
loadPrimaryKeys
(
final
Connection
connection
,
final
String
table
)
throws
SQLException
{
private
static
Collection
<
String
>
loadPrimaryKeys
(
final
Connection
connection
,
final
String
table
,
final
String
databaseType
)
throws
SQLException
{
Collection
<
String
>
result
=
new
HashSet
<>();
try
(
ResultSet
resultSet
=
connection
.
getMetaData
().
getPrimaryKeys
(
connection
.
getCatalog
(),
JdbcUtil
.
getSchema
(
connection
),
table
))
{
try
(
ResultSet
resultSet
=
connection
.
getMetaData
().
getPrimaryKeys
(
connection
.
getCatalog
(),
JdbcUtil
.
getSchema
(
connection
,
databaseType
),
table
))
{
while
(
resultSet
.
next
())
{
result
.
add
(
resultSet
.
getString
(
COLUMN_NAME
));
}
...
...
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/index/IndexMetaDataLoader.java
浏览文件 @
da283c2f
...
...
@@ -40,12 +40,13 @@ public final class IndexMetaDataLoader {
*
* @param connection connection
* @param table table name
* @param databaseType databaseType
* @return index meta data list
* @throws SQLException SQL exception
*/
public
static
Collection
<
IndexMetaData
>
load
(
final
Connection
connection
,
final
String
table
)
throws
SQLException
{
public
static
Collection
<
IndexMetaData
>
load
(
final
Connection
connection
,
final
String
table
,
final
String
databaseType
)
throws
SQLException
{
Collection
<
IndexMetaData
>
result
=
new
HashSet
<>();
try
(
ResultSet
resultSet
=
connection
.
getMetaData
().
getIndexInfo
(
connection
.
getCatalog
(),
JdbcUtil
.
getSchema
(
connection
),
table
,
false
,
false
))
{
try
(
ResultSet
resultSet
=
connection
.
getMetaData
().
getIndexInfo
(
connection
.
getCatalog
(),
JdbcUtil
.
getSchema
(
connection
,
databaseType
),
table
,
false
,
false
))
{
while
(
resultSet
.
next
())
{
String
indexName
=
resultSet
.
getString
(
INDEX_NAME
);
if
(
null
!=
indexName
)
{
...
...
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/schema/SchemaMetaDataLoader.java
浏览文件 @
da283c2f
...
...
@@ -65,7 +65,7 @@ public final class SchemaMetaDataLoader {
public
static
SchemaMetaData
load
(
final
DataSource
dataSource
,
final
int
maxConnectionCount
,
final
String
databaseType
)
throws
SQLException
{
List
<
String
>
tableNames
;
try
(
Connection
connection
=
dataSource
.
getConnection
())
{
tableNames
=
loadAllTableNames
(
connection
);
tableNames
=
loadAllTableNames
(
connection
,
databaseType
);
}
log
.
info
(
"Loading {} tables' meta data."
,
tableNames
.
size
());
if
(
0
==
tableNames
.
size
())
{
...
...
@@ -81,15 +81,15 @@ public final class SchemaMetaDataLoader {
try
(
Connection
con
=
connection
)
{
Map
<
String
,
TableMetaData
>
result
=
new
LinkedHashMap
<>();
for
(
String
each
:
tables
)
{
result
.
put
(
each
,
new
TableMetaData
(
ColumnMetaDataLoader
.
load
(
con
,
each
,
databaseType
),
IndexMetaDataLoader
.
load
(
con
,
each
)));
result
.
put
(
each
,
new
TableMetaData
(
ColumnMetaDataLoader
.
load
(
con
,
each
,
databaseType
),
IndexMetaDataLoader
.
load
(
con
,
each
,
databaseType
)));
}
return
result
;
}
}
private
static
List
<
String
>
loadAllTableNames
(
final
Connection
connection
)
throws
SQLException
{
private
static
List
<
String
>
loadAllTableNames
(
final
Connection
connection
,
final
String
databaseType
)
throws
SQLException
{
List
<
String
>
result
=
new
LinkedList
<>();
try
(
ResultSet
resultSet
=
connection
.
getMetaData
().
getTables
(
connection
.
getCatalog
(),
JdbcUtil
.
getSchema
(
connection
),
null
,
new
String
[]{
TABLE_TYPE
}))
{
try
(
ResultSet
resultSet
=
connection
.
getMetaData
().
getTables
(
connection
.
getCatalog
(),
JdbcUtil
.
getSchema
(
connection
,
databaseType
),
null
,
new
String
[]{
TABLE_TYPE
}))
{
while
(
resultSet
.
next
())
{
String
table
=
resultSet
.
getString
(
TABLE_NAME
);
if
(!
isSystemTable
(
table
))
{
...
...
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/table/TableMetaDataLoader.java
浏览文件 @
da283c2f
...
...
@@ -43,7 +43,7 @@ public final class TableMetaDataLoader {
*/
public
static
TableMetaData
load
(
final
DataSource
dataSource
,
final
String
table
,
final
String
databaseType
)
throws
SQLException
{
try
(
Connection
connection
=
dataSource
.
getConnection
())
{
return
new
TableMetaData
(
ColumnMetaDataLoader
.
load
(
connection
,
table
,
databaseType
),
IndexMetaDataLoader
.
load
(
connection
,
table
));
return
new
TableMetaData
(
ColumnMetaDataLoader
.
load
(
connection
,
table
,
databaseType
),
IndexMetaDataLoader
.
load
(
connection
,
table
,
databaseType
));
}
}
}
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/util/JdbcUtil.java
浏览文件 @
da283c2f
...
...
@@ -29,11 +29,15 @@ public class JdbcUtil {
* Get schema.
*
* @param connection connection
* @param databaseType database type
* @return schema
*/
public
static
String
getSchema
(
final
Connection
connection
)
{
public
static
String
getSchema
(
final
Connection
connection
,
final
String
databaseType
)
{
String
result
=
null
;
try
{
if
(
"Oracle"
.
equals
(
databaseType
))
{
return
null
;
}
result
=
connection
.
getSchema
();
}
catch
(
final
SQLException
ignore
)
{
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录