All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.knowm.yank.handlers.LongColumnListHandler Maven / Gradle / Ivy

package org.knowm.yank.handlers;

import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.commons.dbutils.handlers.ColumnListHandler;

public class LongColumnListHandler extends ColumnListHandler {

  /** The column number to retrieve. */
  private final int columnIndex;

  /** The column name to retrieve. Either columnName or columnIndex will be used but never both. */
  private final String columnName;

  /**
   * Creates a new instance of ColumnListHandler. The first column of each row will be returned from
   * handle().
   */
  public LongColumnListHandler() {
    this(1, null);
  }

  /**
   * Creates a new instance of ColumnListHandler.
   *
   * @param columnIndex The index of the column to retrieve from the ResultSet.
   */
  public LongColumnListHandler(int columnIndex) {
    this(columnIndex, null);
  }

  /**
   * Creates a new instance of ColumnListHandler.
   *
   * @param columnName The name of the column to retrieve from the ResultSet.
   */
  public LongColumnListHandler(String columnName) {
    this(1, columnName);
  }

  /**
   * Private Helper
   *
   * @param columnIndex The index of the column to retrieve from the ResultSet.
   * @param columnName The name of the column to retrieve from the ResultSet.
   */
  private LongColumnListHandler(int columnIndex, String columnName) {
    super();
    this.columnIndex = columnIndex;
    this.columnName = columnName;
  }

  /**
   * Returns one ResultSet column value as Object.
   *
   * @param rs ResultSet to process.
   * @return Object, never null.
   * @throws SQLException if a database access error occurs
   * @throws ClassCastException if the class datatype does not match the column type
   * @see org.apache.commons.dbutils.handlers.AbstractListHandler#handle(ResultSet)
   */
  @Override
  protected Long handleRow(ResultSet rs) throws SQLException {
    if (this.columnName == null) {
      return rs.getLong(this.columnIndex);
    }
    return rs.getLong(this.columnName);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy