KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datasystem > indexsystem > IndexBtreeControlCluster


1 package com.daffodilwoods.daffodildb.server.datasystem.indexsystem;
2
3 import com.daffodilwoods.daffodildb.server.datasystem.btree.*;
4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
5 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.*;
6 import com.daffodilwoods.daffodildb.utils.byteconverter.*;
7 import com.daffodilwoods.database.resource.*;
8 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.versioninfo.VersionHandler;
9 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._DatabaseUser;
10
11 /**
12  * For knowing the Use of This class just read the "Why_we_need_control_clusters_In_Btree.doc"
13  *
14  */

15
16 public class IndexBtreeControlCluster extends BTreeControlCluster{
17
18   public IndexBtreeControlCluster(int address0,_ClusterProvider clusterProvider0) {
19     address = address0;
20     clusterProvider = clusterProvider0;
21     versionHandler = clusterProvider.getVersionHandler();
22   }
23
24
25
26
27   /**
28    * Update the Informations stored in it
29    * 1. Address RootNode of Btree
30    * 2. Size Of Btree
31    */

32
33
34   public void updateBTreeInfo(_DatabaseUser user,BTreeNode node, int btreeSize)throws DException{
35     FixedBTreeCluster cluster = (FixedBTreeCluster)clusterProvider.getCluster(user,new ClusterCharacteristics(address,true));
36     int rootClusterAddress = ((ClusterCharacteristics)node.getNodeKey()).getStartAddress();
37     if(rootNodeAddress != rootClusterAddress){
38       rootNodeAddress = rootClusterAddress;
39       cluster.updateBytes(versionHandler.CLUSTER_STARTPOINTER,CCzufDpowfsufs.getBytes(rootClusterAddress));
40     }
41   }
42
43   /**
44    * Returns the size of btree stored in Control cluster.
45    */

46
47   public int getSize()throws DException{
48     FixedBTreeCluster cluster = null;
49     Cluster temp = null;
50     temp = clusterProvider.getReadCluster(new
51         ClusterCharacteristics(address, true));
52     cluster = (FixedBTreeCluster) temp;
53     return (int)CCzufDpowfsufs.getLongValue(cluster.getBytes(),versionHandler.CLUSTER_STARTPOINTER + 2 * versionHandler.LENGTH);
54   }
55
56   public void releaseControlCluster(_DatabaseUser user) throws DException{
57     clusterProvider.addFreeCluster(user,address);
58   }
59
60   public int getRootClusterAddress() throws DException{
61    if(rootNodeAddress == -1){
62      FixedBTreeCluster controlCluster = (FixedBTreeCluster) clusterProvider.
63          getReadCluster(new ClusterCharacteristics(address, true));
64      rootNodeAddress = CCzufDpowfsufs.getIntValue(controlCluster.getBytes(),
65          versionHandler.
66          CLUSTER_STARTPOINTER);
67    }
68    return rootNodeAddress;
69   }
70 }
71
Popular Tags