Loading of SQL generators refactored

This commit is contained in:
Daniele Teti 2024-10-16 08:10:50 +02:00
parent 2c4c10f60a
commit ac6011143c

View File

@ -46,7 +46,9 @@ uses
MVCFramework.RQL.Parser, MVCFramework.RQL.Parser,
MVCFramework.Cache, MVCFramework.Cache,
MVCFramework.Serializer.Intf, MVCFramework.Serializer.Intf,
MVCFramework.Serializer.Commons, System.SyncObjs, System.TypInfo; MVCFramework.Serializer.Commons,
System.SyncObjs,
System.TypInfo;
type type
EMVCActiveRecord = class(EMVCException) EMVCActiveRecord = class(EMVCException)
@ -879,15 +881,15 @@ type
class var cInstance: TMVCSQLGeneratorRegistry; class var cInstance: TMVCSQLGeneratorRegistry;
class var class var
cLock: TObject;
fSQLGenerators: TDictionary<string, TMVCSQLGeneratorClass>; fSQLGenerators: TDictionary<string, TMVCSQLGeneratorClass>;
cConnectionsLock: TObject;
protected protected
constructor Create; constructor Create;
public public
destructor Destroy; override; destructor Destroy; override;
class function Instance: TMVCSQLGeneratorRegistry; class function Instance: TMVCSQLGeneratorRegistry;
class destructor Destroy;
class constructor Create; class constructor Create;
class destructor Destroy;
procedure RegisterSQLGenerator(const aBackend: string; const aRQLBackendClass: TMVCSQLGeneratorClass); procedure RegisterSQLGenerator(const aBackend: string; const aRQLBackendClass: TMVCSQLGeneratorClass);
procedure UnRegisterSQLGenerator(const aBackend: string); procedure UnRegisterSQLGenerator(const aBackend: string);
function GetSQLGenerator(const aBackend: string): TMVCSQLGeneratorClass; function GetSQLGenerator(const aBackend: string): TMVCSQLGeneratorClass;
@ -966,20 +968,12 @@ uses
FireDAC.Stan.Option, FireDAC.Stan.Option,
Data.FmtBcd, Data.FmtBcd,
System.Variants, System.Variants,
System.Math, System.Math;
{link all sql generators}
MVCFramework.SQLGenerators.PostgreSQL,
MVCFramework.SQLGenerators.Firebird,
MVCFramework.SQLGenerators.Sqlite,
MVCFramework.SQLGenerators.MySQL,
MVCFramework.SQLGenerators.MSSQL,
MVCFramework.SQLGenerators.Interbase;
var var
gCtx: TRttiContext; gCtx: TRttiContext;
gEntitiesRegistry: IMVCEntitiesRegistry; gEntitiesRegistry: IMVCEntitiesRegistry;
gConnections: IMVCActiveRecordConnections; gConnections: IMVCActiveRecordConnections;
gConnectionsLock: TObject;
gTableMap: IMVCActiveRecordTableMap; gTableMap: IMVCActiveRecordTableMap;
gTableMapLock: TObject; gTableMapLock: TObject;
@ -3844,13 +3838,13 @@ end;
class constructor TMVCSQLGeneratorRegistry.Create; class constructor TMVCSQLGeneratorRegistry.Create;
begin begin
cLock := TObject.Create; cConnectionsLock := TObject.Create;
end; end;
class destructor TMVCSQLGeneratorRegistry.Destroy; class destructor TMVCSQLGeneratorRegistry.Destroy;
begin begin
cLock.Free;
cInstance.Free; cInstance.Free;
cConnectionsLock.Free;
end; end;
destructor TMVCSQLGeneratorRegistry.Destroy; destructor TMVCSQLGeneratorRegistry.Destroy;
@ -3871,14 +3865,14 @@ class function TMVCSQLGeneratorRegistry.Instance: TMVCSQLGeneratorRegistry;
begin begin
if not Assigned(cInstance) then if not Assigned(cInstance) then
begin begin
TMonitor.Enter(cLock); TMonitor.Enter(cConnectionsLock);
try try
if not Assigned(cInstance) then if not Assigned(cInstance) then
begin begin
cInstance := TMVCSQLGeneratorRegistry.Create; cInstance := TMVCSQLGeneratorRegistry.Create;
end; end;
finally finally
TMonitor.Exit(cLock); TMonitor.Exit(cConnectionsLock);
end; end;
end; end;
Result := cInstance; Result := cInstance;
@ -4838,7 +4832,6 @@ end;
initialization initialization
gConnectionsLock := TObject.Create;
gTableMapLock := TObject.Create; gTableMapLock := TObject.Create;
gCtx := TRttiContext.Create; gCtx := TRttiContext.Create;
gCtx.FindType(''); gCtx.FindType('');
@ -4846,7 +4839,6 @@ gCtx.FindType('');
finalization finalization
gCtx.Free; gCtx.Free;
gConnectionsLock.Free;
gTableMapLock.Free; gTableMapLock.Free;
end. end.