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


Java HikariDataSource.close方法代码示例

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


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

示例1: enableDatabaseSQLiteTest

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Test
public void enableDatabaseSQLiteTest() {
    try {
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("org.sqlite.JDBC");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:sqlite:PetBlocks.db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assert.fail();
    }
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:18,代码来源:DatabaseIT.java

示例2: enableDatabaseMySQLTest

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Test
public void enableDatabaseMySQLTest() {
    try {
        final DB database = DB.newEmbeddedDB(3306);
        database.start();
        try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
            try (Statement statement = conn.createStatement()) {
                statement.executeUpdate("CREATE DATABASE db");
            }
        }
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("com.mysql.jdbc.Driver");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
        database.stop();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assert.fail();
    }
}
 
开发者ID:Shynixn,项目名称:PetBlocks,代码行数:26,代码来源:DatabaseIT.java

示例3: testConnection

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Override
public void testConnection(String driverClass, String jdbcUrl, String username, String password)
{
	try
	{
		HikariDataSource source = new HikariDataSource();
		source.setDriverClassName(driverClass);
		source.setJdbcUrl(jdbcUrl);
		source.setUsername(username);
		source.setPassword(password);
		source.setMaximumPoolSize(1);

		String testQuery = "SELECT COUNT(*) FROM "
			+ (jdbcUrl.startsWith("jdbc:oracle") ? "ALL_TABLES" : "information_schema.tables");
		new JdbcTemplate(source).query(testQuery, IGNORE_ROWS);

		source.close();
	}
	catch( Exception ex )
	{
		LOGGER.warn("Test connection failure", ex);
		Throwable rootCause = Throwables.getRootCause(ex);
		throw new RuntimeException("Error attempting to connect or while executing test query: "
			+ rootCause.getMessage());
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:27,代码来源:RemoteSqlQueryingServiceImpl.java

示例4: enableDatabaseSQLiteTest

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Test
public void enableDatabaseSQLiteTest() {
    try {
        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("org.sqlite.JDBC");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:sqlite:PetBlocks.db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assertions.fail(ex);
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:18,代码来源:DatabaseTest.java

示例5: enableDatabaseMySQLTest

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Test
public void enableDatabaseMySQLTest() {
    try {
        final DB database = DB.newEmbeddedDB(3306);
        database.start();
        try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/?user=root&password=")) {
            try (Statement statement = conn.createStatement()) {
                statement.executeUpdate("CREATE DATABASE db");
            }
        }

        final HikariConfig config = new HikariConfig();
        config.setDriverClassName("com.mysql.jdbc.Driver");
        config.setConnectionTestQuery("SELECT 1");
        config.setJdbcUrl("jdbc:mysql://localhost:3306/db");
        config.setMaxLifetime(60000);
        config.setIdleTimeout(45000);
        config.setMaximumPoolSize(50);
        final HikariDataSource ds = new HikariDataSource(config);
        ds.close();
        database.stop();
    } catch (final Exception ex) {
        Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to enable database.", ex);
        Assertions.fail(ex);
    }
}
 
开发者ID:Shynixn,项目名称:BlockBall,代码行数:27,代码来源:DatabaseTest.java

示例6: testGuessDialectsByDatasource

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Test
public void testGuessDialectsByDatasource() {
	HikariDataSource ds = buildH2Datasource();
	String dialectName = Dialect.guessDialect(ds).toString();
	Assert.assertEquals("H2Dialect", dialectName);
	ds.close();
}
 
开发者ID:drinkjava2,项目名称:jDialects,代码行数:8,代码来源:DialectTest.java

示例7: gracefulShutdown

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
public static void gracefulShutdown(ExecutorService ex, HikariDataSource ds)
{
    ds.close();
    ConcurrentUtil.shutdownAndAwaitTermination(ex, 5, TimeUnit.SECONDS);
}
 
开发者ID:novarto-oss,项目名称:sane-dbc,代码行数:6,代码来源:Hikari.java

示例8: doTest

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Test
public void doTest() {
	HikariDataSource dataSource = new HikariDataSource();// DataSource

	// H2 is a memory database
	dataSource.setDriverClassName("org.h2.Driver");
	dataSource.setJdbcUrl("jdbc:h2:mem:DBName;MODE=MYSQL;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=0");
	dataSource.setUsername("sa");
	dataSource.setPassword("");

	// MySQL
	// dataSource.setDriverClassName("com.mysql.jdbc.Driver");
	// dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?rewriteBatchedStatements=true&useSSL=false");
	// dataSource.setUsername("root");
	// dataSource.setPassword("root888");

	// MS-SqlServer
	// dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	// dataSource.setJdbcUrl("jdbc:sqlserver://localhost:1433;databaseName=test");
	// dataSource.setUsername("sa");
	// dataSource.setPassword("root888");

	// ORACLE
	// dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
	// dataSource.setJdbcUrl("jdbc:oracle:thin:@127.0.0.1:1521:XE");
	// dataSource.setUsername("root");
	// dataSource.setPassword("root888");

	SqlBoxContext ctx = new SqlBoxContext(dataSource);
	SqlBoxContext.setDefaultContext(ctx);
	ctx.setAllowShowSQL(true);
	String[] ddlArray = ctx.toDropAndCreateDDL(User.class);
	for (String ddl : ddlArray)
		ctx.quiteExecute(ddl);
	for (int i = 1; i <= 100; i++)
		new User().put("firstName", "Foo" + i, "lastName", "Bar" + i, "age", i).insert();

	TransactionFactory transactionFactory = new JdbcTransactionFactory();
	Environment environment = new Environment("demo", transactionFactory, dataSource);
	Configuration configuration = new Configuration(environment);
	configuration.addMapper(UserMapper.class);
	SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
	configuration.addInterceptor(new JDialectsPlugin());

	SqlSession session = null;
	try {
		session = sqlSessionFactory.openSession();
		Connection conn = session.getConnection();
		Assert.assertEquals(100, ctx.nQueryForLongValue(conn, "select count(*) from users"));

		List<Map<String, Object>> users;
		try {
			paginInfo.set(new Object[] { ctx.getDialect(), 3, 10 });
			users = session.getMapper(UserMapper.class).getOlderThan(50);
		} finally {
			paginInfo.remove();
		}
		Assert.assertEquals(10, users.size());
		for (Map<String, Object> map : users)
			System.out.println("UserName=" + map.get("USERNAME") + ", age=" + map.get("AGE"));
	} finally {
		session.close();
	}
	dataSource.close();
}
 
开发者ID:drinkjava2,项目名称:jDialects,代码行数:66,代码来源:Demo.java

示例9: doTest

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Test
public void doTest() {
	HikariDataSource ds = new HikariDataSource();// DataSource

	// H2 is a memory database
	ds.setDriverClassName("org.h2.Driver");
	ds.setJdbcUrl("jdbc:h2:mem:DBName;MODE=MYSQL;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=0");
	ds.setUsername("sa");
	ds.setPassword("");

	// MySQL
	// ds.setDriverClassName("com.mysql.jdbc.Driver");
	// ds.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?rewriteBatchedStatements=true&useSSL=false");
	// ds.setUsername("root");
	// ds.setPassword("root888");

	// MS-SqlServer
	// ds.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	// ds.setJdbcUrl("jdbc:sqlserver://localhost:1433;databaseName=test");
	// ds.setUsername("sa");
	// ds.setPassword("root888");

	// ORACLE
	// ds.setDriverClassName("oracle.jdbc.OracleDriver");
	// ds.setJdbcUrl("jdbc:oracle:thin:@127.0.0.1:1521:XE");
	// ds.setUsername("root");
	// ds.setPassword("root888");

	SqlBoxContext ctx = new SqlBoxContext(ds);
	SqlBoxContext.setDefaultContext(ctx);
	// ctx.setAllowShowSQL(true);

	String[] ddlArray = ctx.toDropAndCreateDDL(User.class);
	for (String ddl : ddlArray)
		ctx.quiteExecute(ddl);

	for (int i = 1; i <= 100; i++) {
		User u = new User();
		u.setFirstName("Foo" + i);
		u.setLastName("Bar" + i);
		u.setAge(i);
		u.insert();
	}
	Assert.assertEquals(100, ctx.nQueryForLongValue("select count(*) from users"));

	List<Map<String, Object>> users = ctx.nQueryForMapList(ctx.paginate(2, 10,
			"select concat(firstName, ' ', lastName) as USERNAME, age from users where age>?"), 50);

	Assert.assertEquals(10, users.size());

	for (Map<String, Object> map : users)
		System.out.println("UserName=" + map.get("USERNAME") + ", age=" + map.get("AGE"));

	ds.close();
}
 
开发者ID:drinkjava2,项目名称:jDialects,代码行数:56,代码来源:Demo.java


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