Search in sources :

Example 1 with CustomDataSourceFactory

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);
    }
}
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 2 with CustomDataSourceFactory

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)));
}
Also used : Database(com.ctrip.framework.dal.cluster.client.database.Database) HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) ConnectionString(com.ctrip.framework.dal.cluster.client.database.ConnectionString) CustomDataSourceFactory(com.ctrip.framework.dal.cluster.client.extended.CustomDataSourceFactory)

Aggregations

ConnectionString (com.ctrip.framework.dal.cluster.client.database.ConnectionString)2 CustomDataSourceFactory (com.ctrip.framework.dal.cluster.client.extended.CustomDataSourceFactory)2 HostSpec (com.ctrip.framework.dal.cluster.client.base.HostSpec)1 DalConfigCustomizedOption (com.ctrip.framework.dal.cluster.client.config.DalConfigCustomizedOption)1 Database (com.ctrip.framework.dal.cluster.client.database.Database)1 DalRuntimeException (com.ctrip.platform.dal.exceptions.DalRuntimeException)1 UnsupportedFeatureException (com.ctrip.platform.dal.exceptions.UnsupportedFeatureException)1 SQLException (java.sql.SQLException)1