KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > prevayler > Database


1 package org.apache.ojb.broker.prevayler;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 import java.io.Serializable JavaDoc;
20 import java.util.Hashtable JavaDoc;
21
22 import org.apache.ojb.broker.Identity;
23 import org.apache.ojb.broker.PersistenceBroker;
24 import org.prevayler.implementation.AbstractPrevalentSystem;
25
26 /**
27  * This class represents the persistent store OJB works against.
28  * It is implement as an PrevalentSystem.
29  * All Commands executed this DB are tracked by Prevayler and written to disk
30  * as command-logs.
31  * If the system is halted, crashes or rebooted for what reason so ever, Prevayler
32  * will establish the state of the Database from the command-logs written to disk.
33  * @author Thomas Mahler
34  *
35  */

36 public class Database extends AbstractPrevalentSystem
37 {
38     
39     private final Hashtable JavaDoc table = new Hashtable JavaDoc();
40     
41     private transient PersistenceBroker broker;
42     
43     
44     public void store(Object JavaDoc obj)
45     {
46         Identity oid = new Identity(obj,broker);
47         this.getTable().put(oid.toString(), obj);
48     }
49     
50     public void remove(Object JavaDoc obj)
51     {
52         Identity oid = new Identity(obj,broker);
53         this.getTable().remove(oid.toString());
54     }
55     
56     public Serializable JavaDoc lookupObjectByIdentity(Identity oid)
57     {
58         return (Serializable JavaDoc) this.getTable().get(oid.toString());
59     }
60
61     /**
62      * Returns the table.
63      * @return Hashtable
64      */

65     public Hashtable JavaDoc getTable()
66     {
67         return table;
68     }
69
70     /**
71      * Returns the broker.
72      * @return PersistenceBroker
73      */

74     public PersistenceBroker getBroker()
75     {
76         return broker;
77     }
78
79     /**
80      * Sets the broker.
81      * @param broker The broker to set
82      */

83     public void setBroker(PersistenceBroker broker)
84     {
85         this.broker = broker;
86     }
87
88 }
89
Popular Tags