WebObjects 4.5 Oracle Adaptor: Reconnecting After an Oracle Connection Failure

This article describes how to get WebObjects 4.5 Oracle Adaptor to recognize additional error codes, other than the standard six, so that it can detect a connection failure.
Symptom

The automatic database reconnection feature in WebObjects 4.5 fails to reconnect a client to the host Oracle database.

Solution

There are only six predefined Oracle error codes recognized by WebObjects as connection failures. When any Oracle error code other than these six occurs, the OracleAdaptor method isDroppedConnectionException returns NO/False. By default, when isDroppedConnectionException returns NO, no reconnection is attempted, and the original exception is raised as usual.

For additional error codes to be recognized, they need to be added to the WebObjects Framework and recompiled.

Recognized Oracle Error codes


Additional information on Oracle error codes is available in Oracle documentation.

Adding Additional Error Codes

To change the default behavior, include this Objective C category to your project, and add the error code. Once the error code is added, Enterprise Object Framework (EOF) will attempt an automatic reconnection.

You must add the OracleEOAdaptor.framework to the list of frameworks in your project to recompile your project successfully.

------File OracleConnectionErrorAdditions.m----------------


#include <OracleEOAdaptor/OracleAdaptor.h>

@implementation
OracleAdaptor(OracleConnectionErrorAdditions)

- (BOOL)isDroppedConnectionException:(NSException
*)exception
{
   NSDictionary *userInfo = [exception userInfo];
   if (userInfo) {
       int errCode = [[userInfo
objectForKey:OracleErrorKey] intValue];
       // 00028 session killed
       // 00030 user session no longer exists
       // 00051 time out
       // 00060 deadlock
       // 00099 PDML deadlock
       // 01012 not logged on
       switch (errCode) {
           case 28:
           case 30:
           case 51:
           case 60:
           case 1012:
           case 99:
       // ADD YOUR ERROR CODE HERE. FOR EXAMPLE ORA-01041:
                 //     ORA-01041: internal error. HOSTDEF extension
does not exist

           case 1041:                                
               return YES;
               // Yes, the exception comes from a dropped connection
           default:
               return NO;
               // adaptor should NOT try to reconnect, and should re-raise the exception

       }
   }
   return NO;
}
@end
-----------------------------------------------------------

Published Date: Feb 20, 2012