1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.melati.poem.odmg;
45
46 import java.util.Map;
47 import java.util.HashMap;
48
49 import org.melati.LogicalDatabase;
50 import org.melati.util.DatabaseInitException;
51
52
53 final class Database implements org.odmg.Database {
54
55
56 private Database() {}
57
58
59
60 static Database getNewDatabase() {
61 return new Database();
62 }
63
64 private org.melati.poem.Database _poemDB = null;
65 private String _logicalDB = null;
66
67 org.melati.poem.Database getPoemDatabase()
68 throws org.odmg.ODMGRuntimeException {
69 if (_poemDB == null) throw new org.odmg.DatabaseClosedException(
70 "org.melati.poem.odmg.Database::getPoemDatabase - POEM DB not set");
71 return _poemDB;
72 }
73
74
75
76
77 public void open(String openParameters, int openType)
78 throws org.odmg.ODMGException {
79 _logicalDB = openParameters;
80 try {
81 _poemDB = LogicalDatabase.getDatabase(_logicalDB);
82 _cachedTables = new HashMap<String,PoemTableAsDCollection<?>>();
83 } catch (DatabaseInitException err) {
84 err.printStackTrace();
85 throw new org.odmg.ODMGException(err.getMessage());
86 }
87 }
88
89 public void close() {
90 _poemDB.disconnect();
91 _poemDB = null;
92 _cachedTables = null;
93 ODMGFactory.resetDb();
94 }
95
96 private Map<String,PoemTableAsDCollection<?>> _cachedTables = null;
97
98
99
100
101
102
103
104 @SuppressWarnings({ "unchecked", "rawtypes" })
105 public Object lookup(String objectIdentifier)
106 throws org.odmg.ObjectNameNotFoundException {
107 if (_poemDB == null) throw new org.odmg.DatabaseClosedException();
108 PoemTableAsDCollection<?> theObject = _cachedTables.get(objectIdentifier);
109 if (theObject == null) {
110 theObject = new PoemTableAsDCollection(_poemDB.
111 getTable(objectIdentifier));
112 _cachedTables.put(objectIdentifier,theObject);
113 }
114 return theObject;
115 }
116
117
118 public void makePersistent(Object objectToBePersistent) {
119 throw new org.odmg.NotImplementedException();
120 }
121
122 public void deletePersistent(Object persistedObject) {
123 throw new org.odmg.NotImplementedException();
124 }
125
126 public void bind(Object objectToBePersistent, String objectIdentifier) {
127 throw new org.odmg.NotImplementedException();
128 }
129
130 public void unbind(String objectIdentifier) {
131 throw new org.odmg.NotImplementedException();
132 }
133
134 }
135