1 {*********************************************************}
3 { Zeos Database Objects }
4 { Database Sequence Component }
6 { Originally written by Stefan Glienke }
8 {*********************************************************}
10 {@********************************************************}
11 { Copyright (c) 1999-2012 Zeos Development Group }
13 { License Agreement: }
15 { This library is distributed in the hope that it will be }
16 { useful, but WITHOUT ANY WARRANTY; without even the }
17 { implied warranty of MERCHANTABILITY or FITNESS FOR }
18 { A PARTICULAR PURPOSE. See the GNU Lesser General }
19 { Public License for more details. }
21 { The source code of the ZEOS Libraries and packages are }
22 { distributed under the Library GNU General Public }
23 { License (see the file COPYING / COPYING.ZEOS) }
24 { with the following modification: }
25 { As a special exception, the copyright holders of this }
26 { library give you permission to link this library with }
27 { independent modules to produce an executable, }
28 { regardless of the license terms of these independent }
29 { modules, and to copy and distribute the resulting }
30 { executable under terms of your choice, provided that }
31 { you also meet, for each linked independent module, }
32 { the terms and conditions of the license of that module. }
33 { An independent module is a module which is not derived }
34 { from or based on this library. If you modify this }
35 { library, you may extend this exception to your version }
36 { of the library, but you are not obligated to do so. }
37 { If you do not wish to do so, delete this exception }
38 { statement from your version. }
41 { The project web site is located on: }
42 { http://zeos.firmos.at (FORUM) }
43 { http://sourceforge.net/p/zeoslib/tickets/ (BUGTRACKER)}
44 { svn://svn.code.sf.net/p/zeoslib/code-0/trunk (SVN) }
46 { http://www.sourceforge.net/projects/zeoslib. }
49 { Zeos Development Group. }
50 {********************************************************@}
59 SysUtils, Classes, {$IFDEF MSEgui}mclasses,{$ENDIF}
60 ZDbcIntfs, ZConnection;
63 {** Represents a component which wraps a sequence to database. }
64 TZSequence = class(TComponent)
66 FSequence: IZSequence;
67 FConnection: TZConnection;
68 FSequenceName: string;
70 procedure SetConnection(const Value: TZConnection);
71 procedure SetBlockSize(const Value: Integer);
72 procedure SetSequenceName(const Value: string);
74 procedure Notification(AComponent: TComponent;
75 Operation: TOperation); override;
76 function GetSequence: IZSequence;
78 constructor Create(AOwner: TComponent); override;
79 // Modified by cipto 8/2/2007 12:09:21 PM
80 destructor Destroy; override;
82 function GetCurrentValue: Int64;
83 function GetNextValue: Int64;
84 function GetCurrentValueSQL: string; // Get the Sequence as SQL-Text
85 function GetNextValueSQL: string; // Get the Sequence as SQL-Text
86 // Modified by cipto 8/2/2007 10:04:41 AM
87 procedure CloseSequence;
89 property BlockSize: Integer read FBlockSize write SetBlockSize default 1;
90 property Connection: TZConnection read FConnection write SetConnection;
91 property SequenceName: string read FSequenceName write SetSequenceName;
98 procedure TZSequence.CloseSequence;
100 if Assigned(FSequence) then
104 constructor TZSequence.Create(AOwner: TComponent);
111 Gets the current unique key generated by this sequence.
112 @param the next generated unique key.
114 destructor TZSequence.Destroy;
116 // Modified by cipto 8/3/2007 10:35:41 AM
117 if Assigned(FConnection) then
118 FConnection.UnregisterSequence(self);
122 function TZSequence.GetCurrentValue: Int64;
125 if Assigned(FSequence) then
126 Result := FSequence.GetCurrentValue
131 function TZSequence.GetCurrentValueSQL: string;
134 if Assigned(FSequence) then begin
135 Result := FSequence.GetCurrentValueSQL;
137 Result := 'IMPLEMENT';
142 Gets the next unique key generated by this sequence.
143 @param the next generated unique key.
145 function TZSequence.GetNextValue: Int64;
148 if Assigned(FSequence) then
149 Result := FSequence.GetNextValue
154 function TZSequence.GetNextValueSQL: string;
157 if Assigned(FSequence) then begin
158 Result := FSequence.GetNextValueSQL;
160 Result := 'IMPLEMENT';
164 function TZSequence.GetSequence: IZSequence;
166 if not Assigned(FSequence) then
168 if Assigned(FConnection) and Assigned(FConnection.DbcConnection) then
169 FSequence := FConnection.DbcConnection.CreateSequence(
170 FSequenceName, FBlockSize);
176 Processes component notifications.
177 @param AComponent a changed component object.
178 @param Operation a component operation code.
180 procedure TZSequence.Notification(AComponent: TComponent;
181 Operation: TOperation);
183 inherited Notification(AComponent, Operation);
185 if (Operation = opRemove) and (AComponent = FConnection) then
187 // Modified by cipto 8/2/2007 12:07:57 PM
189 if Assigned(FSequence) then
194 procedure TZSequence.SetBlockSize(const Value: Integer);
198 if Assigned(FSequence) then
199 FSequence.SetBlockSize(FBlockSize);
202 procedure TZSequence.SetConnection(const Value: TZConnection);
204 if FConnection <> Value then
206 if Assigned(FSequence) then
208 FConnection := Value;
209 // Modified by cipto 8/2/2007 11:59:58 AM
210 if Assigned(FConnection) then
211 FConnection.RegisterSequence(self);
216 procedure TZSequence.SetSequenceName(const Value: string);
218 FSequenceName := Value;
220 if Assigned(FSequence) then
221 FSequence.SetName(FSequenceName);