Actually in some calculations we have more than one or two database requests and it is a time and ressource consuming process to handle all request information in every part of the communication and to do all database requests again and again.
This is my proposal which we shall discuss in detail
Therefore I've selected a singleton in this case the last - the "Multithreaded Singleton" and I want do describe what it does and what it does not.
The first point is the singleton connector itself:
public partial class TSingletonConnector
{
/// <summary>
/// Test routine only
/// </summary>
/// <param name="AInput">new integer value</param>
/// <returns>old integer value</returns>
[RequireModulePermission("FINANCE-1")]
public static int TTestInfo_1(int AInput)
{
int ih = TTestMonthEnd.Instance.TestObject.ITest;
TTestMonthEnd.Instance.TestObject.ITest = AInput;
return ih;
}
}
This routine only gets the singleton access and runs one method in this case a simple exchange of an integer value.
A rudimentär class itself is:
public class TTestMonthEnd
{
private static volatile TTestMonthEnd instance;
private static object smallTestObject = new SmallTestObject();
private TTestMonthEnd() {}
public static TTestMonthEnd Instance
{
get
{
if (instance == null)
{
lock (smallTestObject)
{
if (instance == null)
instance = new TTestMonthEnd();
}
}
return instance;
}
}
public SmallTestObject TestObject
{
get
{
return (SmallTestObject)smallTestObject;
}
}
}
public class SmallTestObject
{
int local = 0;
public SmallTestObject()
{
}
public int ITest
{
get
{
return local;
}
set{
local = value;
}
}
}
and then the test works either on the server and in slightly different looking code on the client.
Assert.AreEqual(0, TSingletonConnector.TTestInfo_1(3), "First call -> 0");
Assert.AreEqual(3, TSingletonConnector.TTestInfo_1(17), "Next call -> 3");
Assert.AreEqual(17, TSingletonConnector.TTestInfo_1(17), "Next call -> 17");
So a database record can be read one time and used for the complete rest of user activities.
A small test done from the client looks like:
private void DoSomething(object btn, EventArgs e)
{
int ih = TRemote.MFinance.GL.WebConnectors.TTestInfo_1(3);
MessageBox.Show(ih.ToString());
ih = TRemote.MFinance.GL.WebConnectors.TTestInfo_1(12);
MessageBox.Show(ih.ToString());
this.Close();
}
The first message box value by runnig the fist DoSomething is 0, because that is the initial value inside the singleton. The first value in the second click is 12 because that is the last value.
But two different users do not see each others. The singleton is a private singleton for the user only.
So we need the following
[]A singleton which is common for all users. This is the only way to avoid that two persons want to run a period month end on the same ledger at the same time for example[/:m]
[]A singleton for each main modules - mFinance, mPartner ... This is the only way to avoid a "load data" "do a little bit", "throw away everythig" in period.[/:m][/list:u]
Actually I do not implement a singleton because it is nothing for a one mans single fight. It only makes sense if we want to have it all.
Best regards
Wolfgang