本文整理汇总了Java中com.alibaba.druid.pool.DruidDataSource类的典型用法代码示例。如果您正苦于以下问题:Java DruidDataSource类的具体用法?Java DruidDataSource怎么用?Java DruidDataSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DruidDataSource类属于com.alibaba.druid.pool包,在下文中一共展示了DruidDataSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: businessSqlSessionFactory
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
@Bean
@Primary
public SqlSessionFactory businessSqlSessionFactory(@Qualifier("businessDataSource") DruidDataSource businessDataSource) throws Exception {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(businessDataSource);
//mybatis分页
PageHelper pageHelper = new PageHelper();
Properties props = new Properties();
props.setProperty("dialect", "mysql");
props.setProperty("reasonable", "true");
props.setProperty("supportMethodsArguments", "true");
props.setProperty("returnPageInfo", "check");
props.setProperty("params", "count=countSql");
pageHelper.setProperties(props);
//添加插件
sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper});
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sqlSessionFactoryBean.setMapperLocations(resolver.getResources(MAPPERXML_LOCATION));
return sqlSessionFactoryBean.getObject();
}
示例2: init
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
/**
* 初始化操作
*
* @param modelName 模块名称
* @param txConfig 配置信息
*/
@Override
public void init(String modelName, TxConfig txConfig) {
dataSource = new DruidDataSource();
final TxDbConfig txDbConfig = txConfig.getTxDbConfig();
dataSource.setUrl(txDbConfig.getUrl());
dataSource.setDriverClassName(txDbConfig.getDriverClassName());
dataSource.setUsername(txDbConfig.getUsername());
dataSource.setPassword(txDbConfig.getPassword());
dataSource.setInitialSize(txDbConfig.getInitialSize());
dataSource.setMaxActive(txDbConfig.getMaxActive());
dataSource.setMinIdle(txDbConfig.getMinIdle());
dataSource.setMaxWait(txDbConfig.getMaxWait());
dataSource.setValidationQuery(txDbConfig.getValidationQuery());
dataSource.setTestOnBorrow(txDbConfig.getTestOnBorrow());
dataSource.setTestOnReturn(txDbConfig.getTestOnReturn());
dataSource.setTestWhileIdle(txDbConfig.getTestWhileIdle());
dataSource.setPoolPreparedStatements(txDbConfig.getPoolPreparedStatements());
dataSource.setMaxPoolPreparedStatementPerConnectionSize(txDbConfig.getMaxPoolPreparedStatementPerConnectionSize());
this.tableName = RepositoryPathUtils.buildDbTableName(modelName);
executeUpdate(SqlHelper.buildCreateTableSql(tableName, txDbConfig.getDriverClassName()));
}
示例3: mafSlaveDataSource
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
@Bean(name = ConfigConstant.NAME_DS_SLAVE)
@ConfigurationProperties(prefix = ConfigConstant.PREFIX_DS_SLAVE)
public DataSource mafSlaveDataSource() {
logger.info("----- MAFIA slave data source INIT -----");
DruidDataSource ds = new DruidDataSource();
try {
ds.setFilters(env.getProperty("ds.filters"));
} catch (SQLException e) {
logger.warn("Data source set filters ERROR:", e);
}
ds.setMaxActive(NumberUtils.toInt(env.getProperty("ds.maxActive"), 90));
ds.setInitialSize(NumberUtils.toInt(env.getProperty("ds.initialSize"), 10));
ds.setMaxWait(NumberUtils.toInt(env.getProperty("ds.maxWait"), 60000));
ds.setMinIdle(NumberUtils.toInt(env.getProperty("ds.minIdle"), 1));
ds.setTimeBetweenEvictionRunsMillis(NumberUtils.toInt(env.getProperty("ds.timeBetweenEvictionRunsMillis"), 60000));
ds.setMinEvictableIdleTimeMillis(NumberUtils.toInt(env.getProperty("ds.minEvictableIdleTimeMillis"), 300000));
ds.setValidationQuery(env.getProperty("ds.validationQuery"));
ds.setTestWhileIdle(BooleanUtils.toBoolean(env.getProperty("ds.testWhileIdle")));
ds.setTestOnBorrow(BooleanUtils.toBoolean(env.getProperty("ds.testOnBorrow")));
ds.setTestOnReturn(BooleanUtils.toBoolean(env.getProperty("ds.testOnReturn")));
ds.setPoolPreparedStatements(BooleanUtils.toBoolean(env.getProperty("ds.poolPreparedStatements")));
ds.setMaxOpenPreparedStatements(NumberUtils.toInt(env.getProperty("ds.maxOpenPreparedStatements"), 20));
return ds;
}
示例4: logDataSource
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
@Bean(initMethod = "init", destroyMethod = "close")
public DruidDataSource logDataSource() throws SQLException, DESException {
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setDriverClassName(dbConfigProperties.getDriveClass());
druidDataSource.setUrl(dbConfigProperties.getLogUrl());
druidDataSource.setUsername(dbConfigProperties.getLogUsername());
druidDataSource.setPassword(dbConfigProperties.getLogPassword());
druidDataSource.setInitialSize(dbConfigProperties.getInitialSize());
druidDataSource.setMinIdle(dbConfigProperties.getMinIdle());
druidDataSource.setMaxActive(dbConfigProperties.getMaxActive());
druidDataSource.setMaxWait(dbConfigProperties.getMaxWait());
druidDataSource.setTimeBetweenEvictionRunsMillis(dbConfigProperties.getTimeBetweenEvictionRunsMillis());
druidDataSource.setMinEvictableIdleTimeMillis(dbConfigProperties.getMinEvictableIdleTimeMillis());
druidDataSource.setValidationQuery(dbConfigProperties.getValidationQuery());
druidDataSource.setTestWhileIdle(dbConfigProperties.getTestWhileIdle());
druidDataSource.setTestOnBorrow(dbConfigProperties.getTestOnBorrow());
druidDataSource.setTestOnReturn(dbConfigProperties.getTestOnReturn());
druidDataSource.setPoolPreparedStatements(dbConfigProperties.getPoolPreparedStatements());
druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(dbConfigProperties.getMaxPoolPreparedStatementPerConnectionSize());
druidDataSource.setFilters(dbConfigProperties.getFilters());
return druidDataSource;
}
示例5: studentDataSource
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
@Bean(name = "studentDataSource")
public DataSource studentDataSource() {
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl(studentUrl);
dataSource.setUsername(studentUser);
dataSource.setPassword(studentPassword);
dataSource.setDriverClassName(studentDriverClass);
//configuration
dataSource.setInitialSize(initialSize);
dataSource.setMinIdle(minIdle);
dataSource.setMaxActive(maxActive);
dataSource.setMaxWait(maxWait);
dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
dataSource.setValidationQuery(validationQuery);
dataSource.setTestWhileIdle(testWhileIdle);
dataSource.setTestOnBorrow(testOnBorrow);
dataSource.setTestOnReturn(testOnReturn);
dataSource.setPoolPreparedStatements(poolPreparedStatements);
dataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
return dataSource;
}
示例6: DataSourceBuilder
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
/**
* new druidDataSource and set config
* @throws Exception
*/
public DataSourceBuilder() throws Exception {
DruidDataSource druidDataSource = new DruidDataSource();
Properties conf = new Properties();
InputStream in = this.getClass().getResourceAsStream("/db_config.properties");
conf.load(in);
in.close();
long maxWait = Long.parseLong(conf.getProperty("druid.maxWait"));
long timeBetweenEvictionRunsMillis = Long.parseLong(conf.getProperty("druid.timeBetweenEvictionRunsMillis"));
druidDataSource.configFromPropety(conf);
druidDataSource.setMaxWait(maxWait);
druidDataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
this.dataSource = druidDataSource;
}
示例7: postProcessBeforeInitialization
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof DruidDataSource) {
// 设置 Druid 名称
((DruidDataSource) bean).setName(beanName);
// 将 'spring.datasource.druid.data-sources.${name}' 的配置绑定到 Bean
if (!resolver.getSubProperties(EMPTY).isEmpty()) {
PropertySourcesBinder binder = new PropertySourcesBinder(environment);
binder.bindTo(PREFIX + beanName, bean);
}
// 用户自定义配置
if (customizers != null && !customizers.isEmpty()) {
for (DruidDataSourceCustomizer customizer : customizers) {
customizer.customize((DruidDataSource) bean);
}
}
boolean isSingle = BEAN_NAME.equals(beanName);
if (isSingle) {
log.debug("druid data-source init...");
} else {
log.debug("druid {}-data-source init...", beanName);
}
}
return bean;
}
示例8: addFilterList
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
private void addFilterList(DruidDataSource ds) {
if (filterList != null) {
List<Filter> targetList = ds.getProxyFilters();
for (Filter add : filterList) {
boolean found = false;
for (Filter target : targetList) {
if (add.getClass().equals(target.getClass())) {
found = true;
break;
}
}
if (! found)
targetList.add(add);
}
}
}
示例9: dataSource
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
@Bean
public DataSource dataSource() {
System.out.println("注入druid!!!");
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(propertyResolver.getProperty("url"));
datasource.setDriverClassName(propertyResolver.getProperty("driver-class-name"));
datasource.setUsername(propertyResolver.getProperty("username"));
datasource.setPassword(propertyResolver.getProperty("password"));
datasource.setInitialSize(Integer.valueOf(propertyResolver.getProperty("initial-size")));
datasource.setMinIdle(Integer.valueOf(propertyResolver.getProperty("min-idle")));
datasource.setMaxWait(Long.valueOf(propertyResolver.getProperty("max-wait")));
datasource.setMaxActive(Integer.valueOf(propertyResolver.getProperty("max-active")));
datasource.setMinEvictableIdleTimeMillis(Long.valueOf(propertyResolver.getProperty("min-evictable-idle-time-millis")));
try {
datasource.setFilters("stat,wall,stat,log4j,default");
} catch (SQLException e) {
e.printStackTrace();
}
return datasource;
}
示例10: dataSource
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
@Bean(initMethod = "init", destroyMethod = "close")
public DruidDataSource dataSource(DruidConfig druidConfig) throws IOException {
DruidDataSource ds = new DruidDataSource();
ds.setDriverClassName("com.mysql.cj.jdbc.Driver");
ds.setUrl(druidConfig.getUrl() + "?" + druidConfig.getOptions());
ds.setUsername(druidConfig.getUser());
ds.setPassword(druidConfig.getPwd());
ds.setInitialSize(druidConfig.getInitialSize());
ds.setMinIdle(druidConfig.getMinIdle());
ds.setMaxActive(druidConfig.getMaxActive());
ds.setMaxWait(druidConfig.getMaxWait());
ds.setTimeBetweenEvictionRunsMillis(druidConfig.getTimeBetweenEvictionRunsMillis());
ds.setMinEvictableIdleTimeMillis(druidConfig.getMinEvictableIdleTimeMillis());
ds.setValidationQuery(druidConfig.getValidationQuery());
ds.setTestWhileIdle(druidConfig.getTestWhileIdle());
ds.setTestOnBorrow(druidConfig.getTestOnBorrow());
ds.setTestOnReturn(druidConfig.getTestOnReturn());
return ds;
}
示例11: init
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
/**
* 初始化操作
*
* @param modelName 模块名称
* @param mythConfig 配置信息
*/
@Override
public void init(String modelName, MythConfig mythConfig) {
dataSource = new DruidDataSource();
final MythDbConfig tccDbConfig = mythConfig.getMythDbConfig();
dataSource.setUrl(tccDbConfig.getUrl());
dataSource.setDriverClassName(tccDbConfig.getDriverClassName());
dataSource.setUsername(tccDbConfig.getUsername());
dataSource.setPassword(tccDbConfig.getPassword());
dataSource.setInitialSize(tccDbConfig.getInitialSize());
dataSource.setMaxActive(tccDbConfig.getMaxActive());
dataSource.setMinIdle(tccDbConfig.getMinIdle());
dataSource.setMaxWait(tccDbConfig.getMaxWait());
dataSource.setValidationQuery(tccDbConfig.getValidationQuery());
dataSource.setTestOnBorrow(tccDbConfig.getTestOnBorrow());
dataSource.setTestOnReturn(tccDbConfig.getTestOnReturn());
dataSource.setTestWhileIdle(tccDbConfig.getTestWhileIdle());
dataSource.setPoolPreparedStatements(tccDbConfig.getPoolPreparedStatements());
dataSource.setMaxPoolPreparedStatementPerConnectionSize(tccDbConfig.getMaxPoolPreparedStatementPerConnectionSize());
this.tableName = RepositoryPathUtils.buildDbTableName(modelName);
executeUpdate(SqlHelper.buildCreateTableSql(tccDbConfig.getDriverClassName(), tableName));
}
示例12: testGetDataSourceByMap
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
@Test
public void testGetDataSourceByMap() throws Exception {
Map<String, String> config = new HashMap<>();
config.put("driverClassName", "com.mysql.jdbc.Driver");
config.put("url", "jdbc:mysql://123.206.133.24:4858/minsx?useUnicode=true&characterEncoding=utf-8&autoReconnect=true");
config.put("username", "wssswcom");
config.put("password", "Ss123456");
config.put("initialSize", "5");
config.put("minIdle", "5");
config.put("maxActive", "50");
config.put("maxWait", "60000");
config.put("timeBetweenEvictionRunsMillis", "60000");
config.put("minEvictableIdleTimeMillis", "300000");
config.put("multiStatementAllow", "true");
config.put("validationQuery", "SELECT 1");
config.put("testWhileIdle", "true");
config.put("testOnBorrow", "false");
config.put("testOnReturn", "false");
config.put("poolPreparedStatements", "false");
config.put("maxPoolPreparedStatementPerConnectionSize", "20");
DruidDataSource dataSource = DataSourceFactory.createDataSource("minsx", config);
Connection connection = dataSource.getConnection();
connection.close();
}
示例13: createDataSource
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
protected DataSource createDataSource() throws SQLException {
// special
DruidDataSource datasource = new DruidDataSource();
datasource.setUrl(commonProperties.getUrl());
datasource.setUsername(commonProperties.getUsername());
datasource.setPassword(commonProperties.getPassword());
// common
datasource.setDriverClassName(commonProperties.getDriverClassName());
datasource.setInitialSize(commonProperties.getInitialSize());
datasource.setMinIdle(commonProperties.getMinIdle());
datasource.setMaxActive(commonProperties.getMaxActive());
datasource.setMaxWait(commonProperties.getMaxWait());
datasource
.setTimeBetweenEvictionRunsMillis(commonProperties.getTimeBetweenEvictionRunsMillis());
datasource.setMinEvictableIdleTimeMillis(commonProperties.getMinEvictableIdleTimeMillis());
datasource.setValidationQuery(commonProperties.getValidationQuery());
datasource.setTestWhileIdle(commonProperties.isTestWhileIdle());
datasource.setTestOnBorrow(commonProperties.isTestOnBorrow());
datasource.setTestOnReturn(commonProperties.isTestOnReturn());
datasource.setPoolPreparedStatements(commonProperties.isPoolPreparedStatements());
datasource.setMaxPoolPreparedStatementPerConnectionSize(
commonProperties.getMaxPoolPreparedStatementPerConnectionSize());
datasource.setFilters(commonProperties.getFilters());
datasource.setConnectionProperties(commonProperties.getConnectionProperties());
return datasource;
}
示例14: definitionDataSource
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的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;
}
示例15: DynamicDataSource
import com.alibaba.druid.pool.DruidDataSource; //导入依赖的package包/类
public DynamicDataSource(MybatisNodeProperties druidNode, DruidProperties defaultDruidProperties, String dataSourceName) throws SQLException {
this.dataSourceName=dataSourceName;
DruidProperties master = druidNode.getMaster();
if (master == null)
master = new DruidProperties();
master.merge(defaultDruidProperties).defaultEmpty().setDefaultReadOnly(false);
this.masterDataSource = master.createDataSource();
this.masterDataSource.setName(dataSourceName + "-Master");
List<DruidProperties> slaves = druidNode.getSlaves();
if (slaves != null && !slaves.isEmpty()) {
for (int i = 0; i < slaves.size(); i++) {
DruidProperties slave = slaves.get(i);
if (slave == null)
continue;
slave.merge(defaultDruidProperties).defaultEmpty().setDefaultReadOnly(true);
String slaveDatasourceName = dataSourceName + "-Slave-" + i;
this.slavesDataSourceNames.add(slaveDatasourceName);
DruidDataSource datasourc = slave.createDataSource();
datasourc.setName(slaveDatasourceName);
this.slaveDataSources.put(slaveDatasourceName, datasourc);
}
}
String rawUrl=master.getUrl();
String dbType = JdbcUtils.getDbType(rawUrl,null);
this.dialect=Dialect.valoueOfName(dbType);
}