KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > client > UnFetchStatus


1 package com.daffodilwoods.daffodildb.client;
2
3 import java.util.*;
4 import com.daffodilwoods.database.resource.*;
5 import com.daffodilwoods.database.utility.P;
6 public class UnFetchStatus {
7
8   /** The status hashmap contains rowReader key as key and a boolean array of two
9    elements first element for fetched before and second for fetch after.
10   */

11   Hashtable status;
12
13   /** Constuctes the object.
14   */

15   public UnFetchStatus() {
16      status = new Hashtable();
17   }
18
19   /**
20     * removes the key from the status hashMap
21    **/

22   public void remove(Object JavaDoc key) throws DException {
23      if(status.containsKey(key))
24         status.remove(key);
25   }
26
27   /** if key not found in hashmap then return true.
28    and if key found then
29    if after is true
30     return its first position.
31    else
32     return its zeroth position
33   */

34   public boolean isFetched(Object JavaDoc key,boolean after) throws DException {
35     if(key == null)
36        return false;
37      if(! status.containsKey(key))
38         return true;
39      Object JavaDoc values = status.get(key);
40      boolean[] afterBefore = (boolean[])values;
41     return after ? afterBefore[1]: afterBefore[0] ;
42   }
43
44   /** to be invoked after fetching the data. it will put the entry for the
45    last row of group of rows fetch in status hashmap and
46    if <after> is true makes its FetchAfter flag false
47    else makes its FetchBefore flag false .
48    It alse check if both flags are true then delete the entry from hashmap
49    stating the both the side fetched.
50   */

51   public void setFetched(Object JavaDoc key,boolean after) throws DException {
52     if(! status.containsKey(key)){
53       boolean [] afterBefore = after ? new boolean[]{true,false} :new boolean[]{false,true};
54       status.put(key,afterBefore);
55     }
56     else{
57       Object JavaDoc values = status.get(key);
58       boolean[] afterBefore = (boolean[])values;
59       if(after ? afterBefore[1] == false && afterBefore[0] == true
60                : afterBefore[0] == false && afterBefore[1] == true)
61
62            remove(key);
63       else{
64         int index = after? 1 : 0;
65         afterBefore[index] = ! afterBefore[index];
66       }
67     }
68
69   }
70
71   public int size() throws DException {
72     return status.size();
73   }
74
75    public void showMap() throws DException {
76     Set set =status.entrySet();
77     Iterator i=set.iterator();
78     while(i.hasNext()){
79       Map.Entry m=(Map.Entry)i.next();
80       P.pln(" key " + m.getKey() + " values " + P.print(m.getValue()));
81     }
82  }
83
84  public Object JavaDoc[] getKeys(){
85      Set keySet = status.keySet();
86      return keySet == null ? null : keySet.toArray();
87  }
88
89 }
90
Popular Tags