My Data Writer
Updated: Aug 24, 2023
This example shows a customizable DataWriter component, allowing you to modify the default behavior of writing data. By leveraging the given class, you can implement your own specialized data-writing logic tailored to specific use cases and requirements.
More information about the usage of MyDataWriter can be found in Write My Own Data Writer.
Java Code Listing
package com.northconcepts.datapipeline.examples.cookbook.customization;
import com.northconcepts.datapipeline.core.DataException;
import com.northconcepts.datapipeline.core.DataWriter;
import com.northconcepts.datapipeline.core.Record;
public class MyDataWriter extends DataWriter {
public void open() throws DataException {
super.open();
// open datasource here
}
public void close() throws DataException {
// close datasource here
super.close();
}
protected void writeImpl(Record record) throws Throwable {
// write record to datasink here
}
}
Code Walkthrough
- This class extends the abstract class DataWriter.
- The abstract method
writeImpl(Record record)should be overridden to implement custom logic for writing data. - The other two methods
open()andclose()are given to configure data source connections. These are optional, but we can insert some steps/operations here when starting and closing a connection with a data source.
