Sync Reader Examples

Contents Hide

  

Example 1. Opening/Closing the reader

These two methods are called upon opening and closing the sync reader script respectively. Typically, they are used to open and close any resources the reader needs to use throughout its execution. An example of this is follows:

function openReader(payload, limit)

{

in = new BufferedReader(new FileReader("filename"));

// ...

}

 

function closeReader()

{

// ...

in.close();

}

Note:

Example 2. Parsing a payload

The openReader() method is where the script receives the user defined query (aka the payload) and thus has the task of configuring the script to return the correct set of records when the read() method is called. A simple example is as follows:

maxrecords = 100 ;

 

function openReader(payload, limit)

{

// ...

maxrecords = payload;

}

 

function read()

{

// something using maxrecords

}

Note:

Example 3. The read() method

Based on how the script is configured via the openReader() method, the read() method will return a specific record set. The read method may be called numerous times by the server, with BrightServer then amalgamating the results via the synchronisation engine.

function read()

{

rs = new RecordSet("TABLE4");

// operations to populate the result set ...

while ((str = in.readLine()) != null)

{

strs = str.split(mark1,2);

strs2;

if (strs.size() < 2)

strs2 = strs[1].split(mark2,2);

 

// create record

record = new Record();

record.add(strs[0]);

record.add(strs2.size() < 2 ? "" : strs[1]);

record.add(strs2.size() < 2 ? "" : strs[2]);

rs.add(record);

}

return rs ;

}

Note: