View Javadoc

1   package org.paneris.bibliomania.fti;
2   
3   import org.melati.poem.transaction.ToTidyList;
4   
5   import com.sleepycat.db.DatabaseException;
6   import com.sleepycat.db.Cursor;
7   import com.sleepycat.db.DatabaseEntry;
8   import com.sleepycat.db.OperationStatus;
9   import com.sleepycat.db.internal.DbConstants;
10  
11  public class IndexCursor implements ToTidyList.Closeable {
12    private final Cursor texts;
13    private final DatabaseEntry word_text;
14    private final DatabaseEntry occurrencesData;
15  
16    //private int wordID = -1;
17  
18    IndexCursor(IndexOther index) throws DatabaseException {
19      texts = index.occurrencesOfWordInText.openCursor(null, null);
20      word_text = DbUtils.userMemDatabaseEntry(IndexOther.wtBytesLength);
21      occurrencesData = DbUtils.userMemDatabaseEntry(500);
22    }
23  
24    public boolean next() {
25      return DbUtils.get(texts, word_text, occurrencesData, DbConstants.DB_NEXT, 500) == OperationStatus.SUCCESS;
26    }
27  
28    public long textID() {
29      return IndexOther.getWT_textID(word_text.getData());
30    }
31  
32    public int wordID() {
33      return IndexOther.getWT_wordID(word_text.getData());
34    }
35  
36    public void close() {
37      try {
38        texts.close();
39      }
40      catch (Exception e) {}
41    }
42  }