use of com.ctrip.framework.dal.cluster.client.config.DalConfigCustomizedOption in project dal by ctripcorp.
the class DalConfigureFactory method getFromDocument.
public DalConfigure getFromDocument(Document doc) throws Exception {
Element root = doc.getDocumentElement();
String name = getAttribute(root, NAME);
DalLogger logger = readComponent(root, LOG_LISTENER, new DefaultLogger(), LOGGER);
// To wrap with a sandbox logger
// logger = new DalSafeLogger(logger);
DalTaskFactory factory = readComponent(root, TASK_FACTORY, new DefaultTaskFactory(), FACTORY);
DalConnectionLocator locator = readComponent(root, CONNECTION_LOCATOR, new DefaultDalConnectionLocator(), LOCATOR, false);
// read config of ''
DalConfigCustomizedOption defaultOption = readOverridableProperty(root);
Map<String, DatabaseSet> databaseSets = readDatabaseSets(getChildNode(root, DATABASE_SETS));
if (locator instanceof InjectableComponentSupport) {
((InjectableComponentSupport) locator).inject(new DatabaseSetsImpl(databaseSets.values()));
}
locator.initialize(getSettings(getChildNode(root, CONNECTION_LOCATOR)));
Map<String, DatabaseSet> clusters = readClusters(getChildNode(root, DATABASE_SETS), locator, defaultOption);
clusters.putAll(databaseSets);
locator.setup(clusters.values());
DatabaseSetAdapter adapter = new ClusterDatabaseSetAdapter(locator);
tryAdaptDatabaseSets(clusters, adapter);
Map<String, DalConnectionString> connectionStrings = DataSourceConfigureLocatorManager.getInstance().getAllConnectionStrings();
adapter = new LocalDatabaseSetAdapter(connectionStrings);
tryAdaptDatabaseSets(clusters, adapter);
DatabaseSelector selector = readComponent(root, DATABASE_SELECTOR, new DefaultDatabaseSelector(), SELECTOR);
return new DalConfigure(name, clusters, logger, locator, factory, selector);
}
use of com.ctrip.framework.dal.cluster.client.config.DalConfigCustomizedOption in project dal by ctripcorp.
the class DalConfigureFactory method readClusters.
private Map<String, DatabaseSet> readClusters(Node databaseSetsNode, DalConnectionLocator locator, DalConfigCustomizedOption defaultOption) throws Exception {
Map<String, DatabaseSet> databaseSets = new HashMap<>();
ClusterManager clusterManager = new ClusterManagerImpl(locator.getIntegratedConfigProvider());
List<Node> clusterList = getChildNodes(databaseSetsNode, CLUSTER);
for (Node node : clusterList) {
DalConfigCustomizedOption option = defaultOption.clone();
String name = getDatabaseSetName(node);
overrideDefaultConfig(node, option);
Cluster cluster = readCluster(node, clusterManager, option);
databaseSets.put(name, new ClusterDatabaseSet(name, cluster, locator, getSettings(node)));
}
return databaseSets;
}
use of com.ctrip.framework.dal.cluster.client.config.DalConfigCustomizedOption 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.config.DalConfigCustomizedOption in project dal by ctripcorp.
the class ClusterDynamicDataSource method getProperties.
private Properties getProperties(Database database) {
Properties properties = new Properties();
DalConfigCustomizedOption customizedOption = cluster.getCustomizedOption();
DataSourceIdentity id = new ClusterDataSourceIdentity(database);
DataSourceConfigure config = provider.getDataSourceConfigure(id);
properties.putAll(config.getProperties());
if (customizedOption.getJdbcDriver() != null) {
properties.setProperty(DRIVER_CLASS_NAME, customizedOption.getJdbcDriver());
}
Properties customProperties = cluster.getCustomProperties();
if (customProperties != null) {
properties.putAll(customProperties);
}
properties.setProperty(DB_NAME, database.getConnectionString().getDbName());
properties.remove(CONNECTION_URL);
return properties;
}
Aggregations