1 2 11 12 package org.objectweb.rmijdbc; 13 14 import java.rmi.*; 15 import java.sql.*; 16 import java.rmi.server.Unreferenced ; 17 18 40 public class RJDriverServer 41 extends java.rmi.server.UnicastRemoteObject 42 implements RJDriverInterface, Unreferenced 43 { 44 45 private String admpasswd_ = null; 46 47 public RJDriverServer() throws RemoteException { 48 this(null); 49 } 50 51 public RJDriverServer(String admpasswd) throws RemoteException { 52 super(RJJdbcServer.rmiJdbcListenerPort, 53 RJJdbcServer.rmiClientSocketFactory, RJJdbcServer.rmiServerSocketFactory); 54 admpasswd_ = admpasswd; 56 } 57 58 public void unreferenced() { 59 Runtime.getRuntime().gc(); 61 } 62 63 66 67 public void shutdown(String pwd) throws RemoteException { 68 if(admpasswd_ == null) 69 throw new RemoteException( 70 "No administrative password defined for this server: shutdown is not allowed"); 71 72 if(admpasswd_.equals(pwd)) { 73 System.out.println("Shutting down RmiJdbc server, good bye!"); 74 System.exit(0); 75 } else { 76 throw new RemoteException("Wrong password: shutdown is not allowed"); 77 } 78 } 79 80 104 public RJConnectionInterface connect(String url, java.util.Properties info) 105 throws RemoteException, SQLException { 106 java.sql.Driver jdbcDriver; 107 if ((jdbcDriver = DriverManager.getDriver(url)) == null) { 108 throw new java.rmi.RemoteException ( 109 "RJDriverServer::connect: No suitable Driver"); 110 } 111 Connection c = jdbcDriver.connect(url, info); 113 if(c == null) { 114 throw new java.rmi.RemoteException ( 115 "RJDriverServer::connect: Underlying driver couldn\'t establish the connection: connect() returned null, check the configuration"); 116 } 117 return new RJConnectionServer(c); 118 } 119 120 129 public boolean acceptsURL(String url) throws RemoteException, SQLException { 130 return(DriverManager.getDriver(url) != null); 131 } 132 133 148 public RJDriverPropertyInfo[] getPropertyInfo(String url, 149 java.util.Properties info) throws RemoteException, SQLException { 150 java.sql.Driver jdbcDriver; 151 if((jdbcDriver = DriverManager.getDriver(url)) == null) { 152 throw new java.rmi.RemoteException ( 153 "RJDriverServer::getPropertyInfo: No suitable Driver"); 154 } 155 156 DriverPropertyInfo infos[] = jdbcDriver.getPropertyInfo(url, info); 159 if(infos == null) return null; 160 RJDriverPropertyInfo dpis[] = new RJDriverPropertyInfo[infos.length]; 161 for(int i=0; i<infos.length; i++) { 162 if(infos[i] == null) dpis[i] = null; 163 dpis[i] = new RJDriverPropertyInfo(infos[i]); 164 } 165 return dpis; 166 } 167 168 169 172 public int getMajorVersion() throws RemoteException, SQLException { 173 return 0; 174 } 175 176 179 public int getMinorVersion() throws RemoteException, SQLException { 180 return 1; 181 } 182 183 184 200 public boolean jdbcCompliant() { 201 return true; 202 } 203 204 }; 205 206 | Popular Tags |