Skip to content

Commit

Permalink
fixed database connection algo.
Browse files Browse the repository at this point in the history
  • Loading branch information
vertigo17 committed Nov 9, 2024
1 parent ffe5e1f commit 7d3343e
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions source/src/main/java/org/cerberus/core/database/DatabaseSpring.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,32 @@ public Connection connect(final String connection) throws CerberusEventException
return ds.getConnection();

} catch (SQLException ex) {
LOG.warn(ex.toString());

} catch (NamingException ex) {
LOG.warn(ex.toString());
LOG.warn(ex.toString(), ex);
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL);
msg
.resolveDescription("JDBC", "jdbc/" + connection)
.resolveDescription("ERROR", ex.toString());
throw new CerberusEventException(msg);
// InitialContext ic;
// try {
// ic = new InitialContext();
// String conName = "java:/comp/env/jdbc/" + connection;
// LOG.info("connecting to '{}'", conName);
// DataSource ds = (DataSource) ic.lookup(conName);
// return ds.getConnection();
// } catch (NamingException | SQLException ex1) {
// LOG.warn(ex.toString());
// }

} catch (NamingException ex) {
InitialContext ic;
try {
ic = new InitialContext();
String conName = "java:/comp/env/jdbc/" + connection;
LOG.info("failed with '" + "jdbc/" + connection + "' --> connecting to '{}'", conName);
DataSource ds = (DataSource) ic.lookup(conName);
return ds.getConnection();

} catch (NamingException | SQLException ex1) {

LOG.warn("failed connection with 'java:/comp/env/jdbc/" + connection + "'", ex.toString());
msg = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_SQL);
msg
.resolveDescription("JDBC", "java:/comp/env/jdbc/" + connection)
.resolveDescription("ERROR", ex.toString());
throw new CerberusEventException(msg);
}
}
return null;
}

public boolean isOnTransaction() {
Expand Down

0 comments on commit 7d3343e

Please sign in to comment.