1 2 package com.teamkonzept.db; 3 4 import java.sql.*; 5 import java.util.Enumeration ; 6 import java.util.Properties ; 7 8 import com.teamkonzept.lib.*; 9 import org.apache.log4j.Category; 10 11 31 public class TKDBManager { 32 33 34 private static final Category CAT = Category.getInstance(TKDBManager.class); 35 36 41 43 49 51 54 57 64 66 69 71 81 87 93 113 122 126 protected static final void register( Thread currThread ) 127 { 128 } 130 131 134 public static void register() 135 { 136 } 138 139 145 public static void register( Object initialContext ) 146 { 147 } 156 157 167 protected static void enterContext( Thread currThread, Object nextContext, boolean leaveOldContext ) throws SQLException 168 { 169 if( leaveOldContext ) { 170 TKDBConnectionManager.getInstance().freeConnection(); 176 } 177 178 } 182 183 186 197 206 213 217 protected static void resetContext() 218 { 219 getManager().resetConnections(); 220 } 221 222 232 public static synchronized void deregister( boolean doClose ) throws SQLException 233 { 234 235 237 241 TKDBConnectionManager.getInstance().freeConnection(); 253 } 254 255 259 public static TKDBConnectionManager getManager() 260 { 261 return TKDBConnectionManager.getInstance(); 268 } 269 270 274 public static Connection getConnection() throws SQLException 275 { 276 return getManager().getConnection(); 277 } 278 279 280 314 public static void beginTransaction() throws SQLException 315 { 316 getManager().beginTransaction(); 317 } 318 319 325 public static void commitTransaction() throws SQLException 326 { 327 getManager().commitTransaction(); 328 } 329 330 335 public static void rollbackTransaction() throws SQLException 336 { 337 getManager().rollbackTransaction(); 338 } 339 340 350 public static void safeRollbackTransaction(Throwable t) 351 { 352 try{ 353 CAT.error("Rollback Reason: ", t); 354 rollbackTransaction(); 355 356 } 357 catch(SQLException e){ 358 CAT.debug("SQLException during rollback", e); 359 } 360 361 if (t instanceof SQLException) 362 { 363 throw new TKSQLError("Rollback: " + t.getMessage(), (SQLException) t); 364 } 365 366 if (t instanceof TKSQLError) 367 { 368 throw new TKSQLError("Rollback: " + t.getMessage(), ((TKSQLError) t).getSQLException()); 369 } 370 371 throw new TKSQLError("Rollback: " + t.getMessage()); 372 } 373 374 375 381 public static void closeNonsensitiveQueries() throws SQLException 382 { 383 getManager().closeNonsensitiveQueries(); 384 } 385 386 387 388 396 public static void executeAsTran(TKQuery [] queryArray) { 397 try{ 398 beginTransaction(); 399 int i; 400 for(i = 0; i < queryArray.length; i++){ 401 queryArray[i].execute(); 402 queryArray[i].close(); 403 } 404 commitTransaction(); 405 } 406 catch( Throwable t){ 407 safeRollbackTransaction(t); 408 } 409 } 410 411 416 421 425 429 433 437 439 450 public static TKQuery newQuery( Class queryClass ) throws SQLException 451 { 452 return getManager().newQuery( queryClass ); 453 } 454 455 459 463 464 472 public static void prepareConnection(Properties prop ) 473 throws SQLException 474 { 475 getManager().prepareConnection( prop ); 476 } 477 478 481 public static void closeConnection() throws SQLException 482 { 483 getManager().closeConnection(); 484 } 485 486 489 public static void freeConnection() throws SQLException 490 { 491 getManager().freeConnection(); 492 } 493 494 498 public static void limitConnections( int count ) 499 { 500 getManager().limitConnections( count ); 501 } 502 503 506 516 public static int getDBVendor() 517 { 518 TKConnectData connectData = getManager().getConnectionData(); 519 520 if(connectData == null){ 521 return QueryConstants.DONTKNOW; 522 } 523 if(connectData instanceof TKOracleConnectData){ 524 return QueryConstants.ORACLE; 525 } 526 if(connectData instanceof TKSybaseConnectData){ 527 return QueryConstants.SYBASE; 528 } 529 if(connectData instanceof TKPostgreSQLConnectData){ 530 return QueryConstants.POSTGRESQL; 531 } 532 else{ 533 return QueryConstants.DONTKNOW; 534 } 535 536 } 537 538 539 } 540 541
| Popular Tags
|