use of com.ctrip.framework.dal.cluster.client.extended.CustomDataSourceFactory in project dal by ctripcorp.
the class ClusterDynamicDataSource method getCustomDataSourceFactory.
private CustomDataSourceFactory getCustomDataSourceFactory() {
DalConfigCustomizedOption customizedOption = cluster.getCustomizedOption();
String clazz = null;
if (customizedOption != null) {
clazz = customizedOption.getDataSourceFactory();
}
if (StringUtils.isEmpty(clazz)) {
Properties properties = cluster.getCustomProperties();
clazz = properties.getProperty(DATASOURCE_FACTORY);
}
try {
return (CustomDataSourceFactory) Class.forName(clazz).newInstance();
} catch (Exception e) {
throw new DalRuntimeException("Construct CustomDataSourceFactory error", e);
}
}
use of com.ctrip.framework.dal.cluster.client.extended.CustomDataSourceFactory in project dal by ctripcorp.
the class ClusterDynamicDataSource method createCustomDataSource.
protected DataSource createCustomDataSource() {
CustomDataSourceFactory dataSourceFactory = getCustomDataSourceFactory();
List<Database> databases = cluster.getDatabases();
Set<HostSpec> hostsInfos = new HashSet<>();
databases.forEach(database -> {
ConnectionString connString = database.getConnectionString();
HostSpec host = HostSpec.of(connString.getPrimaryHost(), connString.getPrimaryPort(), database.getZone());
hostsInfos.add(host);
});
return dataSourceFactory.createDataSource(hostsInfos, getProperties(databases.get(0)));
}
Aggregations