Search in sources :

Example 1 with DalConnectionLocator

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());
}
Also used : DataSourceIdentity(com.ctrip.platform.dal.dao.datasource.DataSourceIdentity) Connection(java.sql.Connection) Cluster(com.ctrip.framework.dal.cluster.client.Cluster) ClusterConfigProvider(com.ctrip.framework.dal.cluster.client.config.ClusterConfigProvider) ConnectionAction(com.ctrip.platform.dal.dao.client.ConnectionAction) DefaultLocalConfigProvider(com.ctrip.framework.dal.cluster.client.config.DefaultLocalConfigProvider) ClusterConfig(com.ctrip.framework.dal.cluster.client.config.ClusterConfig) DalConnectionLocator(com.ctrip.platform.dal.dao.client.DalConnectionLocator) Test(org.junit.Test)

Example 2 with DalConnectionLocator

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);
}
Also used : DalLogger(com.ctrip.platform.dal.dao.client.DalLogger) DefaultTaskFactory(com.ctrip.platform.dal.dao.task.DefaultTaskFactory) DalTaskFactory(com.ctrip.platform.dal.dao.task.DalTaskFactory) DalConfigCustomizedOption(com.ctrip.framework.dal.cluster.client.config.DalConfigCustomizedOption) DefaultLogger(com.ctrip.platform.dal.dao.client.DefaultLogger) DefaultDalConnectionLocator(com.ctrip.platform.dal.dao.datasource.DefaultDalConnectionLocator) DefaultDalConnectionLocator(com.ctrip.platform.dal.dao.datasource.DefaultDalConnectionLocator) DalConnectionLocator(com.ctrip.platform.dal.dao.client.DalConnectionLocator)

Aggregations

DalConnectionLocator (com.ctrip.platform.dal.dao.client.DalConnectionLocator)2 Cluster (com.ctrip.framework.dal.cluster.client.Cluster)1 ClusterConfig (com.ctrip.framework.dal.cluster.client.config.ClusterConfig)1 ClusterConfigProvider (com.ctrip.framework.dal.cluster.client.config.ClusterConfigProvider)1 DalConfigCustomizedOption (com.ctrip.framework.dal.cluster.client.config.DalConfigCustomizedOption)1 DefaultLocalConfigProvider (com.ctrip.framework.dal.cluster.client.config.DefaultLocalConfigProvider)1 ConnectionAction (com.ctrip.platform.dal.dao.client.ConnectionAction)1 DalLogger (com.ctrip.platform.dal.dao.client.DalLogger)1 DefaultLogger (com.ctrip.platform.dal.dao.client.DefaultLogger)1 DataSourceIdentity (com.ctrip.platform.dal.dao.datasource.DataSourceIdentity)1 DefaultDalConnectionLocator (com.ctrip.platform.dal.dao.datasource.DefaultDalConnectionLocator)1 DalTaskFactory (com.ctrip.platform.dal.dao.task.DalTaskFactory)1 DefaultTaskFactory (com.ctrip.platform.dal.dao.task.DefaultTaskFactory)1 Connection (java.sql.Connection)1 Test (org.junit.Test)1