KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.datasystem.indexsystem;
2
3 import java.util.*;
4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
5 import com.daffodilwoods.database.general.*;
6 import com.daffodilwoods.database.resource.DException;
7 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.PersistentSystem;
8
9 /**
10  *
11  * <p>Title: Index System</p>
12  * <p>Description: IndexSystem : In DaffodilDb there are two lowest level systems
13  * 1. Persistent System
14  * 2. Memory System.
15  * Index System is one level above the two systems in DaffodilDB hierarchy.Basicaly index system handles all
16  * the indexes created on underlying system.If it is created above the memory system it handles all the
17  * temporary indexes and in other case it handles all the peramanant indexes.
18  *
19  * Indexes are used for fast searching ( need while condition solving ) and sorting ( In case of order by ) etc.
20  * DaffodilDB uses Balanced Tree Concept for fulfilling all the requirements from an index.
21  *
22  * Requirements :
23  * i. CreatePermanantIndex
24  * ii. CreateTemporaryIndex
25  * iii. DropPermanantIndex
26  * iv. DropTemporaryIndex
27  * v. IndexInformations related to a particular table
28  * vi. Efficient Seeking
29  * </p>
30  */

31 public class IndexSystem implements _DataSystem {
32
33     /**
34      * Instance of Memory or File System to perform database level operations
35      */

36
37    private _DataSystem dataSystem;
38
39     /**
40      * Maintains lists of all database which are Currently in use having
41      * mapping with Database name
42      */

43
44    private HashMap databaseMap;
45
46     /**
47      * Used In Memory Management
48      */

49
50
51    private boolean isReadOnlyMode = false;
52
53     public IndexSystem(_DataSystem dataSystem0,boolean isReadOnlyMode0) {
54         dataSystem = dataSystem0;
55         databaseMap = new HashMap();
56         isReadOnlyMode = isReadOnlyMode0 ;
57     }
58
59     /**
60      * Not Used Now
61      */

62
63     public IndexSystem(_DataSystem dataSystem0, _MemoryManager manager0) {
64         dataSystem = dataSystem0;
65         databaseMap = new HashMap();
66     }
67
68
69     /**
70      * Gets database from underlying system,and makes indexDatabase entry in databaseMap having Mapping with databaseName.
71      *
72      * @param databaseName Name of database which is Required
73      * @throws DException If database doesn't exist
74      */

75
76
77     public synchronized _Database getDatabase(String JavaDoc databaseName) throws DException {
78         _IndexDatabase indexDatabase = (_IndexDatabase)databaseMap.get(databaseName);
79         if(indexDatabase != null)
80             return indexDatabase;
81         indexDatabase = new IndexDatabase(dataSystem.getDatabase(databaseName),isReadOnlyMode);
82         databaseMap.put(databaseName,indexDatabase);
83         return indexDatabase;
84     }
85
86     /**
87      * Drops database from underlying system
88      *
89      * @param databaseName name of database which user want to drop
90      * @throws DException if database on this name is not created or database is locked by another user
91      */

92
93
94     public synchronized void dropDatabase(String JavaDoc databaseName) throws DException {
95         dataSystem.dropDatabase(databaseName);
96         databaseMap.remove(databaseName);
97     }
98
99     public synchronized void createDatabase(String JavaDoc databaseName, Properties prop) throws DException {
100         dataSystem.createDatabase(databaseName,prop);
101     }
102
103     /**
104      * Remove the instance of database from it's map.
105      */

106
107     public void removeDatabase(String JavaDoc databaseURL) throws DException{
108         dataSystem.removeDatabase(databaseURL);
109         databaseMap.remove(databaseURL);
110     }
111
112     public _DataSystem getDataSystem(){
113         return dataSystem;
114     }
115
116     /**
117      * For testing purpose
118      */

119
120     public _Database createSystemDatabase(String JavaDoc path0, String JavaDoc initialSize, int incrementFactor, boolean unicodeSupport, boolean multifileSupport) throws DException{
121         if( dataSystem instanceof PersistentSystem )
122             return ((PersistentSystem)dataSystem).createSystemDatabase(path0,initialSize,incrementFactor,unicodeSupport,multifileSupport);
123         else
124             return null;
125     }
126 }
127
Popular Tags