public class SequenceDataSourceHolder extends Object
Constructor and Description |
---|
SequenceDataSourceHolder(DataSource ds)
构造函数
|
Modifier and Type | Method and Description |
---|---|
Map<String,Map<String,Object>> |
getAllSequenceRecordName(String selectSql,
String nameColumn,
String minValueColumnName,
String maxValueColumnName,
String innerStepColumnName)
获取当前db里所有的sequence记录的指定字段值
|
DataSource |
getDs() |
Map<String,Map<String,Object>> |
getSequenceRecordByName(String selectSql,
String minValueColumnName,
String maxValueColumnName,
String innerStepColumnName,
String sequenceName)
根据sequenceName 获取当前db里的指定sequence记录的各字段值
|
void |
initSequenceRecord(int index,
String sequenceName,
int innerStep,
int outStep,
long minValue,
long maxValue,
String valueColumnName)
初始化sequence 记录,如果db里存在该记录就跳过;否则对此进行初始化
|
void |
setParameters(String tableName,
String selectSql,
String updateSql,
String insertSql,
boolean adjust)
设置常用的参数
|
SequenceRange |
tryOnAvailableDataSource(int index,
String sequenceName,
long minValue,
long maxValue,
int innerStep,
int outStep,
List<Integer> excludeIndexes)
在可用的数据源上获取sequence段,如果发生异常,则进行统计
|
SequenceRange |
tryOnFailedDataSource(int index,
String sequenceName,
long minValue,
long maxValue,
int innerStep,
int outStep,
List<Integer> excludeIndexes)
在故障的数据源上进行单线程重试,每隔2s允许一个业务单线程进入重试状态, 如果访问成功则标记该数据源为可用,否则去寻找其他可用数据源。
采用的是非阻塞锁实现的并发控制。 |
SequenceRange |
tryOnSelectedDataSource(int index,
String sequenceName,
long minValue,
long maxValue,
int innerStep,
int outStep,
List<Integer> excludeIndexes)
在随机选择的数据源上获取sequence段
|
boolean |
tryToConnectDataBase(int dbIndex)
在单线程重试的时候,取到连接后真正和数据库建立连接;
|
public SequenceDataSourceHolder(DataSource ds)
ds
- public void setParameters(String tableName, String selectSql, String updateSql, String insertSql, boolean adjust)
tableName
- 表名selectSql
- select的sql语句updateSql
- 更新语句insertSql
- 插入语句adjust
- 是否开启自动调整开关public DataSource getDs()
public SequenceRange tryOnSelectedDataSource(int index, String sequenceName, long minValue, long maxValue, int innerStep, int outStep, List<Integer> excludeIndexes) throws SequenceException
index
- 数据源序列号sequenceName
- sequence名minValue
- 最小值maxValue
- 最大值innerStep
- 内步长outStep
- 外步长excludeIndexes
- 记录单次内已经故障的数据源SequenceException
public SequenceRange tryOnAvailableDataSource(int index, String sequenceName, long minValue, long maxValue, int innerStep, int outStep, List<Integer> excludeIndexes) throws SequenceException
index
- 数据源序列号sequenceName
- sequence名称minValue
- 最小值maxValue
- 最大值innerStep
- 内步长outStep
- 外步长excludeIndexes
- 记录单次内已经故障的数据源SequenceException
public Map<String,Map<String,Object>> getAllSequenceRecordName(String selectSql, String nameColumn, String minValueColumnName, String maxValueColumnName, String innerStepColumnName) throws SQLException
selectSql
- :select name,min_value,max_value,step from
table_name(default:sequence)nameColumn
- sequence列名minValueColumnName
- 最小值maxValueColumnName
- 最大值innerStepColumnName
- 内步长SQLException
public Map<String,Map<String,Object>> getSequenceRecordByName(String selectSql, String minValueColumnName, String maxValueColumnName, String innerStepColumnName, String sequenceName) throws SQLException, SequenceException
selectSql
- : select value,min_value,max_value,step from sequence where
name=?nameColumn
- sequence列名minValueColumnName
- 最小值maxValueColumnName
- 最大值innerStepColumnName
- 内步长SQLException
SequenceException
public boolean tryToConnectDataBase(int dbIndex)
dbIndex
- public SequenceRange tryOnFailedDataSource(int index, String sequenceName, long minValue, long maxValue, int innerStep, int outStep, List<Integer> excludeIndexes)
index
- 数据源标号sequenceName
- sequence名称minValue
- 最小值maxValue
- 最大值innerStep
- 内步长outStep
- 外步长excludeIndexes
- 单次查询db排除掉的故障数据源标识集合public void initSequenceRecord(int index, String sequenceName, int innerStep, int outStep, long minValue, long maxValue, String valueColumnName) throws SequenceException
index
- db标识sequenceName
- sequence名称innerStep
- 内步长outStep
- 外步长minValue
- 最小值maxValue
- 最大值valueColumnName
- 值列名SequenceException
Copyright © 2006–2018 TinyGroup. All rights reserved.