use of com.ctrip.platform.dal.dao.client.DalConnectionLocator in project dal by ctripcorp.
the class ClusterDatabaseSetTest method testNonShardingCluster.
@Test
public void testNonShardingCluster() {
ClusterConfigProvider provider = new DefaultLocalConfigProvider("NonShardingCluster");
// todo-lhj
ClusterConfig config = provider.getClusterConfig(new DefaultDalConfigCustomizedOption());
Cluster cluster = config.generate();
ClusterDatabaseSet databaseSet = new ClusterDatabaseSet("NonShardingCluster", cluster, new DalConnectionLocator() {
@Override
public void setup(Collection<DatabaseSet> databaseSets) {
}
@Override
public Connection getConnection(String name) throws Exception {
return null;
}
@Override
public Connection getConnection(String name, ConnectionAction action) throws Exception {
return null;
}
@Override
public Connection getConnection(DataSourceIdentity id) throws Exception {
return null;
}
@Override
public Connection getConnection(DataSourceIdentity id, ConnectionAction action) throws Exception {
return null;
}
@Override
public IntegratedConfigProvider getIntegratedConfigProvider() {
return null;
}
@Override
public void setupCluster(Cluster cluster) {
}
@Override
public void uninstallCluster(Cluster cluster) {
}
@Override
public void initialize(Map<String, String> settings) throws Exception {
}
});
Assert.assertFalse(databaseSet.isShardingSupported());
Assert.assertEquals(1, databaseSet.getMasterDbs().size());
Assert.assertEquals(0, databaseSet.getSlaveDbs().size());
}
use of com.ctrip.platform.dal.dao.client.DalConnectionLocator 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);
}
Aggregations