KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > V1HeapStoreSystem


1 /**
2  * com.mckoi.database.V1HeapStoreSystem 20 Feb 2003
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database;
26
27 import com.mckoi.store.*;
28 import java.io.IOException JavaDoc;
29 import java.util.HashMap JavaDoc;
30
31 /**
32  * An implementation of StoreSystem that stores all persistent data on the
33  * heap using HeapStore objects.
34  *
35  * @author Tobias Downer
36  */

37
38 class V1HeapStoreSystem implements StoreSystem {
39
40   /**
41    * A mapping from name to Store object for this heap store system.
42    */

43   private HashMap JavaDoc name_store_map;
44
45   /**
46    * A mapping from Store object to name.
47    */

48   private HashMap JavaDoc store_name_map;
49
50   
51   /**
52    * Constructor.
53    */

54   V1HeapStoreSystem() {
55     name_store_map = new HashMap JavaDoc();
56     store_name_map = new HashMap JavaDoc();
57   }
58   
59   
60   public boolean storeExists(String JavaDoc name) {
61     return (name_store_map.get(name) != null);
62   }
63   
64   public Store createStore(String JavaDoc name) {
65     if (!storeExists(name)) {
66       HeapStore store = new HeapStore();
67       name_store_map.put(name, store);
68       store_name_map.put(store, name);
69       return store;
70     }
71     else {
72       throw new RuntimeException JavaDoc("Store exists: " + name);
73     }
74   }
75
76   public Store openStore(String JavaDoc name) {
77     HeapStore store = (HeapStore) name_store_map.get(name);
78     if (store == null) {
79       throw new RuntimeException JavaDoc("Store does not exist: " + name);
80     }
81     return store;
82   }
83
84   public boolean closeStore(Store store) {
85     if (store_name_map.get(store) == null) {
86       throw new RuntimeException JavaDoc("Store does not exist.");
87     }
88     return true;
89   }
90
91   public boolean deleteStore(Store store) {
92     String JavaDoc name = (String JavaDoc) store_name_map.remove(store);
93     name_store_map.remove(name);
94     return true;
95   }
96
97   public void setCheckPoint() {
98     // Check point logging not necessary with heap store
99
}
100   
101   // ---------- Locking ----------
102

103   public void lock(String JavaDoc lock_name) throws IOException JavaDoc {
104     // Not required because heap memory is not a shared resource that can be
105
// accessed by multiple JVMs
106
}
107
108   public void unlock(String JavaDoc lock_name) throws IOException JavaDoc {
109     // Not required because heap memory is not a shared resource that can be
110
// accessed by multiple JVMs
111
}
112
113 }
114
115
Popular Tags