001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004: //
005: // All Rights Reserved
006: //
007: // This program is free software; you can redistribute it and/or modify
008: // it under the terms of the GNU General Public License and GNU Library
009: // General Public License as published by the Free Software Foundation;
010: // either version 2, or (at your option) any later version.
011: //
012: // This program is distributed in the hope that it will be useful,
013: // but WITHOUT ANY WARRANTY; without even the implied warranty of
014: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: // GNU General Public License and GNU Library General Public License
016: // for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // and GNU Library General Public License along with this program; if
020: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021: // MA 02139, USA.
022: //
023: ///////////////////////////////////////////////////////////////////////////////
024: package org.myoodb.core;
025:
026: import org.myoodb.*;
027: import org.myoodb.exception.*;
028: import org.myoodb.core.command.*;
029:
030: public final class Database extends AbstractDatabase {
031: public Database() {
032: }
033:
034: public MyOodbProxy createRoot(String rootName, String className,
035: String sig, Object[] args) {
036: try {
037: MyOodbProxy result = null;
038: AbstractTransaction tx = MyOodbManager.getTheManager()
039: .getTransactionManager().currentTransaction();
040: if (tx == null) {
041: AbstractCommand command = new CreateCommand(rootName,
042: className, sig, args);
043: MyOodbManager.getTheManager().getTransactionManager()
044: .processCommand(command, null, null);
045: result = (MyOodbProxy) command.getResult();
046: } else {
047: result = tx.create(rootName, className, sig, args)
048: .getProxy();
049: }
050:
051: return result;
052: } catch (RuntimeException e) {
053: throw e;
054: } catch (Exception e) {
055: throw new InternalException("Caught during create root: "
056: + e, e);
057: }
058: }
059:
060: public MyOodbProxy createObject(String className, String sig,
061: Object[] args) {
062: try {
063: MyOodbProxy result = null;
064: AbstractTransaction tx = MyOodbManager.getTheManager()
065: .getTransactionManager().currentTransaction();
066: if (tx == null) {
067: AbstractCommand command = new CreateCommand(className,
068: sig, args);
069: MyOodbManager.getTheManager().getTransactionManager()
070: .processCommand(command, null, null);
071: result = (MyOodbProxy) command.getResult();
072: } else {
073: result = tx.create(null, className, sig, args)
074: .getProxy();
075: }
076:
077: return result;
078: } catch (RuntimeException e) {
079: throw e;
080: } catch (Exception e) {
081: throw new InternalException("Caught during create object: "
082: + e, e);
083: }
084: }
085:
086: public void deleteObject(MyOodbRemote obj) {
087: try {
088: AbstractTransaction tx = MyOodbManager.getTheManager()
089: .getTransactionManager().currentTransaction();
090: if (tx == null) {
091: AbstractCommand command = new DeleteCommand(obj
092: .getDatabaseHandle());
093: MyOodbManager.getTheManager().getTransactionManager()
094: .processCommand(command, null, null);
095: } else {
096: tx.delete(obj.getDatabaseHandle());
097: }
098: } catch (RuntimeException e) {
099: throw e;
100: } catch (Exception e) {
101: throw new InternalException("Caught during delete: " + e, e);
102: }
103: }
104:
105: public MyOodbProxy getRoot(String rootName) {
106: try {
107: MyOodbProxy result = null;
108: AbstractTransaction tx = MyOodbManager.getTheManager()
109: .getTransactionManager().currentTransaction();
110: if (tx == null) {
111: AbstractCommand command = new GetRootCommand(rootName);
112: MyOodbManager.getTheManager().getTransactionManager()
113: .processCommand(command, null, null);
114: result = (MyOodbProxy) command.getResult();
115: } else {
116: result = tx.getRoot(rootName);
117: }
118:
119: return result;
120: } catch (RuntimeException e) {
121: throw e;
122: } catch (Exception e) {
123: throw new InternalException("Caught during get root: " + e,
124: e);
125: }
126: }
127:
128: public final MyOodbLocal getObject(MyOodbRemote obj) {
129: try {
130: org.myoodb.core.MyOodbManager manager = org.myoodb.core.MyOodbManager
131: .getTheManager();
132: return manager.getStoreManager().getContainer(null,
133: obj.getDatabaseHandle()).getTarget();
134: } catch (RuntimeException e) {
135: throw e;
136: } catch (Exception e) {
137: throw new org.myoodb.exception.InternalException(
138: "Caught during get object: " + e, e);
139: }
140: }
141:
142: public MyOodbProxy getObject(org.myoodb.core.Identifier handle) {
143: try {
144: MyOodbProxy result = null;
145: AbstractTransaction tx = MyOodbManager.getTheManager()
146: .getTransactionManager().currentTransaction();
147: if (tx == null) {
148: AbstractCommand command = new GetObjectCommand(handle);
149: MyOodbManager.getTheManager().getTransactionManager()
150: .processCommand(command, null, null);
151: result = (MyOodbProxy) command.getResult();
152: } else {
153: result = tx.getObject(handle);
154: }
155:
156: return result;
157: } catch (RuntimeException e) {
158: throw e;
159: } catch (Exception e) {
160: throw new InternalException("Caught during get object: "
161: + e, e);
162: }
163: }
164:
165: public void setBean(org.myoodb.core.Identifier handle,
166: MyOodbBean bean) {
167: try {
168: AbstractTransaction tx = MyOodbManager.getTheManager()
169: .getTransactionManager().currentTransaction();
170: if (tx == null) {
171: AbstractCommand command = new SetBeanCommand(handle,
172: bean);
173: MyOodbManager.getTheManager().getTransactionManager()
174: .processCommand(command, null, null);
175: } else {
176: tx.setBean(handle, bean);
177: }
178: } catch (RuntimeException e) {
179: throw e;
180: } catch (Exception e) {
181: throw new InternalException("Caught during set bean: " + e,
182: e);
183: }
184: }
185:
186: public MyOodbBean getBean(org.myoodb.core.Identifier handle) {
187: try {
188: MyOodbBean result = null;
189: AbstractTransaction tx = MyOodbManager.getTheManager()
190: .getTransactionManager().currentTransaction();
191: if (tx == null) {
192: AbstractCommand command = new GetBeanCommand(handle);
193: MyOodbManager.getTheManager().getTransactionManager()
194: .processCommand(command, null, null);
195: result = (MyOodbBean) command.getResult();
196: } else {
197: result = tx.getBean(handle);
198: }
199:
200: return result;
201: } catch (RuntimeException e) {
202: throw e;
203: } catch (Exception e) {
204: throw new InternalException("Caught during get bean: " + e,
205: e);
206: }
207: }
208:
209: public void setXML(org.myoodb.core.Identifier handle, String xml) {
210: try {
211: AbstractTransaction tx = MyOodbManager.getTheManager()
212: .getTransactionManager().currentTransaction();
213: if (tx == null) {
214: AbstractCommand command = new SetXMLCommand(handle, xml);
215: MyOodbManager.getTheManager().getTransactionManager()
216: .processCommand(command, null, null);
217: } else {
218: tx.setXML(handle, xml);
219: }
220: } catch (RuntimeException e) {
221: throw e;
222: } catch (Exception e) {
223: throw new InternalException("Caught during set xml: " + e,
224: e);
225: }
226: }
227:
228: public String getXML(org.myoodb.core.Identifier handle) {
229: try {
230: String result = null;
231: AbstractTransaction tx = MyOodbManager.getTheManager()
232: .getTransactionManager().currentTransaction();
233: if (tx == null) {
234: AbstractCommand command = new GetXMLCommand(handle);
235: MyOodbManager.getTheManager().getTransactionManager()
236: .processCommand(command, null, null);
237: result = (String) command.getResult();
238: } else {
239: result = tx.getXML(handle);
240: }
241:
242: return result;
243: } catch (RuntimeException e) {
244: throw e;
245: } catch (Exception e) {
246: throw new InternalException("Caught during get xml: " + e,
247: e);
248: }
249: }
250:
251: public Object invokeMethod(MyOodbRemote obj, String methodName,
252: String sig, Object[] args, int accessLevel, int timeout) {
253: try {
254: // TODO: finish deepConvert support
255: Converter.LocalToProxy(args);
256:
257: Object result = null;
258: AbstractTransaction tx = MyOodbManager.getTheManager()
259: .getTransactionManager().currentTransaction();
260: if (tx == null) {
261: AbstractCommand command = new InvokeMethodCommand(obj
262: .getDatabaseHandle(), methodName, sig, args,
263: accessLevel);
264: MyOodbManager.getTheManager().getTransactionManager()
265: .processCommand(command, null, null);
266: result = command.getResult();
267: } else {
268: result = tx.invokeMethod(obj.getDatabaseHandle(),
269: methodName, sig, args, accessLevel);
270: }
271:
272: if (result instanceof org.myoodb.exception.ObjectException) {
273: throw (org.myoodb.exception.ObjectException) result;
274: }
275:
276: // TODO: finish deepConvert support
277: result = Converter.LocalToProxy(result);
278:
279: return result;
280: } catch (RuntimeException e) {
281: throw e;
282: } catch (Exception e) {
283: throw new InternalException("Caught during invoke method: "
284: + e, e);
285: }
286: }
287:
288: public Object invokeMethod(MyOodbRemote obj, int methodIndex,
289: Object[] args, int accessLevel, int timeout) {
290: try {
291: // TODO: finish deepConvert support
292: Converter.LocalToProxy(args);
293:
294: Object result = null;
295: AbstractTransaction tx = MyOodbManager.getTheManager()
296: .getTransactionManager().currentTransaction();
297: if (tx == null) {
298: AbstractCommand command = new InvokeMethodCommand(obj
299: .getDatabaseHandle(), methodIndex, args,
300: accessLevel);
301: MyOodbManager.getTheManager().getTransactionManager()
302: .processCommand(command, null, null);
303: result = command.getResult();
304: } else {
305: result = tx.invokeMethod(obj.getDatabaseHandle(),
306: methodIndex, args, accessLevel);
307: }
308:
309: if (result instanceof org.myoodb.exception.ObjectException) {
310: throw (org.myoodb.exception.ObjectException) result;
311: }
312:
313: // TODO: finish deepConvert support
314: result = Converter.LocalToProxy(result);
315:
316: return result;
317: } catch (RuntimeException e) {
318: throw e;
319: } catch (Exception e) {
320: throw new InternalException("Caught during invoke method: "
321: + e, e);
322: }
323: }
324:
325: public void setCommunicationInterfacePassword(String oldPassword,
326: String newPassword) {
327: throw new PermissionException(
328: "Invalid invocation (must not be called from within the server)");
329: }
330: }
|