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


Java DriverDataSource类代码示例

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


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

示例1: initialize

import com.zaxxer.hikari.util.DriverDataSource; //导入依赖的package包/类
/**
 * Initialize all required jdbc elements and make the reader ready for iteration.
 *
 * Possible configuration keys :
 * <ol>
 *     <li>JDBCRecordReader.TRIM_STRINGS : Whether or not read strings should be trimmed before being returned. False by default</li>
 *     <li>JDBCRecordReader.JDBC_URL : Jdbc url to use for datastource configuration (see JDBCRecordReaderTest for examples)</li>
 *     <li>JDBCRecordReader.JDBC_DRIVER_CLASS_NAME : Driver class to use for datasource configuration</li>
 *     <li>JDBCRecordReader.JDBC_USERNAME && JDBC_PASSWORD : Username and password to use for datasource configuration</li>
 *     <li>JDBCRecordReader.JDBC_RESULTSET_TYPE : ResultSet type to use (int value defined in jdbc doc)</li>
 * </ol>
 *
 * Url and driver class name are not mandatory. If one of them is specified, the other must be specified as well. If
 * they are set and there already is a DataSource set in the reader, it will be discarded and replaced with the
 * newly created one.
 *
 * @param conf a configuration for initialization
 * @param split not handled yet, will be discarded
 */
@Override
public void initialize(Configuration conf, InputSplit split) throws IOException, InterruptedException {
    this.setConf(conf);
    this.setTrimStrings(conf.getBoolean(TRIM_STRINGS, trimStrings));
    this.setResultSetType(conf.getInt(JDBC_RESULTSET_TYPE, resultSetType));

    String jdbcUrl = conf.get(JDBC_URL);
    String driverClassName = conf.get(JDBC_DRIVER_CLASS_NAME);
    // url and driver must be both unset or both present
    if (jdbcUrl == null ^ driverClassName == null) {
        throw new IllegalArgumentException(
            "Both jdbc url and driver class name must be provided in order to configure JDBCRecordReader's datasource");
    }
    // Both set, initialiaze the datasource
    else if (jdbcUrl != null) {
        // FIXME : find a way to read wildcard properties from conf in order to fill the third argument bellow
        this.dataSource = new DriverDataSource(jdbcUrl, driverClassName, new Properties(), conf.get(JDBC_USERNAME),
            conf.get(JDBC_PASSWORD));
    }
    this.initializeJdbc();
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:41,代码来源:JDBCRecordReader.java

示例2: close

import com.zaxxer.hikari.util.DriverDataSource; //导入依赖的package包/类
/**
 * Shutdown the DataSource and its associated pool.
 */
@Override
public void close()
{
   if (isShutdown.getAndSet(true)) {
      return;
   }

   if (pool != null) {
      try {
         pool.shutdown();
      }
      catch (InterruptedException e) {
     	 LOGGER.warn("Interrupted during closing", e);
      }

      if (pool.getDataSource() instanceof DriverDataSource) {
         ((DriverDataSource) pool.getDataSource()).shutdown();
      }
   }
}
 
开发者ID:openbouquet,项目名称:HikariCP,代码行数:24,代码来源:HikariDataSource.java

示例3: driverTest1

import com.zaxxer.hikari.util.DriverDataSource; //导入依赖的package包/类
@Test
public void driverTest1() throws SQLException
{
   HikariConfig config = new HikariConfig();
   config.setMinimumIdle(1);
   config.setMaximumPoolSize(1);
   config.setConnectionTestQuery("VALUES 1");
   config.setDriverClassName("com.zaxxer.hikari.mocks.StubDriver");
   config.setJdbcUrl("jdbc:stub");
   config.addDataSourceProperty("user", "bart");
   config.addDataSourceProperty("password", "simpson");

   ds = new HikariDataSource(config);

   Assert.assertTrue(ds.isWrapperFor(DriverDataSource.class));

   DriverDataSource unwrap = ds.unwrap(DriverDataSource.class);
   Assert.assertNotNull(unwrap);

   Connection connection = ds.getConnection();
   connection.close();
}
 
开发者ID:openbouquet,项目名称:HikariCP,代码行数:23,代码来源:JdbcDriverTest.java

示例4: testDerbyDriverDataSource

import com.zaxxer.hikari.util.DriverDataSource; //导入依赖的package包/类
@Test
public void testDerbyDriverDataSource() throws SQLException {
    BQRuntime runtime = testFactory.app("-c", "classpath:HikariCPDerbyIT.yml")
            .autoLoadModules()
            .createRuntime();

    DataSource ds5 = runtime.getInstance(DataSourceFactory.class).forName("derby5");
    assertNotNull(ds5);
    assertTrue(ds5 instanceof HikariDataSource);

    HikariDataSource hikariDS = (HikariDataSource) ds5;

    assertEquals("org.apache.derby.jdbc.EmbeddedDriver", hikariDS.getDriverClassName());

    HikariPool pool = (HikariPool) hikariDS.getHikariPoolMXBean();

    assertTrue(pool.getUnwrappedDataSource() instanceof DriverDataSource);

    try (Connection c = hikariDS.getConnection()) {
        assertEquals("jdbc:derby:", c.getMetaData().getURL());
    }
}
 
开发者ID:bootique,项目名称:bootique-jdbc,代码行数:23,代码来源:HikariCPDerbyIT.java


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