JavaBeans ( DataStage )

API は、が既存の Java コードにアクセスできるようにするをサポートします。 Java™ Integration stageJavaBeansJava Integration stage

は、以下の規則を想定しています。 Java Integration stageJavaBeans
  • このクラスには、パブリック・デフォルト・コンストラクター (引数なし) が必要です。
  • このクラスには、プロパティーごとに getter および setter が必要です。
では、以下のタイプの ・プロパティーがサポートされます。 JavaBeansJava Integration stage
  • Boolean/java.lang.Boolean
  • byte[]
  • short/java.lang.Short
  • int/java.lang.Integer
  • long/java.lang.Long
  • float/java.lang.Float
  • double/java.lang.Double
  • java.lang.String
  • java.math.BigInteger
  • java.math.BigDecimal
  • java.sql.Time
  • java.sql.Timestamp
  • java.sql.Date

以下の例は、入力リンクの samples.InputBean クラスと、出力リンクのsamples.OutputBean クラスを使用する方法を示しています。

JavaBeansTransformer.java
package samples;

import com.ibm.is.cc.javastage.api.*;

public class JavaBeansTransformer extends Processor
{
  private InputLink m_inputLink;
  private OutputLink m_outputLink;
  private OutputLink m_rejectLink;

  public Capabilities getCapabilities()
  {
    Capabilities capabilities = new Capabilities();
    // Set minimum number of input links to 1
    capabilities.setMinimumInputLinkCount(1);
    // Set maximum number of input links to 1
    capabilities.setMaximumInputLinkCount(1);
    // Set minimum number of output stream links to 1
    capabilities.setMinimumOutputStreamLinkCount(1);
    // Set maximum number of output stream links to 1
    capabilities.setMaximumOutputStreamLinkCount(1);
    // Set maximum number of reject links to 1
    capabilities.setMaximumRejectLinkCount(1);
    // Set is Wave Generator to false
    capabilities.setIsWaveGenerator(false);
    return capabilities;
  }

  public boolean validateConfiguration(
    Configuration configuration, boolean isRuntime)
    throws Exception
  {
    // Specify current link configurations.
    m_inputLink = configuration.getInputLink(0);
    m_outputLink = configuration.getOutputLink(0);
    if (configuration.getRejectLinkCount() == 1)
    {
      m_rejectLink = m_inputLink.getAssociatedRejectLink();
    }

    return true;
  }

  public void process() throws Exception
  {
    OutputRecord outputRecord = m_outputLink.getOutputRecord();

    // Loop until there is no more input data
    do
    {
      InputRecord record = m_inputLink.readRecord();
      if (record == null)
      {
        // End of data
        break;
      }

      // Get the object from the input row.
      InputBean inputBean = (InputBean) record.getObject();

      // Get the value from name column of the input link.
      // If the value contains "*" character, mark reject flag 
      // and send the record
      // to reject link in later proceessing.
      boolean fReject = false;
      String name = inputBean.getFirstName();
      if ((name == null) || (name.indexOf('*') >= 0))
      {
        fReject = true;
      }

      if (!fReject)
      {
        // Send record to output
        OutputBean outputBean = new OutputBean();
        outputBean.setEmpno(inputBean.getEmpno());
        outputBean.setFirstName(inputBean.getFirstName().toUpperCase());
        outputBean.setLastName(inputBean.getLastName().toUpperCase());
        outputBean.setHireDate(inputBean.getHireDate());
        outputBean.setEdLevel(inputBean.getEdLevel());
        outputBean.setSalary(inputBean.getSalary());
        outputBean.setBonus(inputBean.getBonus());
        outputBean.setLastUpdate(inputBean.getLastUpdate());
        outputRecord.putObject(outputBean);
        m_outputLink.writeRecord(outputRecord);
      }
      else if (m_rejectLink != null)
      {
        // Reject record.  This transfers the row to the reject link.
        // The same kind of forwarding is also possible for regular stream
        // links.
        RejectRecord rejectRecord = m_rejectLink.getRejectRecord(record);

        // Reject record can contain additional columns "ERRORTEXT" and "ERRORCODE".
        // The field will be shown as columns in rejected output records.
        rejectRecord.setErrorText("Name field contains *");
        rejectRecord.setErrorCode(123);
        m_rejectLink.writeRecord(rejectRecord);
      }
    }
    while (true);
  }
   
  public Class<InputBean> getBeanForInput(Link inputLink)
  {
    return InputBean.class;
  }

  public Class<OutputBean> getBeanForOutput(Link outputLink)
  {
    return OutputBean.class;
  }
}
InputBean.java

package samples;

import java.sql.Date;
import java.sql.Time;

public class InputBean
{
  private long      m_empno;
  private String    m_firstname;
  private String    m_lastname;
  private Date      m_hiredate;
  private int       m_edlevel;
  private Double    m_salary;
  private double    m_bonus;
  private Time      m_lastupdate;

  /**
   * Fetches the value of the empno field.
   *
   * @return long value of empno field
   */
  public long getEmpno()
  {
    return m_empno;
  }

  /**
   * Set the value of the empno field.
   *
   * @param empno value of the empno field.
   */
  public void setEmpno(long empno)
  {
    m_empno = empno;
  }

  /**
   * Fetches the value of the firstname field.
   *
   * @return String value of firstname field
   */
  public String getFirstName()
  {
    return m_firstname;
  }

  /**
   * Set the value of the firstname field.
   *
   * @param firstname value of the firstname field.
   */
  public void setFirstName(String firstname)
  {
    m_firstname = firstname;
  }

  /**
   * Fetches the value of the lastname field.
   *
   * @return String value of lastname field
   */
  public String getLastName()
  {
    return m_lastname;
  }

  /**
   * Set the value of the lastname field.
   *
   * @param lastname value of the lastname field.
   */
  public void setLastName(String lastname)
  {
    m_lastname = lastname;
  }

  /**
   * Fetches the value of the hiredate field.
   *
   * @return Date value of hiredate field
   */
  public Date getHireDate()
  {
    return m_hiredate;
  }

  /**
   * Set the value of the hiredate field.
   *
   * @param hiredate value of the hiredate field.
   */
  public void setHireDate(Date hiredate)
  {
    m_hiredate = hiredate;
  }

  /**
   * Fetches the value of the edlevel field.
   *
   * @return int value of edlevel field
   */
  public int getEdLevel()
  {
    return m_edlevel;
  }

  /**
   * Set the value of the edlevel field.
   *
   * @param edlevel value of the edlevel field.
   */
  public void setEdLevel(int edlevel)
  {
    m_edlevel = edlevel;
  }

  /**
   * Fetches the value of the salary field.
   *
   * @return Double value of salary field
   */
  public Double getSalary()
  {
    return m_salary;
  }

  /**
   * Set the value of the salary field.
   *
   * @param salary value of the salary field.
   */
  public void setSalary(Double salary)
  {
    m_salary = salary;
  }

  /**
   * Fetches the value of the bonus field.
   *
   * @return double value of bonus field
   */
  public double getBonus()
  {
    return m_bonus;
  }

  /**
   * Set the value of the bonus field.
   *
   * @param bonus value of the bonus field.
   */
  public void setBonus(double bonus)
  {
    m_bonus = bonus;
  }

  /**
   * Fetches the value of the lastupdate field.
   *
   * @return Time value of lastupdate field
   */
  public Time getLastUpdate()
  {
    return m_lastupdate;
  }

  /**
   * Set the value of the lastupdate field.
   *
   * @param lastupdate value of the lastupdate field.
   */
  public void setLastUpdate(Time lastupdate)
  {
    m_lastupdate = lastupdate;
  }
}
OutputBean.java

package samples;

import java.sql.Date;
import java.sql.Time;

public class OutputBean
{
  private long      m_empno;
  private String    m_firstname;
  private String    m_lastname;
  private Date      m_hiredate;
  private int       m_edlevel;
  private Double    m_salary;
  private double    m_bonus;
  private double    m_income;
  private Time      m_lastupdate;

  /**
   * Fetches the value of the empno field.
   *
   * @return long value of empno field
   */
  public long getEmpno()
  {
    return m_empno;
  }

  /**
   * Set the value of the empno field.
   *
   * @param empno value of the empno field.
   */
  public void setEmpno(long empno)
  {
    m_empno = empno;
  }

  /**
   * Fetches the value of the firstname field.
   *
   * @return String value of firstname field
   */
  public String getFirstName()
  {
    return m_firstname;
  }

  /**
   * Set the value of the firstname field.
   *
   * @param firstname value of the firstname field.
   */
  public void setFirstName(String firstname)
  {
    m_firstname = firstname;
  }

  /**
   * Fetches the value of the lastname field.
   *
   * @return String value of lastname field
   */
  public String getLastName()
  {
    return m_lastname;
  }

  /**
   * Set the value of the lastname field.
   *
   * @param lastname value of the lastname field.
   */
  public void setLastName(String lastname)
  {
    m_lastname = lastname;
  }

  /**
   * Fetches the value of the hiredate field.
   *
   * @return Date value of hiredate field
   */
  public Date getHireDate()
  {
    return m_hiredate;
  }

  /**
   * Set the value of the hiredate field.
   *
   * @param hiredate value of the hiredate field.
   */
  public void setHireDate(Date hiredate)
  {
    m_hiredate = hiredate;
  }

  /**
   * Fetches the value of the edlevel field.
   *
   * @return int value of edlevel field
   */
  public int getEdLevel()
  {
    return m_edlevel;
  }

  /**
   * Set the value of the edlevel field.
   *
   * @param edlevel value of the edlevel field.
   */
  public void setEdLevel(int edlevel)
  {
    m_edlevel = edlevel;
  }

  /**
   * Fetches the value of the salary field.
   *
   * @return Double value of salary field
   */
  public Double getSalary()
  {
    return m_salary;
  }

  /**
   * Set the value of the salary field.
   *
   * @param salary value of the salary field.
   */
  public void setSalary(Double salary)
  {
    m_salary = salary;
  }

  /**
   * Fetches the value of the bonus field.
   *
   * @return double value of bonus field
   */
  public double getBonus()
  {
    return m_bonus;
  }

  /**
   * Set the value of the bonus field.
   *
   * @param bonus value of the bonus field.
   */
  public void setBonus(double bonus)
  {
    m_bonus = bonus;
  }

  /**
   * Fetches the value of the lastupdate field.
   *
   * @return Time value of lastupdate field
   */
  public Time getLastUpdate()
  {
    return m_lastupdate;
  }

  /**
   * Set the value of the lastupdate field.
   *
   * @param lastupdate value of the lastupdate field.
   */
  public void setLastUpdate(Time lastupdate)
  {
    m_lastupdate = lastupdate;
  }
}
Javaコードでリンク上のレコード表現として JavaBeans を使用する場合は、 Processor クラスの getBeanForInput()getBeanforOutput() メソッドをオーバーライドする必要があります。 あなたのJavaコードは、各リンクに対応する JavaBeans クラスの java.lang.Class を返さなければならない。 は、初期化の時点でこれらのメソッドを呼び出します。 Java Integration stage
public Class<InputBean> getBeanForInput(Link inputLink)
{
  return InputBean.class;
}

public Class<OutputBean> getBeanForOutput(Link outputLink)
{
  return OutputBean.class;
入力リンクに対応する クラスは、によってインスタンス化でき、 Java コードは、 インターフェースの メソッドを呼び出すことによってこのインスタンスを取得できます。 JavaBeansJava Integration stagegetObject()InputLink
InputBean inputBean = (InputBean) record.getObject();

      
String name = inputBean.getFirstName();
      :
      :
Javaコードが, JavaBeans, に関連する出力リンクにレコードを書き込む前に,Javaコードは,出力リンクの JavaBeans オブジェクトをインスタンス化し,各Beanプロパティの値を設定しなければならない。 JavaBeans オブジェクトの型は、 getBeanForOutput() メソッドで指定された型と一致する必要がある。
 // Send record to output
 OutputBean outputBean = new OutputBean();
 outputBean.setEmpno(inputBean.getEmpno());
 outputBean.setFirstName(inputBean.getFirstName().toUpperCase());
 outputBean.setLastName(inputBean.getLastName().toUpperCase());
 outputBean.setHireDate(inputBean.getHireDate());
 outputBean.setEdLevel(inputBean.getEdLevel());
 outputBean.setSalary(inputBean.getSalary());
 outputBean.setBonus(inputBean.getBonus());
 outputBean.setLastUpdate(inputBean.getLastUpdate());
最後に、あなたのコードはOutputRecord インターフェイスの putObject(Object) メソッドを呼び出して、この JavaBeans オブジェクトを出力レコードに設定しなければならない。
outputRecord.putObject(outputBean);