ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/FBTransaction.pas
(Generate patch)

Comparing ibx/branches/journaling/fbintf/client/FBTransaction.pas (file contents):
Revision 362 by tony, Tue Dec 7 13:27:39 2021 UTC vs.
Revision 363 by tony, Tue Dec 7 13:30:05 2021 UTC

# Line 84 | Line 84 | type
84    protected
85      FTPB: ITPB;
86      FSeqNo: integer;
87 <    FDefaultCompletion: TTransactionAction;
87 >    FDefaultCompletion: TTransactionCompletion;
88      FAttachments: array of IAttachment; {Keep reference to attachment - ensures
89                                            attachment cannot be freed before transaction}
90 +    FTransactionName: AnsiString;
91      procedure CheckHandle;
92      function GetActivityIntf(att: IAttachment): IActivityMonitor; virtual; abstract;
93 +    function GetJournalIntf(Attachment: IAttachment): IJournallingHook;
94      procedure SetInterface(api: TFBClientAPI); virtual;
95      function GetTrInfo(ReqBuffer: PByte; ReqBufLen: integer): ITrInformation; virtual; abstract;
96 +    procedure InternalStartSingle(attachment: IAttachment); virtual; abstract;
97 +    procedure InternalStartMultiple; virtual; abstract;
98 +    procedure InternalCommit(Force: boolean); virtual; abstract;
99 +    procedure InternalCommitRetaining; virtual; abstract;
100 +    procedure InternalRollback(Force: boolean); virtual; abstract;
101 +    procedure InternalRollbackRetaining; virtual; abstract;
102    public
103 <    constructor Create(api: TFBClientAPI; Attachments: array of IAttachment; Params: array of byte; DefaultCompletion: TTransactionAction); overload;
104 <    constructor Create(api: TFBClientAPI; Attachments: array of IAttachment; TPB: ITPB; DefaultCompletion: TTransactionAction); overload;
105 <    constructor Create(api: TFBClientAPI; Attachment: IAttachment; Params: array of byte; DefaultCompletion: TTransactionAction); overload;
106 <    constructor Create(api: TFBClientAPI; Attachment: IAttachment; TPB: ITPB; DefaultCompletion: TTransactionAction); overload;
103 >    constructor Create(api: TFBClientAPI; Attachments: array of IAttachment; Params: array of byte; DefaultCompletion: TTransactionAction; aName: AnsiString); overload;
104 >    constructor Create(api: TFBClientAPI; Attachments: array of IAttachment; TPB: ITPB; DefaultCompletion: TTransactionAction; aName: AnsiString); overload;
105 >    constructor Create(api: TFBClientAPI; Attachment: IAttachment; Params: array of byte; DefaultCompletion: TTransactionAction; aName: AnsiString); overload;
106 >    constructor Create(api: TFBClientAPI; Attachment: IAttachment; TPB: ITPB; DefaultCompletion: TTransactionAction; aName: AnsiString); overload;
107      destructor Destroy; override;
108      procedure DoDefaultTransactionEnd(Force: boolean);
109      property FirebirdAPI: TFBClientAPI read FFirebirdAPI;
# Line 104 | Line 112 | type
112      {ITransaction}
113      function getTPB: ITPB;
114      procedure PrepareForCommit;virtual; abstract;
115 <    procedure Commit(Force: boolean=false);  virtual; abstract;
116 <    procedure CommitRetaining;  virtual; abstract;
115 >    procedure Commit(Force: boolean=false);
116 >    procedure CommitRetaining;
117      function GetInTransaction: boolean; virtual; abstract;
118      function GetIsReadOnly: boolean;
119      function GetTransactionID: integer;
120      function GetAttachmentCount: integer;
121      function GetAttachment(index: integer): IAttachment;
122 <    procedure Rollback(Force: boolean=false);  virtual; abstract;
123 <    procedure RollbackRetaining;  virtual; abstract;
124 <    procedure Start(DefaultCompletion: TTransactionCompletion=taCommit); overload; virtual; abstract;
122 >    function GetJournalingActive(attachment: IAttachment): boolean;
123 >    function GetDefaultCompletion: TTransactionCompletion;
124 >    procedure Rollback(Force: boolean=false);
125 >    procedure RollbackRetaining;
126 >    procedure Start(DefaultCompletion: TTransactionCompletion=taCommit); overload;
127      procedure Start(TPB: ITPB; DefaultCompletion: TTransactionCompletion=taCommit); overload;
128      function GetTrInformation(Requests: array of byte): ITrInformation; overload;
129      function GetTrInformation(Request: byte): ITrInformation; overload;
130 +    function GetTransactionName: AnsiString;
131 +    procedure SetTransactionName(aValue: AnsiString);
132  
133      property InTransaction: boolean read GetInTransaction;
134      property TransactionSeqNo: integer read FSeqNo;
# Line 150 | Line 162 | type
162      {$ELSE}
163      function GetDPBParamTypeName(ParamType: byte): Ansistring;
164      {$ENDIF}
165 +    function AsText: AnsiString;
166   end;
167  
168    {$IFDEF FPC}
# Line 159 | Line 172 | end;
172  
173    TTrInfoItem = class(TOutputBlockItemGroup<TTrInfoItem,ITrInfoItem>,ITrInfoItem)
174    {$ELSE}
175 <    TTransInfoItem = class(TOutputBlockItemGroup<TOutputBlockItem,ITransInfoItem>,ITransInfoItem)
175 >    TTrInfoItem = class(TOutputBlockItemGroup<TOutputBlockItem,ITrInfoItem>,ITrInfoItem)
176    {$ENDIF}
177      public
178        procedure DecodeTraIsolation(var IsolationType, RecVersion: byte);
# Line 173 | Line 186 | end;
186    public
187      constructor Create(api: TFBClientAPI; aSize: integer = DefaultBufferSize);
188      {$IFNDEF FPC}
189 <    function Find(ItemType: byte): ITransInfoItem;
189 >    function Find(ItemType: byte): ITrInfoItem;
190      {$ENDIF}
191    end;
192  
193 +
194   implementation
195  
196   uses FBMessages;
# Line 227 | Line 241 | begin
241      IBError(ibxeNotInTransaction,[]);
242   end;
243  
244 + function TFBTransaction.GetJournalIntf(Attachment: IAttachment): IJournallingHook;
245 + begin
246 +  Attachment.QueryInterface(IJournallingHook,Result)
247 + end;
248 +
249   procedure TFBTransaction.SetInterface(api: TFBClientAPI);
250   begin
251    FFirebirdAPI := api;
252   end;
253  
254   constructor TFBTransaction.Create(api: TFBClientAPI; Attachments: array of IAttachment;
255 <  Params: array of byte; DefaultCompletion: TTransactionAction);
255 >  Params: array of byte; DefaultCompletion: TTransactionAction; aName: AnsiString);
256   begin
257 <  Create(api, Attachments,GenerateTPB(Params), DefaultCompletion);
257 >  Create(api, Attachments,GenerateTPB(Params), DefaultCompletion, aName);
258   end;
259  
260   constructor TFBTransaction.Create(api: TFBClientAPI; Attachments: array of IAttachment; TPB: ITPB;
261 <  DefaultCompletion: TTransactionAction);
261 >  DefaultCompletion: TTransactionAction; aName: AnsiString);
262   var
263    i: Integer;
264   begin
265    inherited Create(nil);
266 +  FTransactionName := aName;
267    SetInterface(api);
268    if Length(Attachments) = 0 then
269      IBError(ibxeEmptyAttachmentsList,[nil]);
# Line 264 | Line 284 | begin
284   end;
285  
286   constructor TFBTransaction.Create(api: TFBClientAPI; Attachment: IAttachment;
287 <  Params: array of byte; DefaultCompletion: TTransactionAction);
287 >  Params: array of byte; DefaultCompletion: TTransactionAction; aName: AnsiString);
288   begin
289 <  Create(api,Attachment,GenerateTPB(Params),DefaultCompletion);
289 >  Create(api,Attachment,GenerateTPB(Params),DefaultCompletion,aName);
290   end;
291  
292   constructor TFBTransaction.Create(api: TFBClientAPI; Attachment: IAttachment; TPB: ITPB;
293 <  DefaultCompletion: TTransactionAction);
293 >  DefaultCompletion: TTransactionAction; aName: AnsiString);
294   begin
295    inherited Create(nil);
296    SetInterface(api);
# Line 278 | Line 298 | begin
298    SetLength(FAttachments,1);
299    FAttachments[0] := Attachment;
300    FTPB := TPB;
301 +  FTransactionName := aName;
302    Start(DefaultCompletion);
303   end;
304  
# Line 314 | Line 335 | begin
335    Result := FTPB;
336   end;
337  
338 + procedure TFBTransaction.Commit(Force: boolean);
339 + var i: integer;
340 +    TransactionID: integer;
341 +    TransactionEndNeeded: array of boolean;
342 + begin
343 +  if not GetInTransaction then Exit;
344 +
345 +  SetLength(TransactionEndNeeded,Length(FAttachments));
346 +  TransactionID := GetTransactionID;
347 +  for i := 0 to Length(FAttachments) - 1 do
348 +    if (FAttachments[i] <> nil)  then
349 +      TransactionEndNeeded[i] := GetJournalingActive(FAttachments[i])
350 +    else
351 +      TransactionEndNeeded[i] := false;
352 +  InternalCommit(Force);
353 +  for i := 0 to Length(FAttachments) - 1 do
354 +    if TransactionEndNeeded[i] then
355 +       GetJournalIntf(FAttachments[i]).TransactionEnd(TransactionID, TACommit);
356 + end;
357 +
358 + procedure TFBTransaction.CommitRetaining;
359 + var i: integer;
360 +    TransactionID: integer;
361 + begin
362 +  if not GetInTransaction then Exit;
363 +
364 +  TransactionID := GetTransactionID;
365 +  InternalCommitRetaining;
366 +  for i := 0 to Length(FAttachments) - 1 do
367 +    if (FAttachments[i] <> nil) and GetJournalingActive(FAttachments[i]) then
368 +       GetJournalIntf(FAttachments[i]).TransactionRetained(self,TransactionID, TACommitRetaining);
369 + end;
370 +
371   function TFBTransaction.GetIsReadOnly: boolean;
372   var Info: ITrInformation;
373   begin
# Line 346 | Line 400 | begin
400      IBError(ibxeAttachmentListIndexError,[index]);
401   end;
402  
403 + function TFBTransaction.GetJournalingActive(attachment: IAttachment): boolean;
404 + begin
405 +  Result := false;
406 +  if (attachment = nil) and (length(FAttachments) > 0) then
407 +    attachment := FAttachments[0];
408 +  if attachment <> nil then
409 +  with attachment do
410 +  Result := self.GetInTransaction and JournalingActive and
411 +     ((((joReadOnlyTransactions in GetJournalOptions) and self.GetIsReadOnly)) or
412 +     ((joReadWriteTransactions in GetJournalOptions) and not self.GetIsReadOnly));
413 + end;
414 +
415 + function TFBTransaction.GetDefaultCompletion: TTransactionCompletion;
416 + begin
417 +  Result := FDefaultCompletion;
418 + end;
419 +
420 + procedure TFBTransaction.Rollback(Force: boolean);
421 + var i: integer;
422 +    TransactionID: integer;
423 +    TransactionEndNeeded: array of boolean;
424 + begin
425 +  if not GetInTransaction then Exit;
426 +
427 +  SetLength(TransactionEndNeeded,Length(FAttachments));
428 +  TransactionID := GetTransactionID;
429 +  for i := 0 to Length(FAttachments) - 1 do
430 +    if (FAttachments[i] <> nil)  then
431 +      TransactionEndNeeded[i] := GetJournalingActive(FAttachments[i])
432 +    else
433 +      TransactionEndNeeded[i] := false;
434 +  InternalRollback(Force);
435 +  for i := 0 to Length(FAttachments) - 1 do
436 +    if TransactionEndNeeded[i] then
437 +       GetJournalIntf(FAttachments[i]).TransactionEnd(TransactionID, TARollback);
438 + end;
439 +
440 + procedure TFBTransaction.RollbackRetaining;
441 + var i: integer;
442 +    TransactionID: integer;
443 + begin
444 +  if not GetInTransaction then Exit;
445 +
446 +  TransactionID := GetTransactionID;
447 +  InternalRollbackRetaining;
448 +  for i := 0 to Length(FAttachments) - 1 do
449 +    if (FAttachments[i] <> nil) and GetJournalingActive(FAttachments[i]) then
450 +       GetJournalIntf(FAttachments[i]).TransactionRetained(self,TransactionID,TARollbackRetaining);
451 + end;
452 +
453 + procedure TFBTransaction.Start(DefaultCompletion: TTransactionCompletion);
454 + var i: integer;
455 + begin
456 +  if GetInTransaction then
457 +    Exit;
458 +
459 +  FDefaultCompletion := DefaultCompletion;
460 +
461 +  if Length(FAttachments) = 1 then
462 +    InternalStartSingle(FAttachments[0])
463 +  else
464 +    InternalStartMultiple;
465 +  for i := 0 to Length(FAttachments) - 1 do
466 +    if (FAttachments[i] <> nil) and GetJournalingActive(FAttachments[i]) then
467 +      GetJournalIntf(FAttachments[i]).TransactionStart(self);
468 +  Inc(FSeqNo);
469 + end;
470 +
471   procedure TFBTransaction.Start(TPB: ITPB; DefaultCompletion: TTransactionCompletion
472    );
473   begin
# Line 382 | Line 504 | begin
504    Result := GetTrInfo(@Request,1);
505   end;
506  
507 + function TFBTransaction.GetTransactionName: AnsiString;
508 + begin
509 +  Result := FTransactionName;
510 + end;
511 +
512 + procedure TFBTransaction.SetTransactionName(aValue: AnsiString);
513 + begin
514 +  FTransactionName := aValue;
515 + end;
516 +
517   { TTPBItem }
518  
519   function TTPBItem.getParamTypeName: AnsiString;
# Line 402 | Line 534 | end;
534   function TTPB.GetParamTypeName(ParamType: byte): Ansistring;
535   begin
536    if ParamType <= isc_tpb_last_tpb_constant then
537 <    Result := TPBConstantNames[ParamType]
537 >    Result := TPBPrefix + TPBConstantNames[ParamType]
538    else
539      Result := '';
540   end;
541  
542 + function TTPB.AsText: AnsiString;
543 + var i: integer;
544 + begin
545 +  Result := '[';
546 +  for i := 0 to getCount - 1 do
547 +  begin
548 +    Result := Result + GetParamTypeName(getItems(i).getParamType);
549 +    if i < getCount - 1 then
550 +      Result := Result + ',';
551 +  end;
552 +  Result := Result + ']';
553 + end;
554 +
555   {$IFNDEF FPC}
556   function TTPB.GetDPBParamTypeName(ParamType: byte): Ansistring;
557   begin
# Line 505 | Line 650 | begin
650    FIntegerType := dtInteger;
651   end;
652  
653 + {$IFNDEF FPC}
654 + function TTrInformation.Find(ItemType: byte): ITrInfoItem;
655 + begin
656 +  Result := inherited Find(ItemType);
657 +  if Result.GetSize = 0 then
658 +    Result := nil;
659 + end;
660 + {$ENDIF}
661 +
662   end.
663  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines