List of usage examples for org.apache.commons.dbcp.cpdsadapter DriverAdapterCPDS setUrl
public void setUrl(String v)
From source file:com.stehno.sanctuary.core.Sanctuary.java
private static DataSource createDataSource() throws ClassNotFoundException { SharedPoolDataSource poolDataSource = new SharedPoolDataSource(); DriverAdapterCPDS cpds = new DriverAdapterCPDS(); cpds.setDriver("org.h2.Driver"); cpds.setUrl("jdbc:h2:/home/cjstehno/h2/sanctuary"); cpds.setUser("sa"); cpds.setPassword(""); poolDataSource.setConnectionPoolDataSource(cpds); poolDataSource.setMaxActive(10);// ww w.ja v a2 s. c o m poolDataSource.setMaxIdle(5); poolDataSource.setMinEvictableIdleTimeMillis(1000); poolDataSource.setTestWhileIdle(true); poolDataSource.setValidationQuery("select 1"); return poolDataSource; }
From source file:com.silverpeas.wysiwyg.dynamicvalue.pool.ConnectionPoolWithJDBC.java
/** * Initializes the datasource. This datasource is based on the SharedPoolDataSource class, a dbcp * implementation/* w w w.ja va2 s . c om*/ */ private synchronized static void initializeDatasource() { SilverTrace.debug("wysiwyg", ConnectionPoolWithJDBC.class.toString(), " Datasource initialization : starting ..."); if (ds == null) { // check if the information for the pool creation is present. if (poolInfo == null) { SilverTrace.error("wysiwig", ConnectionPoolWithJDBC.class.toString(), "wysiwig.CONNECTION_INIALIZATION_FAILED"); throw new TechnicalException(ConnectionPoolWithJDBC.class.toString() + " : An error occurred during the connection initialization. The Pool information must be set"); } SilverTrace.debug("wysiwyg", ConnectionPoolWithJDBC.class.toString(), " Datasource initialization : poolInfo detail :: " + poolInfo.toString()); // driver registration DriverAdapterCPDS cpds = new DriverAdapterCPDS(); try { cpds.setDriver(poolInfo.getDriver()); } catch (ClassNotFoundException e) { SilverTrace.error("wysiwig", ConnectionPoolWithJDBC.class.toString(), "wysiwig.DRIVER_MISSING"); throw new TechnicalException(ConnectionPoolWithJDBC.class.toString() + " : An error occurred during the connection initializatoin. The JDBC driver isn't in the classpath", e); } cpds.setUrl(poolInfo.getUrl()); cpds.setUser(poolInfo.getUser()); cpds.setPassword(poolInfo.getPassword()); // datasource object creation SharedPoolDataSource tds = new SharedPoolDataSource(); tds.setConnectionPoolDataSource(cpds); tds.setMaxActive(poolInfo.getMaxActive()); tds.setMaxWait(poolInfo.getMaxWait()); tds.setMaxIdle(poolInfo.getMaxIdle()); tds.setTimeBetweenEvictionRunsMillis(poolInfo.getTimeBetweenEvictionRunsMillis()); tds.setNumTestsPerEvictionRun(poolInfo.getNumTestsPerEvictionRun()); tds.setMinEvictableIdleTimeMillis(poolInfo.getMinEvictableIdleTimeMillis()); ds = tds; SilverTrace.debug("wysiwyg", ConnectionPoolWithJDBC.class.toString(), " Datasource initialization : ending ..."); } }
From source file:com.ibm.xsp.extlib.relational.jdbc.datasource.dbcp.DbcpResourceFactory.java
/** * /*w w w .j a v a 2 s.co m*/ */ public DbcpResourceFactory(final String dataSourceName, final String driverClass, final String url, final String userName, final String password, final int maxActive, final int maxIdle) throws PoolException { try { connectionPoolDataSource = AccessController .doPrivileged(new PrivilegedExceptionAction<ConnectionPoolDataSource>() { public ConnectionPoolDataSource run() throws Exception { //Using the generic connection pool adapter from DBCP, todo, look how to use the connection pool datasource provided by each driver DriverAdapterCPDS adapter = new DriverAdapterCPDS(); adapter.setMaxActive(maxActive); adapter.setMaxIdle(maxIdle); adapter.setUrl(url); adapter.setUser(userName); adapter.setPassword(password); adapter.setDriver(driverClass); SharedPoolDataSource tds = new SharedPoolDataSource(); tds.setConnectionPoolDataSource(adapter); tds.setMaxActive(maxActive); ds = tds; return adapter; } }); } catch (Exception e) { // "Unable to initialize the shared connection pool DataSource" String msg = com.ibm.xsp.extlib.relational.RelationalResourceHandler .getSpecialAudienceString("DbcpPoolDataSource.Unabletoinitializethesharedconnec");//$NON-NLS-1$ throw new PoolException(e, msg); } }
From source file:com.mvdit.framework.database.datasources.LocalDatasourceFactory.java
@Override public DataSource initDatasource(String dbId, PropertiesRepository props) { DriverAdapterCPDS cpds = new DriverAdapterCPDS(); try {/*from w ww .j a v a 2s. co m*/ cpds.setDriver(props.getProperty(dbId + ".driver", JDBCDatasource.DATABASES_FILE)); } catch (ClassNotFoundException e) { throw new MvditRuntimeException(e); } String url = props.getProperty(dbId + ".url", JDBCDatasource.DATABASES_FILE); cpds.setUrl(url); cpds.setUser(props.getProperty(dbId + ".username", JDBCDatasource.DATABASES_FILE)); cpds.setPassword(props.getProperty(dbId + ".password", JDBCDatasource.DATABASES_FILE)); SharedPoolDataSource tds = new SharedPoolDataSource(); tds.setConnectionPoolDataSource(cpds); tds.setMaxActive( Integer.valueOf(props.getProperty(dbId + ".pool.maxActive", JDBCDatasource.DATABASES_FILE))); tds.setMaxWait(Integer.valueOf(props.getProperty(dbId + ".pool.maxWait", JDBCDatasource.DATABASES_FILE))); DataSource ds = tds; return ds; }
From source file:hk.hku.cecid.piazza.commons.dao.ds.SimpleDSDAOFactory.java
/** * Initializes this DAOFactory.// w w w. jav a 2 s. c om */ public void initFactory() throws DAOException { try { String driver = null; String url = null; String username = null; String password = null; boolean isPooling = true; int maxIdle = 0; int maxActive = 10; int maxWait = 50; boolean testOnBorrow = false; boolean testOnReturn = false; boolean testWhileIdle = false; String validationQuery = null; try { driver = getParameter("driver"); url = getParameter("url"); username = getParameter("username", null); password = getParameter("password", null); maxIdle = StringUtilities.parseInt(getParameter("maxIdle", null), 0); maxActive = StringUtilities.parseInt(getParameter("maxActive", null), 0); maxWait = StringUtilities.parseInt(getParameter("maxWait", null), -1); validationQuery = StringUtilities.trim(getParameter("validationQuery", null)); if (validationQuery != null) { testOnBorrow = StringUtilities.parseBoolean(getParameter("testOnBorrow", "false")); testOnReturn = StringUtilities.parseBoolean(getParameter("testOnReturn", "false")); testWhileIdle = StringUtilities.parseBoolean(getParameter("testWhileIdle", "false")); } } catch (Exception e) { throw new DAOException("Invalid parameter for SimpleDSDAOFactory."); } if (getParameter("pooling", null) != null) { if (!getParameter("pooling").equalsIgnoreCase("true") && !getParameter("pooling").equalsIgnoreCase("false")) { throw new DAOException("Invalid parameter for SimpleDSDAOFactory."); } isPooling = StringUtilities.parseBoolean(getParameter("pooling", "true")); } DataSource datasource; if (isPooling) { DriverAdapterCPDS cpds = new DriverAdapterCPDS(); cpds.setDriver(driver); cpds.setUrl(url); cpds.setUser(username); cpds.setPassword(password); SharedPoolDataSource sds = new SharedPoolDataSource(); sds.setConnectionPoolDataSource(cpds); sds.setMaxIdle(maxIdle); sds.setMaxActive(maxActive); sds.setMaxWait(maxWait); sds.setTestOnBorrow(testOnBorrow); sds.setTestOnReturn(testOnReturn); sds.setTestWhileIdle(testWhileIdle); sds.setValidationQuery(validationQuery); datasource = sds; } else { datasource = new SimpleDataSource(driver, url, username, password); } setDataSource(datasource); } catch (Exception e) { throw new DAOException("Cannot initialize SimpleDSDAOFactory!", e); } }
From source file:it.grid.storm.persistence.util.db.DBConnectionPool.java
private void init(DataBaseStrategy db, int maxActive, int maxWait) { instance.setDatabaseStrategy(db);//from w ww. j a v a 2 s. co m DriverAdapterCPDS connectionPoolDatasource = new DriverAdapterCPDS(); try { connectionPoolDatasource.setDriver(db.getDriverName()); } catch (Exception ex) { log.error("Exception while getting driver: {}", ex.getMessage(), ex); } connectionPoolDatasource.setUrl(db.getConnectionString()); connectionPoolDatasource.setUser(db.getDbUsr()); connectionPoolDatasource.setPassword(db.getDbPwd()); sharedDatasource = new SharedPoolDataSource(); sharedDatasource.setConnectionPoolDataSource(connectionPoolDatasource); sharedDatasource.setMaxActive(maxActive); sharedDatasource.setMaxWait(maxWait); handle = System.currentTimeMillis(); }
From source file:com.smartmarmot.orabbix.Configurator.java
private DBConn getConnection(String dbName) throws Exception { try {/* w ww . j a va 2s . co m*/ verifyConfig(); SmartLogger.logThis(Level.DEBUG, "getConnection for database " + dbName); String url = ""; try { url = new String(_props.getProperty(dbName + "." + Constants.CONN_URL)); } catch (Exception ex) { SmartLogger.logThis(Level.ERROR, "Error on Configurator getConnection while getting " + dbName + "." + Constants.CONN_URL + " " + ex.getMessage()); } String uname = ""; try { uname = new String(_props.getProperty(dbName + "." + Constants.CONN_USERNAME)); } catch (Exception ex) { try { SmartLogger.logThis(Level.DEBUG, "Error on Configurator getConnection while getting " + dbName + "." + Constants.CONN_USERNAME + " " + ex.getMessage()); uname = new String(_props.getProperty(Constants.CONN_DEFAULT_USERNAME)); } catch (Exception ex1) { SmartLogger.logThis(Level.ERROR, "Error on Configurator getConnection while getting " + Constants.CONN_DEFAULT_USERNAME + " " + ex1.getMessage()); } } String password = ""; try { password = new String(_props.getProperty(dbName + "." + Constants.CONN_PASSWORD)); } catch (Exception ex) { try { SmartLogger.logThis(Level.DEBUG, "Error on Configurator getConnection while getting " + dbName + "." + Constants.CONN_PASSWORD + " " + ex.getMessage()); password = new String(_props.getProperty(Constants.CONN_DEFAULT_PASSWORD)); } catch (Exception ex1) { SmartLogger.logThis(Level.ERROR, "Error on Configurator getConnection while getting " + dbName + "." + Constants.CONN_PASSWORD + " " + ex.getMessage()); } } DriverAdapterCPDS cpds = new DriverAdapterCPDS(); cpds.setDriver(Constants.ORACLE_DRIVER); cpds.setUrl(url.toString()); cpds.setUser(uname.toString()); cpds.setPassword(password.toString()); SharedPoolDataSource tds = new SharedPoolDataSource(); tds.setConnectionPoolDataSource(cpds); // tds.setMaxActive(5); Integer maxActive = new Integer(5); try { maxActive = new Integer(_props.getProperty(dbName + "." + Constants.CONN_MAX_ACTIVE)); } catch (Exception ex) { SmartLogger.logThis(Level.DEBUG, "Note: " + dbName + "." + Constants.CONN_MAX_ACTIVE + " " + ex.getMessage()); try { maxActive = new Integer( _props.getProperty(Constants.DATABASES_LIST + "." + Constants.CONN_MAX_ACTIVE)); } catch (Exception e) { SmartLogger.logThis(Level.WARN, "Note: " + Constants.DATABASES_LIST + "." + Constants.CONN_MAX_ACTIVE + " " + e.getMessage()); SmartLogger.logThis(Level.WARN, "Warning I will use default value " + maxActive); } } tds.setMaxActive(maxActive.intValue()); Integer maxWait = new Integer(100); try { maxWait = new Integer(_props.getProperty(dbName + "." + Constants.CONN_MAX_WAIT)); } catch (Exception ex) { SmartLogger.logThis(Level.DEBUG, "Note: " + dbName + "." + Constants.CONN_MAX_WAIT + " " + ex.getMessage()); try { maxWait = new Integer( _props.getProperty(Constants.DATABASES_LIST + "." + Constants.CONN_MAX_WAIT)); } catch (Exception e) { SmartLogger.logThis(Level.WARN, "Note: " + Constants.DATABASES_LIST + "." + Constants.CONN_MAX_WAIT + " " + e.getMessage()); SmartLogger.logThis(Level.WARN, "Warning I will use default value " + maxWait); } } tds.setMaxWait(maxWait.intValue()); Integer maxIdle = new Integer(1); try { maxIdle = new Integer(_props.getProperty(dbName + "." + Constants.CONN_MAX_IDLE)); } catch (Exception ex) { SmartLogger.logThis(Level.DEBUG, "Note: " + dbName + "." + Constants.CONN_MAX_IDLE + " " + ex.getMessage()); try { maxIdle = new Integer( _props.getProperty(Constants.DATABASES_LIST + "." + Constants.CONN_MAX_IDLE)); } catch (Exception e) { SmartLogger.logThis(Level.WARN, "Note: " + Constants.DATABASES_LIST + "." + Constants.CONN_MAX_IDLE + " " + e.getMessage()); SmartLogger.logThis(Level.WARN, "Warning I will use default value " + maxIdle); } } tds.setMaxIdle(maxIdle.intValue()); SmartLogger.logThis(Level.INFO, "DB Pool created: " + tds); SmartLogger.logThis(Level.INFO, "URL=" + url.toString()); SmartLogger.logThis(Level.INFO, "maxPoolSize=" + tds.getMaxActive()); SmartLogger.logThis(Level.INFO, "maxIdleSize=" + tds.getMaxIdle()); SmartLogger.logThis(Level.INFO, "maxIdleTime=" + tds.getMinEvictableIdleTimeMillis() + "ms"); SmartLogger.logThis(Level.INFO, "poolTimeout=" + tds.getMaxWait()); SmartLogger.logThis(Level.INFO, "timeBetweenEvictionRunsMillis=" + tds.getTimeBetweenEvictionRunsMillis()); SmartLogger.logThis(Level.INFO, "numTestsPerEvictionRun=" + tds.getNumTestsPerEvictionRun()); tds.setValidationQuery(Constants.ORACLE_VALIDATION_QUERY); Connection con = null; con = tds.getConnection(); PreparedStatement p_stmt = null; p_stmt = con.prepareStatement(Constants.ORACLE_WHOAMI_QUERY); ResultSet rs = null; rs = p_stmt.executeQuery(); String tempStr = new String(""); ResultSetMetaData rsmd = rs.getMetaData(); int numColumns = rsmd.getColumnCount(); while (rs.next()) { for (int r = 1; r < numColumns + 1; r++) { tempStr = tempStr + rs.getObject(r).toString().trim(); } } SmartLogger.logThis(Level.INFO, "Connected as " + tempStr); con.close(); con = null; con = tds.getConnection(); p_stmt = con.prepareStatement(Constants.ORACLE_DBNAME_QUERY); rs = p_stmt.executeQuery(); rsmd = rs.getMetaData(); numColumns = rsmd.getColumnCount(); tempStr = ""; while (rs.next()) { for (int r = 1; r < numColumns + 1; r++) { tempStr = tempStr + rs.getObject(r).toString().trim(); } } SmartLogger.logThis(Level.INFO, "--------- on Database -> " + tempStr); con.close(); con = null; DBConn mydbconn = new DBConn(tds, dbName.toString()); return mydbconn; } catch (Exception ex) { SmartLogger.logThis(Level.ERROR, "Error on Configurator for database " + dbName + " -->" + ex.getMessage()); return null; } }
From source file:net.sourceforge.myvd.inserts.jdbc.JdbcInsert.java
public void configure(String name, Properties props, NameSpace nameSpace) throws LDAPException { this.name = name; driver = props.getProperty("driver"); logger.info("Driver : " + driver); url = props.getProperty("url"); logger.info("URL : " + url); user = props.getProperty("user"); logger.info("User : " + user); pwd = props.getProperty("password"); logger.info("Password : **********"); this.valQuery = props.getProperty("validationQuery"); logger.info("Validation Query : '" + this.valQuery + "'"); this.maxCons = Integer.parseInt(props.getProperty("maxCons", "5")); logger.info("Max Cons : " + this.maxCons); this.maxIdleCons = Integer.parseInt(props.getProperty("maxIdleCons", "5")); logger.info("maxIdleCons : " + this.maxIdleCons); DriverAdapterCPDS pool = new DriverAdapterCPDS(); try {//from w w w .j a v a 2 s . co m pool.setDriver(driver); } catch (ClassNotFoundException e) { throw new LDAPException("Could not load JDBC Driver", LDAPException.OPERATIONS_ERROR, driver, e); } pool.setUrl(url); pool.setUser(user); pool.setPassword(pwd); pool.setMaxActive(maxCons); pool.setMaxIdle(maxIdleCons); SharedPoolDataSource tds = new SharedPoolDataSource(); tds.setConnectionPoolDataSource(pool); tds.setMaxActive(maxCons); tds.setMaxWait(50); tds.setTestOnBorrow(true); if (this.valQuery != null) { tds.setValidationQuery(this.valQuery); } this.ds = tds; base = nameSpace.getBase().toString(); rdn = props.getProperty("rdn"); logger.info("RDN : " + rdn); String mapping = props.getProperty("mapping"); logger.info("Mapping : " + mapping); StringTokenizer toker = new StringTokenizer(mapping, ","); this.ldap2db = new HashMap<String, String>(); this.db2ldap = new HashMap<String, String>(); while (toker.hasMoreTokens()) { String token = toker.nextToken(); String ldap = token.substring(0, token.indexOf('=')); String db = token.substring(token.indexOf('=') + 1); ldap2db.put(ldap.toLowerCase(), db.toLowerCase()); db2ldap.put(db.toLowerCase(), ldap.toLowerCase()); } this.objectClass = props.getProperty("objectClass"); logger.info("objectClass : " + objectClass); this.rdn = props.getProperty("rdn"); this.dbRdn = ldap2db.get(rdn); this.useSimple = props.getProperty("useSimple", "false").equalsIgnoreCase("true"); logger.info("Use Simple : " + useSimple); this.SQL = props.getProperty("sql"); logger.info("SQL : " + this.SQL); int whereEnd; String fields = this.SQL.substring(this.SQL.toLowerCase().indexOf("select") + "select".length() + 1, this.SQL.toLowerCase().indexOf("from")); logger.info("fields : " + fields); int where = this.SQL.toLowerCase().indexOf("where"); String table = ""; if (where == -1) { table = this.SQL.substring(this.SQL.toLowerCase().indexOf("from") + "from".length() + 1).trim(); } else { table = this.SQL.substring(this.SQL.toLowerCase().indexOf("from") + "from".length() + 1, where).trim(); } logger.info("table - " + table); try { Class.forName(this.driver).newInstance(); } catch (Exception e) { } /* try { Connection con = DriverManager.getConnection(this.url,this.user,this.pwd); toker = new StringTokenizer(fields,",",false); while (toker.hasMoreTokens()) { String field = toker.nextToken(); ResultSet rs = con.getMetaData().getColumns(null, null, table, field); rs.next(); String type = rs.getString("TYPE_NAME"); logger.info(field + " - " + type); } PreparedStatement ps = null; ps con.close(); } catch (SQLException e) { logger.error("Error loading db schema",e); } */ if (this.useSimple) { this.searchSQL = this.SQL.substring(this.SQL.toLowerCase().indexOf(" from ")); int whereBegin = this.searchSQL.toLowerCase().indexOf(" where "); whereEnd = this.searchSQL.toLowerCase().indexOf(" order "); this.hasPostWhere = true; if (whereEnd == -1) { whereEnd = this.searchSQL.toLowerCase().indexOf(" group "); } if (whereEnd == -1) { this.hasPostWhere = false; whereEnd = this.searchSQL.length(); } if (this.hasPostWhere) { this.postWhere = this.searchSQL.substring(whereEnd); } if (whereBegin != -1) { this.hasWhere = true; this.whereClause = "(" + this.searchSQL.substring(whereBegin + " where ".length(), whereEnd) + ") "; this.searchSQL = this.searchSQL.substring(0, whereBegin); } else { if (this.hasPostWhere) { this.searchSQL = this.searchSQL.substring(0, whereEnd); } this.hasWhere = false; } } else { this.searchSQL = "SELECT " + ldap2db.get(this.rdn.toLowerCase()) + " " + SQL.substring(SQL.indexOf(" FROM ")); } this.baseDN = new DN(base); this.addBaseToFilter = Boolean.parseBoolean(props.getProperty("addBaseToFilter", "true")); logger.info("Add Base To Filter : " + this.addBaseToFilter); this.ns = nameSpace; }
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 www . ja v a 2s. co m*/ */ 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.sakaiproject.content.impl.db.test.CheckBlobSafety.java
@Before public void setUp() throws Exception { DriverAdapterCPDS cpds = new DriverAdapterCPDS(); if (config != null) { log.info("Using Config " + config); File f = new File(config); FileInputStream fin = new FileInputStream(config); p.load(fin);// w w w . ja va 2 s .co m fin.close(); StringBuilder sb = new StringBuilder(); Object[] keys = p.keySet().toArray(); Arrays.sort(keys); for (Object k : keys) { sb.append("\n " + k + ":" + p.get(k)); } log.info("Loaded Properties from " + config + " as " + sb.toString()); } else { log.info("Using Default Config: testblob.config"); InputStream is = this.getClass().getResourceAsStream("testblob.config"); if (is != null) { try { p.load(is); StringBuilder sb = new StringBuilder(); Object[] keys = p.keySet().toArray(); Arrays.sort(keys); for (Object k : keys) { sb.append("\n " + k + ":" + p.get(k)); } log.info("Loaded Default Properties " + config + " as " + sb.toString()); } finally { is.close(); } } } cpds.setDriver(p.getProperty("dbDriver")); cpds.setUrl(p.getProperty("dbURL")); cpds.setUser(p.getProperty("dbUser")); cpds.setPassword(p.getProperty("dbPass")); tds = new SharedPoolDataSource(); tds.setConnectionPoolDataSource(cpds); tds.setMaxActive(10); tds.setMaxWait(5); tds.setDefaultAutoCommit(false); con = tds.getConnection(); Statement stmt = null; try { stmt = con.createStatement(); try { log.info("Executing " + p.getProperty("drop.statement")); stmt.execute(p.getProperty("drop.statement")); } catch (Exception ex) { log.info("Drop failed " + ex.getMessage()); } log.info("Executing " + p.getProperty("create.statement")); stmt.execute(p.getProperty("create.statement")); } finally { try { stmt.close(); } catch (Exception ex) { } } }