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


Java JdbcDataSource类代码示例

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


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

示例1: before

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
@Before
public void before() {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=PostgreSQL");
    DBI dbi = new DBI(ds);

    this.jsondb = new SqlJsonDB(dbi, null,
        Arrays.asList(new Index("/pair", "key"))
    );

    try {
        this.jsondb.dropTables();
    } catch (Exception e) {
    }
    this.jsondb.createTables();
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:17,代码来源:JsonDBTest.java

示例2: initDb

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
@BeforeClass
public static void initDb() throws SQLException {
    ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:estest;DB_CLOSE_DELAY=-1;MVCC=true");
    ds.setUser("sa");
    try (Connection con = ds.getConnection()) {
        executeSql(
            con,
            "create table event (ID varchar, VERSION int, TIMESTAMP timestamp, TYPE varchar, PAYLOAD_VERSION int, PAYLOAD clob, primary key (ID, VERSION))",
            " create table version (ID varchar, VERSION int)",
            " create table snapshot(ID varchar primary key, VERSION int, TIMESTAMP timestamp, PAYLOAD_VERSION int, PAYLOAD clob)",
            // we will not use primary key check to escalate optimistic lock exception in very last step
            "create table event_collision (ID varchar, VERSION int, TIMESTAMP timestamp, TYPE varchar, PAYLOAD_VERSION int, PAYLOAD clob)");
    }
    template = new JdbcTemplate(ds);
}
 
开发者ID:goodees,项目名称:goodees,代码行数:17,代码来源:JdbcTest.java

示例3: builderWithDataSource

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
@Test
public void builderWithDataSource() throws Exception {
	JdbcDataSource ds = new JdbcDataSource();
	ds.setURL("jdbc:h2:mem:SqlAgentTest");

	SqlConfig config = UroboroSQL.builder(ds).build();
	try (SqlAgent agent = config.agent()) {
		String[] sqls = new String(Files.readAllBytes(Paths.get("src/test/resources/sql/ddl/create_tables.sql")),
				StandardCharsets.UTF_8).split(";");
		for (String sql : sqls) {
			if (StringUtils.isNotBlank(sql)) {
				agent.updateWith(sql.trim()).count();
			}
		}

		insert(agent, Paths.get("src/test/resources/data/setup", "testExecuteQuery.ltsv"));
		agent.rollback();
	}

	assertEquals(new H2Dialect().getName(), config.getDialect().getName());
}
 
开发者ID:future-architect,项目名称:uroborosql,代码行数:22,代码来源:UroboroSQLTest.java

示例4: BlockDbH2Impl

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
/**
 * the constructor.
 *
 * @param config
 *            the configuration to use.
 */
public BlockDbH2Impl(final JSONObject config) {
	try (InputStream resourceAsStream = BlockDbH2Impl.class.getResourceAsStream(SQL_CACHE_XML);) {
		final String jsonStr = IOUtils.toString(resourceAsStream, "UTF-8");
		sqlCache = XML.toJSONObject(jsonStr, true).getJSONObject("BlockDbImpl");
	} catch (final IOException | NullPointerException e) {
		throw new RuntimeException("error reading resource\"" + SQL_CACHE_XML + "\" ", e);
	}

	fileSizeDir = new File(config.getString(ConfigurationUtil.FILE_SIZE_DIR));

	ds = new JdbcDataSource();
	ds.setUrl(config.getString(ConfigurationUtil.URL));

	final JdbcTemplate t = new JdbcTemplate(ds);

	executeSqlGroup(t, "create");
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:24,代码来源:BlockDbH2Impl.java

示例5: createDataSource

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
/**
 * Creates a basic data source.
 *
 * @param properties the properties for the data source.
 * @throws SQLException if unsupported properties are supplied, or if data
 *             source can not be created.
 * @return a new data source.
 */
@Override
public DataSource createDataSource(Properties properties)
        throws SQLException {
    // Make copy of properties
    Properties propertiesCopy = new Properties();
    if (properties != null) {
        propertiesCopy.putAll(properties);
    }

    // Verify that no unsupported standard options are used
    rejectUnsupportedOptions(propertiesCopy);

    // Standard pool properties in OSGi not applicable here
    rejectPoolingOptions(propertiesCopy);

    JdbcDataSource dataSource = new JdbcDataSource();

    setupH2DataSource(dataSource, propertiesCopy);

    return dataSource;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:30,代码来源:OsgiDataSourceFactory.java

示例6: createConnectionPoolDataSource

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
/**
 * Creates a pooled data source.
 *
 * @param properties the properties for the data source.
 * @throws SQLException if unsupported properties are supplied, or if data
 *             source can not be created.
 * @return a new data source.
 */
@Override
public ConnectionPoolDataSource createConnectionPoolDataSource(
        Properties properties) throws SQLException {
    // Make copy of properties
    Properties propertiesCopy = new Properties();
    if (properties != null) {
        propertiesCopy.putAll(properties);
    }

    // Verify that no unsupported standard options are used
    rejectUnsupportedOptions(propertiesCopy);

    // The integrated connection pool is H2 is not configurable
    rejectPoolingOptions(propertiesCopy);

    JdbcDataSource dataSource = new JdbcDataSource();

    setupH2DataSource(dataSource, propertiesCopy);

    return dataSource;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:30,代码来源:OsgiDataSourceFactory.java

示例7: createXADataSource

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
/**
 * Creates a pooled XA data source.
 *
 * @param properties the properties for the data source.
 * @throws SQLException if unsupported properties are supplied, or if data
 *             source can not be created.
 * @return a new data source.
 */
@Override
public XADataSource createXADataSource(Properties properties)
        throws SQLException {
    // Make copy of properties
    Properties propertiesCopy = new Properties();
    if (properties != null) {
        propertiesCopy.putAll(properties);
    }

    // Verify that no unsupported standard options are used
    rejectUnsupportedOptions(propertiesCopy);

    // The integrated connection pool is H2 is not configurable
    rejectPoolingOptions(propertiesCopy);

    JdbcDataSource dataSource = new JdbcDataSource();

    setupH2DataSource(dataSource, propertiesCopy);

    return dataSource;
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:30,代码来源:OsgiDataSourceFactory.java

示例8: testMixedXaNormal

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
private void testMixedXaNormal() throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test");
    ds.setUser("sa");
    ds.setPassword("");
    XAConnection xa = ds.getXAConnection();
    Connection c = xa.getConnection();
    assertTrue(c.getAutoCommit());
    MyXid xid = new MyXid();
    XAResource res = xa.getXAResource();

    res.start(xid, XAResource.TMNOFLAGS);
    assertTrue(!c.getAutoCommit());
    res.end(xid, XAResource.TMSUCCESS);
    res.commit(xid, true);
    assertTrue(c.getAutoCommit());

    res.start(xid, XAResource.TMNOFLAGS);
    assertTrue(!c.getAutoCommit());
    res.end(xid, XAResource.TMFAIL);
    res.rollback(xid);
    assertTrue(c.getAutoCommit());

    c.close();
    xa.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:27,代码来源:TestXA.java

示例9: testDataSource

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
private void testDataSource() throws SQLException {
    deleteDb("dataSource");
    JdbcDataSource ds = new JdbcDataSource();
    PrintWriter p = new PrintWriter(new StringWriter());
    ds.setLogWriter(p);
    assertTrue(p == ds.getLogWriter());
    ds.setURL(getURL("dataSource", true));
    ds.setUser(getUser());
    ds.setPassword(getPassword());
    Connection conn;
    conn = ds.getConnection();
    Statement stat;
    stat = conn.createStatement();
    stat.execute("SELECT * FROM DUAL");
    conn.close();
    conn = ds.getConnection(getUser(), getPassword());
    stat = conn.createStatement();
    stat.execute("SELECT * FROM DUAL");
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:20,代码来源:TestDataSource.java

示例10: DLNAMediaDatabase

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
public DLNAMediaDatabase(String name) {
	dbName = name;
	File profileFolder = new File(configuration.getProfileFolder());
	dbDir = new File(profileFolder.isDirectory() ? profileFolder : null, "database").getAbsolutePath();
	boolean logDB = configuration.getDatabaseLogging();
	url = Constants.START_URL + dbDir + File.separator + dbName + (logDB ? ";TRACE_LEVEL_FILE=4" : "");
	LOGGER.debug("Using database URL: {}", url);
	LOGGER.info("Using database located at: \"{}\"", dbDir);
	if (logDB) {
		LOGGER.info("Database logging is enabled");
	} else if (LOGGER.isDebugEnabled()) {
		LOGGER.debug("Database logging is disabled");
	}

	try {
		Class.forName("org.h2.Driver");
	} catch (ClassNotFoundException e) {
		LOGGER.error(null, e);
	}

	JdbcDataSource ds = new JdbcDataSource();
	ds.setURL(url);
	ds.setUser("sa");
	ds.setPassword("");
	cp = JdbcConnectionPool.create(ds);
}
 
开发者ID:DigitalMediaServer,项目名称:DigitalMediaServer,代码行数:27,代码来源:DLNAMediaDatabase.java

示例11: configs

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
@Parameterized.Parameters
    public static Collection<Object[]> configs() {
        EmbeddedDataSource derbyDs = new EmbeddedDataSource();
        derbyDs.setDatabaseName("test");
        derbyDs.setCreateDatabase("create");

        JdbcDataSource h2Ds = new JdbcDataSource();
        h2Ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=PostgreSQL");

        // Tests on postgres disabled

//        PGPoolingDataSource postgresDs = new PGPoolingDataSource();
//        postgresDs.setServerName("localhost");
//        postgresDs.setDatabaseName("syndesis");
//        postgresDs.setUser("postgres");
//        postgresDs.setPassword("password");

        return Arrays.asList(new Object[][]{
            {derbyDs},
//            {postgresDs},
            {h2Ds}
        });
    }
 
开发者ID:syndesisio,项目名称:syndesis-rest,代码行数:24,代码来源:SqlFileStoreTest.java

示例12: createDatabase

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
/**
 * To create certificate management database.
 *
 * @return Datasource.
 * @throws SQLException SQL Exception.
 */
private DataSource createDatabase() throws SQLException {
    URL resourceURL = ClassLoader.getSystemResource("sql-scripts" + File.separator + "h2.sql");
    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:cert;DB_CLOSE_DELAY=-1");
    dataSource.setUser("sa");
    dataSource.setPassword("sa");
    final String LOAD_DATA_QUERY = "RUNSCRIPT FROM '" + resourceURL.getPath() + "'";
    Connection conn = null;
    Statement statement = null;
    try {
        conn = dataSource.getConnection();
        statement = conn.createStatement();
        statement.execute(LOAD_DATA_QUERY);
    } finally {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {}
        }
        if (statement != null) {
            statement.close();
        }
    }
    return dataSource;
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:32,代码来源:CertificateAuthenticatorTest.java

示例13: getH2Connection

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
private static Connection getH2Connection() {
    try {
        String url = "jdbc:h2:./h2db";
        String name = "tully";
        String pass = "tully";

        JdbcDataSource ds = new JdbcDataSource();
        ds.setURL(url);
        ds.setUser(name);
        ds.setPassword(pass);

        Connection connection = DriverManager.getConnection(url, name, pass);
        return connection;
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:vitaly-chibrikov,项目名称:homework_tester,代码行数:19,代码来源:DBServiceImpl.java

示例14: before

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
@Override
public void before() throws Throwable {
    // Set up JMS from super
    super.before();
    log.info("+++ BEFORE on JUnit Rule '" + id(Rule_MatsWithDb.class) + "', H2 database:");
    log.info("Setting up H2 database using DB URL [" + H2_DATABASE_URL + "], dropping all objects.");
    // Set up H2 Database
    _dataSource = new JdbcDataSource();
    _dataSource.setURL(H2_DATABASE_URL);
    try {
        try (Connection con = _dataSource.getConnection();
                Statement stmt = con.createStatement();) {
            stmt.execute("DROP ALL OBJECTS DELETE FILES");
        }
    }
    catch (SQLException e) {
        throw new RuntimeException("Got problems running 'DROP ALL OBJECTS DELETE FILES'.", e);
    }
    log.info("--- BEFORE done! JUnit Rule '" + id(Rule_MatsWithDb.class) + "', H2 database.");
}
 
开发者ID:stolsvik,项目名称:mats,代码行数:21,代码来源:Rule_MatsWithDb.java

示例15: createSimpleDataSource

import org.h2.jdbcx.JdbcDataSource; //导入依赖的package包/类
private void createSimpleDataSource()
{
    String url = DatabaseConfig.buildJdbcUrl(config);

    // By default, H2 closes database when all of the connections are closed. When database
    // is closed, data is gone with in-memory mode. It's unexpected. However, if here disables
    // that such behavior using DB_CLOSE_DELAY=-1 option, there're no methods to close the
    // database explicitly. Only way to close is to not disable shutdown hook of H2 database
    // (DB_CLOSE_ON_EXIT=TRUE). But this also causes unexpected behavior when PreDestroy is
    // triggered in a shutdown hook. Therefore, here needs to rely on injector to take care of
    // dependencies so that the database is closed after calling all other PreDestroy methods
    // that depend on this DataSourceProvider.
    // To solve this issue, here holds one Connection until PreDestroy.
    JdbcDataSource ds = new JdbcDataSource();
    ds.setUrl(url + ";DB_CLOSE_ON_EXIT=FALSE");

    logger.debug("Using database URL {}", url);

    try {
        this.closer = ds.getConnection();
    }
    catch (SQLException ex) {
        throw Throwables.propagate(ex);
    }
    this.ds = ds;
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:27,代码来源:DataSourceProvider.java


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