How can you tell if the database is down or not?

I am using Spring DefaultMessageListenerContainer to consume messages from a queue. The messages are then stored in the Oracle database.

When the database goes down, I throw the exception from the onMessage method and leave the message in the queue for reprocessing. Below you can see that in DataAccessResourceFailureException and CannotCreateTransactionException, I am throwing the exception from the method that returns it to the queue. Other exceptions do not save the message; they correspond to data objectives, etc.

public void onMessage(javax.jms.Message mqMessage) {
    ...get the message blah, blah, blah
    try {
        this.theService.doMessage(tmaticMessage, theHandler);
    } catch (DataAccessResourceFailureException e) {
        this.slowDown(mqMessage);
        throw e;
    } catch (CannotCreateTransactionException e) {
        this.slowDown(mqMessage);
        throw e;
    } catch (DataAccessException e) {
        ...
    } catch (TmUnusableMessageException e) {
        ...
    } catch (Exception e) {
        ...
    }
}

      

Reading the Spring docs, I found that a DataAccessResourceFailureException should be thrown "... when the resource completely fails: for example, if we cannot connect to the database using JDBC". The problem is that I just ran the test when I had the DBA took the database and got a new exception: CannotCreateTransactionException. So this is another exception to throw. I am wondering if there are others.

I am using Spring Connections and getHibernateTemplate () to make my calls. Here's the question. How do I know what exceptions can be thrown when the database is down?

+3


source to share


1 answer


Perhaps the difficulty is due to the fact that you can "dump the database down". For example:

  • deleting a table
  • deleting the entire database
  • disabling db user account
  • shutting down the database server

Everything can be thought of as "dropping the database down", but each can cause a different exception to be dropped.



If you go through the following sections in the spring javadoc, there are lists of exceptions that can be thrown:

http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/dao/package-frame.html

http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/transaction/package-frame.html

0


source







All Articles