B2022-026 RO Memory reduction coding
This commit is contained in:
@@ -81,12 +81,20 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
ClearRefreshList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Collection
|
||||
|
||||
private static List<ROFst> _CacheList = new List<ROFst>();
|
||||
protected static void AddToCache(ROFst rOFst)
|
||||
{
|
||||
if (!_CacheList.Contains(rOFst)) _CacheList.Add(rOFst); // In AddToCache
|
||||
if (!_CacheList.Contains(rOFst))
|
||||
{
|
||||
rOFst.ROLookup = null; // B2022-026 RO Memory reduction
|
||||
_CacheList.Add(rOFst); // In AddToCache
|
||||
}
|
||||
|
||||
}
|
||||
protected static void RemoveFromCache(ROFst rOFst)
|
||||
{
|
||||
@@ -105,6 +113,7 @@ namespace VEPROMS.CSLA.Library
|
||||
_CacheByPrimaryKey[pKey] = new List<ROFst>(); // Add new list for PrimaryKey
|
||||
_CacheByRODbID_DTS[tmp.RODbID.ToString() + "_" + tmp.DTS.ToString()] = new List<ROFst>(); // Add new list for RODbID_DTS
|
||||
}
|
||||
tmp.ROLookup = null; // B2022-026 RO Memory reduction
|
||||
_CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list
|
||||
_CacheByRODbID_DTS[tmp.RODbID.ToString() + "_" + tmp.DTS.ToString()].Add(tmp); // Unique Index
|
||||
_CacheList.RemoveAt(0); // Remove the first ROFst
|
||||
@@ -124,8 +133,11 @@ namespace VEPROMS.CSLA.Library
|
||||
if (_CacheByRODbID_DTS.ContainsKey(key)) return _CacheByRODbID_DTS[key][0];
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Business Methods
|
||||
|
||||
private string _ErrorMessage = string.Empty;
|
||||
public string ErrorMessage
|
||||
{
|
||||
@@ -180,14 +192,21 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] _ROLookup;
|
||||
|
||||
public byte[] ROLookup
|
||||
{
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("ROLookup", true);
|
||||
return _ROLookup;
|
||||
return null; // B2022-026 RO Memory reduction
|
||||
//if (_ROLookup == null)
|
||||
//{
|
||||
// _ROLookup = ROFSTLookup.GetRofstLookupBytes(_ROFstID);
|
||||
//}
|
||||
//return _ROLookup;
|
||||
}
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
set
|
||||
@@ -200,6 +219,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string _Config = string.Empty;
|
||||
public string Config
|
||||
{
|
||||
@@ -557,6 +577,7 @@ namespace VEPROMS.CSLA.Library
|
||||
_Disposed = true;
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
RemoveFromCache(this);
|
||||
@@ -580,6 +601,7 @@ namespace VEPROMS.CSLA.Library
|
||||
_CacheByRODbID_DTS.Remove(myKey); // remove the list
|
||||
}
|
||||
}
|
||||
|
||||
public static ROFst New()
|
||||
{
|
||||
if (!CanAddObject())
|
||||
@@ -593,6 +615,7 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("Error on ROFst.New", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static ROFst New(RODb myRODb, byte[] rOLookup)
|
||||
{
|
||||
ROFst tmp = ROFst.New();
|
||||
@@ -600,6 +623,7 @@ namespace VEPROMS.CSLA.Library
|
||||
tmp.ROLookup = rOLookup;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public static ROFst New(RODb myRODb, byte[] rOLookup, string config, DateTime dts, string userID)
|
||||
{
|
||||
ROFst tmp = ROFst.New();
|
||||
@@ -610,22 +634,7 @@ namespace VEPROMS.CSLA.Library
|
||||
tmp.UserID = userID;
|
||||
return tmp;
|
||||
}
|
||||
public static ROFst MakeROFst(RODb myRODb, byte[] rOLookup, string config, DateTime dts, string userID)
|
||||
{
|
||||
ROFst tmp = ROFst.New(myRODb, rOLookup, config, dts, userID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
tmp._ErrorMessage = "Failed Validation:";
|
||||
foreach (Csla.Validation.BrokenRule br in brc)
|
||||
{
|
||||
tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
|
||||
}
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public static ROFst New(RODb myRODb, byte[] rOLookup, string config)
|
||||
{
|
||||
ROFst tmp = ROFst.New();
|
||||
@@ -634,11 +643,23 @@ namespace VEPROMS.CSLA.Library
|
||||
tmp.Config = config;
|
||||
return tmp;
|
||||
}
|
||||
public static ROFst MakeROFst(RODb myRODb, byte[] rOLookup, string config)
|
||||
|
||||
public static ROFst MakeROFst(RODb myRODb, byte[] rOLookup, string config, DateTime dts, string userID)
|
||||
{
|
||||
ROFst tmp = ROFst.New(myRODb, rOLookup, config);
|
||||
ROFst tmp = ROFst.New(myRODb, rOLookup, config, dts, userID);
|
||||
|
||||
if (tmp.IsSavable)
|
||||
{
|
||||
tmp = tmp.Save();
|
||||
|
||||
// B2022-026 RO Memory reduction
|
||||
if (tmp.ROLookup != null && tmp.ROFstID > 0)
|
||||
{
|
||||
//Force Load the new Lookup Data
|
||||
var RofstLookup = new ROFSTLookup(tmp.ROFstID);
|
||||
tmp.ROLookup = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -648,8 +669,36 @@ namespace VEPROMS.CSLA.Library
|
||||
tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
|
||||
}
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public static ROFst MakeROFst(RODb myRODb, byte[] rOLookup, string config)
|
||||
{
|
||||
ROFst tmp = ROFst.New(myRODb, rOLookup, config);
|
||||
|
||||
if (tmp.IsSavable)
|
||||
{
|
||||
tmp = tmp.Save();
|
||||
|
||||
// B2022-026 RO Memory reduction
|
||||
//Force Load the new Lookup Data
|
||||
var RofstLookup = new ROFSTLookup(tmp.ROFstID);
|
||||
tmp.ROLookup = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
tmp._ErrorMessage = "Failed Validation:";
|
||||
foreach (Csla.Validation.BrokenRule br in brc)
|
||||
{
|
||||
tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
|
||||
}
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public static ROFst Get(int rOFstID)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
@@ -662,11 +711,13 @@ namespace VEPROMS.CSLA.Library
|
||||
tmp = DataPortal.Fetch<ROFst>(new PKCriteria(rOFstID));
|
||||
AddToCache(tmp);
|
||||
}
|
||||
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up ROFst
|
||||
tmp = null;
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -674,6 +725,7 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("Error on ROFst.Get", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static ROFst GetByRODbID_DTS(int rODbID, DateTime dts)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
@@ -735,6 +787,7 @@ namespace VEPROMS.CSLA.Library
|
||||
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
||||
AddToCache(rOFst);//Refresh the item in AllList
|
||||
ProcessRefreshList();
|
||||
rOFst.ROLookup = null; // B2022-026 RO Memory reduction
|
||||
return rOFst;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -781,6 +834,7 @@ namespace VEPROMS.CSLA.Library
|
||||
// CSLATODO: Add any defaults that are necessary
|
||||
ValidationRules.CheckRules();
|
||||
}
|
||||
|
||||
private void ReadData(SafeDataReader dr)
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.ReadData", GetHashCode());
|
||||
@@ -788,7 +842,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
_ROFstID = dr.GetInt32("ROFstID");
|
||||
_RODbID = dr.GetInt32("RODbID");
|
||||
_ROLookup = (byte[])dr.GetValue("ROLookup");
|
||||
//_ROLookup = (byte[])dr.GetValue("ROLookup");
|
||||
_ROLookup = null; // B2022-026 RO Memory reduction
|
||||
_Config = dr.GetString("Config");
|
||||
_DTS = dr.GetDateTime("DTS");
|
||||
_UserID = dr.GetString("UserID");
|
||||
@@ -804,6 +859,7 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("ROFst.ReadData", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void DataPortal_Fetch(PKCriteria criteria)
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Fetch", GetHashCode());
|
||||
@@ -846,6 +902,7 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("ROFst.DataPortal_Fetch", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void DataPortal_Fetch(RODbID_DTSCriteria criteria)
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Fetch", GetHashCode());
|
||||
@@ -883,6 +940,7 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("ROFst.DataPortal_Fetch", ex);
|
||||
}
|
||||
}
|
||||
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
protected override void DataPortal_Insert()
|
||||
{
|
||||
@@ -908,6 +966,7 @@ namespace VEPROMS.CSLA.Library
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.DataPortal_Insert", GetHashCode());
|
||||
}
|
||||
}
|
||||
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
internal void SQLInsert()
|
||||
{
|
||||
@@ -921,12 +980,14 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addROFst";
|
||||
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@RODbID", RODbID);
|
||||
cm.Parameters.AddWithValue("@ROLookup", _ROLookup);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int);
|
||||
param_ROFstID.Direction = ParameterDirection.Output;
|
||||
@@ -934,11 +995,15 @@ namespace VEPROMS.CSLA.Library
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
|
||||
cm.ExecuteNonQuery();
|
||||
|
||||
// Save all values being returned from the Procedure
|
||||
_ROFstID = (int)cm.Parameters["@newROFstID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
|
||||
// Clear Out Any Rofst Binary (Bytes[]) - B2022-026 RO Memory reduction
|
||||
_ROLookup = null;
|
||||
}
|
||||
MarkOld();
|
||||
// update child objects
|
||||
@@ -953,6 +1018,7 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("ROFst.SQLInsert", ex);
|
||||
}
|
||||
}
|
||||
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
public static byte[] Add(SqlConnection cn, ref int rOFstID, RODb myRODb, byte[] rOLookup, string config, DateTime dts, string userID)
|
||||
{
|
||||
@@ -964,12 +1030,14 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addROFst";
|
||||
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@RODbID", myRODb.RODbID);
|
||||
cm.Parameters.AddWithValue("@ROLookup", rOLookup);
|
||||
cm.Parameters.AddWithValue("@Config", config);
|
||||
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
|
||||
cm.Parameters.AddWithValue("@UserID", userID);
|
||||
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_ROFstID = new SqlParameter("@newROFstID", SqlDbType.Int);
|
||||
param_ROFstID.Direction = ParameterDirection.Output;
|
||||
@@ -977,8 +1045,12 @@ namespace VEPROMS.CSLA.Library
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
|
||||
cm.ExecuteNonQuery();
|
||||
|
||||
// Clear Out Any Rofst Binary (Bytes[]) - B2022-026 RO Memory reduction
|
||||
rOLookup = null;
|
||||
|
||||
// Save all values being returned from the Procedure
|
||||
rOFstID = (int)cm.Parameters["@newROFstID"].Value;
|
||||
return (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
@@ -990,6 +1062,7 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("ROFst.Add", ex);
|
||||
}
|
||||
}
|
||||
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
protected override void DataPortal_Update()
|
||||
{
|
||||
@@ -1013,6 +1086,7 @@ namespace VEPROMS.CSLA.Library
|
||||
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
internal void SQLUpdate()
|
||||
{
|
||||
@@ -1029,20 +1103,23 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "updateROFst";
|
||||
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@ROFstID", _ROFstID);
|
||||
cm.Parameters.AddWithValue("@RODbID", RODbID);
|
||||
cm.Parameters.AddWithValue("@ROLookup", _ROLookup);
|
||||
cm.Parameters.AddWithValue("@ROLookup", ROFSTLookup.GetRofstLookupBytes(_ROFstID)); // B2022-026 RO Memory reduction - new calls
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
|
||||
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
|
||||
cm.ExecuteNonQuery();
|
||||
|
||||
// Save all values being returned from the Procedure
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
}
|
||||
@@ -1059,6 +1136,7 @@ namespace VEPROMS.CSLA.Library
|
||||
if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
internal void Update()
|
||||
{
|
||||
if (!this.IsDirty) return;
|
||||
@@ -1074,17 +1152,23 @@ namespace VEPROMS.CSLA.Library
|
||||
if (_ROFstAssociations != null) _ROFstAssociations.Update(this);
|
||||
if (_ROFstFigures != null) _ROFstFigures.Update(this);
|
||||
}
|
||||
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
public static byte[] Update(SqlConnection cn, ref int rOFstID, int rODbID, byte[] rOLookup, string config, DateTime dts, string userID, ref byte[] lastChanged)
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] ROFst.Update", 0);
|
||||
try
|
||||
{
|
||||
// B2022-026 RO Memory reduction - check if we need to get the rOLookup
|
||||
if (rOLookup == null)
|
||||
rOLookup = ROFSTLookup.GetRofstLookupBytes(rOFstID);
|
||||
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "updateROFst";
|
||||
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@ROFstID", rOFstID);
|
||||
cm.Parameters.AddWithValue("@RODbID", rODbID);
|
||||
@@ -1093,12 +1177,14 @@ namespace VEPROMS.CSLA.Library
|
||||
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
|
||||
cm.Parameters.AddWithValue("@UserID", userID);
|
||||
cm.Parameters.AddWithValue("@LastChanged", lastChanged);
|
||||
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
|
||||
cm.ExecuteNonQuery();
|
||||
|
||||
// Save all values being returned from the Procedure
|
||||
return (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
}
|
||||
|
Reference in New Issue
Block a user