1 2 11 12 package org.objectweb.rmijdbc; 13 14 import java.sql.*; 15 16 import java.rmi.*; 17 import java.rmi.server.UnicastRemoteObject ; 18 import java.rmi.server.Unreferenced ; 19 20 24 25 45 public class RJConnectionServer 46 extends UnicastRemoteObject 47 implements RJConnectionInterface, Unreferenced 48 { 49 50 java.sql.Connection jdbcConnection_; 51 52 public RJConnectionServer(java.sql.Connection c) throws RemoteException { 53 super(RJJdbcServer.rmiJdbcListenerPort, RJJdbcServer.rmiClientSocketFactory, RJJdbcServer.rmiServerSocketFactory); 54 jdbcConnection_ = c; 55 } 56 57 58 public void unreferenced() { 59 try { 60 if(jdbcConnection_ != null) { 61 try { 63 if(! jdbcConnection_.getAutoCommit()) 64 jdbcConnection_.rollback(); 65 } catch(Exception e) { 66 } 68 jdbcConnection_.close(); 69 jdbcConnection_ = null; 70 } 71 } catch(Exception e) { 72 jdbcConnection_ = null; 73 } 74 Runtime.getRuntime().gc(); 76 } 77 78 79 protected void finalize() throws Throwable { 80 if (jdbcConnection_ != null) { 81 jdbcConnection_.close(); 82 } 83 Runtime.getRuntime().gc(); 85 } 86 87 95 public RJStatementInterface createStatement() 96 throws RemoteException, SQLException { 97 return new RJStatementServer(jdbcConnection_.createStatement()); 98 } 99 100 121 public RJPreparedStatementInterface prepareStatement(String sql) 122 throws RemoteException, SQLException { 123 return new RJPreparedStatementServer(jdbcConnection_.prepareStatement(sql)); 124 } 125 126 146 public RJCallableStatementInterface prepareCall(String sql) 147 throws RemoteException, SQLException { 148 return new RJCallableStatementServer(jdbcConnection_.prepareCall(sql)); 149 } 150 151 161 public String nativeSQL(String sql) throws RemoteException, SQLException { 162 return jdbcConnection_.nativeSQL(sql); 163 } 164 165 185 public void setAutoCommit(boolean autoCommit) 186 throws RemoteException, SQLException { 187 jdbcConnection_.setAutoCommit(autoCommit); 188 } 189 190 195 public boolean getAutoCommit() throws RemoteException, SQLException { 196 return jdbcConnection_.getAutoCommit(); 197 } 198 199 207 public void commit() throws RemoteException, SQLException { 208 jdbcConnection_.commit(); 209 } 210 211 219 public void rollback() throws RemoteException, SQLException { 220 jdbcConnection_.rollback(); 221 } 222 223 233 public void close() throws RemoteException, SQLException { 234 if(jdbcConnection_ != null) jdbcConnection_.close(); 235 Runtime.getRuntime().gc(); } 237 238 243 public boolean isClosed() throws RemoteException, SQLException { 244 return jdbcConnection_.isClosed(); 245 } 246 247 250 259 public RJDatabaseMetaDataInterface getMetaData() 260 throws RemoteException, SQLException { 261 return new RJDatabaseMetaDataServer(jdbcConnection_.getMetaData()); 262 } 263 264 274 public void setReadOnly(boolean readOnly) 275 throws RemoteException, SQLException { 276 jdbcConnection_.setReadOnly(readOnly); 277 } 278 279 284 public boolean isReadOnly() throws RemoteException, SQLException { 285 return jdbcConnection_.isReadOnly(); 286 } 287 288 293 public void setCatalog(String catalog) throws RemoteException, SQLException { 294 jdbcConnection_.setCatalog(catalog); 295 } 296 297 302 public String getCatalog() throws RemoteException, SQLException { 303 return jdbcConnection_.getCatalog(); 304 } 305 306 319 public void setTransactionIsolation(int level) 320 throws RemoteException, SQLException { 321 jdbcConnection_.setTransactionIsolation(level); 322 } 323 324 329 public int getTransactionIsolation() throws RemoteException, SQLException { 330 return jdbcConnection_.getTransactionIsolation(); 331 } 332 333 342 public SQLWarning getWarnings() throws RemoteException, SQLException { 343 return jdbcConnection_.getWarnings(); 344 } 345 346 350 public void clearWarnings() throws RemoteException, SQLException { 351 jdbcConnection_.clearWarnings(); 352 } 353 354 357 public void setTypeMap(java.util.Map map) 358 throws RemoteException, SQLException { 359 jdbcConnection_.setTypeMap(map); 360 } 361 362 public RJPreparedStatementInterface prepareStatement(String sql, 363 int resultSetType, int resultSetConcurrency) 364 throws RemoteException, SQLException { 365 return new RJPreparedStatementServer( 366 jdbcConnection_.prepareStatement(sql, resultSetType, 367 resultSetConcurrency)); 368 } 369 370 public RJCallableStatementInterface prepareCall(String sql, int resultSetType, 371 int resultSetConcurrency) throws RemoteException, SQLException { 372 return new RJCallableStatementServer(jdbcConnection_.prepareCall(sql, 373 resultSetType,resultSetConcurrency)); 374 } 375 376 377 public java.util.Map getTypeMap() throws RemoteException, SQLException { 378 return jdbcConnection_.getTypeMap(); 379 } 380 381 public RJStatementInterface createStatement(int resultSetType, 382 int resultSetConcurrency) throws RemoteException, SQLException { 383 return new RJStatementServer(jdbcConnection_.createStatement(resultSetType, 384 resultSetConcurrency)); 385 } 386 387 417 418 419 421 public void setHoldability(int holdability) 422 throws java.rmi.RemoteException , SQLException { 423 jdbcConnection_.setHoldability(holdability); 424 } 425 426 public int getHoldability() throws java.rmi.RemoteException , SQLException { 427 return jdbcConnection_.getHoldability(); 428 } 429 430 public RJSavepointInterface setSavepoint() 431 throws java.rmi.RemoteException , SQLException { 432 return new RJSavepointServer(jdbcConnection_.setSavepoint()); 433 } 434 435 public RJSavepointInterface setSavepoint(String name) 436 throws java.rmi.RemoteException , SQLException { 437 return new RJSavepointServer(jdbcConnection_.setSavepoint(name)); 438 } 439 440 public void rollback(Savepoint savepoint) 441 throws java.rmi.RemoteException , SQLException { 442 jdbcConnection_.rollback(savepoint); 443 } 444 445 public void releaseSavepoint(Savepoint savepoint) 446 throws java.rmi.RemoteException , SQLException { 447 jdbcConnection_.releaseSavepoint(savepoint); 448 } 449 450 public RJStatementInterface createStatement(int resultSetType, 451 int resultSetConcurrency, int resultSetHoldability) 452 throws java.rmi.RemoteException , SQLException { 453 return new RJStatementServer( 454 jdbcConnection_.createStatement(resultSetType, resultSetConcurrency, 455 resultSetHoldability)); 456 } 457 458 public RJPreparedStatementInterface prepareStatement(String sql, 459 int resultSetType, int resultSetConcurrency, int resultSetHoldability) 460 throws java.rmi.RemoteException , SQLException { 461 return new RJPreparedStatementServer( 462 jdbcConnection_.prepareStatement(sql, resultSetType, 463 resultSetConcurrency, resultSetHoldability)); 464 } 465 466 public RJCallableStatementInterface prepareCall(String sql, int resultSetType, 467 int resultSetConcurrency, int resultSetHoldability) 468 throws java.rmi.RemoteException , SQLException { 469 return new RJCallableStatementServer( 470 jdbcConnection_.prepareCall(sql, resultSetType, 471 resultSetConcurrency, resultSetHoldability)); 472 } 473 474 public RJPreparedStatementInterface prepareStatement(String sql, 475 int autoGeneratedKeys) throws java.rmi.RemoteException , SQLException { 476 return new RJPreparedStatementServer( 477 jdbcConnection_.prepareStatement(sql, autoGeneratedKeys)); 478 } 479 480 public RJPreparedStatementInterface prepareStatement(String sql, 481 int columnIndexes[]) throws java.rmi.RemoteException , SQLException { 482 return new RJPreparedStatementServer( 483 jdbcConnection_.prepareStatement(sql, columnIndexes)); 484 } 485 486 public RJPreparedStatementInterface prepareStatement(String sql, 487 String columnNames[]) throws java.rmi.RemoteException , SQLException { 488 return new RJPreparedStatementServer( 489 jdbcConnection_.prepareStatement(sql, columnNames)); 490 } 491 492 }; 493 494 | Popular Tags |