aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-11-30 12:24:48 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-11-30 12:24:48 +0200
commitffcd71dda338acbe2e1ad34dd7c233b43c0558f7 (patch)
tree8f661354255909d599a716d3aa753d8edd285e4a
parenta262bf3d1102a413d2c8161e469ab6f3df8baf96 (diff)
Optimize checking for connection status
-rw-r--r--odb/oracle/error.cxx69
1 files changed, 38 insertions, 31 deletions
diff --git a/odb/oracle/error.cxx b/odb/oracle/error.cxx
index f52de31..3e834da 100644
--- a/odb/oracle/error.cxx
+++ b/odb/oracle/error.cxx
@@ -53,36 +53,6 @@ namespace odb
if (htype == OCI_HTYPE_ERROR)
{
- // Mark the connection as failed if necessary.
- //
- if (conn != 0)
- {
- OCIServer* server;
- r = OCIAttrGet (conn->handle (),
- OCI_HTYPE_SVCCTX,
- &server,
- 0,
- OCI_ATTR_SERVER,
- conn->error_handle ());
-
- if (r != OCI_SUCCESS)
- throw invalid_oci_handle ();
-
- ub4 server_status;
- r = OCIAttrGet (server,
- OCI_HTYPE_SERVER,
- &server_status,
- 0,
- OCI_ATTR_SERVER_STATUS,
- conn->error_handle ());
-
- if (r != OCI_SUCCESS)
- throw invalid_oci_handle ();
-
- if (server_status == OCI_SERVER_NOT_CONNECTED)
- conn->mark_failed ();
- }
-
// We need to translate certain Oracle error codes to special
// exceptions, such as deadlock, timeout, etc. The problem is we can
// have multiple records potentially with different error codes. If we
@@ -147,6 +117,38 @@ namespace odb
c = nc;
}
+ // Check if the connection is lost. If code is connection_lost,
+ // then we know it is gone. If code is deadlock, then the
+ // connection is most likely ok.
+ //
+ if (conn != 0 && (c == code_none || c == code_timeout))
+ {
+ OCIServer* server;
+ r = OCIAttrGet (conn->handle (),
+ OCI_HTYPE_SVCCTX,
+ &server,
+ 0,
+ OCI_ATTR_SERVER,
+ conn->error_handle ());
+
+ if (r != OCI_SUCCESS)
+ throw invalid_oci_handle ();
+
+ ub4 server_status;
+ r = OCIAttrGet (server,
+ OCI_HTYPE_SERVER,
+ &server_status,
+ 0,
+ OCI_ATTR_SERVER_STATUS,
+ conn->error_handle ());
+
+ if (r != OCI_SUCCESS)
+ throw invalid_oci_handle ();
+
+ if (server_status == OCI_SERVER_NOT_CONNECTED)
+ conn->mark_failed ();
+ }
+
switch (c)
{
case code_deadlock:
@@ -154,7 +156,12 @@ namespace odb
case code_timeout:
throw timeout ();
case code_connection_lost:
- throw connection_lost ();
+ {
+ if (conn != 0)
+ conn->mark_failed ();
+
+ throw connection_lost ();
+ }
case code_none:
break;
}