My Data Reader

Updated: Aug 6, 2023

This example shows how to create your own custom DataReader class, allowing you to read data from any source. By leveraging the given class, you can implement your own specialized data-reading logic tailored to specific use cases and requirements.

More information about the usage of MyDataReader can be found in Write My Own Data Reader.

 

Java Code Listing

package com.northconcepts.datapipeline.examples.cookbook.customization;

import com.northconcepts.datapipeline.core.DataException;
import com.northconcepts.datapipeline.core.DataReader;
import com.northconcepts.datapipeline.core.Record;

public class MyDataReader extends DataReader {
    
    public void open() throws DataException {
        super.open();
        // open datasource here
    }

    public void close() throws DataException {
        // close datasource here
        super.close();
    }
    
    protected Record readImpl() throws Throwable {
        // write logic to return new instances of Record here
        // return null for end-of-file
        return null;
    }
    
}

 

Code Walkthrough

  1. This class extends the abstract class DataReader.
  2. The abstract method readImpl() should be overridden to implement custom logic for reading data. 
  3. The other two methods open() and close() 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.
Mobile Analytics