public static SqlTemplate create(Config config) { DataSourceProvider dataSourceProvider = ServiceLoader.load(DataSourceProvider.class, config); DataSource dataSource = dataSourceProvider.getDataSource(config); SqlTemplate sqlTemplate = HOLDER.get(dataSource); if (sqlTemplate != null) { return sqlTemplate; } synchronized (HOLDER) { sqlTemplate = HOLDER.get(dataSource); if (sqlTemplate != null) { return sqlTemplate; } sqlTemplate = new SqlTemplateImpl(dataSource); HOLDER.putIfAbsent(dataSource, sqlTemplate); return sqlTemplate; } }
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 static SqlTemplate create(Config config) { DataSourceProvider dataSourceProvider = ServiceLoader.load(DataSourceProvider.class, config); DataSource dataSource = dataSourceProvider.getDataSource(config); SqlTemplate sqlTemplate = HOLDER.get(dataSource); if (sqlTemplate != null) { return sqlTemplate; } synchronized (HOLDER) { sqlTemplate = HOLDER.get(dataSource); if (sqlTemplate != null) { return sqlTemplate; } sqlTemplate = new SqlTemplateImpl(dataSource); HOLDER.putIfAbsent(dataSource, sqlTemplate); return sqlTemplate; } }
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 static SqlTemplate create(Config config) { DataSourceProvider dataSourceProvider = ServiceLoader.load(DataSourceProvider.class, config); DataSource dataSource = dataSourceProvider.getDataSource(config); SqlTemplate sqlTemplate = HOLDER.get(dataSource); if (sqlTemplate != null) { return sqlTemplate; } synchronized (HOLDER) { sqlTemplate = HOLDER.get(dataSource); if (sqlTemplate != null) { return sqlTemplate; } sqlTemplate = new SqlTemplateImpl(dataSource); HOLDER.putIfAbsent(dataSource, sqlTemplate); return sqlTemplate; } }
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; }