本文整理汇总了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();
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}