[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cursors/Iterators



On Mon, 21 Aug 2000, Robert Colquhoun wrote:
> Hi,
> 
> This is a beginner question - i am having real trouble getting some kind of 
> cursor to work, in the class below every time next() is called it returns 
> the first element from the iterator, not progressing to the second element 
> and never reaching the end of the list.
Did you mark the next() method to be an update method? If not, the changes of
the iterator (i.next()) are not persistent. 

> (...surely there must be a better way of designing cursors/iterators)
> 
> PS I was looking at the way new objects are added to the database - from 
> another project(a compiler) i have some classes to create classfiles on the 
> fly(ie make the *Proxy classes on the run) which would remove the need for 
> the dependency on sun.tools.javac and opp if anybody is interested.
Sure. Thanks. Send it to me. I will see if I can use it.


Falko

> 
> - Robert
> 
> public class PRICESImpl extends OzoneObject implements PRICES {
> 
>      DxHashMap records = new DxHashMap();
>      DxHashMap cursors = new DxHashMap();
> 
>      public String get(String key) {
>          return (String)records.elementForKey(key);
>      }
> 
>      public String getCursor() {
>          String cursor = "Cursor_" + ((int)(Math.random() * 10000));
>          cursors.addForKey(records.iterator(), cursor);
>          return cursor;
>      }
> 
>      public String next(String key) {
>          DxIterator i = (DxIterator)cursors.elementForKey(key);
>          if (i == null || i.next() == null) return null;
>          cursors.removeForKey(key);  //for some reason this is needed
>          cursors.addForKey(i, key);
>          return (String)i.key();
>      }
> 
>      public void set(String key, String val) {
>          records.addForKey(val, key);
>      }
> }
-- 
______________________________________________________________________
Falko Braeutigam                              mailto:falko@smb-tec.com
SMB GmbH                                        http://www.smb-tec.com