Exemplo n.º 1
0
  /**
   * Configures this JDBCOutputFormat.
   *
   * @param parameters Configuration containing all parameters.
   */
  @Override
  public void configure(Configuration parameters) {
    this.driverName = parameters.getString(DRIVER_KEY, null);
    this.username = parameters.getString(USERNAME_KEY, null);
    this.password = parameters.getString(PASSWORD_KEY, null);
    this.dbURL = parameters.getString(URL_KEY, null);
    this.query = parameters.getString(QUERY_KEY, null);
    this.fieldCount = parameters.getInteger(FIELD_COUNT_KEY, 0);
    this.batchInterval = parameters.getInteger(BATCH_INTERVAL, DEFAULT_BATCH_INTERVERAL);

    @SuppressWarnings("unchecked")
    Class<Value>[] classes = new Class[this.fieldCount];
    this.fieldClasses = classes;

    for (int i = 0; i < this.fieldCount; i++) {
      @SuppressWarnings("unchecked")
      Class<? extends Value> clazz =
          (Class<? extends Value>) parameters.getClass(FIELD_TYPE_KEY + i, null);
      if (clazz == null) {
        throw new IllegalArgumentException(
            "Invalid configuration for JDBCOutputFormat: " + "No type class for parameter " + i);
      }
      this.fieldClasses[i] = clazz;
    }
  }
Exemplo n.º 2
0
  @Override
  public void configure(Configuration parameters) {
    super.configure(parameters);

    // get the charset for the decoding
    String charsetName = parameters.getString(CHARSET_NAME, DEFAULT_CHARSET_NAME);
    if (charsetName == null || !Charset.isSupported(charsetName)) {
      throw new RuntimeException("Unsupported charset: " + charsetName);
    }

    if (charsetName.equals("ISO-8859-1") || charsetName.equalsIgnoreCase("ASCII")) {
      this.ascii = true;
    } else {
      this.decoder = Charset.forName(charsetName).newDecoder();
      this.byteWrapper = ByteBuffer.allocate(1);
    }

    // get the field position to write in the record
    this.pos = parameters.getInteger(FIELD_POS, 0);
    if (this.pos < 0) {
      throw new RuntimeException(
          "Illegal configuration value for the target position: " + this.pos);
    }
  }