RecordStore with examples - III
15 May 2008I will continue exploring RecordStore with examples in this post.
In the last post, I was talking about enumerateRecords(…) method. Let me show how to use it with example:
/* * Build an enumeration to index through all records. */ RecordEnumeration re = null; try { re = recordStore.enumerateRecords((RecordFilter)null, (RecordComparator)null, false); } catch (RecordStoreNotOpenException rsnoe) { System.err.println(rsnoe.toString()); } while(re.hasNextElement()) { try { System.out.println("Next Record ID = " + re.nextRecordId()); } catch(InvalidRecordIDException iride) { System.err.println(iride.toString());
Now lets see how to build a new RecordEnumeration with a filter to include only integer records. Notice how it will only report the integer records.
IntegerFilter iFilt = new IntegerFilter(); try { re = recordStore.enumerateRecords((RecordFilter)iFilt, null, false); } catch (RecordStoreNotOpenException rsnoe) { System.err.println(rsnoe.toString()); } /* * And walk through it backwards for kicks... */ while(re.hasPreviousElement()) { try { System.out.println("Previous Record ID = " + re.previousRecordId()); } catch(InvalidRecordIDException iride) { System.err.println(iride.toString()); } }
It is always preferred to clean the RecordEnumeration by calling its destory method.
I hope that you have learned to use RecordStore and will use it from now on.
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: RecordStore with examples - III