Package com.mobixess.jodb.tests.clientserver

Source Code of com.mobixess.jodb.tests.clientserver.ServerClientNQTests$SessionCloseListenerImpl

/*
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.NQTests;
import com.mobixess.jodb.tests.NqTestSE;


public class ServerClientNQTests extends NqTestSE{
   
    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws Exception {
        NQTests queryTests = new ServerClientNQTests();
        queryTests.directFieldRef(false);
        queryTests.directFieldRef(true);
        queryTests.sortingUnoptimized(true);
        queryTests.sortingUnoptimized(false);
        queryTests.unoptimized(true);
        queryTests.unoptimized(false);
        queryTests.sorting(true);
        queryTests.sorting(false);
        queryTests.simpleNQuery(false);
        queryTests.simpleNQuery(true);
        System.out.println("Test finished");
    }
    private JODBServer _lastServer;

    @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();
            }
        }
       
    }
}
TOP

Related Classes of com.mobixess.jodb.tests.clientserver.ServerClientNQTests$SessionCloseListenerImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.