Search in sources :

Example 1 with DalConfigCustomizedOption

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);
}
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)

Example 2 with DalConfigCustomizedOption

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;
}
Also used : DalConfigCustomizedOption(com.ctrip.framework.dal.cluster.client.config.DalConfigCustomizedOption) HashMap(java.util.HashMap) ClusterManagerImpl(com.ctrip.platform.dal.dao.cluster.ClusterManagerImpl) Cluster(com.ctrip.framework.dal.cluster.client.Cluster) ClusterManager(com.ctrip.platform.dal.dao.cluster.ClusterManager)

Example 3 with DalConfigCustomizedOption

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);
    }
}
Also used : DalRuntimeException(com.ctrip.platform.dal.exceptions.DalRuntimeException) DalConfigCustomizedOption(com.ctrip.framework.dal.cluster.client.config.DalConfigCustomizedOption) ConnectionString(com.ctrip.framework.dal.cluster.client.database.ConnectionString) CustomDataSourceFactory(com.ctrip.framework.dal.cluster.client.extended.CustomDataSourceFactory) SQLException(java.sql.SQLException) DalRuntimeException(com.ctrip.platform.dal.exceptions.DalRuntimeException) UnsupportedFeatureException(com.ctrip.platform.dal.exceptions.UnsupportedFeatureException)

Example 4 with DalConfigCustomizedOption

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;
}
Also used : DalConfigCustomizedOption(com.ctrip.framework.dal.cluster.client.config.DalConfigCustomizedOption)

Aggregations

DalConfigCustomizedOption (com.ctrip.framework.dal.cluster.client.config.DalConfigCustomizedOption)4 Cluster (com.ctrip.framework.dal.cluster.client.Cluster)1 ConnectionString (com.ctrip.framework.dal.cluster.client.database.ConnectionString)1 CustomDataSourceFactory (com.ctrip.framework.dal.cluster.client.extended.CustomDataSourceFactory)1 DalConnectionLocator (com.ctrip.platform.dal.dao.client.DalConnectionLocator)1 DalLogger (com.ctrip.platform.dal.dao.client.DalLogger)1 DefaultLogger (com.ctrip.platform.dal.dao.client.DefaultLogger)1 ClusterManager (com.ctrip.platform.dal.dao.cluster.ClusterManager)1 ClusterManagerImpl (com.ctrip.platform.dal.dao.cluster.ClusterManagerImpl)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 DalRuntimeException (com.ctrip.platform.dal.exceptions.DalRuntimeException)1 UnsupportedFeatureException (com.ctrip.platform.dal.exceptions.UnsupportedFeatureException)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1