当前位置: 首页>>代码示例>>Java>>正文


Java JdbcConnectionPool.setMaxConnections方法代码示例

本文整理汇总了Java中org.h2.jdbcx.JdbcConnectionPool.setMaxConnections方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcConnectionPool.setMaxConnections方法的具体用法?Java JdbcConnectionPool.setMaxConnections怎么用?Java JdbcConnectionPool.setMaxConnections使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.h2.jdbcx.JdbcConnectionPool的用法示例。


在下文中一共展示了JdbcConnectionPool.setMaxConnections方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTimeout

import org.h2.jdbcx.JdbcConnectionPool; //导入方法依赖的package包/类
private void testTimeout() throws Exception {
    String url = getURL("connectionPool", true), user = getUser();
    String password = getPassword();
    final JdbcConnectionPool man = JdbcConnectionPool.create(url, user, password);
    man.setLoginTimeout(1);
    createClassProxy(man.getClass());
    assertThrows(IllegalArgumentException.class, man).
            setMaxConnections(-1);
    man.setMaxConnections(2);
    // connection 1 (of 2)
    Connection conn = man.getConnection();
    Task t = new Task() {
        @Override
        public void call() {
            while (!stop) {
                // this calls notifyAll
                man.setMaxConnections(1);
                man.setMaxConnections(2);
            }
        }
    };
    t.execute();
    long time = System.currentTimeMillis();
    try {
        // connection 2 (of 1 or 2) may fail
        man.getConnection();
        // connection 3 (of 1 or 2) must fail
        man.getConnection();
        fail();
    } catch (SQLException e) {
        assertTrue(e.toString().toLowerCase().contains("timeout"));
        time = System.currentTimeMillis() - time;
        assertTrue("timeout after " + time + " ms", time > 1000);
    } finally {
        conn.close();
        t.get();
    }

    man.dispose();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:41,代码来源:TestConnectionPool.java

示例2: getConnectionPool

import org.h2.jdbcx.JdbcConnectionPool; //导入方法依赖的package包/类
private JdbcConnectionPool getConnectionPool(int poolSize) {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL(getURL("connectionPool", true));
    ds.setUser(getUser());
    ds.setPassword(getPassword());
    JdbcConnectionPool pool = JdbcConnectionPool.create(ds);
    pool.setMaxConnections(poolSize);
    return pool;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:10,代码来源:TestConnectionPool.java

示例3: setUpJndiConnectionPool

import org.h2.jdbcx.JdbcConnectionPool; //导入方法依赖的package包/类
public static void setUpJndiConnectionPool(int maxConnections, String jndiName)
        throws NamingException {

    if (poolCreated) {
        LOG.info("Pool already exists, and JNDI name already registered");
    } else {
        LOG.info("Creating pool and registering JNDI name");

        // create a data source from the H2 default connection pool of the test database
        JdbcConnectionPool pool = JdbcConnectionPool.create(H2Server.URL, H2Server.USER, H2Server.PASSWORD);
        pool.setMaxConnections(maxConnections);
        pool.setLoginTimeout(1); // set a short login timeout in case of errors

        // this requires the tomcat dependency to work, but is required to init and bind the context
        System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
        System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");

        // init and bind
        Context context = new InitialContext();
        context.createSubcontext("java:");
        context.createSubcontext("java:/comp");
        context.createSubcontext("java:/comp/env");
        context.createSubcontext("java:/comp/env/jdbc");
        context.bind(jndiName, pool);

        poolCreated = true;
    }
}
 
开发者ID:mbeiter,项目名称:eaudit4j,代码行数:29,代码来源:JndiUtil.java

示例4: createDataSource

import org.h2.jdbcx.JdbcConnectionPool; //导入方法依赖的package包/类
/**
 * @return Connection pool
 */
static JdbcConnectionPool createDataSource(int port) {
    JdbcConnectionPool pool = JdbcConnectionPool.create("jdbc:h2:tcp://localhost:" + port +
        "/mem:TestDb;LOCK_MODE=0", "sa", "");

    pool.setMaxConnections(Integer.getInteger("H2_JDBC_CONNECTIONS", 100));
    return pool;
}
 
开发者ID:apache,项目名称:ignite,代码行数:11,代码来源:H2CacheStoreStrategy.java

示例5: dataSource

import org.h2.jdbcx.JdbcConnectionPool; //导入方法依赖的package包/类
/**
 * @return H2 pooled data source
 * @throws SQLException
 */
@Bean(destroyMethod = "dispose")
public DataSource dataSource() throws SQLException {
	final JdbcConnectionPool pool = JdbcConnectionPool.create(url, user, password);
	pool.setMaxConnections(maxPoolConnections);
	Connection con = null;
	con = pool.getConnection();

	final Flyway flyway = new Flyway();
	flyway.setLocations("classpath:sql/migration");
	flyway.setDataSource(pool);
	flyway.setSqlMigrationPrefix("VOS-");
	flyway.setIgnoreFailedFutureMigration(true);

	final JdbcTemplate tpl = new JdbcTemplate(pool);
	if (tpl.queryForObject("select count(*) from information_schema.tables where table_name = 'LOG_SOURCES'",
			int.class) == 0) {
		logger.info("H2 database not found, creating new schema and populate with default data");
		flyway.setBaselineVersion(MigrationVersion.fromVersion(DB_SETUP_VERSION));
		flyway.setBaselineOnMigrate(true);
		try {
			final ResourceDatabasePopulator dbPopulator = new ResourceDatabasePopulator();
			dbPopulator.addScript(new ClassPathResource("/sql/quartz/tables_h2.sql"));
			dbPopulator.addScript(new ClassPathResource("/sql/model/schema_h2.sql"));
			dbPopulator.populate(con);
			newSchema = true;
			logger.info("Established H2 connection pool with new database");
		} finally {
			if (con != null) {
				con.close();
			}
		}
	} else {
		logger.info("Established H2 connection pool with existing database");
		if (tpl.queryForObject("select count(*) from information_schema.tables where table_name = 'schema_version'",
				int.class) == 0) {
			logger.info("Flyway's DB migration not setup in this version, set baseline version to 0.5.0");
			flyway.setBaselineVersion(MigrationVersion.fromVersion("0.5.0"));
			flyway.setBaselineOnMigrate(true);
		}
	}

	logger.debug("Migrating database, base version is: {}", flyway.getBaselineVersion());
	flyway.migrate();
	logger.debug("Database migrated from base version: {}", flyway.getBaselineVersion());

	return pool;
}
 
开发者ID:logsniffer,项目名称:logsniffer,代码行数:52,代码来源:DataSourceAppConfig.java


注:本文中的org.h2.jdbcx.JdbcConnectionPool.setMaxConnections方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。