Skip to content

Commit

Permalink
Passthrough controller now subscribes to next controller. #20
Browse files Browse the repository at this point in the history
  • Loading branch information
bero committed Dec 7, 2024
1 parent 6eea3b6 commit 3783251
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions Source/BoldPersistenceControllerPassthrough.pas
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ TBoldPersistenceControllerPassthrough = class;
{ TBoldPersistenceControllerPassthrough }
TBoldPersistenceControllerPassthrough = class(TBoldPersistenceController)
private
fSubscriber: TBoldPassthroughSubscriber;
fNextPersistenceController: TBoldPersistenceController;
function GetNextPersistenceController: TBoldPersistenceController;
procedure SetNextPersistenceController(const Value: TBoldPersistenceController);
procedure Receive(Originator: TObject; OriginalEvent: TBoldEvent; RequestedEvent: TBoldRequestedEvent);
public
constructor Create;
destructor Destroy; override;
procedure PMExactifyIds(ObjectIdList: TBoldObjectIdList; TranslationList: TBoldIdTranslationList; HandleNonExisting: Boolean); override;
procedure PMFetch(ObjectIdList: TBoldObjectIdList; ValueSpace: IBoldValueSpace; MemberIdList: TBoldMemberIdList; FetchMode: Integer; BoldClientID: TBoldClientID); override;
procedure PMFetchIDListWithCondition(ObjectIdList: TBoldObjectIdList; ValueSpace: IBoldValueSpace; FetchMode: Integer; Condition: TBoldCondition; BoldClientID: TBoldClientID); override;
Expand All @@ -43,8 +47,7 @@ TBoldPersistenceControllerPassthrough = class(TBoldPersistenceController)
procedure CommitTransaction; override;
procedure RollbackTransaction; override;
function DatabaseInterface: IBoldDatabase; override;
property NextPersistenceController: TBoldPersistenceController read getNextPersistenceController
write fNextPersistenceController;
property NextPersistenceController: TBoldPersistenceController read GetNextPersistenceController write SetNextPersistenceController;
end;

implementation
Expand All @@ -63,6 +66,17 @@ function TBoldPersistenceControllerPassthrough.CanEvaluateInPS(sOCL: string;
Result := NextPersistenceController.CanEvaluateInPS(sOCL, aSystem, aContext, aVariableList);
end;

procedure TBoldPersistenceControllerPassthrough.SetNextPersistenceController(const Value: TBoldPersistenceController);
begin
if fNextPersistenceController <> value then
begin
fNextPersistenceController := Value;
FreeAndNil(fSubscriber);
fSubscriber := TBoldPassthroughSubscriber.Create(Receive);
fNextPersistenceController.AddSubscription(fSubscriber, beDestroying);
end;
end;

procedure TBoldPersistenceControllerPassthrough.StartTransaction;
begin
NextPersistenceController.StartTransaction;
Expand Down Expand Up @@ -91,6 +105,12 @@ function TBoldPersistenceControllerPassthrough.DatabaseInterface: IBoldDatabase;
result := nil;
end;

destructor TBoldPersistenceControllerPassthrough.Destroy;
begin
FreeAndNil(fSubscriber);
inherited;
end;

function TBoldPersistenceControllerPassthrough.getNextPersistenceController: TBoldPersistenceController;
begin
if Assigned(fNextPersistenceController) then
Expand Down Expand Up @@ -160,6 +180,13 @@ procedure TBoldPersistenceControllerPassthrough.SubscribeToPersistenceEvents(
NextPersistenceController.SubscribeToPersistenceEvents(Subscriber, Events);
end;

procedure TBoldPersistenceControllerPassthrough.Receive(Originator: TObject; OriginalEvent: TBoldEvent;
RequestedEvent: TBoldRequestedEvent);
begin
if Originator = fNextPersistenceController then
fNextPersistenceController := nil;
end;

procedure TBoldPersistenceControllerPassthrough.ReserveNewIds(ValueSpace: IBoldValueSpace; ObjectIdList: TBoldObjectIdList;
TranslationList: TBoldIdTranslationList);
begin
Expand Down

0 comments on commit 3783251

Please sign in to comment.