01: /*
02: Copyright (C) 2007 Mobixess Inc. http://www.java-objects-database.com
03:
04: This file is part of the JODB (Java Objects Database) open source project.
05:
06: JODB is free software; you can redistribute it and/or modify it under
07: the terms of version 2 of the GNU General Public License as published
08: by the Free Software Foundation.
09:
10: JODB is distributed in the hope that it will be useful, but WITHOUT ANY
11: WARRANTY; without even the implied warranty of MERCHANTABILITY or
12: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: for more details.
14:
15: You should have received a copy of the GNU General Public License along
16: with this program; if not, write to the Free Software Foundation, Inc.,
17: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18: */
19: package com.mobixess.jodb.tests.clientserver;
20:
21: import java.io.File;
22: import java.io.IOException;
23:
24: import com.mobixess.jodb.core.ISessionCloseListener;
25: import com.mobixess.jodb.core.JODB;
26: import com.mobixess.jodb.core.JODBServer;
27: import com.mobixess.jodb.core.JODBSessionContainer;
28: import com.mobixess.jodb.tests.QueryTests;
29:
30: public class ServerClientQueryTest extends QueryTests {
31:
32: private JODBServer _lastServer;
33:
34: /**
35: * @param args
36: * @throws IOException
37: */
38: public static void main(String[] args) throws Exception {
39: QueryTests queryTests = new ServerClientQueryTest();
40: queryTests.queryByExample(true);
41: queryTests.sortingTest();
42: queryTests.queryByExample(false);
43: queryTests.stringFieldQueryCompare(true);
44: queryTests.stringFieldQueryCompare(false);
45: queryTests.primitiveFieldsQuery(true);
46: queryTests.primitiveFieldsQuery(false);
47: queryTests.classTypeConstraints(true);
48: queryTests.classTypeConstraints(false);
49: //queryTests.evaluationQueryTest(true);
50: //queryTests.evaluationQueryTest(false);
51: System.out.println("Test finished");
52: }
53:
54: @Override
55: public JODBSessionContainer getContainerForFile(File file)
56: throws IOException {
57: JODBServer server = _lastServer;
58: // if(server!=null){
59: // server.stop();
60: // }
61: _lastServer = JODB.openServer(file);
62: SessionCloseListenerImpl closeListener = new SessionCloseListenerImpl(
63: _lastServer);
64: JODBSessionContainer container = (JODBSessionContainer) JODB
65: .openClient("//127.0.0.1", null, "rw");
66: container.addCloseListener(closeListener);
67: return container;
68: }
69:
70: private static class SessionCloseListenerImpl implements
71: ISessionCloseListener {
72:
73: JODBServer _server;
74:
75: /**
76: * @param server
77: */
78: public SessionCloseListenerImpl(JODBServer server) {
79: super ();
80: _server = server;
81: }
82:
83: public void sessionClosed(JODBSessionContainer closedSession) {
84: try {
85: _server.stop();
86: } catch (IOException e) {
87: e.printStackTrace();
88: }
89: }
90:
91: }
92: }
|