public void setConnectionCacheProperties(String s) throws SQLException { // Should look something like the below, with any number of spaces around the "," or "=" - // "InitialLimit=5,MinLimit=5,MaxLimit=10" // "InitialLimit=5, MinLimit=5, MaxLimit=10" // "InitialLimit = 5 , MinLimit = 5 , MaxLimit = 10" Properties props = new Properties(); String []args = s.trim().split("[,]"); for (String arg : args) { String[] prop = arg.trim().split("[ =]+"); if (prop.length == 2) { props.setProperty(prop[0], prop[1]); } else { try { getLogWriter().println("setConnectionCacheProperties(" + s + ")"); getLogWriter().println("Found invalid Oracle ConnectionCacheProperties(" + prop.toString() + ")"); } catch (ResourceException e) { throw new SQLException(e.getMessage()); } } } // Setup ConnectionCaching Properties dataSource.setConnectionCacheProperties(props); }
OracleDataSource ods = new OracleDataSource(); // set cache properties java.util.Properties prop = new java.util.Properties(); prop.setProperty("MinLimit", "2"); prop.setProperty("MaxLimit", "10"); // set DataSource properties String url = "jdbc:oracle:oci8:@"; ods.setURL(url); ods.setUser("hr"); ods.setPassword("hr"); ods.setConnectionCachingEnabled(true); // be sure set to true ods.setConnectionCacheProperties (prop); ods.setConnectionCacheName("ImplicitCache01"); // this cache's name // We need to create a connection to create the cache Connection conn = ds.getConnection(user, pass); Statement stmt = conn1.createStatement(); ResultSet rset = stmt.executeQuery("select user from dual"); conn1.close(); ods.close();
/** * Creates a database connection pool object using JDBC 2.0. */ private OracleDataSource createConnectionPool() { try { // Create a OracleConnectionPoolDataSource instance. OracleDataSource ds = new OracleDataSource(); ds.setConnectionCacheName("oraCache"); ds.setConnectionCachingEnabled(true); ds.setURL(TestConfig.tab().stringAt(DBParms.jdbcUrl)); ds.setUser(TestConfig.tab().stringAt(DBParms.rdbUser)); ds.setPassword(TestConfig.tab().stringAt(DBParms.rdbPassword)); Properties cacheProps = new Properties(); cacheProps.setProperty("MinLimit", String.valueOf(TestConfig.tab().intAt(DBParms.poolMinLimit))); ds.setConnectionCacheProperties(cacheProps); return ds; } catch (Exception ex) { Log.getLogWriter().info("Unable to create connection pool: " + ex, ex); throw new HydraRuntimeException("Problem creating connection pool", ex); } }
/** * Creates a database connection pool object using JDBC 2.0. */ private OracleDataSource createConnectionPool() { try { // Create a OracleConnectionPoolDataSource instance. OracleDataSource ds = new OracleDataSource(); ds.setConnectionCacheName("oraCache"); ds.setConnectionCachingEnabled(true); ds.setURL(TestConfig.tab().stringAt(JtaPrms.jdbcUrl)); ds.setUser(TestConfig.tab().stringAt(JtaPrms.rdbUser)); ds.setPassword(TestConfig.tab().stringAt(JtaPrms.rdbPassword)); Properties cacheProps = new Properties(); cacheProps.setProperty("MinLimit", String.valueOf(TestConfig.tab().intAt(JtaPrms.poolMinLimit))); ds.setConnectionCacheProperties(cacheProps); return ds; } catch (Exception ex) { Log.getLogWriter().info("Unable to create connection pool: " + ex, ex); throw new HydraRuntimeException("Problem creating Oracle connection pool", ex); } }