ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/fbintf/client/3.0/FB30Transaction.pas
(Generate patch)

Comparing ibx/trunk/fbintf/client/3.0/FB30Transaction.pas (file contents):
Revision 401 by tony, Mon Jan 10 10:13:17 2022 UTC vs.
Revision 402 by tony, Mon Aug 1 10:07:24 2022 UTC

# Line 48 | Line 48 | type
48    private
49      FTransactionIntf: Firebird.ITransaction;
50      FFirebird30ClientAPI: TFB30ClientAPI;
51    procedure StartMultiple;
51      procedure FreeHandle(Force: boolean);
52    protected
53      function GetActivityIntf(att: IAttachment): IActivityMonitor; override;
54      procedure SetInterface(api: TFBClientAPI); override;
55      function GetTrInfo(ReqBuffer: PByte; ReqBufLen: integer): ITrInformation; override;
56 +    procedure InternalStartSingle(attachment: IAttachment); override;
57 +    procedure InternalStartMultiple; override;
58 +    function InternalCommit(Force: boolean): TTrCompletionState; override;
59 +    procedure InternalCommitRetaining; override;
60 +    function InternalRollback(Force: boolean): TTrCompletionState; override;
61 +    procedure InternalRollbackRetaining; override;
62    public
63 +    constructor Create(api: TFBClientAPI; Attachment: IAttachment; aTransactionIntf: Firebird.ITransaction); overload;
64      destructor Destroy; override;
65      property TransactionIntf: Firebird.ITransaction read FTransactionIntf;
66      {ITransaction}
67      function GetInTransaction: boolean; override;
68      procedure PrepareForCommit; override;
63    procedure Commit(Force: boolean=false); override;
64    procedure CommitRetaining; override;
65    procedure Start(DefaultCompletion: TTransactionCompletion=taCommit); overload; override;
66    procedure Rollback(Force: boolean=false); override;
67    procedure RollbackRetaining; override;
69    end;
70  
71  
# Line 74 | Line 75 | uses FBMessages;
75  
76   { TFB30Transaction }
77  
77 procedure TFB30Transaction.StartMultiple;
78 var Dtc: IDtc;
79    DtcStart: IDtcStart;
80    i: integer;
81 begin
82  with FFirebird30ClientAPI do
83  begin
84    Dtc := MasterIntf.getDtc;
85    DtcStart := Dtc.startBuilder(StatusIntf);
86    Check4DataBaseError;
87
88    for i := 0 to Length(FAttachments) - 1 do
89    if (FAttachments[i] <> nil)  then
90    begin
91      DTCStart.addWithTpb(StatusIntf,
92                          (FAttachments[i] as TFB30Attachment).AttachmentIntf,
93                          (FTPB as TTPB).getDataLength,
94                          BytePtr((FTPB as TTPB).getBuffer));
95      Check4DataBaseError;
96    end;
97    FTransactionIntf := DtcStart.start(StatusIntf);
98    Check4DataBaseError;
99  end;
100 end;
101
78   procedure TFB30Transaction.FreeHandle(Force: boolean);
79   begin
80    if assigned(FTransactionIntf) then
# Line 134 | Line 110 | begin
110    end
111   end;
112  
113 < destructor TFB30Transaction.Destroy;
138 < begin
139 <  inherited Destroy;
140 <  FreeHandle(true);
141 < end;
142 <
143 < function TFB30Transaction.GetInTransaction: boolean;
113 > procedure TFB30Transaction.InternalStartSingle(attachment: IAttachment);
114   begin
115 <  Result := FTransactionIntf <> nil;
115 >  if FTransactionIntf = nil then
116 >  with FFirebird30ClientAPI do
117 >  begin
118 >    FTransactionIntf  := (attachment as TFB30Attachment).AttachmentIntf.startTransaction(StatusIntf,
119 >             (FTPB as TTPB).getDataLength,BytePtr((FTPB as TTPB).getBuffer));
120 >    Check4DataBaseError;
121 >    FTransactionIntf.addRef();
122 >  end;
123 >  SignalActivity;
124   end;
125  
126 < procedure TFB30Transaction.PrepareForCommit;
126 > procedure TFB30Transaction.InternalStartMultiple;
127 > var Dtc: IDtc;
128 >    DtcStart: IDtcStart;
129 >    i: integer;
130   begin
150  if Length(FAttachments) < 2 then
151    IBError(ibxeNotAMultiDatabaseTransaction,[nil]);
131    if FTransactionIntf = nil then
153    Exit;
132    with FFirebird30ClientAPI do
133    begin
134 <    FTransactionIntf.prepare(StatusIntf,0,nil);
134 >    Dtc := MasterIntf.getDtc;
135 >    DtcStart := Dtc.startBuilder(StatusIntf);
136 >    Check4DataBaseError;
137 >
138 >    for i := 0 to Length(FAttachments) - 1 do
139 >    if (FAttachments[i] <> nil)  then
140 >    begin
141 >      DTCStart.addWithTpb(StatusIntf,
142 >                          (FAttachments[i] as TFB30Attachment).AttachmentIntf,
143 >                          (FTPB as TTPB).getDataLength,
144 >                          BytePtr((FTPB as TTPB).getBuffer));
145 >      Check4DataBaseError;
146 >    end;
147 >
148 >    FTransactionIntf := DtcStart.start(StatusIntf);
149      Check4DataBaseError;
150 +    FTransactionIntf.addRef();
151 +    SignalActivity;
152    end;
159  SignalActivity;
153   end;
154  
155 < procedure TFB30Transaction.Commit(Force: boolean);
155 > function TFB30Transaction.InternalCommit(Force: boolean): TTrCompletionState;
156   begin
164  if FTransactionIntf = nil then
165    Exit;
157    with FFirebird30ClientAPI do
158    begin
159 +    Result := trCommitted;
160      FTransactionIntf.commit(StatusIntf);
161 <    if not Force and InErrorState then
161 >    if InErrorState then
162 >    begin
163 >      if Force then
164 >        Result := trCommitFailed
165 >      else
166         IBDataBaseError;
167 +    end;
168    end;
169    SignalActivity;
170    FreeHandle(Force);
171   end;
172  
173 < procedure TFB30Transaction.CommitRetaining;
173 > procedure TFB30Transaction.InternalCommitRetaining;
174   begin
178  if FTransactionIntf = nil then
179    Exit;
175    with FFirebird30ClientAPI do
176    begin
177      FTransactionIntf.commitRetaining(StatusIntf);
# Line 185 | Line 180 | begin
180    SignalActivity;
181   end;
182  
183 < procedure TFB30Transaction.Start(DefaultCompletion: TTransactionCompletion);
183 > function TFB30Transaction.InternalRollback(Force: boolean): TTrCompletionState;
184   begin
185 <  if FTransactionIntf <> nil then
186 <    Exit;
187 <  FDefaultCompletion := DefaultCompletion;
188 <
189 <  if Length(FAttachments) = 1 then
195 <    with FFirebird30ClientAPI do
185 >  with FFirebird30ClientAPI do
186 >  begin
187 >    FTransactionIntf.rollback(StatusIntf);
188 >    Result := trRolledback;
189 >    if InErrorState then
190      begin
191 <      FTransactionIntf  := (FAttachments[0] as TFB30Attachment).AttachmentIntf.startTransaction(StatusIntf,
192 <               (FTPB as TTPB).getDataLength,BytePtr((FTPB as TTPB).getBuffer));
193 <      Check4DataBaseError;
194 <    end
195 <  else
196 <    StartMultiple;
191 >      if Force then
192 >        Result := trRollbackFailed
193 >      else
194 >       IBDataBaseError;
195 >    end;
196 >  end;
197    SignalActivity;
198 <  Inc(FSeqNo);
198 >  FreeHandle(Force);
199   end;
200  
201 < procedure TFB30Transaction.Rollback(Force: boolean);
201 > procedure TFB30Transaction.InternalRollbackRetaining;
202   begin
209  if FTransactionIntf = nil then
210    Exit;
203    with FFirebird30ClientAPI do
204    begin
205 <    FTransactionIntf.rollback(StatusIntf);
206 <    if not Force and InErrorState then
215 <       IBDataBaseError;
205 >    FTransactionIntf.rollbackRetaining(StatusIntf);
206 >    Check4DataBaseError;
207    end;
208    SignalActivity;
218  FreeHandle(Force);
209   end;
210  
211 < procedure TFB30Transaction.RollbackRetaining;
211 > constructor TFB30Transaction.Create(api: TFBClientAPI; Attachment: IAttachment;
212 >  aTransactionIntf: Firebird.ITransaction);
213 > begin
214 >  FTransactionIntf := aTransactionIntf;
215 >  FTransactionIntf.addRef();
216 >  FForeignHandle := true;
217 >  inherited Create(api,Attachment,nil,taCommit,'');
218 > end;
219 >
220 > destructor TFB30Transaction.Destroy;
221 > begin
222 >  inherited Destroy;
223 >  FreeHandle(true);
224 > end;
225 >
226 > function TFB30Transaction.GetInTransaction: boolean;
227   begin
228 +  Result := FTransactionIntf <> nil;
229 + end;
230 +
231 + procedure TFB30Transaction.PrepareForCommit;
232 + begin
233 +  if Length(FAttachments) < 2 then
234 +    IBError(ibxeNotAMultiDatabaseTransaction,[nil]);
235    if FTransactionIntf = nil then
236      Exit;
237    with FFirebird30ClientAPI do
238    begin
239 <    FTransactionIntf.rollbackRetaining(StatusIntf);
239 >    FTransactionIntf.prepare(StatusIntf,0,nil);
240      Check4DataBaseError;
241    end;
242    SignalActivity;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines