Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
651a4929
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,发现更多精彩内容 >>
提交
651a4929
编写于
11月 13, 2018
作者:
T
tristaZero
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' of
ssh://github.com/shardingjdbc/sharding-jdbc
into dev
上级
12947af5
c495b78e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
144 addition
and
10 deletion
+144
-10
sharding-jdbc/sharding-jdbc-core/src/main/java/io/shardingsphere/shardingjdbc/jdbc/adapter/AbstractDataSourceAdapter.java
.../shardingjdbc/jdbc/adapter/AbstractDataSourceAdapter.java
+15
-1
sharding-transaction/sharding-transaction-xa/src/main/java/io/shardingsphere/transaction/xa/convert/dialect/OracleXAProperty.java
...here/transaction/xa/convert/dialect/OracleXAProperty.java
+52
-0
sharding-transaction/sharding-transaction-xa/src/main/java/io/shardingsphere/transaction/xa/convert/dialect/SQLServerXAProperty.java
...e/transaction/xa/convert/dialect/SQLServerXAProperty.java
+52
-0
sharding-transaction/sharding-transaction-xa/src/main/java/io/shardingsphere/transaction/xa/convert/dialect/XAPropertyFactory.java
...ere/transaction/xa/convert/dialect/XAPropertyFactory.java
+4
-0
sharding-transaction/sharding-transaction-xa/src/test/java/io/shardingsphere/transaction/xa/convert/dialect/XADataSourceFactoryTest.java
...ansaction/xa/convert/dialect/XADataSourceFactoryTest.java
+0
-7
sharding-transaction/sharding-transaction-xa/src/test/java/io/shardingsphere/transaction/xa/convert/dialect/XAPropertyFactoryTest.java
...transaction/xa/convert/dialect/XAPropertyFactoryTest.java
+18
-0
sharding-transaction/sharding-transaction-xa/src/test/java/io/shardingsphere/transaction/xa/manager/AtomikosTransactionManagerTest.java
...ransaction/xa/manager/AtomikosTransactionManagerTest.java
+3
-2
未找到文件。
sharding-jdbc/sharding-jdbc-core/src/main/java/io/shardingsphere/shardingjdbc/jdbc/adapter/AbstractDataSourceAdapter.java
浏览文件 @
651a4929
...
...
@@ -28,6 +28,7 @@ import lombok.Setter;
import
javax.sql.DataSource
;
import
java.io.PrintWriter
;
import
java.lang.reflect.Method
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
import
java.util.Collection
;
...
...
@@ -113,9 +114,22 @@ public abstract class AbstractDataSourceAdapter extends AbstractUnsupportedOpera
private
void
closeDataSource
(
final
Map
<
String
,
DataSource
>
dataSourceMap
)
{
for
(
DataSource
each
:
dataSourceMap
.
values
())
{
try
{
each
.
getClass
().
getDeclaredMethod
(
"close"
).
invoke
(
each
);
findMethod
(
each
,
"close"
).
invoke
(
each
);
}
catch
(
final
ReflectiveOperationException
ignored
)
{
}
}
}
@SuppressWarnings
(
"unchecked"
)
private
Method
findMethod
(
final
Object
target
,
final
String
methodName
,
final
Class
<?>...
parameterTypes
)
throws
NoSuchMethodException
{
Class
clazz
=
target
.
getClass
();
while
(
null
!=
clazz
)
{
try
{
return
clazz
.
getDeclaredMethod
(
methodName
,
parameterTypes
);
}
catch
(
NoSuchMethodException
ignored
)
{
}
clazz
=
clazz
.
getSuperclass
();
}
throw
new
NoSuchMethodException
(
String
.
format
(
"Cannot find method '%s' in %s"
,
methodName
,
target
.
getClass
().
getName
()));
}
}
sharding-transaction/sharding-transaction-xa/src/main/java/io/shardingsphere/transaction/xa/convert/dialect/OracleXAProperty.java
0 → 100644
浏览文件 @
651a4929
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package
io.shardingsphere.transaction.xa.convert.dialect
;
import
com.google.common.base.Optional
;
import
io.shardingsphere.core.metadata.datasource.dialect.OracleDataSourceMetaData
;
import
io.shardingsphere.core.rule.DataSourceParameter
;
import
lombok.RequiredArgsConstructor
;
import
java.util.Properties
;
/**
* Create Oracle XA property from datasource parameter.
*
* @author zhaojun
*/
@RequiredArgsConstructor
public
class
OracleXAProperty
{
private
final
DataSourceParameter
dataSourceParameter
;
/**
* Build Oracle XA properties.
*
* @return Oracle XA properties
*/
public
Properties
build
()
{
Properties
result
=
new
Properties
();
OracleDataSourceMetaData
oracleMetaData
=
new
OracleDataSourceMetaData
(
dataSourceParameter
.
getUrl
());
result
.
setProperty
(
"user"
,
dataSourceParameter
.
getUsername
());
result
.
setProperty
(
"password"
,
Optional
.
fromNullable
(
dataSourceParameter
.
getPassword
()).
or
(
""
));
result
.
setProperty
(
"serverName"
,
oracleMetaData
.
getHostName
());
result
.
setProperty
(
"portNumber"
,
String
.
valueOf
(
oracleMetaData
.
getPort
()));
result
.
setProperty
(
"databaseName"
,
oracleMetaData
.
getSchemeName
());
return
result
;
}
}
sharding-transaction/sharding-transaction-xa/src/main/java/io/shardingsphere/transaction/xa/convert/dialect/SQLServerXAProperty.java
0 → 100644
浏览文件 @
651a4929
/*
* Copyright 2016-2018 shardingsphere.io.
* <p>
* Licensed 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.
* </p>
*/
package
io.shardingsphere.transaction.xa.convert.dialect
;
import
com.google.common.base.Optional
;
import
io.shardingsphere.core.metadata.datasource.dialect.SQLServerDataSourceMetaData
;
import
io.shardingsphere.core.rule.DataSourceParameter
;
import
lombok.RequiredArgsConstructor
;
import
java.util.Properties
;
/**
* Create SQLServer XA property from datasource parameter.
*
* @author zhaojun
*/
@RequiredArgsConstructor
public
class
SQLServerXAProperty
{
private
final
DataSourceParameter
dataSourceParameter
;
/**
* Build SQLServer XA properties.
*
* @return SQLServer XA properties
*/
public
Properties
build
()
{
Properties
result
=
new
Properties
();
SQLServerDataSourceMetaData
sqlServerMetaData
=
new
SQLServerDataSourceMetaData
(
dataSourceParameter
.
getUrl
());
result
.
setProperty
(
"user"
,
dataSourceParameter
.
getUsername
());
result
.
setProperty
(
"password"
,
Optional
.
fromNullable
(
dataSourceParameter
.
getPassword
()).
or
(
""
));
result
.
setProperty
(
"serverName"
,
sqlServerMetaData
.
getHostName
());
result
.
setProperty
(
"portNumber"
,
String
.
valueOf
(
sqlServerMetaData
.
getPort
()));
result
.
setProperty
(
"databaseName"
,
sqlServerMetaData
.
getSchemeName
());
return
result
;
}
}
sharding-transaction/sharding-transaction-xa/src/main/java/io/shardingsphere/transaction/xa/convert/dialect/XAPropertyFactory.java
浏览文件 @
651a4929
...
...
@@ -46,6 +46,10 @@ public class XAPropertyFactory {
return
new
PGXAProperty
(
dataSourceParameter
).
build
();
case
H2:
return
new
H2XAProperty
(
dataSourceParameter
).
build
();
case
SQLServer:
return
new
SQLServerXAProperty
(
dataSourceParameter
).
build
();
case
Oracle:
return
new
OracleXAProperty
(
dataSourceParameter
).
build
();
default
:
return
new
Properties
();
}
...
...
sharding-transaction/sharding-transaction-xa/src/test/java/io/shardingsphere/transaction/xa/convert/dialect/XADataSourceFactoryTest.java
浏览文件 @
651a4929
...
...
@@ -18,7 +18,6 @@
package
io.shardingsphere.transaction.xa.convert.dialect
;
import
com.microsoft.sqlserver.jdbc.SQLServerXADataSource
;
import
com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
;
import
io.shardingsphere.core.constant.DatabaseType
;
import
org.h2.jdbcx.JdbcDataSource
;
import
org.junit.Test
;
...
...
@@ -37,12 +36,6 @@ public class XADataSourceFactoryTest {
assertThat
(
xaDataSource
,
instanceOf
(
JdbcDataSource
.
class
));
}
@Test
public
void
assertCreateMysqlXADataSource
()
{
XADataSource
xaDataSource
=
XADataSourceFactory
.
build
(
DatabaseType
.
MySQL
);
assertThat
(
xaDataSource
,
instanceOf
(
MysqlXADataSource
.
class
));
}
@Test
public
void
assertCreatePGXADataSource
()
{
XADataSource
xaDataSource
=
XADataSourceFactory
.
build
(
DatabaseType
.
PostgreSQL
);
...
...
sharding-transaction/sharding-transaction-xa/src/test/java/io/shardingsphere/transaction/xa/convert/dialect/XAPropertyFactoryTest.java
浏览文件 @
651a4929
...
...
@@ -85,5 +85,23 @@ public class XAPropertyFactoryTest {
@Test
public
void
assertGetSQLServerXAProperties
()
{
dataSourceParameter
.
setUrl
(
"jdbc:sqlserver://db.sqlserver:1433;DatabaseName=test_db"
);
Properties
xaProperties
=
XAPropertyFactory
.
build
(
XADatabaseType
.
SQLServer
,
dataSourceParameter
);
assertThat
(
xaProperties
.
getProperty
(
"user"
),
is
(
"root"
));
assertThat
(
xaProperties
.
getProperty
(
"password"
),
is
(
"root"
));
assertThat
(
xaProperties
.
getProperty
(
"serverName"
),
is
(
"db.sqlserver"
));
assertThat
(
xaProperties
.
getProperty
(
"portNumber"
),
is
(
"1433"
));
assertThat
(
xaProperties
.
getProperty
(
"databaseName"
),
is
(
"test_db"
));
}
@Test
public
void
assertGetOracleXAProperties
()
{
dataSourceParameter
.
setUrl
(
"jdbc:oracle:thin:@//db.oracle:9999/test_db"
);
Properties
xaProperties
=
XAPropertyFactory
.
build
(
XADatabaseType
.
Oracle
,
dataSourceParameter
);
assertThat
(
xaProperties
.
getProperty
(
"user"
),
is
(
"root"
));
assertThat
(
xaProperties
.
getProperty
(
"password"
),
is
(
"root"
));
assertThat
(
xaProperties
.
getProperty
(
"serverName"
),
is
(
"db.oracle"
));
assertThat
(
xaProperties
.
getProperty
(
"portNumber"
),
is
(
"9999"
));
assertThat
(
xaProperties
.
getProperty
(
"databaseName"
),
is
(
"test_db"
));
}
}
sharding-transaction/sharding-transaction-xa/src/test/java/io/shardingsphere/transaction/xa/manager/AtomikosTransactionManagerTest.java
浏览文件 @
651a4929
...
...
@@ -27,6 +27,7 @@ import io.shardingsphere.core.exception.ShardingException;
import
io.shardingsphere.core.rule.DataSourceParameter
;
import
io.shardingsphere.transaction.xa.fixture.ReflectiveUtil
;
import
lombok.SneakyThrows
;
import
org.h2.jdbcx.JdbcDataSource
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -136,8 +137,8 @@ public final class AtomikosTransactionManagerTest {
}
@Test
public
void
assertWrapDataSourceFor
MySQL
()
{
XADataSource
xaDataSource
=
new
MysqlXA
DataSource
();
public
void
assertWrapDataSourceFor
H2
()
{
XADataSource
xaDataSource
=
new
Jdbc
DataSource
();
DataSourceParameter
dataSourceParameter
=
new
DataSourceParameter
();
dataSourceParameter
.
setUsername
(
"root"
);
dataSourceParameter
.
setPassword
(
"root"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录