Contents Hide
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:
in is the output buffered writer for the file writer. It is stored as a global variable, as to be accessed by other methods, and closed once the read script is completed, signalled by closeReader().
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:
Above is a simple example, demonstrating how openReader(), read() and global variables are related using the payload.
A more complex example may include a number of global variables and lines within the openReader() method to incorporate the retrieval and access of this data by other methods - typically using string parsing.
The limit parameter is for internal use only, and does not need to be defined for a script to correctly operate.
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:
If not previously defined, the payload variable may be NULL, which in turn may cause problems when returning the desired data set..
If no record sets are to be returned, return (new RecordSet("ANY_STR")) may be used within this function, where "ANY_STR" being any arbitrary string.