KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > db4ounit > extensions > fixtures > Db4oSingleClient


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 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 db4ounit.extensions.fixtures;
22
23 import java.io.IOException JavaDoc;
24
25 import com.db4o.Db4o;
26 import com.db4o.ext.ExtObjectContainer;
27
28 import db4ounit.TestException;
29 import db4ounit.extensions.Db4oTestCase;
30
31 public class Db4oSingleClient extends AbstractClientServerDb4oFixture {
32
33     private ExtObjectContainer _objectContainer;
34
35     public Db4oSingleClient(ConfigurationSource config, String JavaDoc fileName,
36             int port) {
37         super(config, fileName, port);
38     }
39
40     public Db4oSingleClient(ConfigurationSource config) {
41         super(config);
42     }
43
44     public Db4oSingleClient() {
45         this(new IndependentConfigurationSource());
46     }
47
48     public void close() throws Exception JavaDoc {
49         _objectContainer.close();
50         super.close();
51     }
52
53     public void open() throws Exception JavaDoc {
54         super.open();
55         try {
56             _objectContainer = Db4o.openClient(config(), HOST, PORT, USERNAME,
57                     PASSWORD).ext();
58         } catch (IOException JavaDoc e) {
59             e.printStackTrace();
60             throw new TestException(e);
61         }
62     }
63
64     /**
65      * Does not accept a clazz which is assignable from OptOutCS, or not
66      * assignable from Db4oTestCase.
67      *
68      * @return returns false if the clazz is assignable from OptOutCS, or not
69      * assignable from Db4oTestCase. Otherwise, returns true.
70      */

71     public boolean accept(Class JavaDoc clazz) {
72         if ((OptOutCS.class.isAssignableFrom(clazz))
73                 || !Db4oTestCase.class.isAssignableFrom(clazz)) {
74             return false;
75         }
76         return true;
77     }
78
79     public ExtObjectContainer db() {
80         return _objectContainer;
81     }
82
83     public String JavaDoc getLabel() {
84         return "C/S SINGLE-CLIENT";
85     }
86
87 }
88
Popular Tags