Open the specified database connection. @return Connection to the database
()
| 373 | * @return Connection to the database |
| 374 | */ |
| 375 | protected Connection open() { |
| 376 | |
| 377 | try { |
| 378 | Context context; |
| 379 | if (localDataSource) { |
| 380 | context = ContextBindings.getClassLoader(); |
| 381 | context = (Context) context.lookup("comp/env"); |
| 382 | } else { |
| 383 | Server server = getServer(); |
| 384 | if (server == null) { |
| 385 | connectionSuccess = false; |
| 386 | containerLog.error(sm.getString("dataSourceRealm.noNamingContext")); |
| 387 | return null; |
| 388 | } |
| 389 | context = server.getGlobalNamingContext(); |
| 390 | } |
| 391 | DataSource dataSource = (DataSource) context.lookup(dataSourceName); |
| 392 | Connection connection = dataSource.getConnection(); |
| 393 | connectionSuccess = true; |
| 394 | return connection; |
| 395 | } catch (Exception e) { |
| 396 | connectionSuccess = false; |
| 397 | // Log the problem for posterity |
| 398 | containerLog.error(sm.getString("dataSourceRealm.exception"), e); |
| 399 | } |
| 400 | return null; |
| 401 | } |
| 402 | |
| 403 | @Override |
| 404 | protected String getPassword(String username) { |
no test coverage detected