001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.internal;
022:
023: import com.db4o.*;
024: import com.db4o.config.*;
025: import com.db4o.constraints.*;
026: import com.db4o.ext.*;
027: import com.db4o.foundation.*;
028: import com.db4o.internal.callbacks.*;
029: import com.db4o.internal.query.*;
030: import com.db4o.query.*;
031: import com.db4o.reflect.*;
032: import com.db4o.reflect.generic.*;
033: import com.db4o.replication.*;
034: import com.db4o.types.*;
035:
036: /**
037: * @exclude
038: */
039: public abstract class PartialEmbeddedClientObjectContainer implements
040: TransientClass, ObjectContainerSpec {
041:
042: protected final LocalObjectContainer _server;
043:
044: protected final Transaction _transaction;
045:
046: private boolean _closed = false;
047:
048: public PartialEmbeddedClientObjectContainer(
049: LocalObjectContainer server, Transaction trans) {
050: _server = server;
051: _transaction = trans;
052: _transaction.setOutSideRepresentation(cast(this ));
053: }
054:
055: public PartialEmbeddedClientObjectContainer(
056: LocalObjectContainer server) {
057: this (server, server.newTransaction(server.systemTransaction(),
058: server.createReferenceSystem()));
059: }
060:
061: /** @param path */
062: public void backup(String path) throws Db4oIOException,
063: DatabaseClosedException, NotSupportedException {
064: throw new NotSupportedException();
065: }
066:
067: public void bind(Object obj, long id) throws InvalidIDException,
068: DatabaseClosedException {
069: _server.bind(_transaction, obj, id);
070: }
071:
072: public Db4oCollections collections() {
073: return _server.collections(_transaction);
074: }
075:
076: public Configuration configure() {
077:
078: // FIXME: Consider allowing configuring
079: // throw new NotSupportedException();
080:
081: // FIXME: Consider throwing NotSupportedException here.
082: synchronized (lock()) {
083: checkClosed();
084: return _server.configure();
085: }
086: }
087:
088: public Object descend(Object obj, String[] path) {
089: synchronized (lock()) {
090: checkClosed();
091: return _server.descend(_transaction, obj, path);
092: }
093: }
094:
095: private void checkClosed() {
096: if (isClosed()) {
097: throw new DatabaseClosedException();
098: }
099: }
100:
101: public Object getByID(long id) throws DatabaseClosedException,
102: InvalidIDException {
103: synchronized (lock()) {
104: checkClosed();
105: return _server.getByID(_transaction, id);
106: }
107: }
108:
109: public Object getByUUID(Db4oUUID uuid)
110: throws DatabaseClosedException, Db4oIOException {
111: synchronized (lock()) {
112: checkClosed();
113: return _server.getByUUID(_transaction, uuid);
114: }
115: }
116:
117: public long getID(Object obj) {
118: synchronized (lock()) {
119: checkClosed();
120: return _server.getID(_transaction, obj);
121: }
122: }
123:
124: public ObjectInfo getObjectInfo(Object obj) {
125: synchronized (lock()) {
126: checkClosed();
127: return _server.getObjectInfo(_transaction, obj);
128: }
129: }
130:
131: // TODO: Db4oDatabase is shared between embedded clients.
132: // This should work, since there is an automatic bind
133: // replacement. Replication test cases will tell.
134: public Db4oDatabase identity() {
135: synchronized (lock()) {
136: checkClosed();
137: return _server.identity();
138: }
139: }
140:
141: public boolean isActive(Object obj) {
142: synchronized (lock()) {
143: checkClosed();
144: return _server.isActive(_transaction, obj);
145: }
146: }
147:
148: public boolean isCached(long id) {
149: synchronized (lock()) {
150: checkClosed();
151: return _server.isCached(_transaction, id);
152: }
153: }
154:
155: public boolean isClosed() {
156: synchronized (lock()) {
157: return _closed == true;
158: }
159: }
160:
161: public boolean isStored(Object obj) throws DatabaseClosedException {
162: synchronized (lock()) {
163: checkClosed();
164: return _server.isStored(_transaction, obj);
165: }
166: }
167:
168: public ReflectClass[] knownClasses() {
169: synchronized (lock()) {
170: checkClosed();
171: return _server.knownClasses();
172: }
173: }
174:
175: public Object lock() {
176: return _server.lock();
177: }
178:
179: /** @param objectContainer */
180: public void migrateFrom(ObjectContainer objectContainer) {
181: throw new NotSupportedException();
182: }
183:
184: public Object peekPersisted(Object object, int depth,
185: boolean committed) {
186: synchronized (lock()) {
187: checkClosed();
188: return _server.peekPersisted(_transaction, object, depth,
189: committed);
190: }
191: }
192:
193: public void purge() {
194: synchronized (lock()) {
195: checkClosed();
196: _server.purge();
197: }
198: }
199:
200: public void purge(Object obj) {
201: synchronized (lock()) {
202: checkClosed();
203: _server.purge(_transaction, obj);
204: }
205: }
206:
207: public GenericReflector reflector() {
208: synchronized (lock()) {
209: checkClosed();
210: return _server.reflector();
211: }
212: }
213:
214: public void refresh(Object obj, int depth) {
215: synchronized (lock()) {
216: checkClosed();
217: _server.refresh(_transaction, obj, depth);
218: }
219: }
220:
221: public void releaseSemaphore(String name) {
222: synchronized (lock()) {
223: checkClosed();
224: _server.releaseSemaphore(_transaction, name);
225: }
226: }
227:
228: /**
229: * @param peerB
230: * @param conflictHandler
231: * @deprecated
232: */
233: public ReplicationProcess replicationBegin(ObjectContainer peerB,
234: ReplicationConflictHandler conflictHandler) {
235: throw new NotSupportedException();
236: }
237:
238: public void set(Object obj, int depth) {
239: synchronized (lock()) {
240: checkClosed();
241: _server.set(_transaction, obj, depth);
242: }
243: }
244:
245: public boolean setSemaphore(String name, int waitForAvailability) {
246: synchronized (lock()) {
247: checkClosed();
248: return _server.setSemaphore(_transaction, name,
249: waitForAvailability);
250: }
251: }
252:
253: public StoredClass storedClass(Object clazz) {
254: synchronized (lock()) {
255: checkClosed();
256: return _server.storedClass(_transaction, clazz);
257: }
258: }
259:
260: public StoredClass[] storedClasses() {
261: synchronized (lock()) {
262: checkClosed();
263: return _server.storedClasses(_transaction);
264: }
265: }
266:
267: public SystemInfo systemInfo() {
268: synchronized (lock()) {
269: checkClosed();
270: return _server.systemInfo();
271: }
272: }
273:
274: public long version() {
275: synchronized (lock()) {
276: checkClosed();
277: return _server.version();
278: }
279: }
280:
281: public void activate(Object obj, int depth) throws Db4oIOException,
282: DatabaseClosedException {
283: synchronized (lock()) {
284: checkClosed();
285: _server.activate(_transaction, obj, depth);
286: }
287:
288: }
289:
290: public boolean close() throws Db4oIOException {
291: synchronized (lock()) {
292: if (isClosed()) {
293: return false;
294: }
295: if (!_server.isClosed()) {
296: if (!_server.configImpl().isReadOnly()) {
297: commit();
298: }
299: }
300: _transaction.close(false);
301: _closed = true;
302: return true;
303: }
304: }
305:
306: public void commit() throws Db4oIOException,
307: DatabaseClosedException, DatabaseReadOnlyException,
308: UniqueFieldValueConstraintViolationException {
309: synchronized (lock()) {
310: checkClosed();
311: _server.commit(_transaction);
312: }
313: }
314:
315: public void deactivate(Object obj, int depth)
316: throws DatabaseClosedException {
317: synchronized (lock()) {
318: checkClosed();
319: _server.deactivate(_transaction, obj, depth);
320: }
321: }
322:
323: public void delete(Object obj) throws Db4oIOException,
324: DatabaseClosedException, DatabaseReadOnlyException {
325: synchronized (lock()) {
326: checkClosed();
327: _server.delete(_transaction, obj);
328: }
329: }
330:
331: public ExtObjectContainer ext() {
332: return (ExtObjectContainer) this ;
333: }
334:
335: public ObjectSet get(Object template) throws Db4oIOException,
336: DatabaseClosedException {
337: synchronized (lock()) {
338: checkClosed();
339: return _server.get(_transaction, template);
340: }
341: }
342:
343: public Query query() throws DatabaseClosedException {
344: synchronized (lock()) {
345: checkClosed();
346: return _server.query(_transaction);
347: }
348: }
349:
350: public ObjectSet query(Class clazz) throws Db4oIOException,
351: DatabaseClosedException {
352: synchronized (lock()) {
353: checkClosed();
354: return _server.query(_transaction, clazz);
355: }
356: }
357:
358: public ObjectSet query(Predicate predicate) throws Db4oIOException,
359: DatabaseClosedException {
360: synchronized (lock()) {
361: checkClosed();
362: return _server.query(_transaction, predicate);
363: }
364: }
365:
366: public ObjectSet query(Predicate predicate,
367: QueryComparator comparator) throws Db4oIOException,
368: DatabaseClosedException {
369: synchronized (lock()) {
370: checkClosed();
371: return _server.query(_transaction, predicate, comparator);
372: }
373: }
374:
375: public void rollback() throws Db4oIOException,
376: DatabaseClosedException, DatabaseReadOnlyException {
377: synchronized (lock()) {
378: checkClosed();
379: _server.rollback(_transaction);
380: }
381: }
382:
383: public void set(Object obj) throws DatabaseClosedException,
384: DatabaseReadOnlyException {
385: synchronized (lock()) {
386: checkClosed();
387: _server.set(_transaction, obj);
388: }
389: }
390:
391: public ObjectContainerBase container() {
392: return _server;
393: }
394:
395: public Transaction transaction() {
396: return _transaction;
397: }
398:
399: public void callbacks(Callbacks cb) {
400: synchronized (lock()) {
401: checkClosed();
402: _server.callbacks(cb);
403: }
404: }
405:
406: public Callbacks callbacks() {
407: synchronized (lock()) {
408: checkClosed();
409: return _server.callbacks();
410: }
411: }
412:
413: public final NativeQueryHandler getNativeQueryHandler() {
414: synchronized (lock()) {
415: checkClosed();
416: return _server.getNativeQueryHandler();
417: }
418: }
419:
420: public void onCommittedListener() {
421: // do nothing
422: }
423:
424: private static ObjectContainer cast(
425: PartialEmbeddedClientObjectContainer container) {
426: return (ObjectContainer) container;
427: }
428:
429: public ClassMetadata classMetadataForReflectClass(
430: ReflectClass reflectClass) {
431: return _server.classMetadataForReflectClass(reflectClass);
432: }
433:
434: public ClassMetadata classMetadataForName(String name) {
435: return _server.classMetadataForName(name);
436: }
437:
438: public ClassMetadata classMetadataForId(int id) {
439: return _server.classMetadataForId(id);
440: }
441:
442: public HandlerRegistry handlers() {
443: return _server.handlers();
444: }
445:
446: }
|