public DataSource getDataSource(Config config) { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); String cachedKey = StringUtils.concat(url, username, password); DataSource dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource == null) { try { synchronized (lock) { dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource != null) { return dataSource; } dataSource = createDataSource(config); DATA_SOURCE_MAP.put(cachedKey, dataSource); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect datasource failed! url: {}", url), e); } } return dataSource; }
public DataSource getDataSource(Config config) { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); String cachedKey = StringUtils.concat(url, username, password); DataSource dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource == null) { try { synchronized (lock) { dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource != null) { return dataSource; } dataSource = createDataSource(config); DATA_SOURCE_MAP.put(cachedKey, dataSource); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect datasource failed! url: {}", url), e); } } return dataSource; }
public DataSource getDataSource(Config config) { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); if (StringUtils.isEmpty(url)) { throw new IllegalArgumentException(ExtConfig.JDBC_URL + " should not be empty"); } if (StringUtils.isEmpty(ExtConfig.JDBC_USERNAME)) { throw new IllegalArgumentException(ExtConfig.JDBC_USERNAME + " should not be empty"); } String cachedKey = StringUtils.concat(url, username, password); DataSource dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource == null) { try { synchronized (lock) { dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource != null) { return dataSource; } dataSource = createDruidDataSource(config); DATA_SOURCE_MAP.put(cachedKey, dataSource); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect datasource failed! url: {}", url), e); } } return dataSource; }
public DataSource getDataSource(Config config) { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); if (StringUtils.isEmpty(url)) { throw new IllegalArgumentException(ExtConfig.JDBC_URL + " should not be empty"); } if (StringUtils.isEmpty(ExtConfig.JDBC_USERNAME)) { throw new IllegalArgumentException(ExtConfig.JDBC_USERNAME + " should not be empty"); } String cachedKey = StringUtils.concat(url, username, password); DataSource dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource == null) { try { synchronized (lock) { dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource != null) { return dataSource; } dataSource = createDruidDataSource(config); DATA_SOURCE_MAP.put(cachedKey, dataSource); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect datasource failed! url: {}", url), e); } } return dataSource; }
public static Datastore getDataStore(Config config) { String[] addresses = config.getParameter(ExtConfig.MONGO_ADDRESSES, new String[]{"127.0.0.1:27017"}); String database = config.getParameter(ExtConfig.MONGO_DATABASE, "lts"); String username = config.getParameter(ExtConfig.MONGO_USERNAME); String pwd = config.getParameter(ExtConfig.MONGO_PASSWORD); String cachedKey = StringUtils.concat(StringUtils.concat(addresses), database, username, pwd); Datastore datastore = DATA_STORE_MAP.get(cachedKey); if (datastore == null) { try { synchronized (lock) { datastore = DATA_STORE_MAP.get(cachedKey); if (datastore != null) { return datastore; } Morphia morphia = new Morphia(); MongoFactoryBean mongoFactoryBean = new MongoFactoryBean(addresses, username, database, pwd); MongoClient mongo = mongoFactoryBean.createInstance(); datastore = morphia.createDatastore(mongo, database); DATA_STORE_MAP.put(cachedKey, datastore); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect mongo failed! addresses: {}, database: {}", addresses, database), e); } } return datastore; }
public static Datastore getDataStore(Config config) { String[] addresses = config.getParameter(ExtConfig.MONGO_ADDRESSES, new String[]{"127.0.0.1:27017"}); String database = config.getParameter(ExtConfig.MONGO_DATABASE, "lts"); String username = config.getParameter(ExtConfig.MONGO_USERNAME); String pwd = config.getParameter(ExtConfig.MONGO_PASSWORD); String cachedKey = StringUtils.concat(StringUtils.concat(addresses), database, username, pwd); Datastore datastore = DATA_STORE_MAP.get(cachedKey); if (datastore == null) { try { synchronized (lock) { datastore = DATA_STORE_MAP.get(cachedKey); if (datastore != null) { return datastore; } Morphia morphia = new Morphia(); MongoFactoryBean mongoFactoryBean = new MongoFactoryBean(addresses, username, database, pwd); MongoClient mongo = mongoFactoryBean.createInstance(); datastore = morphia.createDatastore(mongo, database); DATA_STORE_MAP.put(cachedKey, datastore); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect mongo failed! addresses: {}, database: {}", addresses, database), e); } } return datastore; }
public DataSource getDataSource(Config config) { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); String cachedKey = StringUtils.concat(url, username, password); DataSource dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource == null) { try { synchronized (lock) { dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource != null) { return dataSource; } dataSource = createDataSource(config); DATA_SOURCE_MAP.put(cachedKey, dataSource); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect datasource failed! url: {}", url), e); } } return dataSource; }
public static Datastore getDataStore(Config config) { String[] addresses = config.getParameter(ExtConfig.MONGO_ADDRESSES, new String[]{"127.0.0.1:27017"}); String database = config.getParameter(ExtConfig.MONGO_DATABASE, "lts"); String username = config.getParameter(ExtConfig.MONGO_USERNAME); String pwd = config.getParameter(ExtConfig.MONGO_PASSWORD); String cachedKey = StringUtils.concat(StringUtils.concat(addresses), database, username, pwd); Datastore datastore = DATA_STORE_MAP.get(cachedKey); if (datastore == null) { try { synchronized (lock) { datastore = DATA_STORE_MAP.get(cachedKey); if (datastore != null) { return datastore; } Morphia morphia = new Morphia(); MongoFactoryBean mongoFactoryBean = new MongoFactoryBean(addresses, username, database, pwd); MongoClient mongo = mongoFactoryBean.createInstance(); datastore = morphia.createDatastore(mongo, database); DATA_STORE_MAP.put(cachedKey, datastore); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect mongo failed! addresses: {}, database: {}", addresses, database), e); } } return datastore; }
public DataSource getDataSource(Config config) { String url = config.getParameter(ExtConfig.JDBC_URL); String username = config.getParameter(ExtConfig.JDBC_USERNAME); String password = config.getParameter(ExtConfig.JDBC_PASSWORD); if (StringUtils.isEmpty(url)) { throw new IllegalArgumentException(ExtConfig.JDBC_URL + " should not be empty"); } if (StringUtils.isEmpty(ExtConfig.JDBC_USERNAME)) { throw new IllegalArgumentException(ExtConfig.JDBC_USERNAME + " should not be empty"); } String cachedKey = StringUtils.concat(url, username, password); DataSource dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource == null) { try { synchronized (lock) { dataSource = DATA_SOURCE_MAP.get(cachedKey); if (dataSource != null) { return dataSource; } dataSource = createDruidDataSource(config); DATA_SOURCE_MAP.put(cachedKey, dataSource); } } catch (Exception e) { throw new IllegalStateException( StringUtils.format("connect datasource failed! url: {}", url), e); } } return dataSource; }