⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dblocalclient.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Core License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
// $Id: DbLocalClient.java,v 1.7 2003/03/12 12:30:23 per_nyfelt Exp $

package org.ozoneDB.core.DbRemote;

import org.ozoneDB.*;
import org.ozoneDB.io.stream.ResolvingObjectInputStream;
import org.ozoneDB.core.Env;
import org.ozoneDB.core.User;

import java.io.*;


/**
 * Note: the entire connection is synchronized when ExternalDatabase is sending
 * a command through; so synchronization of send/receive is not strictly needed
 *
 * @author <a href="http://www.softwarebuero.de/">SMB</a>
 * @version $Revision: 1.7 $Date: 2003/03/12 12:30:23 $
 */
public class DbLocalClient extends DbClient {

    protected Env env;

    protected User user;

    protected DbCommand currentCommand = null;

    protected ByteArrayOutputStream copyStream;

    protected   ProxyObjectGate     proxyObjectGate;

    public DbLocalClient(ExternalDatabase _db,Env _env,String _user) throws /*Exception*/ org.ozoneDB.core.UserManagerException,org.ozoneDB.PermissionDeniedException{
        super( _db, _user );
        env = _env;

        user = env.userManager.userForName( _user );
        if (user == null) {
            throw new PermissionDeniedException( "No such user." );
        }

        copyStream = new ByteArrayOutputStream( 4 * 1024 );

        proxyObjectGate =   new ProxyObjectGate();

        env.getLocalClientTracker().addClient(this);
    }


    public synchronized void send( Object obj ) throws IOException {
        try {
            copyStream.reset();

            // FIXME: copy only args of DbInvoke
            currentCommand = (DbCommand)copyObject( obj, false );
            currentCommand.env = env;
            currentCommand.setProxyObjectGate(getProxyObjectGate());
            env.transactionManager.handleCommand(currentCommand,user/*this*/);
        } catch (Exception e) {
            throw new IOException( e.toString() );
        }
    }


    public synchronized Object receive() throws IOException, ClassNotFoundException {
        if (currentCommand == null) {
            throw new IllegalStateException( "Attempt to receive() without prior send()." );
        }
        Object result = copyObject( currentCommand.result, true );
        currentCommand = null;
        return result;
    }


    /**
     * Copy the given object using ByteArrayStreams so all streamable
     * objects (all database objects) can be copied.
     */
    protected synchronized Object copyObject( Object obj, boolean updateLinks ) throws IOException {
        ObjectInputStream in = null;
        try {
            copyStream.reset();

            ObjectOutputStream out = new ObjectOutputStream( copyStream );
            out.writeObject( obj );
            out.close();

            in = new ResolvingObjectInputStream( new ByteArrayInputStream( copyStream.toByteArray() ) );

            // remove in finally clause
            if (updateLinks) {
                OzoneProxy.linkTable.addForKey( db, in );
            }

            Object result = in.readObject();

            return result;
        } catch (Exception e) {
            throw new IOException( e.toString() );
        } finally {
            if (updateLinks && in != null) {
                OzoneProxy.linkTable.removeForKey( in );
            }
        }

    }


    public boolean objectAvailable() {
        throw new RuntimeException( "Method not implemented." );
    }


    public void close() throws IOException {
    }


    public void onConnect() throws IOException {
        throw new RuntimeException( "Method not implemented." );
    }


    public void onDeconnect() throws IOException {
        throw new RuntimeException( "Method not implemented." );
    }


    public ObjectInputStream inputStream() {
        throw new RuntimeException( "Method not implemented." );
    }


    public ObjectOutputStream outputStream() {
        throw new RuntimeException( "Method not implemented." );
    }

    /**
        Returns the ProxyObjectGate for this Client.
    */
    public ProxyObjectGate getProxyObjectGate() {
        return proxyObjectGate;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -