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

Comparing:
ibx/trunk/fbintf/client/2.5/FB25Transaction.pas (file contents), Revision 263 by tony, Thu Dec 6 15:55:01 2018 UTC vs.
ibx/branches/journaling/fbintf/client/2.5/FB25Transaction.pas (file contents), Revision 363 by tony, Tue Dec 7 13:30:05 2021 UTC

# Line 85 | Line 85 | type
85      FFirebird25ClientAPI: TFB25ClientAPI;
86    protected
87      function GetActivityIntf(att: IAttachment): IActivityMonitor; override;
88 +    function GetTrInfo(ReqBuffer: PByte; ReqBufLen: integer): ITrInformation; override;
89      procedure SetInterface(api: TFBClientAPI); override;
90 +    procedure InternalStartSingle(attachment: IAttachment); override;
91 +    procedure InternalStartMultiple; override;
92 +    procedure InternalCommit(Force: boolean); override;
93 +    procedure InternalRollback(Force: boolean); override;
94 +    procedure InternalCommitRetaining; override;
95 +    procedure InternalRollbackRetaining; override;
96    public
97      property Handle: TISC_TR_HANDLE read FHandle;
98  
# Line 93 | Line 100 | type
100      {ITransaction}
101      function GetInTransaction: boolean; override;
102      procedure PrepareForCommit; override;
96    procedure Commit(Force: boolean=false); override;
97    procedure CommitRetaining; override;
98    procedure Start(DefaultCompletion: TTransactionCompletion=taCommit); overload; override;
99    procedure Rollback(Force: boolean=false); override;
100    procedure RollbackRetaining; override;
103   end;
104  
105   implementation
# Line 111 | Line 113 | begin
113    Result := (att as TFB25Attachment);
114   end;
115  
116 + function TFB25Transaction.GetTrInfo(ReqBuffer: PByte; ReqBufLen: integer
117 +  ): ITrInformation;
118 + begin
119 +  Result := TTrInformation.Create(FFirebird25ClientAPI);
120 +  with FFirebird25ClientAPI, Result as TTrInformation do
121 +     if isc_transaction_info(StatusVector, @(FHandle), ReqBufLen, ReqBuffer,
122 +                               getBufSize, Buffer) > 0 then
123 +          IBDataBaseError;
124 + end;
125 +
126   procedure TFB25Transaction.SetInterface(api: TFBClientAPI);
127   begin
128    inherited SetInterface(api);
# Line 118 | Line 130 | begin
130    OnDatabaseError := FFirebird25ClientAPI.IBDataBaseError;
131   end;
132  
133 < function TFB25Transaction.GetInTransaction: boolean;
134 < begin
123 <  Result := FHandle <> nil;
124 < end;
125 <
126 < procedure TFB25Transaction.PrepareForCommit;
133 > procedure TFB25Transaction.InternalStartSingle(attachment: IAttachment);
134 > var db_handle: TISC_DB_HANDLE;
135   begin
128  if Length(FAttachments) < 2 then
129    IBError(ibxeNotAMultiDatabaseTransaction,[nil]);
130  if FHandle = nil then
131    Exit;
132  with FFirebird25ClientAPI do
133    Call(isc_prepare_transaction(StatusVector, @FHandle));
134 end;
135
136 procedure TFB25Transaction.Commit(Force: boolean);
137 begin
138  if FHandle = nil then
139    Exit;
140  with FFirebird25ClientAPI do
141    Call(isc_commit_transaction(StatusVector, @FHandle),not Force);
142  FHandle := nil;
143 end;
144
145 procedure TFB25Transaction.CommitRetaining;
146 begin
147  if FHandle = nil then
148    Exit;
149  with FFirebird25ClientAPI do
150    Call(isc_commit_retaining(StatusVector, @FHandle));
151 end;
152
153 procedure TFB25Transaction.Start(DefaultCompletion: TTransactionCompletion);
154 var pteb: PISC_TEB_ARRAY;
155    i: integer;
156    db_handle: TISC_DB_HANDLE;
157 begin
158  if FHandle <> nil then
159    Exit;
160  pteb := nil;
161  FDefaultCompletion := DefaultCompletion;
136    with FFirebird25ClientAPI do
163  if (Length(FAttachments) = 1)  then
137    try
138 <    db_handle := (FAttachments[0] as TFB25Attachment).Handle;
138 >    db_handle := (attachment as TFB25Attachment).Handle;
139      Call(isc_start_transaction(StatusVector, @FHandle,1,
140                @db_handle,(FTPB as TTPB).getDataLength,(FTPB as TTPB).getBuffer));
141    except
142      FHandle := nil;
143      raise;
144    end
145 <  else
145 > end;
146 >
147 > procedure TFB25Transaction.InternalStartMultiple;
148 > var pteb: PISC_TEB_ARRAY;
149 >    i: integer;
150 > begin
151 >  pteb := nil;
152 >  with FFirebird25ClientAPI do
153    begin
154      IBAlloc(pteb, 0, Length(FAttachments) * SizeOf(TISC_TEB));
155       try
# Line 180 | Line 160 | begin
160            pteb^[i].tpb_length := (FTPB as TTPB).getDataLength;
161            pteb^[i].tpb_address := (FTPB as TTPB).getBuffer;
162          end;
163 +
164          try
165            Call(isc_start_multiple(StatusVector, @FHandle,
166                                     Length(FAttachments), PISC_TEB(pteb)));
# Line 191 | Line 172 | begin
172          FreeMem(pteb);
173       end;
174    end;
194  Inc(FSeqNo);
175   end;
176  
177 < procedure TFB25Transaction.Rollback(Force: boolean);
177 > procedure TFB25Transaction.InternalCommit(Force: boolean);
178 > begin
179 >  with FFirebird25ClientAPI do
180 >    Call(isc_commit_transaction(StatusVector, @FHandle),not Force);
181 >  FHandle := nil;
182 > end;
183 >
184 > procedure TFB25Transaction.InternalRollback(Force: boolean);
185   begin
199  if FHandle = nil then
200    Exit;
186    with FFirebird25ClientAPI do
187      Call(isc_rollback_transaction(StatusVector, @FHandle),not Force);
188    FHandle := nil;
189   end;
190  
191 < procedure TFB25Transaction.RollbackRetaining;
191 > procedure TFB25Transaction.InternalCommitRetaining;
192 > begin
193 >  with FFirebird25ClientAPI do
194 >    Call(isc_commit_retaining(StatusVector, @FHandle));
195 > end;
196 >
197 > procedure TFB25Transaction.InternalRollbackRetaining;
198 > begin
199 >  with FFirebird25ClientAPI do
200 >    Call(isc_rollback_retaining(StatusVector, @FHandle));
201 > end;
202 >
203 > function TFB25Transaction.GetInTransaction: boolean;
204 > begin
205 >  Result := FHandle <> nil;
206 > end;
207 >
208 > procedure TFB25Transaction.PrepareForCommit;
209   begin
210 +  if Length(FAttachments) < 2 then
211 +    IBError(ibxeNotAMultiDatabaseTransaction,[nil]);
212    if FHandle = nil then
213      Exit;
214    with FFirebird25ClientAPI do
215 <    Call(isc_rollback_retaining(StatusVector, @FHandle));
215 >    Call(isc_prepare_transaction(StatusVector, @FHandle));
216   end;
217  
218   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines