当前位置: 首页>>代码示例>>Java>>正文


Java BasicDataSourceFactory类代码示例

本文整理汇总了Java中org.apache.commons.dbcp2.BasicDataSourceFactory的典型用法代码示例。如果您正苦于以下问题:Java BasicDataSourceFactory类的具体用法?Java BasicDataSourceFactory怎么用?Java BasicDataSourceFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BasicDataSourceFactory类属于org.apache.commons.dbcp2包,在下文中一共展示了BasicDataSourceFactory类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: JdbcModule

import org.apache.commons.dbcp2.BasicDataSourceFactory; //导入依赖的package包/类
public JdbcModule() {

		Properties props = new Properties();
		try (InputStream istream = Thread.currentThread().getContextClassLoader().getResourceAsStream("jdbc.properties")) {
			if (istream == null)
				throw new FileNotFoundException("Could not find JDBC properties");
			props.load(istream);
			dataSource = BasicDataSourceFactory.createDataSource(props);
		} catch (Exception e) {
			throw new RuntimeException("Unable to initialize DataSource", e);
		}

		this.connectionProvider = new TxConnectionProvider(dataSource);
		this.transactionInterceptor = new TransactionInterceptor(connectionProvider);

	}
 
开发者ID:vsite-hr,项目名称:mentor,代码行数:17,代码来源:JdbcModule.java

示例2: MysqlCrawlProcessor

import org.apache.commons.dbcp2.BasicDataSourceFactory; //导入依赖的package包/类
public MysqlCrawlProcessor(MysqlCrawlProcessorConfig config) throws Exception{
    
    super(Math.max(config.tableList.size() + 1, config.concurrentCrawlCount), 
            new ThreadPoolExecutor(
                    config.concurrentCrawlCount, 
                    config.concurrentCrawlCount, 
                    10, 
                    TimeUnit.MINUTES, 
                    new LinkedBlockingQueue<>()));
    
    config.checkValidation();
    this.config = config;
    
    Set<String> dbNameSet = new HashSet<>();
    for(String tableName : config.tableList){
        dbNameSet.add(tableName.split("\\.")[0]);
    }
    this.serverInfo = new MysqlServerInfo(config.host, config.port, config.user, config.password, new ArrayList<>(dbNameSet));
    
    // data source
    final String url = "jdbc:mysql://" + config.host + ":" + config.port + "/?" + config.jdbcConnParam;
    this.dataSource = BasicDataSourceFactory.createDataSource(config.dbcp2Properties);
    this.dataSource.setUrl(url);
    this.dataSource.setUsername(config.user);
    this.dataSource.setPassword(config.password);
    
    // init handler
    @SuppressWarnings("unchecked")
    final Class<? extends MysqlCrawlProcessorHandler> handlerClass = 
            (Class<? extends MysqlCrawlProcessorHandler>) Class.forName(config.handlerClassName);
    handler = handlerClass.newInstance();
    if(!(handler instanceof MysqlCrawlProcessorHandler)){
        throw new IllegalArgumentException("Class [" + config.handlerClassName + "] is invalid.");
    }
    
}
 
开发者ID:kakao,项目名称:adt,代码行数:37,代码来源:MysqlCrawlProcessor.java

示例3: example3

import org.apache.commons.dbcp2.BasicDataSourceFactory; //导入依赖的package包/类
private void example3() throws Exception {
/**/DebugTrace.enter();

	DataSource dataSource = BasicDataSourceFactory.createDataSource(new Properties());
/**/DebugTrace.print("dataSource", dataSource);

/**/DebugTrace.leave();
}
 
开发者ID:MasatoKokubo,项目名称:DebugTrace-java,代码行数:9,代码来源:Example2.java

示例4: primaryDataSource

import org.apache.commons.dbcp2.BasicDataSourceFactory; //导入依赖的package包/类
@Bean(value = "cityInfoDS", destroyMethod = "") //Disable destroy method here to avoid warning for duplicated shutdown
@Primary
public DataSource primaryDataSource() throws Exception {
    return BasicDataSourceFactory.createDataSource(primaryDataSourceProperties());
}
 
开发者ID:bszeti,项目名称:camel-springboot,代码行数:6,代码来源:Application.java

示例5: anotherDataSource

import org.apache.commons.dbcp2.BasicDataSourceFactory; //导入依赖的package包/类
@Bean(destroyMethod = "")
public DataSource anotherDataSource() throws Exception {
    return BasicDataSourceFactory.createDataSource(anotherDataSourceProperties());
}
 
开发者ID:bszeti,项目名称:camel-springboot,代码行数:5,代码来源:Application.java

示例6: build

import org.apache.commons.dbcp2.BasicDataSourceFactory; //导入依赖的package包/类
@Override
public DataSource build(DataSourceConfigProperties configurationProperties) throws ConfigurationException {

	final String dataContextId = configurationProperties.getDataContextId().orElse(null);

	final String url = configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.URL, null);
	if (url == null) {
		throw new ConfigurationException(DefaultDataSourceBuilderConfiguration
				.buildMissingJdbcUrlMessage(getDataSourceType(), dataContextId));
	}

	final String driverClass = configurationProperties.getConfigPropertyValue(
			DataSourceConfigProperties.DRIVER_CLASS_NAME,
			configurationProperties.getDriverClassName()
					.orElseThrow(() -> new ConfigurationException(DefaultDataSourceBuilderConfiguration
							.buildMissingDriverClassMessage(getDataSourceType(), dataContextId))));

	try {
		// specific properties
		Map<String, String> dbcpProperties = configurationProperties.getSubPropertiesUsingPrefix("dbcp");
		Properties poolProperties = new Properties();
		poolProperties.putAll(dbcpProperties);

		BasicDataSource ds = BasicDataSourceFactory.createDataSource(poolProperties);

		ds.setDriverClassName(driverClass);
		ds.setUrl(url);

		// validation query
		configurationProperties.getConnectionValidationQuery().ifPresent(vq -> {
			ds.setTestOnBorrow(true);
			ds.setValidationQuery(vq);
		});

		// credentials
		ds.setUsername(configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.USERNAME, null));
		ds.setPassword(configurationProperties.getConfigPropertyValue(DataSourceConfigProperties.PASSWORD, null));

		// pool size
		Integer minPoolSize = configurationProperties
				.getConfigPropertyValue(DataSourceConfigProperties.MIN_POOL_SIZE, null);
		if (minPoolSize != null && minPoolSize > 0) {
			ds.setInitialSize(minPoolSize);
			ds.setMinIdle(minPoolSize);
		}

		Integer maxPoolSize = configurationProperties.getConfigPropertyValue(
				DataSourceConfigProperties.MAX_POOL_SIZE, DataSourceConfigProperties.DEFAULT_MAX_POOL_SIZE);
		if (maxPoolSize != null && maxPoolSize > 0) {
			ds.setMaxTotal(maxPoolSize);
			if (ds.getMaxIdle() > maxPoolSize) {
				ds.setMaxIdle(maxPoolSize);
			}
		}

		// autocommit
		if (configurationProperties.isDisableAutoCommit()) {
			ds.setDefaultAutoCommit(Boolean.FALSE);
		}

		LOGGER.debug(() -> "(Data context id: " + dataContextId + "): "
				+ "DBCP2 DataSource setted up for jdbc url: " + url + " [Max pool size: " + maxPoolSize + "]");

		return ds;
	} catch (Exception e) {
		throw new ConfigurationException("Failed to configure [" + getDataSourceType() + "] DataSource", e);
	}
}
 
开发者ID:holon-platform,项目名称:holon-jdbc,代码行数:69,代码来源:DBCP2DataSourceFactory.java

示例7: connect

import org.apache.commons.dbcp2.BasicDataSourceFactory; //导入依赖的package包/类
private static void connect() throws Exception {
	dataSource = BasicDataSourceFactory.createDataSource(properties);
}
 
开发者ID:Metazion,项目名称:JGameDemo,代码行数:4,代码来源:DbUtil.java


注:本文中的org.apache.commons.dbcp2.BasicDataSourceFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。