servicenow.community.soap
Class BulkFetcher
java.lang.Object
servicenow.community.soap.BulkFetcher
public class BulkFetcher
- extends java.lang.Object
Used to fetch records from ServiceNow in chunks.
ServiceNow limits the number of records which can be retrieved in a single SOAP call.
Therefore, when reading a large amount of data,
the records must be processed in a double loop as follows.
The outer loop fetches a chunk of records from ServiceNow.
The inner loop processes the records in the chunk.
BulkFetcher fetcher = table.bulkFetcher(filter);
while (fetcher.hasNext()) {
GlideRecordList chunk = fetcher.nextChunk();
GlideRecordIterator iter = chunk.iterator();
while (iter.hasNext()) {
GlideRecord rec = iter.next();
// insert code here to process record
}
}
To read all records into memory use the getAllRecords() method.
GlideRecordList recs = table.bulkFetcher().getAllRecords();
The BulkFetcher uses one of two techniques to fetch the records.
If useKeys is true (setUseKeys(true)
)
then it will call getKeys() to fetch all the sys_ids,
and then fetch the records in chunks using an encoded query
of the form sys_idIN
sys_id1,sys_id2,....
If useKeys is false (setUseKeys(false)
)
then it will fetch the records in chunks by using the
__first_row and __last_row parameters.
- Author:
- Giles Lewis
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
BulkFetcher
public BulkFetcher(GlideTable table)
throws java.io.IOException
- Throws:
java.io.IOException
BulkFetcher
public BulkFetcher(GlideTable table,
GlideFilter filter)
throws java.io.IOException
- Throws:
java.io.IOException
setFilter
public BulkFetcher setFilter(GlideFilter filter)
addFilter
public BulkFetcher addFilter(GlideFilter newfilter)
setUseKeys
public BulkFetcher setUseKeys(boolean useKeys)
setCheckAtEnd
public BulkFetcher setCheckAtEnd(boolean check)
setNoSort
public BulkFetcher setNoSort()
sortAscending
public BulkFetcher sortAscending(java.lang.String fieldname)
sortDescending
public BulkFetcher sortDescending(java.lang.String fieldname)
sortByCreateDate
public BulkFetcher sortByCreateDate()
sortByUpdateDate
public BulkFetcher sortByUpdateDate()
setChunkSize
public BulkFetcher setChunkSize(int chunkSize)
getFirstRow
public int getFirstRow()
setFirstRow
public void setFirstRow(int num)
hasNext
public boolean hasNext()
getParams
protected servicenow.community.soap.Parameters getParams(int firstRow,
int lastRow)
getKeys
public GlideKeyList getKeys()
throws java.io.IOException
- Throws:
java.io.IOException
numKeys
public java.lang.Integer numKeys()
nextChunk
public GlideRecordList nextChunk()
throws java.io.IOException
- Throws:
java.io.IOException
getAllRecords
public GlideRecordList getAllRecords()
throws java.io.IOException
- This method loops internally on the BulkFetcher until no more records
are available. The easiest way to read an entire table
into memory is to use the following construct:
GlideRecordList recs = table.bulkFetcher().getAllRecords();
Warning: This method will read all records into memory.
Do not use this method on large tables
unless you have set a filter on the BulkFetcher.
- Returns:
- A GlideRecordList of all records matching the BulkFetcher filter.
- Throws:
java.io.IOException