com.zaxxer.hikari.util.DriverDataSource Java Examples

The following examples show how to use com.zaxxer.hikari.util.DriverDataSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JDBCRecordReader.java    From DataVec with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #2
Source File: JDBCRecordReader.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #3
Source File: ConsumerSchemaMeta.java    From syncer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public MetaDataBuilder(MysqlConnection connection,
                       HashMap<Consumer, ProducerSink> consumerSink) throws SQLException {
  this.consumerSink = consumerSink;
  Set<String> merged = consumerSink.keySet().stream().map(Consumer::getRepos)
      .flatMap(Set::stream).map(Repo::getConnectionName).collect(Collectors.toSet());
  calculatedSchemaName = getSchemaName(merged);
  jdbcUrl = connection.toConnectionUrl(calculatedSchemaName);
  dataSource = new DriverDataSource(jdbcUrl,
      Driver.class.getName(), new Properties(),
      connection.getUser(), connection.getPassword());
  dataSource.setLoginTimeout(TIMEOUT);
}
 
Example #4
Source File: ConsumerSchemaMeta.java    From syncer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static TableMeta tableMeta(MysqlConnection connection, String schema, String table) throws SQLException {
  String jdbcUrl = connection.toConnectionUrl(schema);
  DataSource dataSource = new DriverDataSource(jdbcUrl, Driver.class.getName(), new Properties(),
      connection.getUser(), connection.getPassword());
  Consumer single = Consumer.singleTable(schema, table);
  HashMap<Consumer, List<SchemaMeta>> res;
  try (Connection dataSourceConnection = dataSource.getConnection()) {
    DatabaseMetaData metaData = dataSourceConnection.getMetaData();
    try (ResultSet tableResultSet = metaData
        .getTables(schema, null, table, new String[]{"TABLE"})) {
      res = getSchemaMeta(metaData, tableResultSet, Sets.newHashSet(single));
    }
  }
  return res.get(single).get(0).findTable(schema, table);
}