Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
2e77c507
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,发现更多精彩内容 >>
提交
2e77c507
编写于
5月 06, 2018
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
for #601: refactor generateCreateDatabaseSQLs
上级
5e840e9f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
9 addition
and
14 deletion
+9
-14
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java
...-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java
+1
-3
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/DatabaseEnvironmentManager.java
.../shardingjdbc/dbtest/init/DatabaseEnvironmentManager.java
+8
-11
未找到文件。
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/StartTest.java
浏览文件 @
2e77c507
...
...
@@ -31,7 +31,6 @@ import org.junit.runners.Parameterized.Parameters;
import
javax.xml.bind.JAXBContext
;
import
javax.xml.bind.JAXBException
;
import
javax.xml.bind.Unmarshaller
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.net.URISyntaxException
;
...
...
@@ -106,9 +105,8 @@ public final class StartTest {
}
private
static
AssertsDefinition
unmarshal
(
final
String
assertFilePath
)
throws
IOException
,
JAXBException
{
Unmarshaller
unmarshal
=
JAXBContext
.
newInstance
(
AssertsDefinition
.
class
).
createUnmarshaller
();
try
(
FileReader
reader
=
new
FileReader
(
assertFilePath
))
{
return
(
AssertsDefinition
)
unmarshal
.
unmarshal
(
reader
);
return
(
AssertsDefinition
)
JAXBContext
.
newInstance
(
AssertsDefinition
.
class
).
createUnmarshaller
()
.
unmarshal
(
reader
);
}
}
...
...
sharding-jdbc-core/src/test/java/io/shardingjdbc/dbtest/init/DatabaseEnvironmentManager.java
浏览文件 @
2e77c507
...
...
@@ -31,7 +31,6 @@ import org.xml.sax.SAXException;
import
javax.xml.bind.JAXBContext
;
import
javax.xml.bind.JAXBException
;
import
javax.xml.bind.Unmarshaller
;
import
javax.xml.parsers.ParserConfigurationException
;
import
javax.xml.xpath.XPathExpressionException
;
import
java.io.FileReader
;
...
...
@@ -44,6 +43,7 @@ import java.sql.SQLException;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.LinkedList
;
import
java.util.List
;
...
...
@@ -79,13 +79,9 @@ public final class DatabaseEnvironmentManager {
assertNotNull
(
databaseInitializationResources
);
DatabaseInitialization
databaseInitialization
=
unmarshal
(
databaseInitializationResources
.
getFile
());
for
(
DatabaseType
each
:
IntegrateTestEnvironment
.
getInstance
().
getDatabaseTypes
())
{
if
(
each
.
equals
(
DatabaseType
.
H2
))
{
continue
;
}
try
(
BasicDataSource
dataSource
=
(
BasicDataSource
)
new
DatabaseEnvironment
(
each
).
createDataSource
(
null
);
Connection
conn
=
dataSource
.
getConnection
();
StringReader
stringReader
=
new
StringReader
(
Joiner
.
on
(
"\n"
).
skipNulls
().
join
(
generateCreateDatabaseSQLs
(
each
,
databaseInitialization
.
getDatabases
()))))
{
ResultSet
resultSet
=
RunScript
.
execute
(
conn
,
stringReader
);
if
(
resultSet
!=
null
)
{
...
...
@@ -97,17 +93,19 @@ public final class DatabaseEnvironmentManager {
}
private
static
DatabaseInitialization
unmarshal
(
final
String
databaseInitializationFilePath
)
throws
IOException
,
JAXBException
{
Unmarshaller
unmarshal
=
JAXBContext
.
newInstance
(
DatabaseInitialization
.
class
).
createUnmarshaller
();
try
(
FileReader
reader
=
new
FileReader
(
databaseInitializationFilePath
))
{
return
(
DatabaseInitialization
)
unmarshal
.
unmarshal
(
reader
);
return
(
DatabaseInitialization
)
JAXBContext
.
newInstance
(
DatabaseInitialization
.
class
).
createUnmarshaller
()
.
unmarshal
(
reader
);
}
}
private
static
Collection
<
String
>
generateCreateDatabaseSQLs
(
final
DatabaseType
databaseType
,
final
List
<
String
>
databases
)
{
String
baseSQL
=
DatabaseType
.
Oracle
==
databaseType
?
"CREATE SCHEMA %s;"
:
"CREATE DATABASE %s;"
;
if
(
DatabaseType
.
H2
==
databaseType
)
{
return
Collections
.
emptyList
();
}
String
sql
=
DatabaseType
.
Oracle
==
databaseType
?
"CREATE SCHEMA %s;"
:
"CREATE DATABASE %s;"
;
Collection
<
String
>
result
=
new
LinkedList
<>();
for
(
String
each
:
databases
)
{
result
.
add
(
String
.
format
(
baseSQL
,
each
));
result
.
add
(
String
.
format
(
sql
,
each
));
}
return
result
;
}
...
...
@@ -129,8 +127,7 @@ public final class DatabaseEnvironmentManager {
.
getResource
(
"integrate/dbtest"
).
getPath
()
+
"/"
+
database
+
"/database.xml"
));
try
(
StringReader
sr
=
new
StringReader
(
oracleSql
);
BasicDataSource
dataSource
=
(
BasicDataSource
)
new
DatabaseEnvironment
(
each
).
createDataSource
(
null
);
Connection
conn
=
dataSource
.
getConnection
();)
{
Connection
conn
=
dataSource
.
getConnection
())
{
ResultSet
resultSet
=
RunScript
.
execute
(
conn
,
sr
);
if
(
resultSet
!=
null
)
{
resultSet
.
close
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录