Skip to content

Commit

Permalink
Handle exception using ErrorHandler when iterating through a result s…
Browse files Browse the repository at this point in the history
…et. (#593)

* Handle exception using ErrorHandler when iterating through a result set.

* Move error handling of readNext to a higher level in order to capture errors on _dataStoreHelper.getResults.
  • Loading branch information
claudiamurialdo authored May 27, 2022
1 parent 4b8117d commit d96969b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 56 deletions.
55 changes: 30 additions & 25 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataADO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,19 +1650,37 @@ public string ExecuteDataSet()
}
catch(GxADODataException e)
{
bool pe = dataRecord.ProcessError( e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
bool pe = ProcessException(e, ref retry, retryCount, "EXECUTE");
retryCount++;
processErrorHandler( status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, "EXECUTE", ref pe, ref retry);
if (! pe)
{
GXLogging.Error(log, e, "GxCommand.ExecuteDataSet Error ");
throw (new GxADODataException(e.ToString(), e));
throw;
}
}
}
return "";
}

internal bool ProcessException(GxADODataException e, ref bool retry, int retryCount, string method)
{
bool pe = dataRecord.ProcessError(e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
processErrorHandler(status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, method, ref pe, ref retry);
if (!pe)
{
try
{
Close();
con.Close();
}
catch (Exception ex)
{
GXLogging.Warn(log, ex, "GxCommand.Close Error on ProcessException");
}
}
return pe;
}

public IDataReader ExecuteReader()
{
try
Expand Down Expand Up @@ -1730,22 +1748,12 @@ public void FetchData(out IDataReader dr)
catch (GxADODataException e)
{
status=0;
bool pe = dataRecord.ProcessError( e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
bool pe = ProcessException(e, ref retry, retryCount, "FETCH");
retryCount++;
processErrorHandler( status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, "FETCH", ref pe, ref retry);
if (! pe)
{
GXLogging.Error(log, e, "GxCommand.FetchData Error ");
try
{
Close();
con.Close();
}
catch(Exception ex)
{
GXLogging.Error(log, ex, "GxCommand.FetchData-Close Error ");
}
throw (new GxADODataException(e.ToString(), e));
throw;
}
}
}
Expand All @@ -1767,13 +1775,12 @@ public void FetchDataRPC(out IDataReader dr)
catch (GxADODataException e)
{
status=0;
bool pe = dataRecord.ProcessError( e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
bool pe = ProcessException(e, ref retry, retryCount, "FETCH");
retryCount++;
processErrorHandler( status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, "FETCH", ref pe, ref retry);
if (! pe)
{
GXLogging.Error(log, e, "GxCommand.FetchDataRPC Error ");
throw (new GxADODataException(e.ToString(), e));
throw;
}
}
}
Expand Down Expand Up @@ -1890,13 +1897,12 @@ public void ExecuteBatch()
}
catch (GxADODataException e)
{
bool pe = dataRecord.ProcessError(e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
bool pe = ProcessException(e, ref retry, retryCount, "EXECUTE");
retryCount++;
processErrorHandler(status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, "EXECUTE", ref pe, ref retry);
if (!pe)
{
GXLogging.Error(log, "GxCommand.ExecuteStmt Error ", e);
throw (new GxADODataException(e.ToString(), e));
throw;
}
}
}
Expand All @@ -1919,14 +1925,13 @@ private void execStmt()
status = 0;
}
catch (GxADODataException e)
{
bool pe = dataRecord.ProcessError(e.DBMSErrorCode, e.ErrorInfo, errMask, con, ref status, ref retry, retryCount);
{
bool pe = ProcessException(e, ref retry, retryCount, "EXECUTE");
retryCount++;
processErrorHandler(status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, errMask, "EXECUTE", ref pe, ref retry);
if (!pe)
{
GXLogging.Error(log, "GxCommand.ExecuteStmt Error ", e);
throw (new GxADODataException(e.ToString(), e));
throw;
}
}
}
Expand Down
34 changes: 20 additions & 14 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataNTier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,24 @@ private void execute(int cursor, Object[] parms, bool batch)

public void readNext(int cursor)
{
ICursor oCur = getCursor(cursor);
oCur.readNext();
_dataStoreHelper.getResults(cursor, oCur.getFieldGetter(), results[cursor]);
dataStoreRequestCount++;
Cursor oCur = getCursor(cursor) as Cursor;
try
{
oCur.readNext();
_dataStoreHelper.getResults(cursor, oCur.getFieldGetter(), results[cursor]);
dataStoreRequestCount++;
}
catch (GxADODataException e)
{
bool retry = false;
int retryCount = 0;
bool pe = oCur.Command.ProcessException(e, ref retry, retryCount, "FETCH");
GXLogging.Error(log, "readNext Error", e);
if (!pe)
{
throw;
}
}

}
public int getStatus(int cursorIdx)
Expand Down Expand Up @@ -538,19 +552,15 @@ private void commitDataStore(IGxDataStore ds, String auditObjectName)
catch (Exception dbEx)
{
//If commit fails it should not retry, it makes no sense because it will no longer be possible. just close the existing connection.
int status = 0;
GxADODataException e = new GxADODataException(dbEx);
bool retry = false;
int retryCount = 0;
bool pe = ds.Connection.DataRecord.ProcessError(e.DBMSErrorCode, e.ErrorInfo, cmd.ErrorMask, ds.Connection, ref status, ref retry, retryCount);
GXLogging.Error(log, "Commit Transaction Error", e);
retryCount++;
cmd.processErrorHandler(status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, cmd.ErrorMask, "FETCH", ref pe, ref retry);
bool pe = cmd.ProcessException(e, ref retry, retryCount, "FETCH");
if (!pe)
{
try
{
ds.Connection.Close();
if (retry)
ds.Connection.Open();
}
Expand All @@ -574,19 +584,15 @@ private void rollbackDataStore(IGxDataStore ds, String auditObjectName)
}
catch (Exception dbEx)
{
int status = 0;
GxADODataException e = new GxADODataException(dbEx);
bool retry = false;
int retryCount = 0;
bool pe = ds.Connection.DataRecord.ProcessError(e.DBMSErrorCode, e.ErrorInfo, cmd.ErrorMask, ds.Connection, ref status, ref retry, retryCount);
bool pe = cmd.ProcessException(e, ref retry, retryCount, "FETCH");
GXLogging.Error(log, "Rollback Transaction Error", e);
retryCount++;
cmd.processErrorHandler(status, e.DBMSErrorCode, e.SqlState, e.ErrorInfo, cmd.ErrorMask, "FETCH", ref pe, ref retry);
if (!pe)
{
try
{
ds.Connection.Close();
if (retry)
ds.Connection.Open();
}
Expand Down
38 changes: 21 additions & 17 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,12 @@ public Cursor(string name, string stmt, GxErrorMask nmask, ICollection parmBinds
{
_staticParameters = staticPars;
}
internal GxCommand Command
{
get { return _gxDbCommand; }
}

public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler)
public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler)
{

if (_state >= 2)
Expand Down Expand Up @@ -1192,24 +1196,24 @@ public override void execute()
_status = Cursor.EOF;
_closed = false;
}
public override void readNext()
{
if (_state < 2)
throw (new GxADODataException("Could not readNext in ForEachCursor:" + _name + "."));
_status = 0;
public override void readNext()
{
if (_state < 2)
throw (new GxADODataException("Could not readNext in ForEachCursor:" + _name + "."));
_status = 0;

if (!_DR.Read())
{
_status = Cursor.EOF;
_gxDbCommand.HasMoreRows = false;
}
else if (_gxDbCommand.Status == 1 || _gxDbCommand.Status == 103 || _gxDbCommand.Status == 500)
{
_status = _gxDbCommand.Status;
}
if (!_DR.Read())
{
_status = Cursor.EOF;
_gxDbCommand.HasMoreRows = false;
}
else if (_gxDbCommand.Status == 1 || _gxDbCommand.Status == 103 || _gxDbCommand.Status == 500)
{
_status = _gxDbCommand.Status;
}

}
}
}
}
public class UpdateCursor : Cursor
{
public UpdateCursor(CursorDef def) : base(def.Name, def.Stmt, def.Nmask, def.ParmBinds, 0)
Expand Down

0 comments on commit d96969b

Please sign in to comment.