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.test.legacy.soda.engines.db4o;
022:
023: import java.io.*;
024:
025: import com.db4o.*;
026: import com.db4o.foundation.*;
027: import com.db4o.query.*;
028: import com.db4o.test.legacy.soda.*;
029:
030: public class STDb4oClientServer implements STEngine {
031:
032: private static final int PORT = 4044;
033: private static final String HOST = "localhost";
034: private static final String FILE = "sodacs.yap";
035: private static final String USER = "S.O.D.A.";
036: private static final String PASS = "rocks";
037:
038: private static final boolean IN_PROCESS_SERVER = true;
039:
040: private com.db4o.ObjectServer server;
041: private com.db4o.ObjectContainer con;
042:
043: /**
044: * starts a db4o server.
045: * <br>To test with a remote server:<br>
046: * - set IN_PROCESS_SERVER to false
047: * - start STDb4oClientServer on the server
048: * - run SodaTest on the client
049: * - STDb4oClientServer needs to be uncommented in SodaTest#ENGINES
050: * The server can be stopped with CTRL + C.
051: */
052: public static void main(String[] args) {
053: new File(FILE).delete();
054: ObjectServer server = Db4o.openServer(FILE, PORT);
055: server.grantAccess(USER, PASS);
056: server.ext().configure().messageLevel(-1);
057: }
058:
059: public void reset() {
060: new File(FILE).delete();
061: }
062:
063: public Query query() {
064: return con.query();
065: }
066:
067: public void open() {
068: Db4o.configure().messageLevel(-1);
069:
070: if (IN_PROCESS_SERVER) {
071: server = Db4o.openServer(FILE, PORT);
072: server.grantAccess(USER, PASS);
073: // wait for the server to be online
074: Cool.sleepIgnoringInterruption(3000);
075: }
076: try {
077: con = Db4o.openClient(HOST, PORT, USER, PASS);
078: } catch (Exception e) {
079: e.printStackTrace();
080: }
081: }
082:
083: public void close() {
084: con.close();
085: if (IN_PROCESS_SERVER) {
086: server.close();
087: }
088: }
089:
090: public void store(Object obj) {
091: con.set(obj);
092: }
093:
094: public void commit() {
095: con.commit();
096: }
097:
098: public void delete(Object obj) {
099: con.delete(obj);
100: }
101: }
|