Skip to content

Commit

Permalink
Cherry pick branch 'genexuslabs:improve-trace-error-detail' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudia Beatriz Murialdo Garrone authored and Beta Bot committed Oct 1, 2024
1 parent b3c49d9 commit 4d41167
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 26 deletions.
35 changes: 22 additions & 13 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataADO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,8 @@ public class GxCommand: IGxDbCommand
internal List<ParDef> ParmDefinition;
static readonly IGXLogger log = GXLoggerFactory.GetLogger<GxCommand>();
string stmt;
String stmtId;
string stmtId;
string objName;
GxParameterCollection parameters;
ushort fetchSize=256;
int timeOut;
Expand Down Expand Up @@ -1484,6 +1485,7 @@ public GxCommand( IGxDataRecord db, String statement, short updatable,
IGxDataStore ds, string objName, string stmtId, int ttl, bool hasNested,bool isForFirst, GxErrorHandler errorHandler):this(db, statement,ds, ttl,hasNested, isForFirst, errorHandler)
{
this.stmtId = stmtId;
this.objName = objName;
}
public GxCommand(IGxDataRecord db, String statement, short updatable,
IGxDataStore ds, string objName, string stmtId, int ttl, bool hasNested, bool isForFirst, GxErrorHandler errorHandler, int batchSize)
Expand Down Expand Up @@ -1593,7 +1595,7 @@ public int ExecuteNonQuery()
}
catch { }
}
GXLogging.Error(log, "Return GxCommand.ExecuteNonQuery Error ", e.Message, e);
GXLogging.Error(log, () => "Return GxCommand.ExecuteNonQuery Error " + e.Message + StmtExceptionDetail, e);
try
{
con.MonitorExit();
Expand Down Expand Up @@ -1689,7 +1691,7 @@ private IDataReader ExecRpc()
}
catch(Exception e)
{
GXLogging.Error(log,"Return GxCommand.ExecRpc Error ", e.Message, e);
GXLogging.Error(log,() => "Return GxCommand.ExecRpc Error " + e.Message + StmtExceptionDetail, e);
throw (new GxADODataException(e));
}
finally
Expand Down Expand Up @@ -1728,7 +1730,7 @@ public string ExecuteDataSet()
}
catch(Exception e)
{
GXLogging.Error(log, "Return GxCommand.ExecuteDataSet Error ", e.Message, e);
GXLogging.Error(log, () => "Return GxCommand.ExecuteDataSet Error " + e.Message + StmtExceptionDetail, e);
throw (new GxADODataException(e));
}
}
Expand All @@ -1738,7 +1740,7 @@ public string ExecuteDataSet()
retryCount++;
if (! pe)
{
GXLogging.Error(log, "GxCommand.ExecuteDataSet Error ", e.Message, e);
GXLogging.Error(log, () => "GxCommand.ExecuteDataSet Error " + e.Message + StmtExceptionDetail, e);
throw;
}
}
Expand Down Expand Up @@ -1805,7 +1807,7 @@ public IDataReader ExecuteReader()
}
catch (Exception e)
{
GXLogging.Error(log, "Return GxCommand.ExecuteReader Error ", e.Message, e);
GXLogging.Error(log, () => "Return GxCommand.ExecuteReader Error " + e.Message + StmtExceptionDetail, e);
if (e.InnerException != null)
{
GXLogging.Error(log, "Inner Error", e.InnerException);
Expand All @@ -1814,6 +1816,13 @@ public IDataReader ExecuteReader()
}

}
private string StmtExceptionDetail
{
get
{
return "\nObjectName:" + objName + "\nStmt:" + stmt;
}
}

public void FetchData(out IDataReader dr)
{
Expand All @@ -1839,7 +1848,7 @@ public void FetchData(out IDataReader dr)
retryCount++;
if (! pe)
{
GXLogging.Error(log, "GxCommand.FetchData Error ", e.Message, e);
GXLogging.Error(log, () => "GxCommand.FetchData Error " + e.Message + StmtExceptionDetail, e);
throw;
}
}
Expand All @@ -1866,7 +1875,7 @@ public void FetchDataRPC(out IDataReader dr)
retryCount++;
if (! pe)
{
GXLogging.Error(log, "GxCommand.FetchDataRPC Error ", e.Message, e);
GXLogging.Error(log, () => "GxCommand.FetchDataRPC Error " + e.Message + StmtExceptionDetail, e);
throw;
}
}
Expand Down Expand Up @@ -1923,7 +1932,7 @@ public int ExecuteBatchQuery()
}
catch (Exception e)
{
GXLogging.Error(log, "Return GxCommand.ExecuteNonQuery Error ", e.Message, e);
GXLogging.Error(log, ()=>"Return GxCommand.ExecuteNonQuery Error " + e.Message + StmtExceptionDetail, e);
con.InternalConnection.RollbackSavePoint(Transaction, stmtId);
con.MonitorExit();
throw (new GxADODataException(e));
Expand Down Expand Up @@ -1986,9 +1995,9 @@ public void ExecuteBatch()
{
bool pe = ProcessException(e, ref retry, retryCount, "EXECUTE");
retryCount++;
if (!pe)
{
GXLogging.Error(log, "GxCommand.ExecuteStmt Error ", e.Message, e);
if (!pe)
{
GXLogging.Error(log, () => "GxCommand.ExecuteStmt Error " + e.Message + StmtExceptionDetail, e);
throw;
}
}
Expand Down Expand Up @@ -2017,7 +2026,7 @@ private void execStmt()
retryCount++;
if (!pe)
{
GXLogging.Error(log, "GxCommand.ExecuteStmt Error ", e.Message, e);
GXLogging.Error(log, ()=> "GxCommand.ExecuteStmt Error " + e.Message + StmtExceptionDetail, e);
throw;
}
}
Expand Down
21 changes: 12 additions & 9 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataNTier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public interface IRemoteDataStoreProvider

public interface ICursor
{
void createCursor( IGxDataStore ds, GxErrorHandler errorHandler );
void createCursor( IGxDataStore ds, GxErrorHandler errorHandler);
void createCursor(IGxDataStore ds, GxErrorHandler errorHandler, string objName);
void execute();
short[] preExecute(int cursorNum, IDataStoreProviderBase connectionProvider, IGxDataStore ds);
void readNext();
Expand All @@ -67,7 +68,7 @@ public interface ICursor
void addRecord(Object[] parms);
int BatchSize { get; set;}
int RecordCount { get;}
void OnCommitEvent(object instance, string method);
void OnCommitEvent(object instance, string method);
int readNextErrorRecord();
List<ParDef> DynamicParameters { get; }
}
Expand Down Expand Up @@ -352,6 +353,7 @@ public class DataStoreProvider : IDataStoreProviderBase,IDataStoreProvider
IDictionary<int, Object[]> errorBuffers;
IGxDataStore _ds;
IDataStoreHelper _dataStoreHelper;
string _dataStoreHelperType;
object [] _dynConstraints;
GxErrorHandler _errorHandler;
IGxContext _context;
Expand All @@ -362,24 +364,25 @@ public class DataStoreProvider : IDataStoreProviderBase,IDataStoreProvider

public DataStoreProvider( IGxContext context, IDataStoreHelper dataStoreHelper, Object[][] cursorParms)
{
GXLogging.Debug(log, "Start DataStoreProvider.Ctr, Parameters: handle '"+ context.handle + "', dataStoreHelper:" + dataStoreHelper.GetType());
_dataStoreHelperType = dataStoreHelper.GetType().ToString();
GXLogging.Debug(log, "Start DataStoreProvider.Ctr, Parameters: handle '"+ context.handle + "', dataStoreHelper:" + _dataStoreHelperType);
_dataStoreHelper = dataStoreHelper;
_context = context;
_context = context;
_ds = context.GetDataStore( dataStoreHelper.getDataStoreName());
if (_ds == null)
{

_ds = new GxDataStore(new GxSqlServer(),dataStoreHelper.getDataStoreName(), context);
context.AddDataStore(_ds);
GXLogging.Error(log, dataStoreHelper.GetType() + " Datastore " + dataStoreHelper.getDataStoreName() + " not found in app config");
GXLogging.Error(log, _dataStoreHelperType + " Datastore " + dataStoreHelper.getDataStoreName() + " not found in app config");
}
_ds.Handle=context.handle;
_cursor = dataStoreHelper.getCursors();
results = cursorParms;
errorBuffers = new Dictionary<int, Object[]>();
if (Preferences.Instrumented)
{
wmiDataStoreProvider = WMIDataStoreProviders.Instance().AddDataStoreProvider(dataStoreHelper.GetType().ToString());
wmiDataStoreProvider = WMIDataStoreProviders.Instance().AddDataStoreProvider(_dataStoreHelperType);
}
dataStoreRequestCount++;

Expand Down Expand Up @@ -423,8 +426,8 @@ private void execute(int cursor, Object[] parms, bool batch)
}
if (!batch)
{
oCur.createCursor(_ds, _errorHandler);
}
oCur.createCursor(_ds, _errorHandler, _dataStoreHelperType);
}
short[] parmHasValue = oCur.preExecute(cursor, this, _ds);
if (Preferences.Instrumented && wmiDataStoreProvider != null)
{
Expand Down Expand Up @@ -682,7 +685,7 @@ public void initializeBatch(int cursor, int batchSize, object instance, string m
if (oCur.BatchSize == 0)
{
oCur.BatchSize = batchSize;
oCur.createCursor(_ds, _errorHandler);
oCur.createCursor(_ds, _errorHandler, _dataStoreHelperType);
oCur.OnCommitEvent(instance, method);
}
}
Expand Down
12 changes: 8 additions & 4 deletions dotnet/src/dotnetframework/GxClasses/Data/GXDataNTierADO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,7 @@ internal GxCommand Command
{
get { return _gxDbCommand; }
}

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

if (_state >= 2)
Expand All @@ -874,7 +873,7 @@ public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler)
return;
}
_stmt = (_staticParameters == null)? _stmt : String.Format(_stmt, _staticParameters);
_gxDbCommand = new GxCommand(ds.Db, _stmt, _updatable, ds, "", _name, TTL, hasNested, isForFirst, errorHandler, _batchSize);
_gxDbCommand = new GxCommand(ds.Db, _stmt, _updatable, ds, objectName, _name, TTL, hasNested, isForFirst, errorHandler, _batchSize);
_gxDbCommand.IsCursor = true;
if (_blockSize > 0)
_gxDbCommand.FetchSize = Convert.ToUInt16(_blockSize);
Expand All @@ -886,7 +885,12 @@ public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler)
_gxDbCommand.ErrorMask = _errMask;

}
protected virtual void bindParms(Object[] ptb)
public void createCursor(IGxDataStore ds, GxErrorHandler errorHandler)
{
createCursor(ds, errorHandler, string.Empty);
}

protected virtual void bindParms(Object[] ptb)
{
int pos = 1;
if (ptb != null)
Expand Down
12 changes: 12 additions & 0 deletions dotnet/src/dotnetframework/GxClasses/Helpers/GXLogging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,18 @@ internal static void ErrorSanitized(IGXLogger logger, string msg, Exception ex)
}
}
}
internal static void Error(IGXLogger logger, Func<string> buildMsg, Exception ex)
{
if (logger != null)
{
if (logger.IsErrorEnabled)
{
string msg = buildMsg();
logger.LogError(msg, ex);
}
}
}


internal static void Error(IGXLogger logger, string msg1, string msg2, Exception ex)
{
Expand Down

0 comments on commit 4d41167

Please sign in to comment.