📄 remotedatabase.java
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Library 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: RemoteDatabase.java,v 1.5 2002/09/18 06:54:13 per_nyfelt Exp $
package org.ozoneDB;
import org.ozoneDB.core.DbRemote.*;
import java.io.IOException;
import java.util.Hashtable;
/**
* This class represents a remote database server that is connected via
* a network connection. For a detailed description of the API see {@link
* OzoneInterface}.
*
*
* @author <a href="http://www.softwarebuero.de/">SMB</a>
* @version $Revision: 1.5 $Date: 2002/09/18 06:54:13 $
* @see OzoneInterface
*/
public final class RemoteDatabase extends ExternalDatabase {
protected String hostname;
protected int portNum;
protected String userName;
protected String passwd;
public RemoteDatabase() {
}
/**
* Open a new database connection.
* @param hostName name of the host where the server resides
* @param portNum port of the server (default server setting: 3000)
*/
public void open( String hostName, int portNum ) throws Exception {
String userName = System.getProperty( "user.name" );
open( hostName, portNum, userName, userName );
}
/**
* Open a new database connection.
* @param hostName name of the host where the server resides
* @param portNum port of the server (default server setting: 3000)
* @param userName
* @param passwd
*/
public void open( String hostName, int portNum, String userName, String passwd ) throws Exception {
Hashtable props = new Hashtable();
props.put( PROP_HOST, hostName );
props.put( PROP_PORT, new Integer( portNum ) );
props.put( PROP_USER, userName );
props.put( PROP_PASSWD, passwd );
open( props );
}
/**
* @param _props The properties for the new connection.
*/
protected synchronized void open( Hashtable _props ) throws Exception {
try {
super.open( _props );
hostname = (String)_props.get( PROP_HOST );
portNum = 0;
if (_props.get( PROP_PORT ) != null) {
portNum = ((Integer)_props.get( PROP_PORT )).intValue();
}
userName = (String)_props.get( PROP_USER );
passwd = (String)_props.get( PROP_HOST );
if (hostname == null || portNum == 0) {
throw new RuntimeException( "No host and/or port specified." );
}
// try to open one real database connection to see if we are able to
// connect the server
DbClient connection = acquirePooledConnection();
releasePooledConnection( connection );
}
catch (Exception e) {
close();
throw e;
}
}
protected DbClient newConnection() throws Exception,DatabaseNotOpenException,IOException,org.ozoneDB.TransactionException,java.lang.ClassNotFoundException,org.ozoneDB.OzoneObjectException {
if (portNum == 0) {
throw new DatabaseNotOpenException();
}
DbClient connection = new DbRemoteClient(this,hostname,portNum,userName);
sendCommand(new DbOpen(userName),true,connection);
return connection;
}
public String toString() {
return "RemoteDatabase: " + hostname + ", " + portNum;
}
protected void finalize() throws Exception {
close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -