org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl#org.h2.jdbcx.JdbcDataSource源码实例Demo

下面列出了org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl#org.h2.jdbcx.JdbcDataSource 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: JImageHash   文件: DatabaseManager.java
public DatabaseManager(String subPath, String username, String password) throws SQLException {
	// Setup database connection
	JdbcDataSource ds = new JdbcDataSource();
	ds.setURL("jdbc:h2:" + subPath);
	ds.setUser(username);
	ds.setPassword(password);
	conn = ds.getConnection();

	createTables();

	prepareStatements();

	// Make sure to release the database at shutdown. lose connection
	Runtime.getRuntime().addShutdownHook(new Thread(() -> {
		try {
			if (!conn.isClosed()) {
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}));

}
 
源代码2 项目: Spring5Tutorial   文件: Main.java
public static void main(String[] args) throws IOException {
    Properties prop = new Properties();
    prop.load(Main.class.getClassLoader().getResourceAsStream("jdbc.properties"));        
    
    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL(prop.getProperty("cc.openhome.jdbcUrl"));
    dataSource.setUser(prop.getProperty("cc.openhome.user"));
    dataSource.setPassword(prop.getProperty("cc.openhome.password"));
    
    AccountDAO acctDAO = new AccountDAOJdbcImpl(dataSource);
    MessageDAO messageDAO = new MessageDAOJdbcImpl(dataSource);
    
    UserService userService = new UserService(acctDAO, messageDAO);
    
    userService.messages("caterpillar")
               .forEach(message -> {
                   System.out.printf("%s\t%s%n",
                       message.getLocalDateTime(),
                       message.getBlabla());
               });

}
 
源代码3 项目: syndesis   文件: JsonDBTest.java
@BeforeAll
public void before() {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test1;DB_CLOSE_DELAY=-1;MODE=PostgreSQL");
    DBI dbi = new DBI(ds);

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

    try {
        this.jsondb.dropTables();
    } catch (Exception e) {
    }
    this.jsondb.createTables();
}
 
/**
 * 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;
}
 
源代码5 项目: homework_tester   文件: DBServiceImpl.java
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;
}
 
源代码6 项目: digdag   文件: DataSourceProvider.java
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;
}
 
源代码7 项目: stepic_java_webserver   文件: DBService.java
public 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;
}
 
源代码8 项目: rxjava-jdbc   文件: DatabaseViaDataSourceTest.java
private static DataSource initDataSource() {
    JdbcDataSource dataSource = new JdbcDataSource();
    String dbUrl = DatabaseCreator.nextUrl();
    dataSource.setURL(dbUrl);

    String jndiName = "jdbc/RxDS";

    try {
        Context context = new InitialContext();
        context.rebind(jndiName, dataSource);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }

    return dataSource;
}
 
public static JdbcDataSource getJdbcDataSource(String initScriptLocation) {
    Validate.notEmpty(initScriptLocation, "initScriptLocation is empty");

    String mavenRelativePath = "src/main/resources/" + initScriptLocation;
    String mavenRootRelativePath = "camel-cookbook-transactions/" + mavenRelativePath;

    // check that we can load the init script
    FileLocator locator = new FileLocator().with(initScriptLocation).with(mavenRelativePath).with(mavenRootRelativePath);
    File file = locator.find();
    Validate.notNull(file, locator.getErrorMessage());
    FileSystemResource script = new FileSystemResource(file);

    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1");
    dataSource.setUser("sa");
    dataSource.setPassword("");

    DataSourceInitializer.initializeDataSource(dataSource, script);

    return dataSource;
}
 
源代码10 项目: jqm   文件: DbConfig.java
@Bean
public DataSource dataSource()
{
    try
    {
        // When running inside a container, use its resource directory.
        return (DataSource) new JndiTemplate().lookup("jdbc/spring_ds");
    }
    catch (NamingException e)
    {
        // When running on the command line, just create a temporary file DB (only needed for debug).
        System.out.println("JNDI datasource does not exist - falling back on hard coded DS");
        JdbcDataSource ds = new JdbcDataSource();
        ds.setURL("jdbc:h2:./target/TEST.db");
        ds.setUser("sa");
        ds.setPassword("sa");
        return ds;
    }
}
 
源代码11 项目: journalkeeper   文件: H2DataSourceFactory.java
@Override
public DataSource createDataSource(Path path, Properties properties) {
    String url = properties.getProperty(H2Configs.DATASOURCE_URL);
    if (StringUtils.isBlank(url)) {
        url = String.format("jdbc:h2:file:%s/data;AUTO_SERVER=TRUE;MVCC=TRUE;LOCK_TIMEOUT=30000", path.toString());
    }
    JdbcDataSource datasource = new JdbcDataSource();
    datasource.setURL(url);
    return datasource;
}
 
private static DataSource dataSource() {
  JdbcDataSource jdbcDataSource = new JdbcDataSource();
  jdbcDataSource.setUrl("jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
  jdbcDataSource.setUser("sa");
  jdbcDataSource.setPassword("");
  return jdbcDataSource;
}
 
源代码13 项目: presto   文件: H2DaoProvider.java
@Inject
public H2DaoProvider(DbResourceGroupConfig config)
{
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL(requireNonNull(config.getConfigDbUrl(), "resource-groups.config-db-url is null"));
    // TODO: this should use onDemand()
    this.dao = Jdbi.create(ds)
            .installPlugin(new SqlObjectPlugin())
            .open()
            .attach(H2ResourceGroupsDao.class);
}
 
private DataSource createDataSource(String jdbcUrl, String jdbcUsername, String jdbcPassword) {
  JdbcDataSource ds = new JdbcDataSource();
  ds.setURL(jdbcUrl);
  ds.setUser(jdbcUsername);
  ds.setPassword(jdbcPassword);
  return ds;
}
 
源代码15 项目: Spring5Tutorial   文件: AppConfig.java
@Bean
public DataSource getDataSource() {
    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL(jdbcUrl);
    dataSource.setUser(user);
    dataSource.setPassword(password);
    return dataSource;
}
 
源代码16 项目: Spring5Tutorial   文件: Service.java
public static UserService getUserService() throws IOException {
	Properties prop = new Properties();
	prop.load(Main.class.getClassLoader().getResourceAsStream("jdbc.properties"));		
	
	JdbcDataSource dataSource = new JdbcDataSource();
       dataSource.setURL(prop.getProperty("cc.openhome.jdbcUrl"));
       dataSource.setUser(prop.getProperty("cc.openhome.user"));
       dataSource.setPassword(prop.getProperty("cc.openhome.password"));
       
       AccountDAO acctDAO = new AccountDAOJdbcImpl(dataSource);
       MessageDAO messageDAO = new MessageDAOJdbcImpl(dataSource);
       
       UserService userService = new UserService(acctDAO, messageDAO);
	return userService;
}
 
源代码17 项目: Spring5Tutorial   文件: AppConfig.java
@Profile("dev")
@Bean
public DataSource getDataSource() {
    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL(jdbcUrl);
    dataSource.setUser(user);
    dataSource.setPassword(password);
    
    return dataSource;
}
 
源代码18 项目: Spring5Tutorial   文件: AppConfig.java
@Bean
public DataSource getDataSource() {
    JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:tcp://localhost/c:/workspace/SpringDI/gossip");
    dataSource.setUser("caterpillar");
    dataSource.setPassword("12345678");
    return dataSource;
}
 
源代码19 项目: metanome-algorithms   文件: JdbcTest.java
private static DataSource getDataSource() {
	JdbcDataSource dataSource = new JdbcDataSource();
	dataSource.setURL(JDBC_URL);
	dataSource.setUser(USER);
	dataSource.setPassword(PASSWORD);
	return dataSource;
}
 
源代码20 项目: syndesis   文件: MetricsCollectorTest.java
@Before
public void before() throws IOException, ParseException {
    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();

    jsondbRM = new JsonDBRawMetrics(jsondb);

    load();

    CacheManager cacheManager = new LRUCacheManager(100);
    EncryptionComponent encryptionComponent = new EncryptionComponent(null);
    ResourceLoader resourceLoader = new DefaultResourceLoader();
    //Create Data Manager
    dataManager = new DataManager(cacheManager, Collections.emptyList(), null, encryptionComponent, resourceLoader, null);
    intMH = new IntegrationMetricsHandler(dataManager);
}
 
源代码21 项目: syndesis   文件: ActivityTrackingControllerTest.java
@Before
public void before() {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:t;DB_CLOSE_DELAY=-1;MODE=PostgreSQL");
    this.dbi = new DBI(ds);
    this.jsondb = new SqlJsonDB(dbi, null);
    this.jsondb.createTables();

    client = mock(KubernetesClient.class);
    when(client.getConfiguration()).thenReturn(new ConfigBuilder().withMasterUrl("http://master").build());
}
 
源代码22 项目: syndesis   文件: MemorySqlJsonDB.java
public static CloseableJsonDB create(Collection<Index> indexes) {
    JdbcDataSource ds = new JdbcDataSource();
    DBI dbi = new DBI(ds);
    ds.setURL("jdbc:h2:mem:"+ KeyGenerator.createKey()+";MODE=PostgreSQL");
    try {
        Connection keepsDBOpen = ds.getConnection();
        ClosableSqlJsonDB result = new ClosableSqlJsonDB(keepsDBOpen, dbi, indexes);
        result.createTables();
        return result;
    } catch (SQLException e) {
        throw new JsonDBException(e);
    }
}
 
源代码23 项目: crnk-framework   文件: JpaTestConfig.java
@Bean
public DataSource testDataSource() {
	JdbcDataSource dataSource = new JdbcDataSource();
	dataSource.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE");
	dataSource.setUser("sa");
	return dataSource;
}
 
源代码24 项目: crnk-framework   文件: OperationsTestConfig.java
@Bean
public DataSource testDataSource() {
	JdbcDataSource dataSource = new JdbcDataSource();
	dataSource.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE");
	dataSource.setUser("sa");
	return dataSource;
}
 
源代码25 项目: spring-boot-inside   文件: MyDataSourceConfig.java
@Bean(name = "dataSource1")
public DataSource dataSource1(@Value("${db.user}") String user) {
	System.err.println("user: " + user);
	JdbcDataSource ds = new JdbcDataSource();
	ds.setURL("jdbc:h2:˜/test");
	ds.setUser(user);
	return ds;
}
 
源代码26 项目: gradle-plugins   文件: LiquibaseSchemaTarget.java
private Connection setupDataSource(File file) throws SQLException, IOException {
	JdbcDataSource dataSource = new JdbcDataSource();
	dataSource.setUrl("jdbc:h2:mem:test");
	String script = FileUtils.readAsString(file);
	Connection connection = dataSource.getConnection();
	SqlUtils.executeSql(connection, script, ";");
	return connection;

}
 
源代码27 项目: Plan   文件: H2DB.java
private Connection getConnectionFor(String dbFilePath) throws SQLException {
    String username = config.get(DatabaseSettings.H2_USER);
    String password = config.get(DatabaseSettings.H2_PASS);

    JdbcDataSource jdbcDataSource = new JdbcDataSource();
    jdbcDataSource.setURL("jdbc:h2:file:" + dbFilePath + ";mode=MySQL;DATABASE_TO_UPPER=false");
    jdbcDataSource.setUser(username);
    jdbcDataSource.setPassword(password);

    return jdbcDataSource.getConnection();
}
 
源代码28 项目: enkan   文件: DomaEntityTaskTest.java
@Test
void test() throws Exception {
    JdbcDataSource ds = new JdbcDataSource();
    ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
    createTable(ds);
    DomaEntityTask task = new DomaEntityTask("example/entity", "product", ds);
    PathResolverMock resolver = new PathResolverMock();
    task.execute(resolver);
}
 
源代码29 项目: katharsis-framework   文件: TestConfig.java
@Bean
public DataSource testDataSource() {
	JdbcDataSource dataSource = new JdbcDataSource();
	dataSource.setUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE");
	dataSource.setUser("sa");
	return dataSource;
}
 
源代码30 项目: shardingsphere   文件: DataSourceSwapperTest.java
private void assertResult(final XADataSource xaDataSource) {
    assertThat(xaDataSource, instanceOf(JdbcDataSource.class));
    JdbcDataSource h2XADataSource = (JdbcDataSource) xaDataSource;
    assertThat(h2XADataSource.getUrl(), is("jdbc:mysql://localhost:3306/demo_ds"));
    assertThat(h2XADataSource.getUser(), is("root"));
    assertThat(h2XADataSource.getPassword(), is("root"));
}