KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myoodb > core > Database


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
4
//
5
// All Rights Reserved
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License and GNU Library
9
// General Public License as published by the Free Software Foundation;
10
// either version 2, or (at your option) any later version.
11
//
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License and GNU Library General Public License
16
// for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// and GNU Library General Public License along with this program; if
20
// not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21
// MA 02139, USA.
22
//
23
///////////////////////////////////////////////////////////////////////////////
24
package org.myoodb.core;
25
26 import org.myoodb.*;
27 import org.myoodb.exception.*;
28 import org.myoodb.core.command.*;
29
30 public final class Database extends AbstractDatabase
31 {
32     public Database()
33     {
34     }
35
36     public MyOodbProxy createRoot(String JavaDoc className,String JavaDoc rootName,String JavaDoc sig,Object JavaDoc[] args)
37     {
38         try
39         {
40             MyOodbProxy result = null;
41             AbstractTransaction tx = MyOodbManager.getTheManager().getTransactionManager().currentTransaction();
42             if (tx == null)
43             {
44                 AbstractCommand command = new CreateCommand(className, rootName, sig, args);
45                 MyOodbManager.getTheManager().getTransactionManager().processCommand(command, null, null);
46                 result = (MyOodbProxy) command.getResult();
47             }
48             else
49             {
50                 result = tx.create(className, rootName, sig, args).getProxy();
51             }
52
53             return result;
54         }
55         catch (RuntimeException JavaDoc e)
56         {
57             throw e;
58         }
59         catch (Exception JavaDoc e)
60         {
61             throw new InternalException("Caught during create root: " + e, e);
62         }
63     }
64
65     public MyOodbProxy createObject(String JavaDoc className,String JavaDoc sig,Object JavaDoc[] args)
66     {
67         try
68         {
69             MyOodbProxy result = null;
70             AbstractTransaction tx = MyOodbManager.getTheManager().getTransactionManager().currentTransaction();
71             if (tx == null)
72             {
73                 AbstractCommand command = new CreateCommand(className, null, sig, args);
74                 MyOodbManager.getTheManager().getTransactionManager().processCommand(command, null, null);
75                 result = (MyOodbProxy) command.getResult();
76             }
77             else
78             {
79                 result = tx.create(className, null, sig, args).getProxy();
80             }
81
82             return result;
83         }
84         catch (RuntimeException JavaDoc e)
85         {
86             throw e;
87         }
88         catch (Exception JavaDoc e)
89         {
90             throw new InternalException("Caught during create object: " + e, e);
91         }
92     }
93
94     public void delete(MyOodbRemote obj)
95     {
96         try
97         {
98             AbstractTransaction tx = MyOodbManager.getTheManager().getTransactionManager().currentTransaction();
99             if (tx == null)
100             {
101                 AbstractCommand command = new DeleteCommand((MyOodbProxy)obj);
102                 MyOodbManager.getTheManager().getTransactionManager().processCommand(command, null, null);
103             }
104             else
105             {
106                 tx.delete(((MyOodbProxy)obj).getDatabaseHandle());
107             }
108         }
109         catch (RuntimeException JavaDoc e)
110         {
111             throw e;
112         }
113         catch (Exception JavaDoc e)
114         {
115             throw new InternalException("Caught during delete: " + e, e);
116         }
117     }
118
119     public MyOodbProxy getRoot(String JavaDoc rootName)
120     {
121         try
122         {
123             MyOodbProxy result = null;
124             AbstractTransaction tx = MyOodbManager.getTheManager().getTransactionManager().currentTransaction();
125             if (tx == null)
126             {
127                 AbstractCommand command = new GetRootCommand(rootName);
128                 MyOodbManager.getTheManager().getTransactionManager().processCommand(command, null, null);
129                 result = (MyOodbProxy) command.getResult();
130             }
131             else
132             {
133                 result = tx.getRoot(rootName);
134             }
135
136             return result;
137         }
138         catch (RuntimeException JavaDoc e)
139         {
140             throw e;
141         }
142         catch (Exception JavaDoc e)
143         {
144             throw new InternalException("Caught during get root: " + e, e);
145         }
146     }
147
148     public MyOodbProxy getObject(org.myoodb.core.Identifier handle)
149     {
150         try
151         {
152             MyOodbProxy result = null;
153             AbstractTransaction tx = MyOodbManager.getTheManager().getTransactionManager().currentTransaction();
154             if (tx == null)
155             {
156                 AbstractCommand command = new GetObjectCommand(handle);
157                 MyOodbManager.getTheManager().getTransactionManager().processCommand(command, null, null);
158                 result = (MyOodbProxy) command.getResult();
159             }
160             else
161             {
162                 result = tx.getObject(handle);
163             }
164
165             return result;
166         }
167         catch (RuntimeException JavaDoc e)
168         {
169             throw e;
170         }
171         catch (Exception JavaDoc e)
172         {
173             throw new InternalException("Caught during get object: " + e, e);
174         }
175     }
176
177     public void setBean(org.myoodb.core.Identifier handle, MyOodbBean bean)
178     {
179         try
180         {
181             AbstractTransaction tx = MyOodbManager.getTheManager().getTransactionManager().currentTransaction();
182             if (tx == null)
183             {
184                 AbstractCommand command = new SetBeanCommand(handle, bean);
185                 MyOodbManager.getTheManager().getTransactionManager().processCommand(command, null, null);
186             }
187             else
188             {
189                 tx.setBean(handle, bean);
190             }
191         }
192         catch (RuntimeException JavaDoc e)
193         {
194             throw e;
195         }
196         catch (Exception JavaDoc e)
197         {
198             throw new InternalException("Caught during set bean: " + e, e);
199         }
200     }
201
202     public MyOodbBean getBean(org.myoodb.core.Identifier handle)
203     {
204         try
205         {
206             MyOodbBean result = null;
207             AbstractTransaction tx = MyOodbManager.getTheManager().getTransactionManager().currentTransaction();
208             if (tx == null)
209             {
210                 AbstractCommand command = new GetBeanCommand(handle);
211                 MyOodbManager.getTheManager().getTransactionManager().processCommand(command, null, null);
212                 result = (MyOodbBean) command.getResult();
213             }
214             else
215             {
216                 result = tx.getBean(handle);
217             }
218
219             return result;
220         }
221         catch (RuntimeException JavaDoc e)
222         {
223             throw e;
224         }
225         catch (Exception JavaDoc e)
226         {
227             throw new InternalException("Caught during get bean: " + e, e);
228         }
229     }
230
231     public void setXML(org.myoodb.core.Identifier handle, String JavaDoc xml)
232     {
233         try
234         {
235             AbstractTransaction tx = MyOodbManager.getTheManager().getTransactionManager().currentTransaction();
236             if (tx == null)
237             {
238                 AbstractCommand command = new SetXMLCommand(handle, xml);
239                 MyOodbManager.getTheManager().getTransactionManager().processCommand(command, null, null);
240             }
241             else
242             {
243                 tx.setXML(handle, xml);
244             }
245         }
246         catch (RuntimeException JavaDoc e)
247         {
248             throw e;
249         }
250         catch (Exception JavaDoc e)
251         {
252             throw new InternalException("Caught during set xml: " + e, e);
253         }
254     }
255
256     public String JavaDoc getXML(org.myoodb.core.Identifier handle)
257     {
258         try
259         {
260             String JavaDoc result = null;
261             AbstractTransaction tx = MyOodbManager.getTheManager().getTransactionManager().currentTransaction();
262             if (tx == null)
263             {
264                 AbstractCommand command = new GetXMLCommand(handle);
265                 MyOodbManager.getTheManager().getTransactionManager().processCommand(command, null, null);
266                 result = (String JavaDoc) command.getResult();
267             }
268             else
269             {
270                 result = tx.getXML(handle);
271             }
272
273             return result;
274         }
275         catch (RuntimeException JavaDoc e)
276         {
277             throw e;
278         }
279         catch (Exception JavaDoc e)
280         {
281             throw new InternalException("Caught during get xml: " + e, e);
282         }
283     }
284
285     public Object JavaDoc invokeMethod(MyOodbRemote obj, String JavaDoc methodName, String JavaDoc sig, Object JavaDoc[] args, int accessLevel, int timeout)
286     {
287         try
288         {
289             // TODO: finish deepConvert support
290
Converter.LocalToProxy(args);
291
292             Object JavaDoc result = null;
293             AbstractTransaction tx = MyOodbManager.getTheManager().getTransactionManager().currentTransaction();
294             if (tx == null)
295             {
296                 AbstractCommand command = new InvokeMethodCommand((MyOodbProxy)obj, methodName, sig, args, accessLevel);
297                 MyOodbManager.getTheManager().getTransactionManager().processCommand(command, null, null);
298                 result = command.getResult();
299             }
300             else
301             {
302                 result = tx.invokeMethod(((MyOodbProxy) obj).getDatabaseHandle(), methodName, sig, args, accessLevel);
303             }
304
305             // TODO: finish deepConvert support
306
result = Converter.LocalToProxy(result);
307
308             return result;
309         }
310         catch (RuntimeException JavaDoc e)
311         {
312             throw e;
313         }
314         catch (Exception JavaDoc e)
315         {
316             throw new InternalException("Caught during invoke method: " + e, e);
317         }
318     }
319
320     public Object JavaDoc invokeMethod(MyOodbRemote obj, int methodIndex, Object JavaDoc[] args, int accessLevel, int timeout)
321     {
322         try
323         {
324             // TODO: finish deepConvert support
325
Converter.LocalToProxy(args);
326
327             Object JavaDoc result = null;
328             AbstractTransaction tx = MyOodbManager.getTheManager().getTransactionManager().currentTransaction();
329             if (tx == null)
330             {
331                 AbstractCommand command = new InvokeMethodCommand((MyOodbProxy)obj, methodIndex, args, accessLevel);
332                 MyOodbManager.getTheManager().getTransactionManager().processCommand(command, null, null);
333                 result = command.getResult();
334             }
335             else
336             {
337                 result = tx.invokeMethod(((MyOodbProxy) obj).getDatabaseHandle(), methodIndex, args, accessLevel);
338             }
339
340             // TODO: finish deepConvert support
341
result = Converter.LocalToProxy(result);
342
343             return result;
344         }
345         catch (RuntimeException JavaDoc e)
346         {
347             throw e;
348         }
349         catch (Exception JavaDoc e)
350         {
351             throw new InternalException("Caught during invoke method: " + e, e);
352         }
353     }
354
355     public void setCommunicationInterfacePassword(String JavaDoc oldPassword, String JavaDoc newPassword)
356     {
357         throw new PermissionException("Invalid invocation (must not be called from within the server)");
358     }
359 }
360
Popular Tags