01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.osgi.test;
22:
23: import java.io.*;
24:
25: import org.osgi.framework.*;
26:
27: import com.db4o.*;
28: import com.db4o.config.*;
29: import com.db4o.foundation.*;
30: import com.db4o.osgi.*;
31:
32: import db4ounit.extensions.*;
33: import db4ounit.extensions.fixtures.*;
34:
35: class Db4oOSGiBundleFixture extends AbstractSoloDb4oFixture {
36:
37: private final BundleContext _context;
38: private final String _fileName;
39: private Configuration _config;
40:
41: public Db4oOSGiBundleFixture(BundleContext context, String fileName) {
42: super (new IndependentConfigurationSource());
43: _context = context;
44: _fileName = fileName;
45: }
46:
47: protected ObjectContainer createDatabase(Configuration config) {
48: // hack around sticky stream reference, should actually be fixed in config API
49: _config = config;
50: if (_config instanceof DeepClone) {
51: _config = (Configuration) ((DeepClone) _config)
52: .deepClone(null);
53: }
54: ServiceReference sRef = _context
55: .getServiceReference(Db4oService.class.getName());
56: Db4oService dbs = (Db4oService) _context.getService(sRef);
57: return dbs.openFile(_config, _fileName);
58: }
59:
60: protected void doClean() {
61: _config = null;
62: new File(_fileName).delete();
63: }
64:
65: public void defragment() throws Exception {
66: defragment(_fileName);
67: }
68:
69: public String getLabel() {
70: return "OSGi/bundle";
71: }
72:
73: public boolean accept(Class clazz) {
74: return super .accept(clazz)
75: && (!(OptOutNoFileSystemData.class
76: .isAssignableFrom(clazz)));
77: }
78:
79: public void configureAtRuntime(RuntimeConfigureAction action) {
80: action.apply(_config);
81: }
82:
83: }
|