Implementing the RowLoader Interface

To create a RowLoader, you define a class that implements the interface com.pivotal.gemfirexd.callbacks.RowLoader, and then attach your implementation to a table using a system procedure. The implementation then acts as the SQL data loader.

Procedure
  1. Include a public, static method that takes no parameters, and that returns an instance of the loader. For example:
    ExampleRowLoader.java 
    
    package example.callbacks; 
    import java.sql.*; 
    import javax.sql.*; 
    import javax.sql.rowset.*; 
    import com.pivotal.gemfirexd.callbacks.RowLoader; 
     
    public class MyRowLoader implements RowLoader{ 
      
      public static MyRowLoader create() { 
             return new ExampleRowLoader(); 
      } 
      
  2. Implement an init(String initStr) method to obtain parameters that are defined when you register your implementation with a table. GemFire XD calls your implementation's init() method when the SYS.ATTACH_LOADER procedure is used to register the RowLoader with a table. All parameters are passed in the single String object.
  3. GemFire XD calls the getRow(String schemaName, String tableName, Object[] primarykey) method implementation to provide the schema name, table name and an array of objects that are the primary key values (in the order presented by the table definition) each time the loader is invoked to fetch data from the external source. Your implementatino of this method must return one of the following:
    • An object array with one element with the value for each column, including the primary key, in the order defined by the GemFire XD table definition.
    • null, if there is no element found.
    • An instance of java.sql.ResultSet, possibly the result of a query against another database. Only the first row will be used. The result columns should match the GemFire XD table.
    • An empty java.sql.ResultSet if no element is found.
  4. After compiling your RowLoader implementation and adding it to the classpath, register the RowLoader with a table by executing the built-in SYS.ATTACH_LOADER procedure.