/
DataServer.prg
501 lines (348 loc) · 12.9 KB
/
DataServer.prg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
//
// Copyright (c) XSharp B.V. All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
//
[XSharp.Internal.TypesChanged];
ABSTRACT CLASS DataServer
PROTECT oHyperLabel AS HyperLabel
PROTECT oHLStatus AS HyperLabel
PROTECT wFieldCount AS DWORD
PROTECT aDataFields AS ARRAY
PROTECT aClients AS ARRAY
PROTECT nClients AS DWORD
PROTECT nCCMode AS DWORD
PROTECT nLastLock AS LONG
/// <include file="System.xml" path="doc/DataServer.ctor/*" />
CONSTRUCTOR( )
SELF:aClients := { }
SELF:aDataFields := {}
RETURN
/// <exclude />
METHOD __ClearLocks( ) AS VOID STRICT
SWITCH nCCMode
CASE ccStable
SELF:UnLock( nLastLock )
CASE ccRepeatable
SELF:UnLock( )
CASE ccFile
SELF:UnLock( )
END SWITCH
RETURN
/// <exclude />
METHOD __SetupLocks( ) AS VOID STRICT
nLastLock := 0
SWITCH nCCMode
CASE ccNone
CASE ccOptimistic
//nothing to do
NOP
CASE ccStable
CASE ccRepeatable
nLastLock := SELF:RecNo
// Do not free locks in case user has other locks
IF ! SELF:RLock( nLastLock )
nLastLock := 0
oHLStatus := SELF:Status
ENDIF
CASE ccFile
IF ! SELF:FLock( )
oHLStatus := SELF:Status
ENDIF
OTHERWISE
BREAK DbError{ SELF, #ConcurrencyControl, EG_ARG, ;
__CavoStr(__CAVOSTR_DBFCLASS_BADCONCURRENCYASSIGN), nCCMode, "nCCMode" }
END SWITCH
RETURN
/// <include file="System.xml" path="doc/DataServer.Append/*" />
METHOD Append( lReleaseLocks AS LOGIC) AS LOGIC
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.AsString/*" />
METHOD AsString( ) AS STRING STRICT
RETURN oHyperLabel:AsString( )
/// <include file="System.xml" path="doc/DataServer.BoF/*" />
ACCESS BoF AS LOGIC
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.Clients/*" />
ACCESS Clients AS ARRAY
RETURN SELF:aClients
/// <include file="System.xml" path="doc/DataServer.Clients/*" />
ASSIGN Clients(aNewClients AS ARRAY)
SELF:aClients := aNewClients
SELF:nClients := ALen(SELF:aClients)
RETURN
/// <include file="System.xml" path="doc/DataServer.Close/*" />
METHOD Close( ) AS LOGIC STRICT
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.Commit/*" />
METHOD Commit( ) AS LOGIC STRICT
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.ConcurrencyControl/*" />
ACCESS ConcurrencyControl( ) AS USUAL
RETURN SELF:nCCMode
/// <include file="System.xml" path="doc/DataServer.ConcurrencyControl/*" />
ASSIGN ConcurrencyControl( nMode AS USUAL)
LOCAL newMode := nMode AS USUAL
IF UsualType( newMode ) == STRING
newMode := String2Symbol( nMode )
ENDIF
IF UsualType( newMode ) == SYMBOL
SWITCH newMode:ToString()
CASE "CCNONE"
newMode := ccNone
CASE "CCOPTIMISTIC"
newMode := ccOptimistic
CASE "CCSTABLE"
newMode := ccStable
CASE "CCREPEATABLE"
newMode := ccRepeatable
CASE "CCFILE"
newMode := ccFile
OTHERWISE
BREAK DbError{ SELF, #ConcurrencyControl, EG_ARG, ;
__CavoStr( __CAVOSTR_DBFCLASS_BADCONCURRENCYASSIGN ), nMode, "nMode" }
END SWITCH
ENDIF
IF IsNumeric( newMode ) .AND. ( newMode != SELF:nCCMode )
SELF:__ClearLocks( )
SELF:nCCMode := newMode
SELF:__SetupLocks( )
ENDIF
RETURN
/// <include file="System.xml" path="doc/DataServer.DataField/*" />
METHOD DataField( nFieldPosition AS USUAL) AS DataField
LOCAL nPos := SELF:FieldPos(nFieldPosition) AS DWORD
IF nPos > 0
RETURN aDataFields[ nPos ]
ENDIF
RETURN NULL_OBJECT
/// <include file="System.xml" path="doc/DataServer.DBStruct/*" />
ACCESS DBStruct AS ARRAY
LOCAL aStruct AS ARRAY
LOCAL oDF AS DataField
LOCAL w AS DWORD
aStruct := ArrayNew( wFieldCount )
FOR w := 1 UPTO wFieldCount
oDF := aDataFields[ w ]
VAR oFS := oDF:FieldSpec
aStruct[ w ] := { oDF:Name, oFS:UsualType, oFS:Length, oFS:Decimals }
NEXT
RETURN aStruct
/// <include file="System.xml" path="doc/DataServer.Delete/*" />
METHOD Delete( ) AS LOGIC CLIPPER
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.EoF/*" />
ACCESS EoF AS LOGIC
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.FCount/*" />
ACCESS FCount AS DWORD
RETURN wFieldCount
/// <include file="System.xml" path="doc/DataServer.FieldGet/*" />
METHOD FieldGet( nFieldPosition AS USUAL) AS USUAL
RETURN NIL
/// <include file="System.xml" path="doc/DataServer.FieldGetFormatted/*" />
METHOD FieldGetFormatted( nFieldPosition AS USUAL) AS USUAL
RETURN NIL
/// <include file="System.xml" path="doc/DataServer.FieldHyperLabel/*" />
METHOD FieldHyperLabel( nFieldPosition AS USUAL) AS HyperLabel
LOCAL nPos := SELF:FieldPos(nFieldPosition) AS DWORD
IF nPos > 0
RETURN SELF:DataField(nPos):HyperLabel
ENDIF
RETURN NULL_OBJECT
/// <include file="System.xml" path="doc/DataServer.FieldName/*" />
METHOD FieldName( nFieldPosition AS USUAL ) AS STRING
LOCAL nPos := SELF:FieldPos(nFieldPosition) AS DWORD
IF nPos > 0
RETURN SELF:DataField(nPos):HyperLabel:Name
ENDIF
RETURN NULL_STRING
/// <include file="System.xml" path="doc/DataServer.FieldPos/*" />
METHOD FieldPos( nFieldPosition AS USUAL) AS DWORD
RETURN 0
/// <include file="System.xml" path="doc/DataServer.FieldPut/*" />
METHOD FieldPut( nFieldPosition AS USUAL, uValue AS USUAL) AS USUAL
RETURN NIL
/// <include file="System.xml" path="doc/DataServer.FieldSpec/*" />
METHOD FieldSpec( nFieldPosition AS USUAL) AS FieldSpec
LOCAL nPos := SELF:FieldPos(nFieldPosition) AS DWORD
IF nPos > 0
RETURN SELF:DataField(nPos):FieldSpec
ENDIF
RETURN NULL_OBJECT
/// <include file="System.xml" path="doc/DataServer.FieldStatus/*" />
METHOD FieldStatus( nFieldPosition AS USUAL) AS HyperLabel
LOCAL nPos := SELF:FieldPos(nFieldPosition) AS DWORD
IF nPos > 0
RETURN SELF:DataField(nPos):FieldSpec:Status
ENDIF
RETURN NULL_OBJECT
/// <include file="System.xml" path="doc/DataServer.FieldSym/*" />
METHOD FieldSym( nFieldPosition AS USUAL ) AS SYMBOL
LOCAL nPos := SELF:FieldPos(nFieldPosition) AS DWORD
IF nPos > 0
RETURN SELF:DataField(nPos):HyperLabel:NameSym
ENDIF
RETURN NULL_SYMBOL
/// <include file="System.xml" path="doc/DataServer.FieldValidate/*" />
METHOD FieldValidate( nFieldPosition AS USUAL, uValue AS USUAL) AS LOGIC
LOCAL nPos := SELF:FieldPos(nFieldPosition) AS DWORD
IF nPos > 0
RETURN SELF:DataField(nPos):FieldSpec:Validate(uValue)
ENDIF
RETURN TRUE
/// <include file="System.xml" path="doc/DataServer.FLOCK/*" />
METHOD FLock( ) AS LOGIC STRICT
RETURN FALSE
/// <include file="Rdd.xml" path="doc/DbServer.GetLookupTable/*" />
abstract METHOD GetLookupTable( nMaxRows , uField1 , uField2 , uSearchValue ) AS ARRAY CLIPPER
/// <include file="System.xml" path="doc/DataServer.GoBottom/*" />
METHOD GoBottom( ) AS LOGIC STRICT
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.GoTo/*" />
METHOD GoTo( nPosition AS LONG ) AS LOGIC
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.GoTop/*" />
METHOD GoTop( ) AS LOGIC STRICT
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.HLStatus/*" />
ACCESS HLStatus AS HyperLabel
// This always returns the status, regardless of the error flag
RETURN SELF:oHLStatus
/// <include file="System.xml" path="doc/DataServer.HyperLabel/*" />
ACCESS HyperLabel AS HyperLabel
RETURN oHyperLabel
/// <include file="System.xml" path="doc/DataServer.HyperLabel/*" />
ASSIGN HyperLabel( oHL AS HyperLabel)
oHyperLabel := oHL
RETURN
/// <include file="System.xml" path="doc/DataServer.RecCount/*" />
ACCESS LastRec AS LONG
RETURN 0
method LockCurrentRecord( ) as logic strict
return self:RLock(self:RecNo)
/// <include file="System.xml" path="doc/DataServer.Name/*" />
ACCESS Name AS STRING
IF SELF:oHyperLabel != NULL_OBJECT
RETURN oHyperLabel:Name
ENDIF
RETURN NULL_STRING
/// <include file="System.xml" path="doc/DataServer.NameSym/*" />
ACCESS NameSym as symbol
IF oHyperLabel != NULL_OBJECT
RETURN oHyperLabel:NameSym
ENDIF
RETURN NULL_STRING
/// <include file="System.xml" path="doc/DataServer.NoIVarGet/*" />
METHOD NoIVarGet( symFieldName AS USUAL) AS USUAL
RETURN SELF:FieldGet( symFieldName )
/// <include file="System.xml" path="doc/DataServer.NoIVarPut/*" />
METHOD NoIVarPut( symFieldName AS USUAL, uValue AS USUAL) AS USUAL
SELF:FieldPut( symFieldName, uValue )
SELF:Notify( NOTIFYFIELDCHANGE, symFieldName )
RETURN uValue
/// <include file="System.xml" path="doc/DataServer.Notify/*" />
METHOD Notify( kNotification AS LONG, uDescription := NIL AS USUAL) AS USUAL
FOREACH oClient AS OBJECT IN AClone(aClients)
Send(oClient, #Notify, kNotification, uDescription )
NEXT
RETURN SELF
/// <include file="System.xml" path="doc/DataServer.PostInit/*" />
METHOD PostInit( ) AS USUAL CLIPPER
RETURN SELF
/// <include file="System.xml" path="doc/DataServer.PreInit/*" />
METHOD PreInit( ) AS USUAL CLIPPER
RETURN SELF
/// <include file="System.xml" path="doc/DataServer.RecCount/*" />
ACCESS RecCount AS LONG
RETURN 0
/// <include file="System.xml" path="doc/DataServer.RecNo/*" />
ACCESS RecNo AS LONG
RETURN 0L
/// <include file="System.xml" path="doc/DataServer.RecNo/*" />
ASSIGN RecNo( lRecNo AS LONG)
RETURN
/// <include file="System.xml" path="doc/DataServer.RegisterClient/*" />
METHOD RegisterClient( oForm AS OBJECT) AS LOGIC
IF AScan( aClients, oForm ) # 0
RETURN FALSE
ENDIF
AAdd( aClients, oForm )
nClients := ALen( aClients )
RETURN TRUE
/// <include file="System.xml" path="doc/DataServer.ResetNotification/*" />
METHOD ResetNotification( ) AS LONG STRICT
RETURN 0
/// <include file="System.xml" path="doc/DataServer.RLOCK/*" />
METHOD RLock( nRecord AS LONG ) AS LOGIC
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.RLockVerify/*" />
METHOD RLockVerify( ) AS LOGIC STRICT
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.Rollback/*" />
METHOD Rollback( ) AS LOGIC STRICT
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.Seek/*" />
METHOD Seek( ) AS LOGIC CLIPPER
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.SetDataField/*" />
METHOD SetDataField( nFieldPosition AS DWORD, oDataField AS DataField ) AS LOGIC
IF aDataFields == NULL
BREAK DbError{ SELF, #SetDataField, EG_SEQUENCE, ;
__CavoStr( __CAVOSTR_DBFCLASS_NODATAFIELDSEXIST ) }
ELSEIF nFieldPosition < 1 .OR. nFieldPosition > ALen(aDataFields)
BREAK DbError{ SELF, #SetDataField, EG_ARG, ;
__CavoStr(__CAVOSTR_DBFCLASS_BADFIELDPOSITION), nFieldPosition, "nFieldPosition" }
ELSE
LOCAL oExisting := aDataFields[ nFieldPosition ] AS DataField
IF oExisting == NULL
aDataFields[ nFieldPosition ] := oDataField
RETURN TRUE
ELSEIF oDataField:Name == oExisting:Name .AND. ;
oDataField:FieldSpec:UsualType == oExisting:FieldSpec:UsualType .AND. ;
oDataField:FieldSpec:Length == oExisting:FieldSpec:Length .AND. ;
oDataField:FieldSpec:Decimals == oExisting:FieldSpec:Decimals
aDataFields[ nFieldPosition ] := oDataField
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDIF
/// <include file="System.xml" path="doc/DataServer.Skip/*" />
METHOD Skip( nRelativePosition := 1 AS LONG) AS LOGIC
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.Status/*" />
ACCESS Status AS HyperLabel
// Usual because there may be a field Status as well
RETURN oHLStatus
/// <include file="System.xml" path="doc/DataServer.Status/*" />
ASSIGN Status(oHl AS HyperLabel)
// Usual because there may be a field Status as well
IF IsInstanceOfUsual(oHl, #HyperLabel)
SELF:oHLStatus := oHl
ENDIF
RETURN
/// <include file="System.xml" path="doc/DataServer.SuspendNotification/*" />
METHOD SuspendNotification( ) AS LONG STRICT
RETURN 0
/// <include file="System.xml" path="doc/DataServer.UnLock/*" />
METHOD UnLock(nRecno := 0 AS LONG) AS LOGIC
RETURN FALSE
/// <include file="System.xml" path="doc/DataServer.UnRegisterClient/*" />
METHOD UnRegisterClient( oClient AS OBJECT, lAllowClose := TRUE AS LOGIC) AS LOGIC
LOCAL w AS DWORD
IF ( w := AScan( aClients, oClient ) ) = 0
RETURN FALSE
ELSE
ADel( aClients, w )
nClients := ALen( aClients ) -1
ASize( aClients, nClients )
IF lAllowClose .AND. nClients = 0
SELF:Close( )
ENDIF
RETURN TRUE
ENDIF
/// <include file="System.xml" path="doc/DataServer.Update/*" />
METHOD Update( ) AS LOGIC CLIPPER
RETURN FALSE
END CLASS