當前位置: 首頁>>代碼示例>>Java>>正文


Java BasicDataSource.setValidationQuery方法代碼示例

本文整理匯總了Java中org.apache.commons.dbcp2.BasicDataSource.setValidationQuery方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicDataSource.setValidationQuery方法的具體用法?Java BasicDataSource.setValidationQuery怎麽用?Java BasicDataSource.setValidationQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.dbcp2.BasicDataSource的用法示例。


在下文中一共展示了BasicDataSource.setValidationQuery方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBasicDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private static BasicDataSource getBasicDataSource(DatasourceConfiguration configuration) {
    BasicDataSource dbcpDataSource = new BasicDataSource();
    dbcpDataSource.setDriverClassName(configuration.getDriverClassname());
    dbcpDataSource.setUrl(configuration.getUrl());
    dbcpDataSource.setUsername(configuration.getUser());
    dbcpDataSource.setPassword(configuration.getPassword());

    // Enable statement caching (Optional)
    dbcpDataSource.setPoolPreparedStatements(true);
    dbcpDataSource.setValidationQuery("Select 1 ");
    dbcpDataSource.setMaxOpenPreparedStatements(50);
    dbcpDataSource.setLifo(true);
    dbcpDataSource.setMaxTotal(10);
    dbcpDataSource.setInitialSize(2);
    return dbcpDataSource;
}
 
開發者ID:drinkwater-io,項目名稱:drinkwater-java,代碼行數:17,代碼來源:DBCPSqlDataStore.java

示例2: invokeGetDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public DataSource invokeGetDataSource() {
	BasicDataSource bds = new BasicDataSource();
	bds.setDriverClassName("com.mysql.jdbc.Driver");
	bds.setUrl("jdbc:mysql://127.0.0.1:3306/inst02");
	bds.setUsername("root");
	bds.setPassword("123456");
	bds.setMaxTotal(50);
	bds.setInitialSize(20);
	bds.setMaxWaitMillis(60000);
	bds.setMinIdle(6);
	bds.setLogAbandoned(true);
	bds.setRemoveAbandonedOnBorrow(true);
	bds.setRemoveAbandonedOnMaintenance(true);
	bds.setRemoveAbandonedTimeout(1800);
	bds.setTestWhileIdle(true);
	bds.setTestOnBorrow(false);
	bds.setTestOnReturn(false);
	bds.setValidationQuery("select 'x' ");
	bds.setValidationQueryTimeout(1);
	bds.setTimeBetweenEvictionRunsMillis(30000);
	bds.setNumTestsPerEvictionRun(20);
	return bds;
}
 
開發者ID:liuyangming,項目名稱:ByteTCC-sample,代碼行數:24,代碼來源:ConsumerConfig.java

示例3: invokeGetDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public DataSource invokeGetDataSource() {
	BasicDataSource bds = new BasicDataSource();
	bds.setDriverClassName("com.mysql.jdbc.Driver");
	bds.setUrl("jdbc:mysql://127.0.0.1:3306/inst01");
	bds.setUsername("root");
	bds.setPassword("123456");
	bds.setMaxTotal(50);
	bds.setInitialSize(20);
	bds.setMaxWaitMillis(60000);
	bds.setMinIdle(6);
	bds.setLogAbandoned(true);
	bds.setRemoveAbandonedOnBorrow(true);
	bds.setRemoveAbandonedOnMaintenance(true);
	bds.setRemoveAbandonedTimeout(1800);
	bds.setTestWhileIdle(true);
	bds.setTestOnBorrow(false);
	bds.setTestOnReturn(false);
	bds.setValidationQuery("select 'x' ");
	bds.setValidationQueryTimeout(1);
	bds.setTimeBetweenEvictionRunsMillis(30000);
	bds.setNumTestsPerEvictionRun(20);
	return bds;
}
 
開發者ID:liuyangming,項目名稱:ByteTCC-sample,代碼行數:24,代碼來源:ProviderConfig.java

示例4: init

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@PostConstruct
/**
 * Creates security data-source to be used with the sample DB 
 */
public void init() {
       securityDataSource = new BasicDataSource();
       securityDataSource.setDriverClassName(com.mysql.jdbc.Driver.class.getName());
       securityDataSource.setUrl("jdbc:mysql://localhost:3306/java_one_2014");
       securityDataSource.setUsername("java_one");
       securityDataSource.setPassword("");
	securityDataSource.setInitialSize(5);
       securityDataSource.setMaxTotal(30);
       securityDataSource.setMaxIdle(15);
       securityDataSource.setMaxWaitMillis(3000);
       securityDataSource.setLogAbandoned(true);
       securityDataSource.setTestWhileIdle(true);
       securityDataSource.setTestOnBorrow(true);
       securityDataSource.setValidationQuery("select 1");
}
 
開發者ID:ishaigor,項目名稱:rest-retro-sample,代碼行數:20,代碼來源:PersistenceConfiguration.java

示例5: setupDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
/**
 * TODO: write documentation
 * 
 * @throws ClassNotFoundException
 */
private void setupDataSource() throws ClassNotFoundException {

	// request classloader to load JDBC driver class
	Class.forName(jdbcDriverClassName);

	// prepare and configure data source
	dataSource = new BasicDataSource();
	dataSource.setDefaultAutoCommit(true);
	dataSource.setDriverClassName(jdbcDriverClassName);
	dataSource.setUsername(jdbcLogin);
	dataSource.setPassword(jdbcPass);
	dataSource.setUrl(jdbcUrl + jdbcSchema);
	dataSource.setValidationQuery("select 1");
	dataSource.setDefaultQueryTimeout(1000);
	dataSource.setMaxConnLifetimeMillis(100000);
}
 
開發者ID:rwth-acis,項目名稱:mobsos-surveys,代碼行數:22,代碼來源:SurveyService.java

示例6: initialize

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Override
public Addon initialize(ServiceConfig serviceConfig) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl(url);
    dataSource.setDriverClassName(driverClassName);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setValidationQuery(validationQuery);

    return this.withDataSource(dataSource);
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:12,代碼來源:BasicDatasourceAddon.java

示例7: getValidationQuery

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Override
public void getValidationQuery() {
	BasicDataSource dataSource = createDataSource();
	dataSource.setValidationQuery("SELECT FROM FOO");
	assertThat(
			new CommonsDbcp2DataSourcePoolMetadata(dataSource).getValidationQuery())
					.isEqualTo("SELECT FROM FOO");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:9,代碼來源:CommonsDbcp2DataSourcePoolMetadataTests.java

示例8: chatDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Bean
public DataSource chatDataSource() throws ConfigurationException, IOException {
	BasicDataSource datasource = new BasicDataSource();
	String path = this.configuration().getString(GlobalConfig.DB_PATH);
	if (path == null) {
		path = GlobalConfig.DB_PATH_DEFAULT;
	}
	datasource.setUsername(this.configuration().getString(GlobalConfig.DB_USERNAME));
	datasource.setPassword(this.configuration().getString(GlobalConfig.DB_PASSWORD));
	datasource.setDriverClassName("org.h2.Driver");
	datasource.setUrl("jdbc:h2:" + path);
	datasource.setMaxIdle(3);
	datasource.setMaxWaitMillis(5000);
	datasource.setRemoveAbandonedOnBorrow(true);
	datasource.setRemoveAbandonedOnBorrow(true);
	datasource.setRemoveAbandonedTimeout(20);
	datasource.setLogAbandoned(true);
	datasource.setValidationQuery("select 1");
	datasource.setMinEvictableIdleTimeMillis(3600000);
	datasource.setTimeBetweenEvictionRunsMillis(1800000);
	datasource.setNumTestsPerEvictionRun(10);
	datasource.setTestOnBorrow(true);
	datasource.setTestOnReturn(false);
	datasource.addConnectionProperty("useUnicode", "yes");
	datasource.addConnectionProperty("characterEncoding", "utf8");
	return datasource;
}
 
開發者ID:shilongdai,項目名稱:LSChatServer,代碼行數:28,代碼來源:ApplicationRootContext.java

示例9: setupDataSourcePool

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Override
protected BasicDataSource setupDataSourcePool( DataSourceConfiguration config )
        throws Exception
{
    BasicDataSource pool = new BasicDataSource();

    Class.forName( config.driver().get() );
    pool.setDriverClassName( config.driver().get() );
    pool.setUrl( config.url().get() );

    if ( !config.username().get().equals( "" ) ) {
        pool.setUsername( config.username().get() );
        pool.setPassword( config.password().get() );
    }

    if ( config.minPoolSize().get() != null ) {
        pool.setMinIdle( config.minPoolSize().get() );
    }
    if ( config.maxPoolSize().get() != null ) {
        pool.setMaxTotal( config.maxPoolSize().get() );
    }
    if ( config.loginTimeoutSeconds().get() != null ) {
        pool.setLoginTimeout( config.loginTimeoutSeconds().get() );
    }
    if ( config.maxConnectionAgeSeconds().get() != null ) {
        pool.setMinEvictableIdleTimeMillis( config.maxConnectionAgeSeconds().get() * 1000 );
    }
    if ( config.validationQuery().get() != null ) {
        pool.setValidationQuery( config.validationQuery().get() );
    }

    return pool;
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:34,代碼來源:DBCPDataSourceServiceImporter.java

示例10: load

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Override
public BasicDataSource load(List<String> key) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl(key.get(0));
    dataSource.setDriverClassName(key.get(1));
    dataSource.setValidationQuery("SELECT 1");
    LOG.info("load DataSource:" + dataSource + ", " + key.get(0) + " " + key.get(1));
    return dataSource;
}
 
開發者ID:bitnine-oss,項目名稱:octopus,代碼行數:10,代碼來源:JdbcUtils.java

示例11: retrySetup

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private void retrySetup(BasicDataSource ds) {
	if (!"org.hibernate.dialect.HSQLDialect".equals(mainEnv.getDialect())) {
		ds.setTestOnBorrow(dbcpEnv.isTestOnBorrow());
		ds.setValidationQuery(dbcpEnv.getValidationQuery());
		ds.setMaxTotal(dbcpEnv.getMaxTotal());
		ds.setMinEvictableIdleTimeMillis(dbcpEnv.getMinEvictableIdleTime());
		ds.setTimeBetweenEvictionRunsMillis(dbcpEnv.getTimeBetweenEvictionRuns());
		ds.setNumTestsPerEvictionRun(dbcpEnv.getNumTestsPerEvictionRun());
		ds.setTestWhileIdle(dbcpEnv.isTestWhileIdle());
		ds.setTestOnReturn(dbcpEnv.isTestOnReturn());
	}
}
 
開發者ID:aol,項目名稱:micro-server,代碼行數:13,代碼來源:DBCPDataSourceBuilder.java

示例12: setupDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private static DataSource setupDataSource(String dbUrl, String dbUserName, String dbPassword) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl(dbUrl + "?useSSL=false&serverTimezone=UTC");
    dataSource.setUsername(dbUserName);
    dataSource.setPassword(dbPassword);
    dataSource.setValidationQuery("SELECT 1;");
    dataSource.setTestOnBorrow(true); // test each connection when borrowing from the pool with the validation query
    dataSource.setMaxConnLifetimeMillis(1000 * 60 * 60); // max connection life time 1h. mysql drops connection after 8h.
    return dataSource;
}
 
開發者ID:rwth-acis,項目名稱:las2peer-ActivityTracker,代碼行數:12,代碼來源:ActivityTrackerService.java

示例13: setImcmsDataSourceProperties

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private void setImcmsDataSourceProperties(BasicDataSource basicDataSource) {
    basicDataSource.setDriverClassName(imcmsProperties.getProperty("JdbcDriver"));
    basicDataSource.setUrl(imcmsProperties.getProperty("JdbcUrl"));
    basicDataSource.setUsername(imcmsProperties.getProperty("User"));
    basicDataSource.setPassword(imcmsProperties.getProperty("Password"));
    basicDataSource.setTestOnBorrow(true);
    basicDataSource.setValidationQuery("select 1");
    basicDataSource.setDefaultAutoCommit(false);
    basicDataSource.setMaxTotal(20);
    basicDataSource.setMaxTotal(Integer.parseInt(imcmsProperties.getProperty("MaxConnectionCount")));
}
 
開發者ID:imCodePartnerAB,項目名稱:imcms,代碼行數:12,代碼來源:DBConfig.java

示例14: dataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Scope("prototype")
@Bean(destroyMethod = "close")
public DataSource dataSource() {
    BasicDataSource ds = new BasicDataSource();

    ds.setDriverClassName(env.getRequiredProperty("JdbcDriver"));
    ds.setUsername(env.getRequiredProperty("User"));
    ds.setPassword(env.getRequiredProperty("Password"));
    ds.setTestOnBorrow(true);
    ds.setValidationQuery("select 1");
    ds.setMaxTotal(1);

    return ds;
}
 
開發者ID:imCodePartnerAB,項目名稱:imcms,代碼行數:15,代碼來源:TestConfig.java

示例15: provideDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Provides
@Singleton
private DataSource provideDataSource() {
  BasicDataSource dataSource = new BasicDataSource();
  dataSource.setDriverClassName(DRIVER_CLASS_NAME);
  dataSource.setUsername(USERNAME);
  dataSource.setPassword(PASSWORD);
  dataSource.setUrl(URL);
  dataSource.setValidationQuery(VALIDATION_QUERY);
  return dataSource;
}
 
開發者ID:nodchip,項目名稱:QMAClone,代碼行數:12,代碼來源:DatabaseModule.java


注:本文中的org.apache.commons.dbcp2.BasicDataSource.setValidationQuery方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。