本文整理汇总了Java中com.alibaba.druid.pool.DruidDataSourceFactory类的典型用法代码示例。如果您正苦于以下问题:Java DruidDataSourceFactory类的具体用法?Java DruidDataSourceFactory怎么用?Java DruidDataSourceFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DruidDataSourceFactory类属于com.alibaba.druid.pool包,在下文中一共展示了DruidDataSourceFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dataSource
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
private DataSource dataSource() {
Map<String,Object> properties=new HashMap<>();
properties.put(DruidDataSourceFactory.PROP_DRIVERCLASSNAME,env.getProperty("spring.datasource.driverClassName"));
properties.put(DruidDataSourceFactory.PROP_URL,env.getProperty("spring.datasource.url"));
properties.put(DruidDataSourceFactory.PROP_USERNAME,env.getProperty("spring.datasource.username"));
properties.put(DruidDataSourceFactory.PROP_PASSWORD,env.getProperty("spring.datasource.password"));
//添加统计、SQL注入、日志过滤器
properties.put(DruidDataSourceFactory.PROP_FILTERS,env.getProperty("druid.propFilters"));
//sql合并,慢查询定义为5s
properties.put(DruidDataSourceFactory.PROP_CONNECTIONPROPERTIES,env.getProperty("druid.propConnectionProperties"));
try {
return DruidDataSourceFactory.createDataSource(properties);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例2: definitionDataSource
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Bean
public DataSource definitionDataSource() throws Exception {
StatFilter statFilter = new StatFilter();
Properties config = new Properties();
config.setProperty("url", dataSourceProperties.getUrl());
config.setProperty("username", dataSourceProperties.getUsername());
config.setProperty("password", dataSourceProperties.getPassword());
config.setProperty("driverClassName", dataSourceProperties.getDriverClassName());
config.setProperty("filters", "slf4j");
DruidDataSource dataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(config);
dataSource.setProxyFilters(Collections.singletonList(statFilter));
return dataSource;
}
示例3: druidDataSource
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
/**
* druid数据源
* @return
*/
@Bean
@ConfigurationProperties(prefix = DB_PREFIX)
public DataSource druidDataSource() {
Properties dbProperties = new Properties();
Map<String, Object> map = new HashMap<>();
for (Iterator<PropertySource<?>> it = ((AbstractEnvironment) environment).getPropertySources().iterator(); it.hasNext();) {
PropertySource<?> propertySource = it.next();
getPropertiesFromSource(propertySource, map);
}
dbProperties.putAll(map);
DruidDataSource dds = null;
try {
dds = (DruidDataSource) DruidDataSourceFactory.createDataSource(dbProperties);
if (null != dds) {
dds.init();
}
} catch (Exception e) {
throw new RuntimeException("load datasource error, dbProperties is :" + dbProperties, e);
}
return dds;
}
示例4: afterPropertiesSet
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
if (dataSourceName == null) {
dataSourceName = Constants.CONF_DATASOURCE_ITEM;
}
String path = Config.getContext().getString(dataSourceName);
try {
Properties ps = InitTool.loadFile(path);
DataSource ds = DruidDataSourceFactory.createDataSource(ps);
if (ps.containsKey("name")) {
((DruidDataSource) ds).setName(ps.getProperty("name"));
} else {
String url = ((DruidDataSource) ds).getRawJdbcUrl();
String ip_port = url.split("/")[2].replaceAll(":", "_");
((DruidDataSource) ds).setName(ip_port);
}
setTargetDataSource(ds);
} catch (Exception e) {
Validate.isTrue(false, "DataSource Init Error");
}
super.afterPropertiesSet();
}
示例5: handleEvent
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Subscribe
public void handleEvent(Map<String, ConfigItem> config) {
if (!config.containsKey(this.davinciCode))
return;
ConfigItem ci = config.get(this.davinciCode);
if (this.configItem != null && this.configItem.getVersion() >= ci.getVersion())
return;
try {
setTargetDataSource(DruidDataSourceFactory.createDataSource(buildProperties(ci)));
super.afterPropertiesSet();
getTargetDataSource().getConnection().isValid(1000);
this.configItem = ci;
} catch (Exception e) {
LOG.error("DataSourceUnit Handle Event Error : ", e);
Validate.isTrue(false, e.getMessage());
}
}
示例6: getDataSource
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
public static DataSource getDataSource() {
if (dataSource == null) {
try {
dataSource = DruidDataSourceFactory.createDataSource(loadPropertyFile(configFile));
} catch (Exception e) {
e.printStackTrace();
}
}
return dataSource;
}
示例7: test1DataSource
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Bean
public DataSource test1DataSource() throws Exception {
Properties props = new Properties();
props.put("driverClassName", environment.getProperty("dbpool.database1.driver-class-name"));
props.put("url", environment.getProperty("dbpool.database1.url"));
props.put("username", environment.getProperty("dbpool.database1.username"));
props.put("password", environment.getProperty("dbpool.database1.password"));
return DruidDataSourceFactory.createDataSource(props);
}
示例8: test2DataSource
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Bean
@Primary
public DataSource test2DataSource() throws Exception {
Properties props = new Properties();
props.put("driverClassName", environment.getProperty("dbpool.database2.driver-class-name"));
props.put("url", environment.getProperty("dbpool.database2.url"));
props.put("username", environment.getProperty("dbpool.database2.username"));
props.put("password", environment.getProperty("dbpool.database2.password"));
return DruidDataSourceFactory.createDataSource(props);
}
示例9: test1DataSource
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
/**
* 创建数据源(数据源的名称:方法名可以取为XXXDataSource(),XXX为数据库名称,该名称也就是数据源的名称)
*/
@Bean
public DataSource test1DataSource() throws Exception {
Properties props = new Properties();
props.put("driverClassName", environment.getProperty("test1-datasource.driverClassName"));
props.put("url", environment.getProperty("test1-datasource.url"));
props.put("username", environment.getProperty("test1-datasource.username"));
props.put("password", environment.getProperty("test1-datasource.password"));
return DruidDataSourceFactory.createDataSource(props);
}
示例10: test2DataSource
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Bean
public DataSource test2DataSource() throws Exception {
Properties props = new Properties();
props.put("driverClassName", environment.getProperty("test2-datasource.driverClassName"));
props.put("url", environment.getProperty("test2-datasource.url"));
props.put("username", environment.getProperty("test2-datasource.username"));
props.put("password", environment.getProperty("test2-datasource.password"));
return DruidDataSourceFactory.createDataSource(props);
}
示例11: JdbcOperatorUnit
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
public JdbcOperatorUnit() {
//只构建一次数据源
if(dataSource==null) {
try {
String druidpath = TFile.getSystemPath("/classes/database.properties");
Properties druidProperites = TProperties.getProperties(new File(druidpath));
dataSource = (DruidDataSource)DruidDataSourceFactory.createDataSource(druidProperites);
dataSource.init();
Logger.info("Database connection pool init finished");
} catch (Exception e) {
Logger.error(e);
}
}
}
示例12: init
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
/**
* 连接初始化
*
* @throws java.lang.Exception
*/
public synchronized static void init() throws Exception {
/* 导入配置文件形成的mapMAP */
config = loadProerties();
for (Map.Entry<String, Map<String, String>> row : config.entrySet()) {
_DATASOURCEMAP.put(row.getKey(),
DruidDataSourceFactory.createDataSource(config.get(row.getKey())));
}
log.info("线程池初始化完毕..");
}
示例13: configure
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public void configure(Map configurationValues) {
logger.info("DruidDataSource init:: "+configurationValues);
try {
DruidDataSourceFactory.config(dataSource, configurationValues);
} catch (SQLException e) {
throw new IllegalArgumentException("config error", e);
}
}
示例14: getDataSource
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
public static DataSource getDataSource() {
if(source == null){
Properties properties = new Properties();
try {
InputStream in = DbPoolConnection.class.getClassLoader().getResourceAsStream(FILE_NAME);
properties.load(in);
source = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
} catch (Exception e) {
e.printStackTrace();
}
}
return source;
}
示例15: setUp
import com.alibaba.druid.pool.DruidDataSourceFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
File configFile = new File("application.properties");
FileInputStream fis = new FileInputStream(configFile);
BufferedInputStream bis = new BufferedInputStream(fis);
Properties prop = new Properties();
prop.load(bis);
bis.close();
dataSource = DruidDataSourceFactory.createDataSource(prop);
}