KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > storage > classicStore > ClassicStore


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id$
8

9 package org.ozoneDB.core.storage.classicStore;
10
11 import org.ozoneDB.OzoneCompatible;
12 import org.ozoneDB.PermissionDeniedException;
13 import org.ozoneDB.ObjectNotFoundException;
14 import org.ozoneDB.DxLib.DxSet;
15 import org.ozoneDB.DxLib.DxBag;
16 import org.ozoneDB.DxLib.DxIterator;
17 import org.ozoneDB.core.*;
18 import org.ozoneDB.core.storage.classicStore.ClassicObjectContainer;
19 import org.ozoneDB.util.LogWriter;
20
21 import java.io.IOException JavaDoc;
22
23
24 /**
25  * ClassicStore acts as the mediator (director) of the classicStore module
26  * especially for ClusterSpace, ObjectSpace, PersistentSpace. Currently it
27  * serves only as container for the references but this should change in the
28  * future to decouple class implementations.
29  *
30  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
31  */

32 public final class ClassicStore extends ServerComponent implements StoreManager {
33     /** */
34     protected Env env;
35     protected ObjectSpace objectSpace;
36
37
38     /** */
39     public ClassicStore(Env env) {
40         super(env);
41     }
42
43
44     /** */
45     public void init( Env _env ) {
46         env = _env;
47         objectSpace = new ObjectSpace( _env );
48     }
49
50     public void save() throws Exception JavaDoc {
51         // do nothing for now...
52
}
53
54     /** */
55     public void startup() throws Exception JavaDoc {
56         env.logWriter.newEntry( this, "startup...", LogWriter.INFO );
57         objectSpace.startup();
58     }
59
60
61     /** */
62     public void shutdown() throws Exception JavaDoc {
63         env.logWriter.newEntry( this, "shutdown...", LogWriter.INFO );
64         objectSpace.shutdown();
65     }
66
67     /**
68      * Creates a new object container and initializes it with the specified
69      * target object. The new container is immediatly accessible from the calling
70      * transaction via containerByID but it is not joined to this transaction.
71      * It needs to be joined and commited afterwards.
72      *
73      * Iff this method returns normally, the returned container is pinned and thus has to be unpinned.
74      * Iff this method returns normally, the returned container is locked with the given lock level.
75      *
76      * @param ta
77      * @param target
78      * @param objID
79      * @param permissions
80      * @param lockLevel
81      * @return An container-proxy for the created container.
82      */

83     public ObjectContainer newContainerAndLock(Transaction ta, OzoneCompatible target, ObjectID objID,
84                                                      Permissions permissions, int lockLevel) throws Exception JavaDoc {
85         return objectSpace.newContainer( ta, target, objID, permissions );
86     }
87
88
89     public Object JavaDoc newTransactionData() {
90         throw new RuntimeException JavaDoc("not yet implemented");
91     }
92
93     /**
94      * Update lock level of the given container according to the level of the
95      * containers lock object.
96      */

97     public void updateLockLevel(Transaction ta, ObjectContainer container) throws IOException JavaDoc {
98         throw new RuntimeException JavaDoc("not yet implemented");
99     }
100
101     /**
102      * @param ta the running transaction
103      * @return a String array of the all object names defined
104      */

105     public DxSet objectNames(Transaction ta) {
106         throw new RuntimeException JavaDoc("not yet implemented");
107     }
108
109     public ObjectContainer containerForID(Transaction ta, ObjectID id) throws ObjectNotFoundException, IOException JavaDoc, ClassNotFoundException JavaDoc {
110         return objectSpace.objectForID( id );
111     }
112
113     /**
114      * @param name The object name to search for.
115      * @param ta
116      * @return The object container for the name or null.
117      */

118     public ObjectContainer containerForName(Transaction ta, String JavaDoc name) throws Exception JavaDoc {
119        return objectSpace.objectForName( name );
120     }
121
122     /**
123      * Force the Store to make a guess which objects are used together with the
124      * container with the specified id.
125      * @param id The ObjectID if the container.
126      */

127     public DxBag clusterOfID(ObjectID id) throws Exception JavaDoc {
128         throw new RuntimeException JavaDoc("not yet implemented");
129     }
130
131     public DxIterator objectIDIterator() {
132         throw new RuntimeException JavaDoc("not yet implemented");
133     }
134
135     /**
136      Tells this StoreManager to report every named object to the garbage collector.
137      */

138     public void reportNamedObjectsToGarbageCollector() {
139         throw new RuntimeException JavaDoc("not yet implemented");
140     }
141
142
143     /**
144      * @param ta
145      * @param container
146      * @param name
147      */

148     public void nameContainer( Transaction ta, ObjectContainer container, String JavaDoc name ) throws PermissionDeniedException {
149         try {
150             objectSpace.nameObject( container, name );
151         } catch (ClassicStoreException e) {
152             throw new PermissionDeniedException( e.toString() );
153         }
154     }
155
156
157 // /** */
158
// public void join( Transaction ta, ObjectContainer container, int lockLevel ) throws Exception {
159
// //System.out.println ("join: " + container.id());
160
// ClassicObjectContainer classicCon = (ClassicObjectContainer)container;
161
// classicCon.upgradeLockLevel( ta, lockLevel );
162
//
163
// ta.idTable.addForKey( classicCon, classicCon.id() );
164
// }
165

166     public Transaction createTransaction(Env env, User user) {
167         return new ClassicTransaction(env, user);
168     }
169
170     /**
171      * @param ta Transaction that will be commited.
172      */

173     public void prepareCommitTransaction( Transaction ta ) {
174         objectSpace.prepareCommitObjects((ClassicTransaction) ta );
175     }
176
177
178     /** */
179     public void commitTransaction( Transaction ta ) {
180         objectSpace.commitObjects( ta );
181     }
182
183
184     /**
185      * @param ta ID of the comitting transaction.
186      */

187     public void abortTransaction( Transaction ta ) {
188         try {
189             objectSpace.abortObjects((ClassicTransaction) ta );
190         } catch (Exception JavaDoc e) {
191             env.logWriter.newEntry( this, "Abort of transaction " + ta.taID() + " failed !\n" + e, LogWriter.ERROR );
192         }
193     }
194
195
196     /** */
197     public void upgradeLockLevel( Transaction ta, ObjectContainer container, int lockLevel ) throws Exception JavaDoc {
198         ((ClassicObjectContainer)container).upgradeLockLevel( ta, lockLevel );
199     }
200 }
201
Popular Tags