RecordStore with examples - III

15 May 2008

I 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.

del.icio.us:RecordStore with examples - III  digg:RecordStore with examples - III  spurl:RecordStore with examples - III  wists:RecordStore with examples - III  simpy:RecordStore with examples - III  newsvine:RecordStore with examples - III  blinklist:RecordStore with examples - III  furl:RecordStore with examples - III  reddit:RecordStore with examples - III  fark:RecordStore with examples - III  blogmarks:RecordStore with examples - III  Y!:RecordStore with examples - III  smarking:RecordStore with examples - III  magnolia:RecordStore with examples - III  segnalo:RecordStore with examples - III  gifttagging:RecordStore with examples - III

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

Leave a Reply