List of usage examples for org.apache.commons.dbcp BasicDataSource setTestOnReturn
public synchronized void setTestOnReturn(boolean testOnReturn)
testOnReturn
property. From source file:com.alibaba.otter.common.push.datasource.media.MediaPushDataSource.java
protected DataSource doCreateDataSource(String url) { BasicDataSource dbcpDs = new BasicDataSource(); dbcpDs.setInitialSize(initialSize);// ? dbcpDs.setMaxActive(maxActive);// ????? dbcpDs.setMaxIdle(maxIdle);// ?? dbcpDs.setMinIdle(minIdle);// ?0? dbcpDs.setMaxWait(maxWait);// ??-1? dbcpDs.setRemoveAbandoned(true);// ??removeAbandonedTimeout dbcpDs.setLogAbandoned(true);// ?? dbcpDs.setRemoveAbandonedTimeout(removeAbandonedTimeout); // ? dbcpDs.setNumTestsPerEvictionRun(numTestsPerEvictionRun);// ?? dbcpDs.setTestOnBorrow(false);// ?? dbcpDs.setTestOnReturn(false);// ?? dbcpDs.setTestWhileIdle(true);// ???? dbcpDs.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); // ???????? dbcpDs.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); // ??????? // ??/*w w w . j a v a 2 s . co m*/ dbcpDs.setDriverClassName(driverClassName); dbcpDs.setUrl(url); dbcpDs.setUsername(userName); dbcpDs.setPassword(password); if (dataMediaType.isOracle()) { dbcpDs.addConnectionProperty("restrictGetTables", "true"); dbcpDs.setValidationQuery("select 1 from dual"); } else if (dataMediaType.isMysql()) { // open the batch mode for mysql since 5.1.8 dbcpDs.addConnectionProperty("useServerPrepStmts", "false"); dbcpDs.addConnectionProperty("rewriteBatchedStatements", "true"); dbcpDs.addConnectionProperty("zeroDateTimeBehavior", "convertToNull");// 0000-00-00null dbcpDs.addConnectionProperty("yearIsDateType", "false");// ??year?date? if (StringUtils.isNotEmpty(encoding)) { dbcpDs.addConnectionProperty("characterEncoding", encoding); } dbcpDs.setValidationQuery("select 1"); } else { logger.error("ERROR ## Unknow database type"); } return dbcpDs; }
From source file:com.alfaariss.oa.util.database.jdbc.DataSourceFactory.java
private static DataSource addOptionalSettings(IConfigurationManager configurationManager, Element eConfig, BasicDataSource dataSource) throws DatabaseException { try {//ww w .j a v a 2 s.co m String sMaxActive = configurationManager.getParam(eConfig, "maxactive"); int iMaxActive = -1; if (sMaxActive != null) { try { iMaxActive = Integer.parseInt(sMaxActive); } catch (NumberFormatException e) { _logger.error("Wrong 'maxactive' item found in configuration: " + sMaxActive, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } } dataSource.setMaxActive(iMaxActive); String sMaxIdle = configurationManager.getParam(eConfig, "maxidle"); if (sMaxIdle != null) { int iMaxIdle = -1; try { iMaxIdle = Integer.parseInt(sMaxIdle); } catch (NumberFormatException e) { _logger.error("Wrong 'maxidle' item found in configuration: " + sMaxIdle, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setMaxIdle(iMaxIdle); } String sMaxWait = configurationManager.getParam(eConfig, "maxwait"); if (sMaxWait != null) { int iMaxWait = -1; try { iMaxWait = Integer.parseInt(sMaxWait); } catch (NumberFormatException e) { _logger.error("Wrong 'maxwait' item found in configuration: " + sMaxWait, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setMaxWait(iMaxWait); } String sTestOnBorrow = configurationManager.getParam(eConfig, "testonborrow"); if (sTestOnBorrow != null) { boolean bTestOnBorrow = false; if (sTestOnBorrow.equalsIgnoreCase("true")) bTestOnBorrow = true; else if (!sTestOnBorrow.equalsIgnoreCase("false")) { _logger.error("Wrong 'testonborrow' item found in configuration: " + sTestOnBorrow); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setTestOnBorrow(bTestOnBorrow); } String sTestOnReturn = configurationManager.getParam(eConfig, "testonreturn"); if (sTestOnReturn != null) { boolean bTestOnReturn = false; if (sTestOnReturn.equalsIgnoreCase("true")) bTestOnReturn = true; else if (!sTestOnReturn.equalsIgnoreCase("false")) { _logger.error("Wrong 'testonreturn' item found in configuration: " + sTestOnReturn); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setTestOnReturn(bTestOnReturn); } String sTimeBetweenEvictionRunsMillis = configurationManager.getParam(eConfig, "timebetweenevictionrunsmillis"); if (sTimeBetweenEvictionRunsMillis != null) { try { long lTimeBetweenEvictionRunsMillis = Long.parseLong(sTimeBetweenEvictionRunsMillis); dataSource.setTimeBetweenEvictionRunsMillis(lTimeBetweenEvictionRunsMillis); } catch (NumberFormatException e) { _logger.error("Wrong 'timebetweenevictionrunsmillis' item found in configuration: " + sTimeBetweenEvictionRunsMillis, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } } String sNumTestsPerEvictionRun = configurationManager.getParam(eConfig, "numtestsperevictionrun"); if (sNumTestsPerEvictionRun != null) { int iNumTestsPerEvictionRun = -1; try { iNumTestsPerEvictionRun = Integer.parseInt(sNumTestsPerEvictionRun); } catch (NumberFormatException e) { _logger.error("Wrong 'numtestsperevictionrun' item found in configuration: " + sNumTestsPerEvictionRun, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setNumTestsPerEvictionRun(iNumTestsPerEvictionRun); } String sMinEvictableIdleTimeMillis = configurationManager.getParam(eConfig, "minevictableidletimemillis"); if (sMinEvictableIdleTimeMillis != null) { try { long lMinEvictableIdleTimeMillis = Long.parseLong(sMinEvictableIdleTimeMillis); dataSource.setMinEvictableIdleTimeMillis(lMinEvictableIdleTimeMillis); } catch (NumberFormatException e) { _logger.error("Wrong 'minevictableidletimemillis' item found in configuration: " + sMinEvictableIdleTimeMillis, e); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } } String sTestWhileIdle = configurationManager.getParam(eConfig, "testwhileidle"); if (sTestWhileIdle != null) { boolean bTestWhileIdle = false; if (sTestWhileIdle.equalsIgnoreCase("true")) bTestWhileIdle = true; else if (!sTestWhileIdle.equalsIgnoreCase("false")) { _logger.error("Wrong 'testwhileidle' item found in configuration: " + sTestWhileIdle); throw new DatabaseException(SystemErrors.ERROR_CONFIG_READ); } dataSource.setTestWhileIdle(bTestWhileIdle); } String sValidationQuery = configurationManager.getParam(eConfig, "validationquery"); if (sValidationQuery != null) { dataSource.setValidationQuery(sValidationQuery); } } catch (DatabaseException e) { throw e; } catch (Exception e) { _logger.fatal("Could not create datasource", e); throw new DatabaseException(SystemErrors.ERROR_INTERNAL); } return dataSource; }
From source file:net.comze.framework.orm.datasource.DbcpDataSourceFactory.java
private BasicDataSource initialize(Properties properties) { ObjectUtils.notNull(properties, "properties"); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(properties.getProperty(JDBC_DRIVER)); basicDataSource.setUrl(properties.getProperty(JDBC_URL)); basicDataSource.setUsername(properties.getProperty(JDBC_USERNAME)); basicDataSource.setPassword(properties.getProperty(JDBC_PASSWORD)); if (properties.containsKey(DBCP_INITIALSIZE)) { basicDataSource.setInitialSize(Integer.parseInt(properties.getProperty(DBCP_INITIALSIZE))); }/*www . j ava 2 s . co m*/ if (properties.containsKey(DBCP_MAXACTIVE)) { basicDataSource.setMaxActive(Integer.parseInt(properties.getProperty(DBCP_MAXACTIVE))); } if (properties.containsKey(DBCP_MAXIDLE)) { basicDataSource.setMaxIdle(Integer.parseInt(properties.getProperty(DBCP_MAXIDLE))); } if (properties.containsKey(DBCP_MAXWAIT)) { basicDataSource.setMaxWait(Long.parseLong(properties.getProperty(DBCP_MAXWAIT))); } if (properties.containsKey(DBCP_MINEVICTABLEIDLETIMEMILLIS)) { basicDataSource.setMinEvictableIdleTimeMillis( Long.parseLong(properties.getProperty(DBCP_MINEVICTABLEIDLETIMEMILLIS))); } if (properties.containsKey(DBCP_MINIDLE)) { basicDataSource.setMinIdle(Integer.parseInt(properties.getProperty(DBCP_MINIDLE))); } if (properties.containsKey(DBCP_NUMTESTSPEREVICTIONRUN)) { basicDataSource.setNumTestsPerEvictionRun( Integer.parseInt(properties.getProperty(DBCP_NUMTESTSPEREVICTIONRUN))); } if (properties.containsKey(DBCP_REMOVEABANDONED)) { basicDataSource.setRemoveAbandoned(Boolean.parseBoolean(properties.getProperty(DBCP_REMOVEABANDONED))); } if (properties.containsKey(DBCP_REMOVEABANDONEDTIMEOUT)) { basicDataSource.setRemoveAbandonedTimeout( Integer.parseInt(properties.getProperty(DBCP_REMOVEABANDONEDTIMEOUT))); } if (properties.containsKey(DBCP_TESTONBORROW)) { basicDataSource.setTestOnBorrow(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONBORROW))); } if (properties.containsKey(DBCP_TESTONCREATE)) { basicDataSource.setTestOnReturn(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONCREATE))); } if (properties.containsKey(DBCP_TESTONRETURN)) { basicDataSource.setTestOnReturn(Boolean.parseBoolean(properties.getProperty(DBCP_TESTONRETURN))); } if (properties.containsKey(DBCP_TESTWHILEIDLE)) { basicDataSource.setTestWhileIdle(Boolean.parseBoolean(properties.getProperty(DBCP_TESTWHILEIDLE))); } if (properties.containsKey(DBCP_TIMEBETWEENEVICTIONRUNSMILLIS)) { basicDataSource.setTimeBetweenEvictionRunsMillis( Long.parseLong(properties.getProperty(DBCP_TIMEBETWEENEVICTIONRUNSMILLIS))); } if (properties.containsKey(DBCP_VALIDATIONQUERY)) { basicDataSource.setValidationQuery(properties.getProperty(DBCP_VALIDATIONQUERY)); } if (properties.containsKey(DBCP_VALIDATIONQUERYTIMEOUT)) { basicDataSource.setValidationQueryTimeout( Integer.parseInt(properties.getProperty(DBCP_VALIDATIONQUERYTIMEOUT))); } return basicDataSource; }
From source file:jetsennet.orm.datasource.DbcpDataSourceCreator.java
@Override public DataSource createDatasource(ConnectionInfo conn, DbPoolInfo props) throws SQLException { org.apache.commons.dbcp.BasicDataSource dataSource = new org.apache.commons.dbcp.BasicDataSource(); dataSource.setDriverClassName(conn.driver); dataSource.setUrl(conn.url);/*w w w. j a v a 2 s . c o m*/ dataSource.setUsername(conn.user); dataSource.setPassword(conn.pwd); String connectionProperties = props.get("connectionProperties"); if (connectionProperties != null && connectionProperties.trim().length() > 0) { dataSource.setConnectionProperties(connectionProperties); } Boolean defaultAutoCommit = Utils.str2Boolean(props.get("defaultAutoCommit")); if (defaultAutoCommit != null) { dataSource.setDefaultAutoCommit(defaultAutoCommit); } Boolean defaultReadOnly = Utils.str2Boolean(props.get("defaultReadOnly")); if (defaultReadOnly != null) { dataSource.setDefaultReadOnly(defaultReadOnly); } Integer defaultTransactionIsolation = Utils.strToInteger(props.get("defaultTransactionIsolation")); if (defaultTransactionIsolation != null) { dataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); } String defaultCatalog = props.get("defaultCatalog"); if (defaultCatalog != null && defaultCatalog.trim().length() > 0) { dataSource.setDefaultCatalog(defaultCatalog); } int initialSize = Utils.strToInt(props.get("initialSize")); if (initialSize > 0) { dataSource.setInitialSize(initialSize); } int maxActive = Utils.strToInt(props.get("maxActive")); if (maxActive > 0) { dataSource.setMaxActive(maxActive); } int maxIdle = Utils.strToInt(props.get("maxIdle")); if (maxIdle > 0) { dataSource.setMaxIdle(maxIdle); } int minIdle = Utils.strToInt(props.get("minIdle")); if (minIdle > 0) { dataSource.setMinIdle(minIdle); } int maxWait = Utils.strToInt(props.get("maxWait")); if (maxWait > 0) { dataSource.setMaxWait(maxWait); } String validationQuery = props.get("validationQuery"); if (validationQuery != null && validationQuery.trim().length() > 0) { dataSource.setValidationQuery(validationQuery); } Integer validationQueryTimeout = Utils.strToInteger(props.get("validationQueryTimeout")); if (validationQueryTimeout != null) { dataSource.setValidationQueryTimeout(validationQueryTimeout); } Boolean testOnBorrow = Utils.str2Boolean(props.get("testOnBorrow")); if (testOnBorrow != null) { dataSource.setTestOnBorrow(testOnBorrow); } Boolean testOnReturn = Utils.str2Boolean(props.get("testOnReturn")); if (testOnReturn != null) { dataSource.setTestOnReturn(testOnReturn); } Boolean testWhileIdle = Utils.str2Boolean(props.get("testWhileIdle")); if (testWhileIdle != null) { dataSource.setTestWhileIdle(testWhileIdle); } Integer timeBetweenEvictionRunsMillis = Utils.strToInteger(props.get("timeBetweenEvictionRunsMillis")); if (timeBetweenEvictionRunsMillis != null) { dataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); } Integer numTestsPerEvictionRun = Utils.strToInteger(props.get("numTestsPerEvictionRun")); if (numTestsPerEvictionRun != null) { dataSource.setNumTestsPerEvictionRun(numTestsPerEvictionRun); } int minEvictableIdleTimeMillis = Utils.strToInt(props.get("minEvictableIdleTimeMillis")); if (minEvictableIdleTimeMillis > 0) { dataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); } Boolean removeAbandoned = Utils.str2Boolean(props.get("removeAbandoned")); if (removeAbandoned != null) { dataSource.setRemoveAbandoned(removeAbandoned); } int removeAbandonedTimeout = Utils.strToInt(props.get("removeAbandonedTimeout")); if (removeAbandonedTimeout > 0) { dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); } Boolean logAbandoned = Utils.str2Boolean(props.get("logAbandoned")); if (logAbandoned != null) { dataSource.setLogAbandoned(logAbandoned); } return dataSource; }
From source file:org.apache.synapse.commons.datasource.factory.DataSourceFactory.java
/** * Factory method to create a DataSource based on provided information * which is encapsulated in the DataSourceInformation object. * * @param dataSourceInformation Information about DataSource * @return DataSource Instance if one can be created , * otherwise null or exception if provided details are not valid or enough to create * a DataSource//from ww w . ja v a 2 s.c om */ public static DataSource createDataSource(DataSourceInformation dataSourceInformation) { String dsType = dataSourceInformation.getType(); String driver = dataSourceInformation.getDriver(); if (driver == null || "".equals(driver)) { handleException("Database driver class name cannot be found."); } String url = dataSourceInformation.getUrl(); if (url == null || "".equals(url)) { handleException("Database connection URL cannot be found."); } String user = dataSourceInformation.getSecretInformation().getUser(); String password = dataSourceInformation.getSecretInformation().getResolvedSecret(); int defaultTransactionIsolation = dataSourceInformation.getDefaultTransactionIsolation(); if (DataSourceInformation.BASIC_DATA_SOURCE.equals(dsType)) { BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setDriverClassName(driver); basicDataSource.setUrl(url); if (user != null && !"".equals(user)) { basicDataSource.setUsername(user); } if (password != null && !"".equals(password)) { basicDataSource.setPassword(password); } basicDataSource.setMaxActive(dataSourceInformation.getMaxActive()); basicDataSource.setMaxIdle(dataSourceInformation.getMaxIdle()); basicDataSource.setMaxWait(dataSourceInformation.getMaxWait()); basicDataSource.setMinIdle(dataSourceInformation.getMinIdle()); basicDataSource.setDefaultAutoCommit(dataSourceInformation.isDefaultAutoCommit()); basicDataSource.setDefaultReadOnly(dataSourceInformation.isDefaultReadOnly()); basicDataSource.setTestOnBorrow(dataSourceInformation.isTestOnBorrow()); basicDataSource.setTestOnReturn(dataSourceInformation.isTestOnReturn()); basicDataSource.setTestWhileIdle(dataSourceInformation.isTestWhileIdle()); basicDataSource.setMinEvictableIdleTimeMillis(dataSourceInformation.getMinEvictableIdleTimeMillis()); basicDataSource .setTimeBetweenEvictionRunsMillis(dataSourceInformation.getTimeBetweenEvictionRunsMillis()); basicDataSource.setNumTestsPerEvictionRun(dataSourceInformation.getNumTestsPerEvictionRun()); basicDataSource.setMaxOpenPreparedStatements(dataSourceInformation.getMaxOpenPreparedStatements()); basicDataSource.setAccessToUnderlyingConnectionAllowed( dataSourceInformation.isAccessToUnderlyingConnectionAllowed()); basicDataSource.setInitialSize(dataSourceInformation.getInitialSize()); basicDataSource.setPoolPreparedStatements(dataSourceInformation.isPoolPreparedStatements()); if (defaultTransactionIsolation != -1) { basicDataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); } String defaultCatalog = dataSourceInformation.getDefaultCatalog(); if (defaultCatalog != null && !"".equals(defaultCatalog)) { basicDataSource.setDefaultCatalog(defaultCatalog); } String validationQuery = dataSourceInformation.getValidationQuery(); if (validationQuery != null && !"".equals(validationQuery)) { basicDataSource.setValidationQuery(validationQuery); } return basicDataSource; } else if (DataSourceInformation.PER_USER_POOL_DATA_SOURCE.equals(dsType)) { DriverAdapterCPDS adapterCPDS = new DriverAdapterCPDS(); try { adapterCPDS.setDriver(driver); } catch (ClassNotFoundException e) { handleException("Error setting driver : " + driver + " in DriverAdapterCPDS", e); } adapterCPDS.setUrl(url); if (user != null && !"".equals(user)) { adapterCPDS.setUser(user); } if (password != null && !"".equals(password)) { adapterCPDS.setPassword(password); } adapterCPDS.setPoolPreparedStatements(dataSourceInformation.isPoolPreparedStatements()); adapterCPDS.setMaxIdle(dataSourceInformation.getMaxIdle()); PerUserPoolDataSource perUserPoolDataSource = new PerUserPoolDataSource(); perUserPoolDataSource.setConnectionPoolDataSource(adapterCPDS); perUserPoolDataSource.setDefaultMaxActive(dataSourceInformation.getMaxActive()); perUserPoolDataSource.setDefaultMaxIdle(dataSourceInformation.getMaxIdle()); perUserPoolDataSource.setDefaultMaxWait((int) dataSourceInformation.getMaxWait()); perUserPoolDataSource.setDefaultAutoCommit(dataSourceInformation.isDefaultAutoCommit()); perUserPoolDataSource.setDefaultReadOnly(dataSourceInformation.isDefaultReadOnly()); perUserPoolDataSource.setTestOnBorrow(dataSourceInformation.isTestOnBorrow()); perUserPoolDataSource.setTestOnReturn(dataSourceInformation.isTestOnReturn()); perUserPoolDataSource.setTestWhileIdle(dataSourceInformation.isTestWhileIdle()); perUserPoolDataSource .setMinEvictableIdleTimeMillis((int) dataSourceInformation.getMinEvictableIdleTimeMillis()); perUserPoolDataSource.setTimeBetweenEvictionRunsMillis( (int) dataSourceInformation.getTimeBetweenEvictionRunsMillis()); perUserPoolDataSource.setNumTestsPerEvictionRun(dataSourceInformation.getNumTestsPerEvictionRun()); if (defaultTransactionIsolation != -1) { perUserPoolDataSource.setDefaultTransactionIsolation(defaultTransactionIsolation); } String validationQuery = dataSourceInformation.getValidationQuery(); if (validationQuery != null && !"".equals(validationQuery)) { perUserPoolDataSource.setValidationQuery(validationQuery); } return perUserPoolDataSource; } else { handleException("Unsupported DataSource : " + dsType); } return null; }
From source file:org.apache.synapse.config.xml.AbstractDBMediatorFactory.java
/** * Create a custom DataSource using the specified properties and Apache DBCP * @param pool the toplevel 'pool' element that holds DataSource information * @param mediator the mediator to store properties for serialization * @return a DataSource created using specified properties *///from w w w . j av a2s .c o m private DataSource createCustomDataSource(OMElement pool, AbstractDBMediator mediator) { BasicDataSource ds = new BasicDataSource(); // load the minimum required properties ds.setDriverClassName(getValue(pool, DRIVER_Q)); ds.setUsername(getValue(pool, USER_Q)); ds.setPassword(getValue(pool, PASS_Q)); ds.setUrl(getValue(pool, URL_Q)); //save loaded properties for later mediator.addDataSourceProperty(DRIVER_Q, getValue(pool, DRIVER_Q)); mediator.addDataSourceProperty(URL_Q, getValue(pool, URL_Q)); mediator.addDataSourceProperty(USER_Q, getValue(pool, USER_Q)); mediator.addDataSourceProperty(PASS_Q, getValue(pool, PASS_Q)); Iterator props = pool.getChildrenWithName(PROP_Q); while (props.hasNext()) { OMElement prop = (OMElement) props.next(); String name = prop.getAttribute(ATT_NAME).getAttributeValue(); String value = prop.getAttribute(ATT_VALUE).getAttributeValue(); // save property for later mediator.addDataSourceProperty(name, value); if ("autocommit".equals(name)) { if ("true".equals(value)) { ds.setDefaultAutoCommit(true); } else if ("false".equals(value)) { ds.setDefaultAutoCommit(false); } } else if ("isolation".equals(name)) { try { if ("Connection.TRANSACTION_NONE".equals(value)) { ds.setDefaultTransactionIsolation(Connection.TRANSACTION_NONE); } else if ("Connection.TRANSACTION_READ_COMMITTED".equals(value)) { ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); } else if ("Connection.TRANSACTION_READ_UNCOMMITTED".equals(value)) { ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); } else if ("Connection.TRANSACTION_REPEATABLE_READ".equals(value)) { ds.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); } else if ("Connection.TRANSACTION_SERIALIZABLE".equals(value)) { ds.setDefaultTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); } } catch (NumberFormatException ignore) { } } else if ("initialsize".equals(name)) { try { ds.setInitialSize(Integer.parseInt(value)); } catch (NumberFormatException ignore) { } } else if ("maxactive".equals(name)) { try { ds.setMaxActive(Integer.parseInt(value)); } catch (NumberFormatException ignore) { } } else if ("maxidle".equals(name)) { try { ds.setMaxIdle(Integer.parseInt(value)); } catch (NumberFormatException ignore) { } } else if ("maxopenstatements".equals(name)) { try { ds.setMaxOpenPreparedStatements(Integer.parseInt(value)); } catch (NumberFormatException ignore) { } } else if ("maxwait".equals(name)) { try { ds.setMaxWait(Long.parseLong(value)); } catch (NumberFormatException ignore) { } } else if ("minidle".equals(name)) { try { ds.setMinIdle(Integer.parseInt(value)); } catch (NumberFormatException ignore) { } } else if ("poolstatements".equals(name)) { if ("true".equals(value)) { ds.setPoolPreparedStatements(true); } else if ("false".equals(value)) { ds.setPoolPreparedStatements(false); } } else if ("testonborrow".equals(name)) { if ("true".equals(value)) { ds.setTestOnBorrow(true); } else if ("false".equals(value)) { ds.setTestOnBorrow(false); } } else if ("testonreturn".equals(name)) { if ("true".equals(value)) { ds.setTestOnReturn(true); } else if ("false".equals(value)) { ds.setTestOnReturn(false); } } else if ("testwhileidle".equals(name)) { if ("true".equals(value)) { ds.setTestWhileIdle(true); } else if ("false".equals(value)) { ds.setTestWhileIdle(false); } } else if ("validationquery".equals(name)) { ds.setValidationQuery(value); } } return ds; }
From source file:org.ngrinder.infra.config.Database.java
/** * Setup the database common features.//from w w w .java 2s. c om * * @param dataSource datasource */ protected void setupCommon(BasicDataSource dataSource) { dataSource.setDriverClassName(getJdbcDriverName()); dataSource.setInitialSize(DB_INITIAL_SIZE); dataSource.setMaxActive(DB_MAX_ACTIVE); dataSource.setMinIdle(DB_MIN_IDLE); dataSource.setMaxWait(DB_MAX_WAIT); dataSource.setPoolPreparedStatements(true); dataSource.setMaxOpenPreparedStatements(DB_MAX_OPEN_PREPARED_STATEMENTS); dataSource.setTestWhileIdle(true); dataSource.setTestOnBorrow(true); dataSource.setTestOnReturn(true); dataSource.setValidationQuery("SELECT 1"); }
From source file:org.plista.kornakapi.core.storage.MySqlStorage.java
public MySqlStorage(StorageConfiguration storageConf, String label, BasicDataSource dataSource) { dataSource.setDriverClassName(storageConf.getJdbcDriverClass()); dataSource.setUrl(storageConf.getJdbcUrl()); dataSource.setUsername(storageConf.getUsername()); dataSource.setPassword(storageConf.getPassword()); //TODO should be made configurable dataSource.setMaxActive(10);/*w w w . jav a 2 s. com*/ dataSource.setMinIdle(5); dataSource.setInitialSize(5); dataSource.setValidationQuery("SELECT 1;"); dataSource.setTestOnBorrow(false); dataSource.setTestOnReturn(false); dataSource.setTestWhileIdle(true); dataSource.setTimeBetweenEvictionRunsMillis(5000); dataModel = new LabeledMySQLJDBCDataModel(dataSource, "taste_preferences", "user_id", "item_id", "preference", "timestamp", "taste_candidates", "label", label); this.dataSource = dataSource; this.timeWindow = storageConf.getTimeWindow(); if (timeWindow % 6 != 0 || timeWindow == 0) { timeWindow = 24; } }