See ChangeLog

Monotone-Parent: ea7589320f5747a3bd1bbec33e1bd8776e4041db
Monotone-Revision: cc4b29880c63c661301ca909ec3695f67b0775dd

Monotone-Author: ludovic@Sophos.ca
Monotone-Date: 2009-04-21T15:20:52
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Ludovic Marcotte
2009-04-21 15:20:52 +00:00
parent fa7408ebc1
commit d1bbd65944
76 changed files with 7520 additions and 5817 deletions
+79 -14
View File
@@ -173,15 +173,19 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
**
** Author: Ludovic Marcotte <ludovic@inverse.ca>
**
@@ -30,6 +30,7 @@
@@ -30,6 +30,11 @@
#import <NGExtensions/NSObject+Logs.h>
+#include <unistd.h>
+
+static BOOL debugOn = NO;
+static int maxTry = 3;
+static int maxSleep = 500;
//
//
//
@@ -41,10 +42,11 @@
@@ -41,10 +46,11 @@
@implementation OracleAdaptorChannel (Private)
@@ -194,7 +198,7 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
[_resultSetProperties removeAllObjects];
@@ -58,11 +60,29 @@
@@ -58,11 +64,29 @@
// so we just free the value instead.
if (info->value)
{
@@ -226,7 +230,7 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
[_row_buffer removeObjectAtIndex: c];
}
@@ -78,8 +98,7 @@
@@ -78,8 +102,7 @@
//
@implementation OracleAdaptorChannel
@@ -236,7 +240,7 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
{
if (OCITerminate(OCI_DEFAULT))
NSLog(@"FAILED: OCITerminate()");
@@ -89,6 +108,11 @@
@@ -89,6 +112,11 @@
+ (void) initialize
{
@@ -248,7 +252,7 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
// We Initialize the OCI process environment.
if (OCIInitialize((ub4)OCI_DEFAULT, (dvoid *)0,
(dvoid * (*)(dvoid *, size_t)) 0,
@@ -156,14 +180,17 @@
@@ -156,14 +184,17 @@
[super closeChannel];
// We logoff from the database.
@@ -269,7 +273,7 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
// OCIHandleFree(_oci_env, OCI_HTYPE_ENV);
_oci_ctx = (OCISvcCtx *)0;
@@ -177,7 +204,8 @@
@@ -177,7 +208,8 @@
//
- (void) dealloc
{
@@ -279,7 +283,16 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
[self _cleanup];
@@ -231,6 +259,9 @@
@@ -222,7 +254,7 @@
{
EOAttribute *attribute;
OCIParam *param;
-
+ int rCount;
column_info *info;
ub4 i, clen, count;
text *sql, *cname;
@@ -231,6 +263,9 @@
[self _cleanup];
@@ -289,7 +302,59 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
if (!theExpression || ![theExpression length])
{
[NSException raise: @"OracleInvalidExpressionException"
@@ -302,7 +333,9 @@
@@ -244,7 +279,9 @@
}
sql = (text *)[theExpression UTF8String];
-
+
+ rCount = 0;
+ retry:
// We alloc our statement handle
if ((status = OCIHandleAlloc((dvoid *)_oci_env, (dvoid **)&_current_stm, (ub4)OCI_HTYPE_STMT, (CONST size_t) 0, (dvoid **) 0)))
{
@@ -264,13 +301,39 @@
// We check if we're doing a SELECT and if so, we're fetching data!
OCIAttrGet(_current_stm, OCI_HTYPE_STMT, &type, 0, OCI_ATTR_STMT_TYPE, _oci_err);
self->isFetchInProgress = (type == OCI_STMT_SELECT ? YES : NO);
-
+
// We execute our statement. Not that we _MUST_ set iter to 0 for non-SELECT statements.
if ((status = OCIStmtExecute(_oci_ctx, _current_stm, _oci_err, (self->isFetchInProgress ? (ub4)0 : (ub4)1), (ub4)0, (CONST OCISnapshot *)NULL, (OCISnapshot *)NULL,
([(OracleAdaptorContext *)[self adaptorContext] autoCommit] ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT))))
{
+ ub4 serverStatus;
+
checkerr(_oci_err, status);
NSLog(@"Statement execute failed (OCI_ERROR): %@", theExpression);
+
+ // We check to see if we lost connection and need to reconnect.
+ serverStatus = 0;
+ OCIAttrGet((dvoid *)_oci_env, OCI_HTYPE_SERVER, (dvoid *)&serverStatus, (ub4 *)0, OCI_ATTR_SERVER_STATUS, _oci_err);
+
+ if (serverStatus == OCI_SERVER_NOT_CONNECTED)
+ {
+ // We cleanup our previous handles
+ [self cancelFetch];
+ [self closeChannel];
+
+ // We try to reconnect a couple of times before giving up...
+ while (rCount < maxTry)
+ {
+ usleep(maxSleep);
+ rCount++;
+
+ if ([self openChannel])
+ {
+ NSLog(@"Connection re-established to Oracle - retrying to process the statement.");
+ goto retry;
+ }
+ }
+ }
return NO;
}
@@ -302,7 +365,9 @@
// We read the maximum width of a column
info->max_width = 0;
status = OCIAttrGet((dvoid*)param, (ub4)OCI_DTYPE_PARAM, (dvoid*)&(info->max_width), (ub4 *)0, (ub4)OCI_ATTR_DATA_SIZE, (OCIError *)_oci_err);
@@ -300,7 +365,7 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
attribute = [EOAttribute attributeWithOracleType: info->type name: cname length: clen width: info->max_width];
[_resultSetProperties addObject: attribute];
@@ -394,16 +427,17 @@
@@ -394,16 +459,17 @@
return NO;
}
@@ -319,7 +384,7 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
return NO;
}
@@ -414,7 +448,10 @@
@@ -414,7 +480,10 @@
// Under Oracle 10g, the third parameter of OCILogon() has the form: [//]host[:port][/service_name]
// See http://download-west.oracle.com/docs/cd/B12037_01/network.101/b10775/naming.htm#i498306 for
// all juicy details.
@@ -331,7 +396,7 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
// We logon to the database.
if (OCILogon(_oci_env, _oci_err, &_oci_ctx, (const OraText*)username, strlen(username),
@@ -422,6 +459,7 @@
@@ -422,6 +491,7 @@
{
NSLog(@"FAILED: OCILogon(). username = %s password = %s"
@" database = %s", username, password, database);
@@ -339,7 +404,7 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
return NO;
}
@@ -438,6 +476,11 @@
@@ -438,6 +508,11 @@
{
sword status;
@@ -351,7 +416,7 @@ Index: sope-gdl1/Oracle8/OracleAdaptorChannel.m
status = OCIStmtFetch2(_current_stm, _oci_err, (ub4)1, (ub4)OCI_FETCH_NEXT, (sb4)0, (ub4)OCI_DEFAULT);
if (status == OCI_NO_DATA)
@@ -609,7 +652,7 @@
@@ -609,7 +684,7 @@
/* GCSEOAdaptorChannel protocol */
static NSString *sqlFolderFormat = (@"CREATE TABLE %@ (\n" \