Java Code Examples for com.mchange.v2.c3p0.ComboPooledDataSource#setMaxStatements()
The following examples show how to use
com.mchange.v2.c3p0.ComboPooledDataSource#setMaxStatements() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: C3P0DataSourceFactoryBean.java From cloud-config with MIT License | 6 votes |
private ComboPooledDataSource createNewDataSource() throws Exception { ComboPooledDataSource c3p0DataSource = new ComboPooledDataSource(); c3p0DataSource.setDriverClass(config.getDriverClassName()); //loads the jdbc driver c3p0DataSource.setJdbcUrl(config.getJdbcUrl()); c3p0DataSource.setUser(config.getUserName()); c3p0DataSource.setPassword(config.getPassword()); // the settings below are optional -- c3p0 can work with defaults c3p0DataSource.setMinPoolSize(config.getMinPoolSize()); c3p0DataSource.setMaxPoolSize(config.getMaxPoolSize()); c3p0DataSource.setAcquireIncrement(config.getAcquireIncrement()); c3p0DataSource.setMaxStatements(config.getMaxStatements()); c3p0DataSource.setIdleConnectionTestPeriod(config.getIdleTestPeriod()); c3p0DataSource.setMaxIdleTime(config.getMaxIdleTime()); return c3p0DataSource; }
Example 2
Source File: C3p0DataSourcePool.java From EasyReport with Apache License 2.0 | 6 votes |
@Override public DataSource wrap(ReportDataSource rptDs) { try { ComboPooledDataSource dataSource = new ComboPooledDataSource(); dataSource.setDriverClass(rptDs.getDriverClass()); dataSource.setJdbcUrl(rptDs.getJdbcUrl()); dataSource.setUser(rptDs.getUser()); dataSource.setPassword(rptDs.getPassword()); dataSource.setInitialPoolSize(MapUtils.getInteger(rptDs.getOptions(), "initialPoolSize", 3)); dataSource.setMinPoolSize(MapUtils.getInteger(rptDs.getOptions(), "minPoolSize", 1)); dataSource.setMaxPoolSize(MapUtils.getInteger(rptDs.getOptions(), "maxPoolSize", 20)); dataSource.setMaxStatements(MapUtils.getInteger(rptDs.getOptions(), "maxStatements", 50)); dataSource.setMaxIdleTime(MapUtils.getInteger(rptDs.getOptions(), "maxIdleTime", 1800)); dataSource.setAcquireIncrement(MapUtils.getInteger(rptDs.getOptions(), "acquireIncrement", 3)); dataSource.setAcquireRetryAttempts(MapUtils.getInteger(rptDs.getOptions(), "acquireRetryAttempts", 30)); dataSource.setIdleConnectionTestPeriod( MapUtils.getInteger(rptDs.getOptions(), "idleConnectionTestPeriod", 60)); dataSource.setBreakAfterAcquireFailure( MapUtils.getBoolean(rptDs.getOptions(), "breakAfterAcquireFailure", false)); dataSource.setTestConnectionOnCheckout( MapUtils.getBoolean(rptDs.getOptions(), "testConnectionOnCheckout", false)); return dataSource; } catch (Exception ex) { throw new RuntimeException("C3p0DataSourcePool Create Error", ex); } }
Example 3
Source File: C3P0DataSource.java From maven-framework-project with MIT License | 6 votes |
private C3P0DataSource() throws IOException, SQLException, PropertyVetoException { cpds = new ComboPooledDataSource(); cpds.setDriverClass("org.h2.Driver"); // loads the jdbc driver cpds.setJdbcUrl("jdbc:h2:./target/test;AUTO_SERVER=TRUE"); cpds.setUser("sa"); cpds.setPassword(""); // the settings below are optional -- c3p0 can work with defaults cpds.setMinPoolSize(5); cpds.setAcquireIncrement(5); cpds.setMaxPoolSize(20); cpds.setMaxStatements(180); this.setDataSource(cpds); }
Example 4
Source File: DAOFactory.java From uavstack with Apache License 2.0 | 5 votes |
protected DAOFactory(String facName, String driverClassName, String jdbcURL, String userName, String userPassword, int initPoolSize, int MinPoolSize, int MaxPoolSize, int maxIdleTime, int idleConnectionTestPeriod, String testQuerySQL) { this.facName = facName; ds = new ComboPooledDataSource(); // 设置JDBC的Driver类 try { ds.setDriverClass(driverClassName); } catch (PropertyVetoException e) { throw new RuntimeException(e); } // 设置JDBC的URL ds.setJdbcUrl(jdbcURL); // 设置数据库的登录用户名 ds.setUser(userName); // 设置数据库的登录用户密码 ds.setPassword(userPassword); // 设置连接池的最大连接数 ds.setMaxPoolSize(MaxPoolSize); // 设置连接池的最小连接数 ds.setMinPoolSize(MinPoolSize); // 设置初始化连接数 ds.setInitialPoolSize(initPoolSize); // 设置最大闲置时间 ds.setMaxIdleTime(maxIdleTime); // 设置测试SQL ds.setPreferredTestQuery(testQuerySQL); // 设置闲置测试周期 ds.setIdleConnectionTestPeriod(idleConnectionTestPeriod); // 增加单个连接的Statements数量 ds.setMaxStatements(0); // 连接池内单个连接所拥有的最大缓存statements数 ds.setMaxStatementsPerConnection(200); // 获取空闲连接超时时间 ds.setCheckoutTimeout(10 * 1000); }
Example 5
Source File: Database.java From SQLite-sync.com with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Database() { String version = ""; try { String resourceName = "project.properties"; ClassLoader loader = Thread.currentThread().getContextClassLoader(); Properties props = new Properties(); try(InputStream resourceStream = loader.getResourceAsStream(resourceName)) { props.load(resourceStream); } version = props.getProperty("version"); } catch (IOException ex){ Logs.write(Logs.Level.ERROR, "GetVersionOfSQLiteSyncCOM: " + ex.getMessage()); } SQLiteSyncVersion = version; SQLiteSyncConfig.Load(); try { cpds = new ComboPooledDataSource(); cpds.setDriverClass(SQLiteSyncConfig.DBDRIVER); //loads the jdbc driver cpds.setJdbcUrl(SQLiteSyncConfig.DBURL); cpds.setUser(SQLiteSyncConfig.DBUSER); cpds.setPassword(SQLiteSyncConfig.DBPASS); // the settings below are optional -- c3p0 can work with defaults cpds.setMinPoolSize(3); cpds.setAcquireIncrement(3); cpds.setMaxPoolSize(10); cpds.setIdleConnectionTestPeriod(300); cpds.setMaxIdleTime(240); cpds.setTestConnectionOnCheckin(false); cpds.setMaxStatements(2000); cpds.setMaxStatementsPerConnection(100); } catch (PropertyVetoException e){ Logs.write(Logs.Level.ERROR, "Database constructor: " + e.getMessage()); } }
Example 6
Source File: ConnectionPoolManager.java From ezScrum with GNU General Public License v2.0 | 5 votes |
private DataSource createDataSource(String driverClass, String url, String account, String password) { ComboPooledDataSource dataSource = new ComboPooledDataSource(); try { dataSource.setDriverClass(driverClass); dataSource.setJdbcUrl(url); dataSource.setUser(account); dataSource.setPassword(password); dataSource.setMinPoolSize(10); dataSource.setMaxPoolSize(35); dataSource.setAcquireIncrement(0); dataSource.setMaxStatements(0); /** 最大允許的閒置時間(秒) */ dataSource.setMaxIdleTime(300); /** 對閒置的連線進行Query測試設置(秒) */ dataSource.setIdleConnectionTestPeriod(1800); /** Checkin connection時不檢查連線是否有效 */ dataSource.setTestConnectionOnCheckin(false); /** Checkout connection時檢查連線的有效性*/ dataSource.setTestConnectionOnCheckout(true); /** 進行test時使用的 Query設定*/ dataSource.setPreferredTestQuery("SELECT 1;"); /** Connection的最大有效時數(秒)*/ dataSource.setMaxConnectionAge(28800); /** Connection checkout 之後的有效時數(毫秒)*/ dataSource.setCheckoutTimeout(28800000); } catch (PropertyVetoException e) { e.printStackTrace(); } mPoolMap.put(url, dataSource); return dataSource; }
Example 7
Source File: PGDb.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
public boolean open( String dbPath ) throws Exception { this.mDbPath = dbPath; connectionData = new ConnectionData(); connectionData.connectionLabel = dbPath; connectionData.connectionUrl = new String(dbPath); connectionData.user = user; connectionData.password = password; connectionData.dbType = getType().getCode(); boolean dbExists = true; String jdbcUrl = EDb.POSTGRES.getJdbcPrefix() + dbPath; if (makePooled) { Properties p = new Properties(System.getProperties()); p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog"); p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "OFF"); // Off or any // other level System.setProperties(p); // testConnectionOnCheckin validates the connection when it is returned to the pool. // idleConnectionTestPeriod sets a limit to how long a connection will stay idle before testing it. // maxIdleTimeExcessConnections will bring back the connectionCount back down to minPoolSize after a spike in activity. comboPooledDataSource = new ComboPooledDataSource(); comboPooledDataSource.setDriverClass(DRIVER_CLASS); comboPooledDataSource.setJdbcUrl(jdbcUrl); if (user != null && password != null) { comboPooledDataSource.setUser(user); comboPooledDataSource.setPassword(password); } comboPooledDataSource.setMinPoolSize(5); comboPooledDataSource.setMaxPoolSize(30); comboPooledDataSource.setAcquireIncrement(1); comboPooledDataSource.setInitialPoolSize(10); comboPooledDataSource.setMaxStatements(100); comboPooledDataSource.setTestConnectionOnCheckin(true); comboPooledDataSource.setIdleConnectionTestPeriod(300); comboPooledDataSource.setMaxIdleTimeExcessConnections(240); // comboPooledDataSource.setCheckoutTimeout(2000); comboPooledDataSource.setAcquireRetryAttempts(1); // comboPooledDataSource.setBreakAfterAcquireFailure(false); // TODO remove after debug // comboPooledDataSource.setUnreturnedConnectionTimeout(180); } else { if (user != null && password != null) { singleJdbcConn = DriverManager.getConnection(jdbcUrl, user, password); } else { singleJdbcConn = DriverManager.getConnection(jdbcUrl); } } if (mPrintInfos) { String[] dbInfo = getDbInfo(); Logger.INSTANCE.insertDebug(null, "Postgresql Version: " + dbInfo[0] + "(" + dbPath + ")"); } return dbExists; }
Example 8
Source File: H2Db.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
public boolean open( String dbPath ) throws Exception { this.mDbPath = dbPath; connectionData = new ConnectionData(); connectionData.connectionLabel = dbPath; connectionData.connectionUrl = new String(dbPath); connectionData.user = user; connectionData.password = password; connectionData.dbType = getType().getCode(); boolean dbExists = false; if (dbPath != null) { File dbFile = new File(dbPath + "." + EDb.H2.getExtension()); if (dbFile.exists()) { if (mPrintInfos) Logger.INSTANCE.insertInfo(null, "Database exists"); dbExists = true; } if (dbPath.toLowerCase().startsWith("tcp")) { // no way to check, assume it exists dbExists = true; // also cleanup path int first = dbPath.indexOf('/'); int second = dbPath.indexOf('/', first + 1); int third = dbPath.indexOf('/', second + 1); int lastSlash = dbPath.indexOf('/', third + 1); if (lastSlash != -1) { mDbPath = dbPath.substring(lastSlash, dbPath.length()); } } } else { dbPath = "mem:syntax"; dbExists = false; } String jdbcUrl = EDb.H2.getJdbcPrefix() + dbPath; if (makePooled) { Properties p = new Properties(System.getProperties()); p.put("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog"); p.put("com.mchange.v2.log.FallbackMLog.DEFAULT_CUTOFF_LEVEL", "OFF"); System.setProperties(p); comboPooledDataSource = new ComboPooledDataSource(); comboPooledDataSource.setDriverClass(DRIVER_CLASS); comboPooledDataSource.setJdbcUrl(jdbcUrl); if (user != null && password != null) { comboPooledDataSource.setUser(user); comboPooledDataSource.setPassword(password); } comboPooledDataSource.setInitialPoolSize(10); comboPooledDataSource.setMinPoolSize(5); comboPooledDataSource.setAcquireIncrement(5); comboPooledDataSource.setMaxPoolSize(30); comboPooledDataSource.setMaxStatements(100); comboPooledDataSource.setMaxIdleTime(14400); // 4 hours by default // comboPooledDataSource.setCheckoutTimeout(2000); comboPooledDataSource.setAcquireRetryAttempts(1); // comboPooledDataSource.setBreakAfterAcquireFailure(false); // TODO remove after debug // comboPooledDataSource.setUnreturnedConnectionTimeout(180); } else { if (user != null && password != null) { singleJdbcConn = DriverManager.getConnection(jdbcUrl, user, password); } else { singleJdbcConn = DriverManager.getConnection(jdbcUrl); } } if (mPrintInfos) { String[] dbInfo = getDbInfo(); Logger.INSTANCE.insertDebug(null, "H2 Version: " + dbInfo[0] + "(" + dbPath + ")"); } return dbExists; }
Example 9
Source File: C3P0DataSourceProvider.java From vertx-jdbc-client with Apache License 2.0 | 4 votes |
@Override public DataSource getDataSource(JsonObject config) throws SQLException { String url = config.getString("url"); if (url == null) throw new NullPointerException("url cannot be null"); String driverClass = config.getString("driver_class"); String user = config.getString("user"); String password = config.getString("password"); Integer maxPoolSize = config.getInteger("max_pool_size"); Integer initialPoolSize = config.getInteger("initial_pool_size"); Integer minPoolSize = config.getInteger("min_pool_size"); Integer maxStatements = config.getInteger("max_statements"); Integer maxStatementsPerConnection = config.getInteger("max_statements_per_connection"); Integer maxIdleTime = config.getInteger("max_idle_time"); Integer acquireRetryAttempts = config.getInteger("acquire_retry_attempts"); Integer acquireRetryDelay = config.getInteger("acquire_retry_delay"); Boolean breakAfterAcquireFailure = config.getBoolean("break_after_acquire_failure"); // If you want to configure any other C3P0 properties you can add a file c3p0.properties to the classpath ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setJdbcUrl(url); if (driverClass != null) { try { cpds.setDriverClass(driverClass); } catch (PropertyVetoException e) { throw new IllegalArgumentException(e); } } if (user != null) { cpds.setUser(user); } if (password != null) { cpds.setPassword(password); } if (maxPoolSize != null) { cpds.setMaxPoolSize(maxPoolSize); } if (minPoolSize != null) { cpds.setMinPoolSize(minPoolSize); } if (initialPoolSize != null) { cpds.setInitialPoolSize(initialPoolSize); } if (maxStatements != null) { cpds.setMaxStatements(maxStatements); } if (maxStatementsPerConnection != null) { cpds.setMaxStatementsPerConnection(maxStatementsPerConnection); } if (maxIdleTime != null) { cpds.setMaxIdleTime(maxIdleTime); } if(acquireRetryAttempts != null){ cpds.setAcquireRetryAttempts(acquireRetryAttempts); } if(acquireRetryDelay != null){ cpds.setAcquireRetryDelay(acquireRetryDelay); } if(breakAfterAcquireFailure != null){ cpds.setBreakAfterAcquireFailure(breakAfterAcquireFailure); } return cpds; }