From ac6011143cb74113220a884c887ce1ed02200957 Mon Sep 17 00:00:00 2001 From: Daniele Teti Date: Wed, 16 Oct 2024 08:10:50 +0200 Subject: [PATCH] Loading of SQL generators refactored --- sources/MVCFramework.ActiveRecord.pas | 28 ++++++++++----------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/sources/MVCFramework.ActiveRecord.pas b/sources/MVCFramework.ActiveRecord.pas index eef777f1..b0f2dd9a 100644 --- a/sources/MVCFramework.ActiveRecord.pas +++ b/sources/MVCFramework.ActiveRecord.pas @@ -46,7 +46,9 @@ uses MVCFramework.RQL.Parser, MVCFramework.Cache, MVCFramework.Serializer.Intf, - MVCFramework.Serializer.Commons, System.SyncObjs, System.TypInfo; + MVCFramework.Serializer.Commons, + System.SyncObjs, + System.TypInfo; type EMVCActiveRecord = class(EMVCException) @@ -879,15 +881,15 @@ type class var cInstance: TMVCSQLGeneratorRegistry; class var - cLock: TObject; fSQLGenerators: TDictionary; + cConnectionsLock: TObject; protected constructor Create; public destructor Destroy; override; class function Instance: TMVCSQLGeneratorRegistry; - class destructor Destroy; class constructor Create; + class destructor Destroy; procedure RegisterSQLGenerator(const aBackend: string; const aRQLBackendClass: TMVCSQLGeneratorClass); procedure UnRegisterSQLGenerator(const aBackend: string); function GetSQLGenerator(const aBackend: string): TMVCSQLGeneratorClass; @@ -966,20 +968,12 @@ uses FireDAC.Stan.Option, Data.FmtBcd, System.Variants, - System.Math, - {link all sql generators} - MVCFramework.SQLGenerators.PostgreSQL, - MVCFramework.SQLGenerators.Firebird, - MVCFramework.SQLGenerators.Sqlite, - MVCFramework.SQLGenerators.MySQL, - MVCFramework.SQLGenerators.MSSQL, - MVCFramework.SQLGenerators.Interbase; + System.Math; var gCtx: TRttiContext; gEntitiesRegistry: IMVCEntitiesRegistry; gConnections: IMVCActiveRecordConnections; - gConnectionsLock: TObject; gTableMap: IMVCActiveRecordTableMap; gTableMapLock: TObject; @@ -3844,13 +3838,13 @@ end; class constructor TMVCSQLGeneratorRegistry.Create; begin - cLock := TObject.Create; + cConnectionsLock := TObject.Create; end; class destructor TMVCSQLGeneratorRegistry.Destroy; begin - cLock.Free; cInstance.Free; + cConnectionsLock.Free; end; destructor TMVCSQLGeneratorRegistry.Destroy; @@ -3871,14 +3865,14 @@ class function TMVCSQLGeneratorRegistry.Instance: TMVCSQLGeneratorRegistry; begin if not Assigned(cInstance) then begin - TMonitor.Enter(cLock); + TMonitor.Enter(cConnectionsLock); try if not Assigned(cInstance) then begin cInstance := TMVCSQLGeneratorRegistry.Create; end; finally - TMonitor.Exit(cLock); + TMonitor.Exit(cConnectionsLock); end; end; Result := cInstance; @@ -4838,7 +4832,6 @@ end; initialization -gConnectionsLock := TObject.Create; gTableMapLock := TObject.Create; gCtx := TRttiContext.Create; gCtx.FindType(''); @@ -4846,7 +4839,6 @@ gCtx.FindType(''); finalization gCtx.Free; -gConnectionsLock.Free; gTableMapLock.Free; end.