RE: Connection to Database Exception
"Watkins, Garry" <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.devel |
|---|---|
| Message-ID | <[email protected]> |
Try looking at ERXDatabaseContextDelegate of project wonder. I extended
and modified their version to handle SQL Server, look at code below.
Garry
/**
* Allows custom handling of dropped connection exceptions.
* @param dbc current database context
* @param e throw exception
* @return if the exception is one of the bad ones that isn't
handled then the method <code>handleDroppedConnection</code>
* is called directly on the database object of the context
and <code>false</code> is returned otherwise <code>true</code>.
*/
public boolean
databaseContextShouldHandleDatabaseException(EODatabaseContext dbc,
Throwable e) {
EOAdaptor adaptor=dbc.adaptorContext().adaptor();
boolean manuallyHandleConnection = false;
if(e instanceof EOGeneralAdaptorException)
log.error(((EOGeneralAdaptorException)e).userInfo());
else
log.error(e);
if (adaptor.isDroppedConnectionException((Exception)e)){
log.error("Adaptor detected a dropped connection -
Adaptor should handle it");
return true;
}
// SQLServer Error Handling
JDBCAdaptorException jdbcException = null;
if (e instanceof JDBCAdaptorException) {
jdbcException =(JDBCAdaptorException) e;
}
String errorMessage = e.getMessage();
if (null != jdbcException){
SQLException sqlx = jdbcException.sqlException();
if ("Not connected".equals(errorMessage)){
manuallyHandleConnection = true;
}
else if ("Invalid state, the Connection object is
closed.".equals(errorMessage)){
manuallyHandleConnection = true;
}
else if (null != sqlx) {
if ("HY010".equals(sqlx.getSQLState())){
manuallyHandleConnection = true;
}
else if ("08S01".equals(sqlx.getSQLState())){
manuallyHandleConnection = true;
}
else if ("S0002".equals(sqlx.getSQLState())){
manuallyHandleConnection = true;
}
}
}
// Oracle Error Handling
if (null != errorMessage &&
errorMessage.indexOf("ORA-01041")!=-1) {
manuallyHandleConnection = true;
}
if (manuallyHandleConnection){
log.error("Forcing reconnect " + errorMessage);
dbc.lock();
dbc.database().handleDroppedConnection();
dbc.unlock();
return false;
}
return true;
}
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Michael
Deninger
Sent: Monday, July 03, 2006 4:08 PM
To: WebObjects Development ListServ
Subject: Connection to Database Exception
Hi,
I have looked through the mailing list archives and several of the sites
like WODev but could not find an easy answer to this question:
Is there any way to catch the exception that is thrown when the
connection to the database is lost? I would like to catch this and try
to reestablish the connection manually instead of giving an error page
to my users.
Any pointers would be gladly accepted.
_______________________________________________
WebObjects-dev mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/webobjects-dev
Confidential & Privileged
Unless otherwise indicated or obvious from its nature, the information contained in this communication is attorney-client privileged and confidential information/work product. This communication is intended for the use of the individual or entity named above. If the reader of this communication is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error or are not sure whether it is privileged, please immediately notify us by return e-mail and destroy any copies--electronic, paper or otherwise--which you may have of this communication.