List of usage examples for org.apache.commons.dbcp BasicDataSource setDefaultAutoCommit
public synchronized void setDefaultAutoCommit(boolean defaultAutoCommit)
Sets default auto-commit state of connections returned by this datasource.
Note: this method currently has no effect once the pool has been initialized.
From source file:org.compass.core.lucene.engine.store.jdbc.DbcpDataSourceProvider.java
protected DataSource doCreateDataSource(String url, CompassSettings settings) throws CompassException { BasicDataSource dataSource = new BasicDataSource(); if (!externalAutoCommit) { dataSource.setDefaultAutoCommit(autoCommit); }/*from w w w . j a va 2 s. c o m*/ dataSource.setDriverClassName(driverClass); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); if (settings.getSetting( LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.DEFAULT_TRANSACTION_ISOLATION) != null) { dataSource.setDefaultTransactionIsolation(settings.getSettingAsInt( LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.DEFAULT_TRANSACTION_ISOLATION, 0)); } if (settings.getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.INITIAL_SIZE) != null) { dataSource.setInitialSize( settings.getSettingAsInt(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.INITIAL_SIZE, 0)); } if (settings.getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_ACTIVE) != null) { dataSource.setMaxActive( settings.getSettingAsInt(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_ACTIVE, 0)); } if (settings.getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_IDLE) != null) { dataSource.setMaxIdle( settings.getSettingAsInt(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_IDLE, 0)); } if (settings.getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MIN_IDLE) != null) { dataSource.setMinIdle( settings.getSettingAsInt(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MIN_IDLE, 0)); } if (settings.getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_WAIT) != null) { dataSource.setMaxWait( settings.getSettingAsLong(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_WAIT, 0)); } if (settings.getSetting( LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_OPEN_PREPARED_STATEMENTS) != null) { dataSource.setMaxOpenPreparedStatements(settings.getSettingAsInt( LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.MAX_OPEN_PREPARED_STATEMENTS, 0)); } if (settings .getSetting(LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.POOL_PREPARED_STATEMENTS) != null) { dataSource.setPoolPreparedStatements(settings.getSettingAsBoolean( LuceneEnvironment.JdbcStore.DataSourceProvider.Dbcp.POOL_PREPARED_STATEMENTS, false)); } return dataSource; }
From source file:org.datacleaner.connection.JdbcDatastore.java
public DataSource createDataSource() { initializeDriver();// w ww. j av a2 s.c om BasicDataSource ds = new BasicDataSource(); ds.setDefaultAutoCommit(false); ds.setUrl(_jdbcUrl); ds.setMaxActive(getSystemPropertyValue(SYSTEM_PROPERTY_CONNECTION_POOL_MAX_SIZE, -1)); ds.setMinEvictableIdleTimeMillis( getSystemPropertyValue(SYSTEM_PROPERTY_CONNECTION_POOL_MIN_EVICTABLE_IDLE_TIME_MILLIS, 500)); ds.setTimeBetweenEvictionRunsMillis( getSystemPropertyValue(SYSTEM_PROPERTY_CONNECTION_POOL_TIME_BETWEEN_EVICTION_RUNS_MILLIS, 1000)); if (_username != null && _password != null) { ds.setUsername(_username); ds.setPassword(_password); } return ds; }
From source file:org.datacleaner.test.TestHelper.java
public static DataSource createSampleDatabaseDataSource() { BasicDataSource _dataSource = new BasicDataSource(); _dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); _dataSource.setUrl("jdbc:hsqldb:res:testwareorderdb;readonly=true"); _dataSource.setMaxActive(-1);/*from w w w .jav a2 s . c o m*/ _dataSource.setDefaultAutoCommit(false); return _dataSource; }
From source file:org.eclipse.dirigible.repository.datasource.DataSourceFacade.java
private DataSource createDirectDataSource(Properties properties) { String id = properties.getProperty(DataSourceFacade.PARAM_DB_ID); String name = properties.getProperty(DataSourceFacade.PARAM_DB_NAME); String url = properties.getProperty(DataSourceFacade.PARAM_DB_LOC); String driver = properties.getProperty(DataSourceFacade.PARAM_DB_DRIVER); String user = properties.getProperty(DataSourceFacade.PARAM_DB_USER); String password = properties.getProperty(DataSourceFacade.PARAM_DB_PASSWORD); String defaultAutoCommit = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_COMMIT); String maxActive = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_MAX_ACTIVE); String maxIdle = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_MAX_IDLE); String maxWait = properties.getProperty(DataSourceFacade.PARAM_DB_AUTO_MAX_WAIT); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(driver); basicDataSource.setUrl(url);//ww w.java 2 s . co m basicDataSource.setUsername(user); basicDataSource.setPassword(password); basicDataSource.setDefaultAutoCommit(Boolean.parseBoolean(defaultAutoCommit)); basicDataSource.setMaxActive(maxActive != null ? Integer.parseInt(maxActive) : 100); basicDataSource.setMaxIdle(maxIdle != null ? Integer.parseInt(maxIdle) : 30); basicDataSource.setMaxWait(maxWait != null ? Integer.parseInt(maxWait) : 10000); return basicDataSource; }
From source file:org.eobjects.analyzer.connection.JdbcDatastore.java
public DataSource createDataSource() { initializeDriver();/* w w w . j ava2 s .co m*/ BasicDataSource ds = new BasicDataSource(); ds.setMaxActive(-1); ds.setDefaultAutoCommit(false); ds.setUrl(_jdbcUrl); if (_username != null && _password != null) { ds.setUsername(_username); ds.setPassword(_password); } return ds; }
From source file:org.gaixie.jibu.utils.ConnectionUtils.java
/** * ???? jibu.properties ?/*from w ww . ja v a2s .c o m*/ * <p> * @param defaultAutoCommit ??? */ public static void setDefaultAutoCommit(boolean defaultAutoCommit) { BasicDataSource bds = (BasicDataSource) dataSource; bds.setDefaultAutoCommit(defaultAutoCommit); }
From source file:org.geoserver.security.jdbc.AbstractJDBCService.java
/** * initialize a {@link DataSource} form a * {@link JdbcSecurityServiceConfig} object * /*from w ww . j a va2 s. com*/ * @param config * @throws IOException */ public void initializeDSFromConfig(SecurityNamedServiceConfig namedConfig) throws IOException { JDBCSecurityServiceConfig config = (JDBCSecurityServiceConfig) namedConfig; if (config.isJndi()) { String jndiName = config.getJndiName(); try { Context initialContext = new InitialContext(); datasource = (DataSource) initialContext.lookup(jndiName); } catch (NamingException e) { throw new IOException(e); } } else { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(config.getDriverClassName()); bds.setUrl(config.getConnectURL()); bds.setUsername(config.getUserName()); bds.setPassword(config.getPassword()); bds.setDefaultAutoCommit(false); bds.setDefaultTransactionIsolation(DEFAULT_ISOLATION_LEVEL); bds.setMaxActive(10); datasource = bds; } }
From source file:org.jxstar.dao.pool.PooledConnection.java
/** * ???/*from w w w . j av a 2 s .c o m*/ * @param dsName * @return */ private DataSource createSelfDataSource(DataSourceConfig dsConfig) { String dsName = dsConfig.getDataSourceName(); BasicDataSource ds = (BasicDataSource) _myDataSourceMap.get(dsName); if (ds != null) return ds; ds = new BasicDataSource(); //??? int iTranLevel = getTranLevelConstant(dsConfig.getTranLevel()); int maxnum = Integer.parseInt(dsConfig.getMaxConNum()); ds.setDriverClassName(dsConfig.getDriverClass()); ds.setUrl(dsConfig.getJdbcUrl()); ds.setUsername(dsConfig.getUserName()); ds.setPassword(dsConfig.getPassWord()); ds.setMaxIdle(maxnum); ds.setMaxActive(maxnum); ds.setMaxWait(Long.parseLong(dsConfig.getMaxWaitTime())); ds.setDefaultAutoCommit(false); ds.setDefaultTransactionIsolation(iTranLevel); //????SystemVarserver.xml? String validTest = dsConfig.getValidTest(); String validQuery = dsConfig.getValidQuery(); if (validTest.equalsIgnoreCase("true") && validQuery.length() > 0) { _log.showDebug("pool test use query..."); ds.setTestOnBorrow(true); ds.setValidationQuery(validQuery); ds.setValidationQueryTimeout(3); } //?mysql??? //????? if (dsConfig.getValidIdle().equalsIgnoreCase("true")) { _log.showDebug("pool idle valid thread started..."); ds.setMinIdle(5); ds.setTestWhileIdle(true); //1030?5 ds.setMinEvictableIdleTimeMillis(30 * 60 * 1000);//30 minus ds.setTimeBetweenEvictionRunsMillis(10 * 60 * 1000);//10 minus } //??? _myDataSourceMap.put(dsName, ds); return ds; }
From source file:org.kaaproject.kaa.server.datamigration.utils.DataSources.java
/** * Create data source based on passed options. * * @param opt options that used to build data source * @return the data source/*w w w . ja v a2s . c o m*/ */ public static DataSource getDataSource(Options opt) { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName(opt.getDriverClassName()); bds.setUrl(opt.getJdbcUrl()); bds.setUsername(opt.getUsername()); bds.setPassword(opt.getPassword()); bds.setDefaultAutoCommit(false); return bds; }
From source file:org.paxml.tag.sql.SqlDataSourceTag.java
private DataSource getCacheOrCreate() { String key = getCacheKey();/*from w w w. ja va2 s . c o m*/ DataSource ds = CACHE.get(key); if (ds == null) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(getDriver()); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setDefaultAutoCommit(true); DataSource existing = CACHE.putIfAbsent(key, dataSource); if (existing != null) { ds = existing; } else { ds = dataSource; } } return ds; }