0 / 0
Writing Records to Output Link (Java Integration stage)

Writing Records to Output Link (Java Integration stage)

To write records to output link, your Java™ code needs to instantiate an OutputRecord object by using the getOutputRecord() method of the OutputLink interface.

The following example shows the simple transformer stage implementations that converts string texts in the consumed record to upper case, and then write it to an output link.
package samples;

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

public class ToUpperTransformer extends Processor
{
  private InputLink m_inputLink;
  private OutputLink m_outputLink;

  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(0);
    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);

     return true;
  }

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

    do
    {
      InputRecord inputRecord = m_inputLink.readRecord();
      if (inputRecord == null)
      {
        // No more input
        break;
      }
      
      for (int i = 0; i < m_inputLink.getColumnCount(); i++)
      {
        Object value = inputRecord.getValue(columnIndex);
        if (value instanceof String)
        {
          String str = (String)value;
          value = str.toUpperCase();
        }
        outputRecord.setValue(i, value);
      }
      m_outputLink.writeRecord(outputRecord);
    }
    while (true);
  }
}
To write records to an output link, your Java code needs to instantiate an OutputRecord object by using the getOutputRecord() method of the OutputLink interface.
OutputRecord outputRecord = m_outputLink.getOutputRecord();
Methods provided by OutputRecord interface
  • putObject()
  • setValue(String columnName, Object value)
  • setValue(int columnIndex, Object value)
  • setValueAsString(String columnName, String value)
  • setValueAsString(int columnIndex, String value)
  • copyColumnsFromInputRecord(InputRecord inputRecord)
  • getOfLink()

After you instantiate the OutputRecord object, you can then set the value for each column by using the setValue(String columnName, Object value) or the setValue(int columnIndex, Object value) methods of the OutputRecord interface.

The following example shows how to set the value to the column corresponding to a given column index “i”.
outputRecord.setValue(i, value);
You can also set the value by specifying the column name as follows:
outputRecord.setValue(“name”, value);
Finally, your Java code writes this output record by calling the writeRecord() method of the OutputLink interface. The instance of the OutputLink is available in the Configuration object that is provided as argument of the validateConfiguration() method.
m_outputLink.writeRecord(outputRecord);
Methods provided by OutputLink interface
  • getOutputRecord()
  • getOutputRecord(InputRecord)
  • getRejectRecord(InputRecord)
  • writeRecord()
  • writeRecord(RejectRecord)
  • writeWaveMarker()
  • isRcpEnabled()
Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more