public abstract class AbstractDBCluster extends Object implements IDBCluster
| Modifier and Type | Field and Description |
|---|---|
private IClusterConfig |
config
集群配置.
|
private org.apache.curator.framework.CuratorFramework |
curatorClient
curator client.
|
private IContainer<DBClusterInfo> |
dbClusterInfoC
cluster info.
|
private IDBGenerator |
dbGenerator
数据库表生成器.
|
private IContainer<IClusterRouter> |
dbRouterC
cluster router.
|
protected EnumDB |
enumDb
数据库类型.
|
private IIdGenerator |
idGenerator
主键生成器.
|
private boolean |
isShardInfoFromZk
数据分片信息是否从zookeeper中获取.
|
private static org.slf4j.Logger |
LOG
日志
|
private IPrimaryCache |
primaryCache
一级缓存.
|
private String |
scanPackage
扫描数据对象包.
|
private ISecondCache |
secondCache
二级缓存.
|
private EnumSyncAction |
syncAction
同步数据表操作.
|
private ITableCluster |
tableCluster
集群中的表集合.
|
| Constructor and Description |
|---|
AbstractDBCluster(EnumDB enumDb)
构造方法.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
_createTable(List<DBTable> tables)
创建数据库表.
|
private IClusterConfig |
_getConfig(String xmlFilePath)
读取配置.
|
private void |
_initDatabaseName(DBInfo dbInfo) |
private void |
_initDBCluster(Collection<DBClusterInfo> dbClusterInfos) |
private Map<String,Integer> |
_loadTableInfo(String clusterName,
List<DBTable> tables)
build table info by table meta.
|
private void |
_syncToZookeeper(List<DBTable> tables)
将表分片信息同步到zookeeper.
|
abstract void |
buildDataSource(DBInfo dbInfo)
创建数据源连接.
|
abstract void |
closeDataSource(DBInfo dbConnInfo)
关闭数据源连接
|
Lock |
createLock(String lockName)
create a destribute lock by give name.
|
List<DB> |
getAllMasterShardingDB(Class<?> clazz)
获取此实体对象对应的所有的分库分表引用.
|
List<DB> |
getAllMasterShardingDB(int tableNum,
String clusterName,
String tableName)
get all master sharding info.
|
List<DB> |
getAllSlaveShardingDB(Class<?> clazz,
EnumDBMasterSlave slave)
获取集群从库列表.
|
IClusterConfig |
getClusterConfig()
获取集群配置.
|
IDataLayerBuilder |
getDataLayerBuilder()
get data layer component builder.
|
Collection<DBClusterInfo> |
getDBClusterInfo()
Get all info about this cluster.
|
DBClusterInfo |
getDBClusterInfo(String clusterName)
获取集群信息.
|
IDBGenerator |
getDBGenerator()
获取db生成器.
|
IClusterRouter |
getDBRouter(String clusterName)
get cluster router.
|
List<DBTable> |
getDBTableFromJvm()
从Jvm中获取分片信息.
|
List<DBTable> |
getDBTableFromZk()
从Zookeeper中获取分片信息.
|
IIdGenerator |
getIdGenerator()
获取id生成器.
|
DBInfo |
getMasterGlobalConn(String clusterName)
获取主全局库连接.
|
DBInfo |
getSlaveGlobalDbConn(String clusterName,
EnumDBMasterSlave slave)
获取从库的全局库连接
|
EnumSyncAction |
getSyncAction() |
ITableCluster |
getTableCluster()
获取集群表集合.
|
DB |
selectDbFromMaster(String tableName,
IShardingKey<?> value)
从主库集群中获取被操作的库表.
|
DB |
selectDbFromSlave(String tableName,
IShardingKey<?> value,
EnumDBMasterSlave slaveNum)
从从库集群中获取被操作的库表.
|
void |
setScanPackage(String scanPackage)
设置需要扫描的实体对象包.
|
void |
setShardInfoFromZk(boolean value)
设置此集群是否从zookeeper中加载分片信息.
|
void |
setSyncAction(EnumSyncAction syncAction)
设置数据表同步动作.
|
void |
shutdown()
relase resource.
|
void |
startup()
启动集群.
|
void |
startup(String xmlFilePath)
启动集群.
|
private static final org.slf4j.Logger LOG
private EnumSyncAction syncAction
private String scanPackage
private boolean isShardInfoFromZk
protected EnumDB enumDb
private IDBGenerator dbGenerator
private IIdGenerator idGenerator
private IPrimaryCache primaryCache
private ISecondCache secondCache
private IContainer<IClusterRouter> dbRouterC
private IContainer<DBClusterInfo> dbClusterInfoC
private ITableCluster tableCluster
private IClusterConfig config
private org.apache.curator.framework.CuratorFramework curatorClient
public AbstractDBCluster(EnumDB enumDb)
enumDb - 数据库类型.public Collection<DBClusterInfo> getDBClusterInfo()
IDBClustergetDBClusterInfo in interface IDBClusterpublic DBClusterInfo getDBClusterInfo(String clusterName)
IDBClustergetDBClusterInfo in interface IDBClusterclusterName - 集群名public void startup()
throws DBClusterException
IDBClusterstartup in interface IDBClusterDBClusterException - 初始化失败public void startup(String xmlFilePath) throws DBClusterException
IDBClusterstartup in interface IDBClusterxmlFilePath - 配置文件绝对路径DBClusterException - 初始化失败public void shutdown()
throws DBClusterException
shutdown in interface IDBClusterDBClusterException - 关闭失败public DBInfo getMasterGlobalConn(String clusterName) throws DBClusterException
IDBClustergetMasterGlobalConn in interface IDBClusterDBClusterExceptionpublic DBInfo getSlaveGlobalDbConn(String clusterName, EnumDBMasterSlave slave) throws DBClusterException
IDBClustergetSlaveGlobalDbConn in interface IDBClusterDBClusterExceptionpublic DB selectDbFromMaster(String tableName, IShardingKey<?> value) throws DBClusterException
IDBClusterselectDbFromMaster in interface IDBClustertableName - 数据表名value - 分库分表因子.DBClusterExceptionpublic DB selectDbFromSlave(String tableName, IShardingKey<?> value, EnumDBMasterSlave slaveNum) throws DBClusterException
IDBClusterselectDbFromSlave in interface IDBClustertableName - 数据库表名value - 分库分表因子slaveNum - 从库DBClusterExceptionpublic List<DB> getAllMasterShardingDB(Class<?> clazz)
IDBClustergetAllMasterShardingDB in interface IDBClusterclazz - 数据对象public List<DB> getAllMasterShardingDB(int tableNum, String clusterName, String tableName)
getAllMasterShardingDB in interface IDBClustertableNum - clusterName - tableName - public List<DB> getAllSlaveShardingDB(Class<?> clazz, EnumDBMasterSlave slave)
IDBClustergetAllSlaveShardingDB in interface IDBClusterclazz - 数据对象slave - 从库号public Lock createLock(String lockName)
IDBClustercreateLock in interface IDBClusterpublic IDataLayerBuilder getDataLayerBuilder()
IDBClustergetDataLayerBuilder in interface IDBClusterIDataLayerBuilderpublic void setShardInfoFromZk(boolean value)
IDBClustersetShardInfoFromZk in interface IDBClustervalue - true:是, false:否.public List<DBTable> getDBTableFromZk()
IDBClustergetDBTableFromZk in interface IDBClusterpublic List<DBTable> getDBTableFromJvm()
IDBClustergetDBTableFromJvm in interface IDBClusterprivate void _syncToZookeeper(List<DBTable> tables) throws Exception
Exceptionprivate void _createTable(List<DBTable> tables) throws Exception
IOExceptionExceptionprivate void _initDBCluster(Collection<DBClusterInfo> dbClusterInfos) throws LoadConfigException
LoadConfigExceptionprivate void _initDatabaseName(DBInfo dbInfo)
private Map<String,Integer> _loadTableInfo(String clusterName, List<DBTable> tables) throws DBClusterException
DBClusterExceptionpublic IClusterRouter getDBRouter(String clusterName)
IDBClustergetDBRouter in interface IDBClusterprivate IClusterConfig _getConfig(String xmlFilePath) throws LoadConfigException
LoadConfigExceptionpublic abstract void buildDataSource(DBInfo dbInfo) throws LoadConfigException
LoadConfigExceptionpublic abstract void closeDataSource(DBInfo dbConnInfo)
dbConnInfo - public EnumSyncAction getSyncAction()
public void setSyncAction(EnumSyncAction syncAction)
IDBClustersetSyncAction in interface IDBClusterpublic IDBGenerator getDBGenerator()
IDBClustergetDBGenerator in interface IDBClusterpublic IIdGenerator getIdGenerator()
IDBClustergetIdGenerator in interface IDBClusterpublic void setScanPackage(String scanPackage)
IDBClustersetScanPackage in interface IDBClusterscanPackage - 包名public ITableCluster getTableCluster()
IDBClustergetTableCluster in interface IDBClusterpublic IClusterConfig getClusterConfig()
IDBClustergetClusterConfig in interface IDBClusterCopyright © 2015. All rights reserved.