01: package org.apache.ojb.broker.prevayler;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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: import java.io.Serializable;
19: import java.util.Hashtable;
20:
21: import org.apache.ojb.broker.Identity;
22: import org.apache.ojb.broker.PersistenceBroker;
23: import org.prevayler.implementation.AbstractPrevalentSystem;
24:
25: /**
26: * This class represents the persistent store OJB works against.
27: * It is implement as an PrevalentSystem.
28: * All Commands executed this DB are tracked by Prevayler and written to disk
29: * as command-logs.
30: * If the system is halted, crashes or rebooted for what reason so ever, Prevayler
31: * will establish the state of the Database from the command-logs written to disk.
32: * @author Thomas Mahler
33: *
34: */
35: public class Database extends AbstractPrevalentSystem {
36:
37: private final Hashtable table = new Hashtable();
38:
39: private transient PersistenceBroker broker;
40:
41: public void store(Object obj) {
42: Identity oid = new Identity(obj, broker);
43: this .getTable().put(oid.toString(), obj);
44: }
45:
46: public void remove(Object obj) {
47: Identity oid = new Identity(obj, broker);
48: this .getTable().remove(oid.toString());
49: }
50:
51: public Serializable lookupObjectByIdentity(Identity oid) {
52: return (Serializable) this .getTable().get(oid.toString());
53: }
54:
55: /**
56: * Returns the table.
57: * @return Hashtable
58: */
59: public Hashtable getTable() {
60: return table;
61: }
62:
63: /**
64: * Returns the broker.
65: * @return PersistenceBroker
66: */
67: public PersistenceBroker getBroker() {
68: return broker;
69: }
70:
71: /**
72: * Sets the broker.
73: * @param broker The broker to set
74: */
75: public void setBroker(PersistenceBroker broker) {
76: this.broker = broker;
77: }
78:
79: }
|