Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
c4077e04
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,发现更多精彩内容 >>
提交
c4077e04
编写于
9月 01, 2016
作者:
G
gaoht
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix #141 ExecutorEngine parameter error
上级
577ae0bb
变更
23
显示空白变更内容
内联
并排
Showing
23 changed file
with
280 addition
and
39 deletion
+280
-39
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/config/ShardingPropertiesConstant.java
...frame/rdb/sharding/config/ShardingPropertiesConstant.java
+2
-2
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/ExecutorEngine.java
...angdang/ddframe/rdb/sharding/executor/ExecutorEngine.java
+17
-2
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/ShardingDataSource.java
...angdang/ddframe/rdb/sharding/jdbc/ShardingDataSource.java
+11
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/db/AbstractShardingDataBasesOnlyDBUnitTest.java
...integrate/db/AbstractShardingDataBasesOnlyDBUnitTest.java
+17
-3
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/dynamic/pstatement/DynamicShardingBothForPStatementWithDMLTest.java
...tatement/DynamicShardingBothForPStatementWithDMLTest.java
+13
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/dynamic/pstatement/DynamicShardingBothForPStatementWithSelectTest.java
...ement/DynamicShardingBothForPStatementWithSelectTest.java
+13
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/dynamic/statement/DynamicShardingBothForStatementWithAggregateTest.java
...ent/DynamicShardingBothForStatementWithAggregateTest.java
+12
-3
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/dynamic/statement/DynamicShardingBothForStatementWithDMLTest.java
...statement/DynamicShardingBothForStatementWithDMLTest.java
+13
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/dynamic/statement/DynamicShardingBothForStatementWithSelectTest.java
...tement/DynamicShardingBothForStatementWithSelectTest.java
+13
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/pstatement/StaticShardingBothForPStatementWithAggregateTest.java
...ent/StaticShardingBothForPStatementWithAggregateTest.java
+12
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/pstatement/StaticShardingBothForPStatementWithDMLTest.java
...statement/StaticShardingBothForPStatementWithDMLTest.java
+13
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/pstatement/StaticShardingBothForPStatementWithGroupByTest.java
...ement/StaticShardingBothForPStatementWithGroupByTest.java
+13
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/pstatement/StaticShardingBothForPStatementWithSelectTest.java
...tement/StaticShardingBothForPStatementWithSelectTest.java
+13
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/statement/StaticShardingBothForStatementWithAggregateTest.java
...ment/StaticShardingBothForStatementWithAggregateTest.java
+12
-3
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/statement/StaticShardingBothForStatementWithDMLTest.java
.../statement/StaticShardingBothForStatementWithDMLTest.java
+13
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/statement/StaticShardingBothForStatementWithSelectTest.java
...atement/StaticShardingBothForStatementWithSelectTest.java
+13
-1
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/hint/AbstractShardingDataBasesOnlyHintDBUnitTest.java
...ate/hint/AbstractShardingDataBasesOnlyHintDBUnitTest.java
+19
-5
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/masterslave/AbstractShardingMasterSlaveDBUnitTest.java
...te/masterslave/AbstractShardingMasterSlaveDBUnitTest.java
+18
-3
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/nullable/AbstractShardingNullableDBUnitTest.java
...ntegrate/nullable/AbstractShardingNullableDBUnitTest.java
+19
-4
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/tbl/AbstractShardingTablesOnlyDBUnitTest.java
...b/integrate/tbl/AbstractShardingTablesOnlyDBUnitTest.java
+18
-3
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/executor/PreparedStatementExecutorTest.java
.../rdb/sharding/executor/PreparedStatementExecutorTest.java
+2
-0
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/executor/StatementExecutorTest.java
.../ddframe/rdb/sharding/executor/StatementExecutorTest.java
+1
-0
sharding-jdbc-doc/content/post/release_notes.md
sharding-jdbc-doc/content/post/release_notes.md
+3
-0
未找到文件。
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/config/ShardingPropertiesConstant.java
浏览文件 @
c4077e04
...
...
@@ -70,10 +70,10 @@ public enum ShardingPropertiesConstant {
* 最大工作线程数量.
*
* <p>
* 默认值:
CPU的核数 * 2
* 默认值:
100
* </p>
*/
EXECUTOR_MAX_SIZE
(
"executor.max.size"
,
String
.
valueOf
(
Runtime
.
getRuntime
().
availableProcessors
()
*
2
)
,
int
.
class
),
EXECUTOR_MAX_SIZE
(
"executor.max.size"
,
"100"
,
int
.
class
),
/**
* 工作线程空闲时超时时间.
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/executor/ExecutorEngine.java
浏览文件 @
c4077e04
...
...
@@ -19,6 +19,7 @@ package com.dangdang.ddframe.rdb.sharding.executor;
import
com.dangdang.ddframe.rdb.sharding.config.ShardingProperties
;
import
com.dangdang.ddframe.rdb.sharding.config.ShardingPropertiesConstant
;
import
com.dangdang.ddframe.rdb.sharding.exception.ShardingJdbcException
;
import
com.google.common.util.concurrent.FutureCallback
;
import
com.google.common.util.concurrent.Futures
;
import
com.google.common.util.concurrent.ListenableFuture
;
...
...
@@ -32,7 +33,7 @@ import java.util.List;
import
java.util.Set
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.
LinkedBlocking
Queue
;
import
java.util.concurrent.
Synchronous
Queue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -51,7 +52,7 @@ public final class ExecutorEngine {
int
executorMaxSize
=
shardingProperties
.
getValue
(
ShardingPropertiesConstant
.
EXECUTOR_MAX_SIZE
);
long
executorMaxIdleTimeoutMilliseconds
=
shardingProperties
.
getValue
(
ShardingPropertiesConstant
.
EXECUTOR_MAX_IDLE_TIMEOUT_MILLISECONDS
);
executorService
=
MoreExecutors
.
listeningDecorator
(
MoreExecutors
.
getExitingExecutorService
(
new
ThreadPoolExecutor
(
executorMinIdleSize
,
executorMaxSize
,
executorMaxIdleTimeoutMilliseconds
,
TimeUnit
.
MILLISECONDS
,
new
LinkedBlocking
Queue
<
Runnable
>())));
new
ThreadPoolExecutor
(
executorMinIdleSize
,
executorMaxSize
,
executorMaxIdleTimeoutMilliseconds
,
TimeUnit
.
MILLISECONDS
,
new
Synchronous
Queue
<
Runnable
>())));
}
/**
...
...
@@ -84,6 +85,20 @@ public final class ExecutorEngine {
return
mergeUnit
.
merge
(
execute
(
inputs
,
executeUnit
));
}
/**
* 安全关闭执行器,并释放线程.
*/
public
void
shutdown
()
{
executorService
.
shutdownNow
();
try
{
executorService
.
awaitTermination
(
5
,
TimeUnit
.
SECONDS
);
}
catch
(
final
InterruptedException
ignored
)
{
}
if
(!
executorService
.
isTerminated
())
{
throw
new
ShardingJdbcException
(
"ExecutorEngine can not been terminated"
);
}
}
private
<
I
,
O
>
ListenableFuture
<
List
<
O
>>
submitFutures
(
final
Collection
<
I
>
inputs
,
final
ExecuteUnit
<
I
,
O
>
executeUnit
)
{
Set
<
ListenableFuture
<
O
>>
result
=
new
HashSet
<>(
inputs
.
size
());
for
(
final
I
each
:
inputs
)
{
...
...
sharding-jdbc-core/src/main/java/com/dangdang/ddframe/rdb/sharding/jdbc/ShardingDataSource.java
浏览文件 @
c4077e04
...
...
@@ -41,6 +41,8 @@ public class ShardingDataSource extends AbstractDataSourceAdapter {
private
final
ShardingProperties
shardingProperties
;
private
final
ExecutorEngine
executorEngine
;
private
final
ShardingContext
shardingContext
;
public
ShardingDataSource
(
final
ShardingRule
shardingRule
)
{
...
...
@@ -51,8 +53,9 @@ public class ShardingDataSource extends AbstractDataSourceAdapter {
Preconditions
.
checkNotNull
(
shardingRule
);
Preconditions
.
checkNotNull
(
props
);
shardingProperties
=
new
ShardingProperties
(
props
);
executorEngine
=
new
ExecutorEngine
(
shardingProperties
);
try
{
shardingContext
=
new
ShardingContext
(
shardingRule
,
new
SQLRouteEngine
(
shardingRule
,
DatabaseType
.
valueFrom
(
getDatabaseProductName
(
shardingRule
))),
new
ExecutorEngine
(
shardingProperties
)
);
shardingContext
=
new
ShardingContext
(
shardingRule
,
new
SQLRouteEngine
(
shardingRule
,
DatabaseType
.
valueFrom
(
getDatabaseProductName
(
shardingRule
))),
executorEngine
);
}
catch
(
final
SQLException
ex
)
{
throw
new
ShardingJdbcException
(
ex
);
}
...
...
@@ -80,4 +83,11 @@ public class ShardingDataSource extends AbstractDataSourceAdapter {
MetricsContext
.
init
(
shardingProperties
);
return
new
ShardingConnection
(
shardingContext
);
}
/**
* 关闭数据源,释放相关资源.
*/
public
void
shutdown
()
{
executorEngine
.
shutdown
();
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/db/AbstractShardingDataBasesOnlyDBUnitTest.java
浏览文件 @
c4077e04
...
...
@@ -27,6 +27,7 @@ import com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingS
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.NoneTableShardingAlgorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.junit.AfterClass
;
import
java.util.Arrays
;
import
java.util.Collections
;
...
...
@@ -34,7 +35,9 @@ import java.util.List;
public
abstract
class
AbstractShardingDataBasesOnlyDBUnitTest
extends
AbstractDBUnitTest
{
private
final
String
dataSourceName
=
"dataSource_%s"
;
private
static
boolean
isShutdown
;
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
List
<
String
>
getSchemaFiles
()
{
...
...
@@ -67,13 +70,24 @@ public abstract class AbstractShardingDataBasesOnlyDBUnitTest extends AbstractDB
}
protected
final
ShardingDataSource
getShardingDataSource
()
{
DataSourceRule
dataSourceRule
=
new
DataSourceRule
(
createDataSourceMap
(
dataSourceName
));
if
(
null
!=
shardingDataSource
&&
!
isShutdown
)
{
return
shardingDataSource
;
}
isShutdown
=
false
;
DataSourceRule
dataSourceRule
=
new
DataSourceRule
(
createDataSourceMap
(
"dataSource_%s"
));
TableRule
orderTableRule
=
TableRule
.
builder
(
"t_order"
).
dataSourceRule
(
dataSourceRule
).
build
();
TableRule
orderItemTableRule
=
TableRule
.
builder
(
"t_order_item"
).
dataSourceRule
(
dataSourceRule
).
build
();
ShardingRule
shardingRule
=
ShardingRule
.
builder
().
dataSourceRule
(
dataSourceRule
).
tableRules
(
Arrays
.
asList
(
orderTableRule
,
orderItemTableRule
))
.
bindingTableRules
(
Collections
.
singletonList
(
new
BindingTableRule
(
Arrays
.
asList
(
orderTableRule
,
orderItemTableRule
))))
.
databaseShardingStrategy
(
new
DatabaseShardingStrategy
(
Collections
.
singletonList
(
"user_id"
),
new
MultipleKeysModuloDatabaseShardingAlgorithm
()))
.
tableShardingStrategy
(
new
TableShardingStrategy
(
Collections
.
singletonList
(
"order_id"
),
new
NoneTableShardingAlgorithm
())).
build
();
return
new
ShardingDataSource
(
shardingRule
);
shardingDataSource
=
new
ShardingDataSource
(
shardingRule
);
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
isShutdown
=
true
;
shardingDataSource
.
shutdown
();
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/dynamic/pstatement/DynamicShardingBothForPStatementWithDMLTest.java
浏览文件 @
c4077e04
...
...
@@ -21,6 +21,7 @@ import com.dangdang.ddframe.rdb.integrate.dbtbl.common.pstatement.AbstractShardi
import
com.dangdang.ddframe.rdb.integrate.dbtbl.dynamic.DynamicShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.dbunit.DatabaseUnitException
;
import
org.junit.AfterClass
;
import
org.junit.Test
;
import
java.sql.Connection
;
...
...
@@ -29,9 +30,20 @@ import java.sql.SQLException;
public
final
class
DynamicShardingBothForPStatementWithDMLTest
extends
AbstractShardingBothForPStatementWithDMLTest
{
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
ShardingDataSource
getShardingDataSource
()
{
return
DynamicShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
if
(
null
!=
shardingDataSource
)
{
return
shardingDataSource
;
}
shardingDataSource
=
DynamicShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
@Test
(
expected
=
IllegalStateException
.
class
)
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/dynamic/pstatement/DynamicShardingBothForPStatementWithSelectTest.java
浏览文件 @
c4077e04
...
...
@@ -21,15 +21,27 @@ import com.dangdang.ddframe.rdb.integrate.dbtbl.common.pstatement.AbstractShardi
import
com.dangdang.ddframe.rdb.integrate.dbtbl.dynamic.DynamicShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.dbunit.DatabaseUnitException
;
import
org.junit.AfterClass
;
import
org.junit.Test
;
import
java.sql.SQLException
;
public
final
class
DynamicShardingBothForPStatementWithSelectTest
extends
AbstractShardingBothForPStatementWithSelectTest
{
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
ShardingDataSource
getShardingDataSource
()
{
return
DynamicShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
if
(
null
!=
shardingDataSource
)
{
return
shardingDataSource
;
}
shardingDataSource
=
DynamicShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
@Test
(
expected
=
UnsupportedOperationException
.
class
)
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/dynamic/statement/DynamicShardingBothForStatementWithAggregateTest.java
浏览文件 @
c4077e04
...
...
@@ -21,6 +21,7 @@ import com.dangdang.ddframe.rdb.integrate.dbtbl.common.AbstractShardingBothTest;
import
com.dangdang.ddframe.rdb.integrate.dbtbl.dynamic.DynamicShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.dbunit.DatabaseUnitException
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -28,11 +29,19 @@ import java.sql.SQLException;
public
final
class
DynamicShardingBothForStatementWithAggregateTest
extends
AbstractShardingBothTest
{
private
ShardingDataSource
shardingDataSource
;
private
static
ShardingDataSource
shardingDataSource
;
@Before
public
void
init
()
throws
SQLException
{
shardingDataSource
=
getShardingDataSource
();
public
void
init
()
{
if
(
null
!=
shardingDataSource
)
{
return
;
}
shardingDataSource
=
DynamicShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
@Override
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/dynamic/statement/DynamicShardingBothForStatementWithDMLTest.java
浏览文件 @
c4077e04
...
...
@@ -21,6 +21,7 @@ import com.dangdang.ddframe.rdb.integrate.dbtbl.common.statement.AbstractShardin
import
com.dangdang.ddframe.rdb.integrate.dbtbl.dynamic.DynamicShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.dbunit.DatabaseUnitException
;
import
org.junit.AfterClass
;
import
org.junit.Test
;
import
java.sql.Connection
;
...
...
@@ -29,9 +30,20 @@ import java.sql.Statement;
public
final
class
DynamicShardingBothForStatementWithDMLTest
extends
AbstractShardingBothForStatementWithDMLTest
{
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
ShardingDataSource
getShardingDataSource
()
{
return
DynamicShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
if
(
null
!=
shardingDataSource
)
{
return
shardingDataSource
;
}
shardingDataSource
=
DynamicShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
@Test
(
expected
=
IllegalStateException
.
class
)
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/dynamic/statement/DynamicShardingBothForStatementWithSelectTest.java
浏览文件 @
c4077e04
...
...
@@ -21,15 +21,27 @@ import com.dangdang.ddframe.rdb.integrate.dbtbl.common.statement.AbstractShardin
import
com.dangdang.ddframe.rdb.integrate.dbtbl.dynamic.DynamicShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.dbunit.DatabaseUnitException
;
import
org.junit.AfterClass
;
import
org.junit.Test
;
import
java.sql.SQLException
;
public
final
class
DynamicShardingBothForStatementWithSelectTest
extends
AbstractShardingBothForStatementWithSelectTest
{
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
ShardingDataSource
getShardingDataSource
()
{
return
DynamicShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
if
(
null
!=
shardingDataSource
)
{
return
shardingDataSource
;
}
shardingDataSource
=
DynamicShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
@Test
(
expected
=
UnsupportedOperationException
.
class
)
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/pstatement/StaticShardingBothForPStatementWithAggregateTest.java
浏览文件 @
c4077e04
...
...
@@ -20,11 +20,22 @@ package com.dangdang.ddframe.rdb.integrate.dbtbl.statically.pstatement;
import
com.dangdang.ddframe.rdb.integrate.dbtbl.common.pstatement.AbstractShardingBothForPStatementWithAggregateTest
;
import
com.dangdang.ddframe.rdb.integrate.dbtbl.statically.StaticShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.junit.AfterClass
;
public
final
class
StaticShardingBothForPStatementWithAggregateTest
extends
AbstractShardingBothForPStatementWithAggregateTest
{
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
ShardingDataSource
getShardingDataSource
()
{
return
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
if
(
null
!=
shardingDataSource
)
{
return
shardingDataSource
;
}
shardingDataSource
=
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/pstatement/StaticShardingBothForPStatementWithDMLTest.java
浏览文件 @
c4077e04
...
...
@@ -21,6 +21,7 @@ import com.dangdang.ddframe.rdb.integrate.dbtbl.common.pstatement.AbstractShardi
import
com.dangdang.ddframe.rdb.integrate.dbtbl.statically.StaticShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.dbunit.DatabaseUnitException
;
import
org.junit.AfterClass
;
import
org.junit.Test
;
import
java.sql.Connection
;
...
...
@@ -32,9 +33,20 @@ import static org.junit.Assert.assertThat;
public
final
class
StaticShardingBothForPStatementWithDMLTest
extends
AbstractShardingBothForPStatementWithDMLTest
{
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
ShardingDataSource
getShardingDataSource
()
{
return
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
if
(
null
!=
shardingDataSource
)
{
return
shardingDataSource
;
}
shardingDataSource
=
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
@Test
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/pstatement/StaticShardingBothForPStatementWithGroupByTest.java
浏览文件 @
c4077e04
...
...
@@ -20,11 +20,23 @@ package com.dangdang.ddframe.rdb.integrate.dbtbl.statically.pstatement;
import
com.dangdang.ddframe.rdb.integrate.dbtbl.common.pstatement.AbstractShardingBothForPStatementWithGroupByTest
;
import
com.dangdang.ddframe.rdb.integrate.dbtbl.statically.StaticShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.junit.AfterClass
;
public
final
class
StaticShardingBothForPStatementWithGroupByTest
extends
AbstractShardingBothForPStatementWithGroupByTest
{
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
ShardingDataSource
getShardingDataSource
()
{
return
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
if
(
null
!=
shardingDataSource
)
{
return
shardingDataSource
;
}
shardingDataSource
=
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/pstatement/StaticShardingBothForPStatementWithSelectTest.java
浏览文件 @
c4077e04
...
...
@@ -21,15 +21,27 @@ import com.dangdang.ddframe.rdb.integrate.dbtbl.common.pstatement.AbstractShardi
import
com.dangdang.ddframe.rdb.integrate.dbtbl.statically.StaticShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.dbunit.DatabaseUnitException
;
import
org.junit.AfterClass
;
import
org.junit.Test
;
import
java.sql.SQLException
;
public
final
class
StaticShardingBothForPStatementWithSelectTest
extends
AbstractShardingBothForPStatementWithSelectTest
{
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
ShardingDataSource
getShardingDataSource
()
{
return
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
if
(
null
!=
shardingDataSource
)
{
return
shardingDataSource
;
}
shardingDataSource
=
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
@Test
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/statement/StaticShardingBothForStatementWithAggregateTest.java
浏览文件 @
c4077e04
...
...
@@ -21,6 +21,7 @@ import com.dangdang.ddframe.rdb.integrate.dbtbl.common.AbstractShardingBothTest;
import
com.dangdang.ddframe.rdb.integrate.dbtbl.statically.StaticShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.dbunit.DatabaseUnitException
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -28,11 +29,19 @@ import java.sql.SQLException;
public
final
class
StaticShardingBothForStatementWithAggregateTest
extends
AbstractShardingBothTest
{
private
ShardingDataSource
shardingDataSource
;
private
static
ShardingDataSource
shardingDataSource
;
@Before
public
void
init
()
throws
SQLException
{
shardingDataSource
=
getShardingDataSource
();
public
void
init
()
{
if
(
null
!=
shardingDataSource
)
{
return
;
}
shardingDataSource
=
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
@Override
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/statement/StaticShardingBothForStatementWithDMLTest.java
浏览文件 @
c4077e04
...
...
@@ -21,6 +21,7 @@ import com.dangdang.ddframe.rdb.integrate.dbtbl.common.statement.AbstractShardin
import
com.dangdang.ddframe.rdb.integrate.dbtbl.statically.StaticShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.dbunit.DatabaseUnitException
;
import
org.junit.AfterClass
;
import
org.junit.Test
;
import
java.sql.Connection
;
...
...
@@ -32,9 +33,20 @@ import static org.junit.Assert.assertThat;
public
final
class
StaticShardingBothForStatementWithDMLTest
extends
AbstractShardingBothForStatementWithDMLTest
{
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
ShardingDataSource
getShardingDataSource
()
{
return
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
if
(
null
!=
shardingDataSource
)
{
return
shardingDataSource
;
}
shardingDataSource
=
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
@Test
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/dbtbl/statically/statement/StaticShardingBothForStatementWithSelectTest.java
浏览文件 @
c4077e04
...
...
@@ -21,15 +21,27 @@ import com.dangdang.ddframe.rdb.integrate.dbtbl.common.statement.AbstractShardin
import
com.dangdang.ddframe.rdb.integrate.dbtbl.statically.StaticShardingBothHelper
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.dbunit.DatabaseUnitException
;
import
org.junit.AfterClass
;
import
org.junit.Test
;
import
java.sql.SQLException
;
public
final
class
StaticShardingBothForStatementWithSelectTest
extends
AbstractShardingBothForStatementWithSelectTest
{
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
ShardingDataSource
getShardingDataSource
()
{
return
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
if
(
null
!=
shardingDataSource
)
{
return
shardingDataSource
;
}
shardingDataSource
=
StaticShardingBothHelper
.
getShardingDataSource
(
createDataSourceMap
(
"dataSource_%s"
));
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
shardingDataSource
.
shutdown
();
}
@Test
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/hint/AbstractShardingDataBasesOnlyHintDBUnitTest.java
浏览文件 @
c4077e04
...
...
@@ -31,6 +31,7 @@ import com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource;
import
com.dangdang.ddframe.rdb.sharding.parser.result.router.Condition
;
import
com.google.common.collect.Lists
;
import
org.dbunit.DatabaseUnitException
;
import
org.junit.AfterClass
;
import
java.sql.Connection
;
import
java.sql.SQLException
;
...
...
@@ -38,9 +39,11 @@ import java.util.Arrays;
import
java.util.Collections
;
import
java.util.List
;
public
abstract
class
AbstractShardingDataBasesOnlyHintDBUnitTest
extends
AbstractDBUnitTest
{
abstract
class
AbstractShardingDataBasesOnlyHintDBUnitTest
extends
AbstractDBUnitTest
{
private
final
String
dataSourceName
=
"dataSource_%s"
;
private
static
boolean
isShutdown
;
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
List
<
String
>
getSchemaFiles
()
{
...
...
@@ -73,14 +76,25 @@ public abstract class AbstractShardingDataBasesOnlyHintDBUnitTest extends Abstra
}
protected
final
ShardingDataSource
getShardingDataSource
()
{
DataSourceRule
dataSourceRule
=
new
DataSourceRule
(
createDataSourceMap
(
dataSourceName
));
if
(
null
!=
shardingDataSource
&&
!
isShutdown
)
{
return
shardingDataSource
;
}
isShutdown
=
false
;
DataSourceRule
dataSourceRule
=
new
DataSourceRule
(
createDataSourceMap
(
"dataSource_%s"
));
TableRule
orderTableRule
=
TableRule
.
builder
(
"t_order"
).
dataSourceRule
(
dataSourceRule
).
build
();
TableRule
orderItemTableRule
=
TableRule
.
builder
(
"t_order_item"
).
dataSourceRule
(
dataSourceRule
).
build
();
ShardingRule
shardingRule
=
ShardingRule
.
builder
().
dataSourceRule
(
dataSourceRule
).
tableRules
(
Lists
.
newArrayList
(
orderTableRule
,
orderItemTableRule
))
.
bindingTableRules
(
Collections
.
singletonList
(
new
BindingTableRule
(
Arrays
.
asList
(
orderTableRule
,
orderItemTableRule
))))
.
databaseShardingStrategy
(
new
DatabaseShardingStrategy
(
Collections
.
singletonList
(
"user_id"
),
new
MultipleKeysModuloDatabaseShardingAlgorithm
()))
.
tableShardingStrategy
(
new
TableShardingStrategy
(
Collections
.
singletonList
(
"order_id"
),
new
NoneTableShardingAlgorithm
())).
build
();
return
new
ShardingDataSource
(
shardingRule
);
shardingDataSource
=
new
ShardingDataSource
(
shardingRule
);
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
isShutdown
=
true
;
shardingDataSource
.
shutdown
();
}
protected
void
assertDataSet
(
final
String
expectedDataSetFile
,
final
DynamicShardingValueHelper
helper
,
...
...
@@ -97,7 +111,7 @@ public abstract class AbstractShardingDataBasesOnlyHintDBUnitTest extends Abstra
}
}
protected
class
DynamicShardingValueHelper
implements
AutoCloseable
{
class
DynamicShardingValueHelper
implements
AutoCloseable
{
private
final
HintManager
hintManager
;
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/masterslave/AbstractShardingMasterSlaveDBUnitTest.java
浏览文件 @
c4077e04
...
...
@@ -30,6 +30,7 @@ import com.dangdang.ddframe.rdb.sharding.hint.HintManagerHolder;
import
com.dangdang.ddframe.rdb.sharding.jdbc.MasterSlaveDataSource
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.junit.After
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
import
javax.sql.DataSource
;
...
...
@@ -41,7 +42,9 @@ import java.util.Map;
public
abstract
class
AbstractShardingMasterSlaveDBUnitTest
extends
AbstractDBUnitTest
{
private
final
String
dataSourceName
=
"dataSource_%s"
;
private
static
boolean
isShutdown
;
private
static
ShardingDataSource
shardingDataSource
;
@Before
@After
...
...
@@ -101,7 +104,11 @@ public abstract class AbstractShardingMasterSlaveDBUnitTest extends AbstractDBUn
}
protected
final
ShardingDataSource
getShardingDataSource
()
{
Map
<
String
,
DataSource
>
masterSlaveDataSourceMap
=
createDataSourceMap
(
dataSourceName
);
if
(
null
!=
shardingDataSource
&&
!
isShutdown
)
{
return
shardingDataSource
;
}
isShutdown
=
false
;
Map
<
String
,
DataSource
>
masterSlaveDataSourceMap
=
createDataSourceMap
(
"dataSource_%s"
);
MasterSlaveDataSource
masterSlaveDs0
=
new
MasterSlaveDataSource
(
"ms_0"
,
masterSlaveDataSourceMap
.
get
(
"dataSource_master_0"
),
Collections
.
singletonList
(
masterSlaveDataSourceMap
.
get
(
"dataSource_slave_0"
)));
MasterSlaveDataSource
masterSlaveDs1
=
new
MasterSlaveDataSource
(
"ms_1"
,
masterSlaveDataSourceMap
.
get
(
"dataSource_master_1"
),
...
...
@@ -161,6 +168,14 @@ public abstract class AbstractShardingMasterSlaveDBUnitTest extends AbstractDBUn
.
bindingTableRules
(
Collections
.
singletonList
(
new
BindingTableRule
(
Arrays
.
asList
(
orderTableRule
,
orderItemTableRule
))))
.
databaseShardingStrategy
(
new
DatabaseShardingStrategy
(
"user_id"
,
new
SingleKeyModuloDatabaseShardingAlgorithm
()))
.
tableShardingStrategy
(
new
TableShardingStrategy
(
"order_id"
,
new
SingleKeyModuloTableShardingAlgorithm
())).
build
();
return
new
ShardingDataSource
(
shardingRule
);
shardingDataSource
=
new
ShardingDataSource
(
shardingRule
);
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
isShutdown
=
true
;
shardingDataSource
.
shutdown
();
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/nullable/AbstractShardingNullableDBUnitTest.java
浏览文件 @
c4077e04
...
...
@@ -27,14 +27,17 @@ import com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingS
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.NoneTableShardingAlgorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.junit.AfterClass
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
public
abstract
class
AbstractShardingNullableDBUnitTest
extends
AbstractDBUnitTest
{
abstract
class
AbstractShardingNullableDBUnitTest
extends
AbstractDBUnitTest
{
private
final
String
dataSourceName
=
"dataSource_%s"
;
private
static
boolean
isShutdown
;
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
List
<
String
>
getSchemaFiles
()
{
...
...
@@ -67,13 +70,25 @@ public abstract class AbstractShardingNullableDBUnitTest extends AbstractDBUnitT
}
protected
final
ShardingDataSource
getShardingDataSource
()
{
DataSourceRule
dataSourceRule
=
new
DataSourceRule
(
createDataSourceMap
(
dataSourceName
));
if
(
null
!=
shardingDataSource
&&
!
isShutdown
)
{
return
shardingDataSource
;
}
isShutdown
=
false
;
DataSourceRule
dataSourceRule
=
new
DataSourceRule
(
createDataSourceMap
(
"dataSource_%s"
));
TableRule
orderTableRule
=
TableRule
.
builder
(
"t_order"
).
dataSourceRule
(
dataSourceRule
).
build
();
ShardingRule
shardingRule
=
ShardingRule
.
builder
().
dataSourceRule
(
dataSourceRule
).
tableRules
(
Collections
.
singletonList
(
orderTableRule
))
.
bindingTableRules
(
Collections
.
singletonList
(
new
BindingTableRule
(
Collections
.
singletonList
(
orderTableRule
))))
.
databaseShardingStrategy
(
new
DatabaseShardingStrategy
(
Collections
.
singletonList
(
"user_id"
),
new
MultipleKeysModuloDatabaseShardingAlgorithm
()))
.
tableShardingStrategy
(
new
TableShardingStrategy
(
Collections
.
singletonList
(
"order_id"
),
new
NoneTableShardingAlgorithm
())).
build
();
return
new
ShardingDataSource
(
shardingRule
);
shardingDataSource
=
new
ShardingDataSource
(
shardingRule
);
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
isShutdown
=
true
;
shardingDataSource
.
shutdown
();
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/integrate/tbl/AbstractShardingTablesOnlyDBUnitTest.java
浏览文件 @
c4077e04
...
...
@@ -27,6 +27,7 @@ import com.dangdang.ddframe.rdb.sharding.api.strategy.database.DatabaseShardingS
import
com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm
;
import
com.dangdang.ddframe.rdb.sharding.api.strategy.table.TableShardingStrategy
;
import
com.dangdang.ddframe.rdb.sharding.jdbc.ShardingDataSource
;
import
org.junit.AfterClass
;
import
java.util.Arrays
;
import
java.util.Collections
;
...
...
@@ -34,7 +35,9 @@ import java.util.List;
public
abstract
class
AbstractShardingTablesOnlyDBUnitTest
extends
AbstractDBUnitTest
{
private
final
String
dataSourceName
=
"dataSource_%s"
;
private
static
boolean
isShutdown
;
private
static
ShardingDataSource
shardingDataSource
;
@Override
protected
List
<
String
>
getSchemaFiles
()
{
...
...
@@ -47,7 +50,11 @@ public abstract class AbstractShardingTablesOnlyDBUnitTest extends AbstractDBUni
}
protected
final
ShardingDataSource
getShardingDataSource
()
{
DataSourceRule
dataSourceRule
=
new
DataSourceRule
(
createDataSourceMap
(
dataSourceName
));
if
(
null
!=
shardingDataSource
&&
!
isShutdown
)
{
return
shardingDataSource
;
}
isShutdown
=
false
;
DataSourceRule
dataSourceRule
=
new
DataSourceRule
(
createDataSourceMap
(
"dataSource_%s"
));
TableRule
orderTableRule
=
TableRule
.
builder
(
"t_order"
).
actualTables
(
Arrays
.
asList
(
"t_order_0"
,
"t_order_1"
,
...
...
@@ -76,6 +83,14 @@ public abstract class AbstractShardingTablesOnlyDBUnitTest extends AbstractDBUni
.
bindingTableRules
(
Collections
.
singletonList
(
new
BindingTableRule
(
Arrays
.
asList
(
orderTableRule
,
orderItemTableRule
))))
.
databaseShardingStrategy
(
new
DatabaseShardingStrategy
(
"user_id"
,
new
NoneDatabaseShardingAlgorithm
()))
.
tableShardingStrategy
(
new
TableShardingStrategy
(
"order_id"
,
new
SingleKeyModuloTableShardingAlgorithm
())).
build
();
return
new
ShardingDataSource
(
shardingRule
);
shardingDataSource
=
new
ShardingDataSource
(
shardingRule
);
return
shardingDataSource
;
}
@AfterClass
public
static
void
clear
()
{
isShutdown
=
true
;
shardingDataSource
.
shutdown
();
}
}
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/executor/PreparedStatementExecutorTest.java
浏览文件 @
c4077e04
...
...
@@ -72,8 +72,10 @@ public final class PreparedStatementExecutorTest {
ExecutorTestUtil
.
clear
();
DMLExecutionEventBus
.
clearListener
();
DQLExecutionEventBus
.
clearListener
();
executorEngine
.
shutdown
();
}
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
assertNoStatement
()
throws
SQLException
{
PreparedStatementExecutor
actual
=
new
PreparedStatementExecutor
(
executorEngine
,
Collections
.
EMPTY_LIST
);
...
...
sharding-jdbc-core/src/test/java/com/dangdang/ddframe/rdb/sharding/executor/StatementExecutorTest.java
浏览文件 @
c4077e04
...
...
@@ -76,6 +76,7 @@ public final class StatementExecutorTest {
ExecutorTestUtil
.
clear
();
DMLExecutionEventBus
.
clearListener
();
DQLExecutionEventBus
.
clearListener
();
executorEngine
.
shutdown
();
}
@Test
...
...
sharding-jdbc-doc/content/post/release_notes.md
浏览文件 @
c4077e04
+++
date = "2016-02-05T17:03:18+08:00"
title = "Release Notes"
...
...
@@ -18,6 +19,8 @@ weight = 1
1.
[
ISSUE #114
](
https://github.com/dangdangdotcom/sharding-jdbc/issues/114
)
ShardingPreparedStatement执行批处理任务时,反复解析sql导致oom
1.
[
ISSUE #33
](
https://github.com/dangdangdotcom/sharding-jdbc/issues/33
)
Limit支持问题
1.
[
ISSUE #124
](
https://github.com/dangdangdotcom/sharding-jdbc/issues/124
)
com.dangdang.ddframe.rdb.sharding.jdbc.adapter.AbstractStatementAdapter.getUpdateCount返回值不符合JDBC规范
1.
[
ISSUE #141
](
https://github.com/dangdangdotcom/sharding-jdbc/issues/141
)
多线程执行器参数设置失效
## 1.3.1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录