/*
Copyright (C) 2007 Mobixess Inc. http://www.java-objects-database.com
This file is part of the JODB (Java Objects Database) open source project.
JODB is free software; you can redistribute it and/or modify it under
the terms of version 2 of the GNU General Public License as published
by the Free Software Foundation.
JODB is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.mobixess.jodb.tests.clientserver;
import java.io.File;
import java.io.IOException;
import com.mobixess.jodb.core.ISessionCloseListener;
import com.mobixess.jodb.core.JODB;
import com.mobixess.jodb.core.JODBServer;
import com.mobixess.jodb.core.JODBSessionContainer;
import com.mobixess.jodb.tests.QueryTests;
public class ServerClientQueryTest extends QueryTests {
private JODBServer _lastServer;
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws Exception {
QueryTests queryTests = new ServerClientQueryTest();
queryTests.queryByExample(true);
queryTests.sortingTest();
queryTests.queryByExample(false);
queryTests.stringFieldQueryCompare(true);
queryTests.stringFieldQueryCompare(false);
queryTests.primitiveFieldsQuery(true);
queryTests.primitiveFieldsQuery(false);
queryTests.classTypeConstraints(true);
queryTests.classTypeConstraints(false);
//queryTests.evaluationQueryTest(true);
//queryTests.evaluationQueryTest(false);
System.out.println("Test finished");
}
@Override
public JODBSessionContainer getContainerForFile(File file) throws IOException
{
JODBServer server = _lastServer;
// if(server!=null){
// server.stop();
// }
_lastServer = JODB.openServer(file);
SessionCloseListenerImpl closeListener = new SessionCloseListenerImpl(_lastServer);
JODBSessionContainer container = (JODBSessionContainer) JODB.openClient("//127.0.0.1", null, "rw", null);
container.addCloseListener(closeListener);
return container;
}
private static class SessionCloseListenerImpl implements ISessionCloseListener{
JODBServer _server;
/**
* @param server
*/
public SessionCloseListenerImpl(JODBServer server) {
super();
_server = server;
}
public void sessionClosed(JODBSessionContainer closedSession) {
try {
_server.stop();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}