1 9 package org.ozoneDB; 10 11 import org.ozoneDB.core.DbRemote.*; 12 13 import java.io.IOException ; 14 import java.util.Hashtable ; 15 16 17 27 public final class RemoteDatabase extends ExternalDatabase { 28 29 protected String hostname; 30 31 protected int portNum; 32 33 protected String userName; 34 35 protected String passwd; 36 37 38 public RemoteDatabase() { 39 } 40 41 42 47 public void open( String hostName, int portNum ) throws Exception { 48 String userName = System.getProperty( "user.name" ); 49 open( hostName, portNum, userName, userName ); 50 } 51 52 53 60 public void open( String hostName, int portNum, String userName, String passwd ) throws Exception { 61 Hashtable props = new Hashtable (); 62 props.put( PROP_HOST, hostName ); 63 props.put( PROP_PORT, new Integer ( portNum ) ); 64 props.put( PROP_USER, userName ); 65 props.put( PROP_PASSWD, passwd ); 66 open( props ); 67 } 68 69 70 73 protected synchronized void open( Hashtable _props ) throws Exception { 74 try { 75 super.open( _props ); 76 77 hostname = (String )_props.get( PROP_HOST ); 78 portNum = 0; 79 if (_props.get( PROP_PORT ) != null) { 80 portNum = ((Integer )_props.get( PROP_PORT )).intValue(); 81 } 82 userName = (String )_props.get( PROP_USER ); 83 passwd = (String )_props.get( PROP_HOST ); 84 85 if (hostname == null || portNum == 0) { 86 throw new RuntimeException ( "No host and/or port specified." ); 87 } 88 89 DbClient connection = acquirePooledConnection(); 92 releasePooledConnection( connection ); 93 } 94 catch (Exception e) { 95 close(); 96 throw e; 97 } 98 } 99 100 101 protected DbClient newConnection() throws Exception ,DatabaseNotOpenException,IOException ,org.ozoneDB.TransactionException,java.lang.ClassNotFoundException ,org.ozoneDB.OzoneObjectException { 102 if (portNum == 0) { 103 throw new DatabaseNotOpenException(); 104 } 105 DbClient connection = new DbRemoteClient(this,hostname,portNum,userName); 106 107 sendCommand(new DbOpen(userName),true,connection); 108 109 return connection; 110 } 111 112 113 public String toString() { 114 return "RemoteDatabase: " + hostname + ", " + portNum; 115 } 116 117 118 protected void finalize() throws Exception { 119 close(); 120 } 121 122 } 123 | Popular Tags |