-
Notifications
You must be signed in to change notification settings - Fork 9
/
AbstractDataProvider.qc
1829 lines (1529 loc) · 72.8 KB
/
AbstractDataProvider.qc
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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- mode: qore; indent-tabs-mode: nil -*-
#! Qore AbstractDataProvider class definition
/** AbstractDataProvider.qc Copyright 2019 - 2022 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
%requires(reexport) Logger
#! contains all public definitions in the DataProvider module
public namespace DataProvider {
/** @defgroup db_provider_upsert_results DB Provider Upsert Result Codes
These are the results codes returned with single-record upsert actions
*/
#@{
#! Indicates that the record was inserted
public const UpsertResultInserted = "inserted";
#! Indicates that the record was updated
public const UpsertResultUpdated = "updated";
#! Indicates that the record was verified as already in the target state
public const UpsertResultVerified = "verified";
#! Indicates that the record was left unchanged
public const UpsertResultUnchanged = "unchanged";
#! Indicates that the record was deleted
public const UpsertResultDeleted = "deleted";
#@}
#! Data provider option info
public hashdecl DataProviderOptionInfo {
#! The option value type or types
softlist<AbstractDataProviderType> type;
#! Required flag
bool required = False;
#! The option description
string desc;
}
#! Data provider search operator info
public hashdecl DataProviderSearchOperatorInfo {
#! The option value type or types
softlist<AbstractDataProviderType> type;
#! The search operator display name
string name;
#! The option description
string desc;
}
#! Data provider info
public hashdecl DataProviderInfo {
#! Data provider name
/** @note this is a dynamic attribute; it differs for different data providers of the same type
*/
string name;
#! The name of the provider type
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
string type;
#! Does the data provider support reading
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
bool supports_read = False;
#! Does the data provider support record creation?
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
bool supports_create = False;
#! Does the data provider support record updates?
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
bool supports_update = False;
#! Does the data provider support record upserts (create or update)?
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
bool supports_upsert = False;
#! Does the data provider support record deletion?
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
bool supports_delete = False;
#! Does the data provider support native record searching?
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
bool supports_native_search = False;
#! Does the data provider support native / optimized bulk reads?
/** if this is @ref False and \a supports_read is @ref True, the data provider will still support bulk read
APIs but without any performance improvements for bulk data (simulated bulk reads)
@note this is a static attribute; it is the same for all data providers of the same type
*/
bool supports_bulk_read = False;
#! Does the data provider support native / optimized bulk creation?
/** if this is @ref False and \a supports_creation is @ref True, the data provider will still support bulk write
APIs but without any performance improvements for bulk data (simulated bulk creates)
@note this is a static attribute; it is the same for all data providers of the same type
*/
bool supports_bulk_create = False;
#! Does the data provider support native / optimized bulk upserts?
/** if this is @ref False and \a supports_upsert is @ref True, the data provider will still support bulk upsert
APIs but without any performance improvements for bulk data (simulated bulk upserts)
@note this is a static attribute; it is the same for all data providers of the same type
*/
bool supports_bulk_upsert = False;
#! Does the data provider support the request API?
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
bool supports_request = False;
#! Does the data provider support children?
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
bool supports_children = False;
#! Does the data provider require transaction management?
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
bool transaction_management = False;
#! Does the data provider provide a record?
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
bool has_record = False;
#! Do we require search options to retrieve the record type?
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
bool record_requires_search_options = False;
#! Does the data provider support creating new child providers?
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.0
*/
bool supports_child_create = False;
#! Does the data provider support deleting new child providers?
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.0
*/
bool supports_child_delete = False;
#! Does the data provider support adding new fields?
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.0
*/
bool supports_add_field = False;
#! Does the data provider support updating existing fields?
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.0
*/
bool supports_update_field = False;
#! Does the data provider support deleting fields?
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.0
*/
bool supports_delete_field = False;
#! Does the data provider support a schema?
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.2
*/
bool supports_schema = False;
#! Returns the schema type supported by this data provider
/**
@since DataProvider 2.2
*/
*string schema_type;
#! Constructor options supported by the data provider for the constructor variant taking a hash
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
*hash<string, hash<DataProviderOptionInfo>> constructor_options;
#! Create options supported by the data provider
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
*hash<string, hash<DataProviderOptionInfo>> create_options;
#! Upsert options supported by the data provider
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
*hash<string, hash<DataProviderOptionInfo>> upsert_options;
#! Search options supported by the data provider
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
*hash<string, hash<DataProviderOptionInfo>> search_options;
#! Request options supported by the data provider
/** @note this is a static attribute; it is the same for all data providers of the same type
*/
*hash<string, hash<DataProviderOptionInfo>> request_options;
#! Child creation options supported by the data provider
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.0
*/
*hash<string, hash<DataProviderOptionInfo>> child_create_options;
#! Child deletion options supported by the data provider
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.0
*/
*hash<string, hash<DataProviderOptionInfo>> child_delete_options;
#! Add field options supported by the data provider
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.0
*/
*hash<string, hash<DataProviderOptionInfo>> add_field_options;
#! Update field options supported by the data provider
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.0
*/
*hash<string, hash<DataProviderOptionInfo>> update_field_options;
#! Delete field options supported by the data provider
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.0
*/
*hash<string, hash<DataProviderOptionInfo>> delete_field_options;
#! Search operators supported by the data provider
/** @note this is a static attribute; it is the same for all data providers of the same type
@since DataProvider 2.3
*/
*hash<string, hash<DataProviderSearchOperatorInfo>> search_operators;
#! A hash of mapper key information
/** @note
- this is a static attribute; it is the same for all data providers of the same type
- the \a handler keys are not returned as they are only valid at runtime
*/
hash<string, hash<MapperRuntimeKeyInfo>> mapper_keys = Mapper::MapperKeyInfo;
#! A markdown description of the data provider
/** @note this is a dynamic attribute; it differs for different data providers of the same type
*/
*string desc;
#! A list of child data providers in this data provider
/** @note this is a dynamic attribute; it differs for different data providers of the same type
*/
*list<string> children;
}
#! The AbstractDataProvider class
public class AbstractDataProvider {
public {
#! Generic search operators
/** The following are generic search operators implemented for all data providers that do not provide any
native search functionality
*/
const GenericRecordSearchOperators = {
DP_SEARCH_OP_EQ: <DataProviderSearchOperatorInfo>{
"name": "equals (=)",
"type": AbstractDataProviderType::get(AbstractDataProviderType::anyType),
"desc": "a value for equality comparisons; the type of the value should correspond to the field type",
},
DP_SEARCH_OP_NE: <DataProviderSearchOperatorInfo>{
"name": "not equals (!=)",
"type": AbstractDataProviderType::get(AbstractDataProviderType::anyType),
"desc": "a value for not=equals comparisons; the type of the value should correspond to the field "
"type",
},
DP_SEARCH_OP_LT: <DataProviderSearchOperatorInfo>{
"name": "less than (<)",
"type": AbstractDataProviderType::get(AbstractDataProviderType::anyType),
"desc": "a value for less than comparisons; if the field value is less than the argument, then the "
"operation returns true; the type of the value should correspond to the field type",
},
DP_SEARCH_OP_LE: <DataProviderSearchOperatorInfo>{
"name": "less than or equals (<=)",
"type": AbstractDataProviderType::get(AbstractDataProviderType::anyType),
"desc": "a value for less than or equals comparisons; if the field value is less than or equal to "
"the argument, then the operation returns true; the type of the value should correspond to the "
"field type",
},
DP_SEARCH_OP_GT: <DataProviderSearchOperatorInfo>{
"name": "greater than (>)",
"type": AbstractDataProviderType::get(AbstractDataProviderType::anyType),
"desc": "a value for less than comparisons; if the field value is less than the argument, then the "
"operation returns true; the type of the value should correspond to the field type",
},
DP_SEARCH_OP_GE: <DataProviderSearchOperatorInfo>{
"name": "greater than or equals (>=)",
"type": AbstractDataProviderType::get(AbstractDataProviderType::anyType),
"desc": "a value for greater than or equals comparisons; if the field value is greater than or equal "
"to the argument, then the operation returns true; the type of the value should correspond to "
"the field type",
},
DP_SEARCH_OP_BETWEEN: <DataProviderSearchOperatorInfo>{
"name": "between",
"type": AbstractDataProviderType::get(AutoListType),
"desc": "A list with two elements giving the lower and upper bounds of the field value; the list "
"element value types must be equal to the field's type",
},
DP_SEARCH_OP_IN: <DataProviderSearchOperatorInfo>{
"name": "in",
"type": AbstractDataProviderType::get(AutoListType),
"desc": "A list giving possible values of the field; if the field's value matches any of the values "
"in the list, then the operation returns true; element value types must be equal to the field's "
"type",
},
DP_SEARCH_OP_NOT: <DataProviderSearchOperatorInfo>{
"name": "logical not (!)",
"type": AbstractDataProviderType::get(Reflection::NothingType),
"desc": "This operator takes no arguments and reverses the logical value of the field value or "
"implicit operand",
},
DP_SEARCH_OP_REGEX: <DataProviderSearchOperatorInfo>{
"name": "regular expression match",
"type": (new HashDataType())
.addField(new QoreDataField("pattern", "the regular expression pattern to apply on the field "
"value", StringType))
.addField(new QoreDataField("options", "a bitfield of regular expression options to use; ex: "
"1: case-insensitive, 2: multi line matches, 4: dot matches newlines", IntType)),
"desc": "a value for equality comparisons; the type of the value should correspond to the field type",
},
};
}
private {
#! Logger for logging
Logger logger;
#! flag if callbacks are locked
static bool callbacks_locked = False;
#! static callback the returns a bool if the value needs dynamic resolution
static code cb_value_needs_resolution;
#! static callback for dynamic value resolution
static code cb_resolve_value;
#! Generic record search options; see details below
/** Each record-based data provider should support the following search options:
- \c columns: a list of one or more field names; allows a subset of fields to be output in searches
- \c limit: the maximum number of records to return
- \c offset: the offset number in records to return
*/
const GenericRecordSearchOptions = {
"columns": <DataProviderOptionInfo>{
"type": AbstractDataProviderType::get(AbstractDataProviderType::anyType),
"desc": "allows a subset of fields to be output in searches",
},
"limit": <DataProviderOptionInfo>{
"type": AbstractDataProviderType::get(IntType),
"desc": "the maximum number of records to return",
},
"offset": <DataProviderOptionInfo>{
"type": AbstractDataProviderType::get(IntType),
"desc": "the offset number in records to return",
},
};
}
#! Creates the data provider
constructor() {
}
#! Creates the data provider with the given Logger
constructor(Logger logger) {
self.logger = logger;
}
#! Sets or replaces the logger
setLogger(Logger logger) {
self.logger = logger;
}
#! Returns static provider information as data; no objects are returned
/** @param with_type_info if @ref True then more type information will be returned in the response
@note the \c name and \c children attributes are not returned as they are dynamic attributes
*/
hash<auto> getInfoAsData(*bool with_type_info) {
return DataProvider::getInfoAsData(getInfo(), with_type_info);
}
#! Returns data provider info
hash<DataProviderInfo> getInfo() {
hash<DataProviderInfo> rv({
"name": getName(),
"desc": getDesc(),
});
rv += getStaticInfoImpl() + {
"children": getChildProviderNames(),
};
if (!exists rv.has_record) {
rv.has_record = rv.supports_read;
}
return rv;
}
#! Returns the data provider description
*string getDesc() {
# this method intentionally left blank
}
#! Creates the given record in the data provider
/** @param rec a hash representing a single input record
@param create_options the create options; will be processed by validateCreateOptions()
@return the data written to the data provider
@throw INVALID-OPERATION the data provider does not support record creation
@throw CREATE-RECORD-ERROR the data provider raised an exception in the record creation operation
@throw DUPLICATE-RECORD this exception should be thrown if the provider fails due to an attempt to create a
duplicate record
*/
*hash<auto> createRecord(hash<auto> rec, *hash<auto> create_options) {
checkCreate();
on_error {
if ($1.err != "DUPLICATE-RECORD" && $1.err != "CREATE-RECORD-ERROR") {
rethrow "CREATE-RECORD-ERROR", sprintf("%s: %s", $1.err, $1.desc), $1.arg;
}
}
return createRecordImpl(rec, validateCreateOptions(create_options));
}
#! Upserts the given record in the data provider
/** @param rec a hash representing a single input record
@param upsert_options the upsert options; will be processed by validateUpsertOptions()
@return see @ref db_provider_upsert_results for possible values
@throw INVALID-OPERATION the data provider does not support upsert operations
*/
string upsertRecord(hash<auto> rec, *hash<auto> upsert_options) {
checkUpsert();
return upsertRecordImpl(rec, validateUpsertOptions(upsert_options));
}
#! Returns the first record matching the search options
/** @param where_cond the search criteria; will be processed by processFieldValues()
@param search_options the search options; will be processed by validateSearchOptions()
@throw INVALID-OPERATION the data provider does not support reading
*/
*hash<auto> searchFirstRecord(hash<auto> where_cond, *hash<auto> search_options) {
checkRead();
search_options = validateSearchOptions(search_options);
return searchFirstRecordImpl(processFieldValues(where_cond, search_options), search_options);
}
#! Returns a single record matching the search options
/** @param where_cond the search criteria; will be processed by processFieldValues()
@param search_options the search options; will be processed by validateSearchOptions()
@throw INVALID-OPERATION the data provider does not support reading
@throw MULTIPLE-RECORDS-ERROR multiple records found
*/
*hash<auto> searchSingleRecord(hash<auto> where_cond, *hash<auto> search_options) {
checkRead();
search_options = validateSearchOptions(search_options);
return searchSingleRecordImpl(processFieldValues(where_cond, search_options), search_options);
}
#! Returns an iterator iterating all records
/** @param search_options the search options; will be processed by validateSearchOptions()
@throw INVALID-OPERATION the data provider does not support reading
*/
AbstractDataProviderRecordIterator getRecordIterator(*hash<auto> search_options) {
checkRead();
return searchRecords(NOTHING, validateSearchOptions(search_options));
}
#! Returns an iterator iterating all records with the bulk read API
/** @param block_size the number of records in a read block; must be a positive number
@param search_options the search options; will be processed by validateSearchOptions()
@return a bulk record interface object that will return the records in bulk format
@throw INVALID-BLOCK-SIZE the block size must be a positive number
@throw INVALID-OPERATION the data provider does not support reading
*/
AbstractDataProviderBulkRecordInterface getBulkRecordInterface(int block_size = 1000,
*hash<auto> search_options) {
checkRead();
return searchRecordsBulk(block_size, NOTHING, validateSearchOptions(search_options));
}
#! Returns an iterator for zero or more records matching the search options
/** @param block_size the number of records in a read block; must be a positive number
@param where_cond the search criteria; will be processed by processFieldValues()
@param search_options the search options; will be processed by validateSearchOptions()
@return a bulk record interface object that will return the records in bulk format
@throw INVALID-BLOCK-SIZE the block size must be a positive number
@throw INVALID-OPERATION the data provider does not support reading
*/
AbstractDataProviderBulkRecordInterface searchRecordsBulk(int block_size = 1000, *hash<auto> where_cond,
*hash<auto> search_options) {
checkRead();
if (block_size <= 0) {
throw "INVALID-BLOCK-SIZE", sprintf("block_size %d is invalid; the block size mst be a positive number",
block_size);
}
search_options = validateSearchOptions(search_options);
return searchRecordsBulkImpl(block_size, processFieldValues(where_cond, search_options), search_options);
}
#! Returns an iterator for zero or more records matching the search options
/** @param where_cond the search criteria; will be processed by processFieldValues()
@param search_options the search options; will be processed by validateSearchOptions()
@throw INVALID-OPERATION the data provider does not support reading
*/
AbstractDataProviderRecordIterator searchRecords(*hash<auto> where_cond, *hash<auto> search_options) {
checkRead();
search_options = validateSearchOptions(search_options);
return searchRecordsImpl(processFieldValues(where_cond, search_options), search_options);
}
#! Returns an iterator for zero or more records matching the search options according to an API request
/** @param req the request to serialize and make according to the request type
@param where_cond the search criteria; will be processed by processFieldValues()
@param search_options the search options after processing by validateSearchOptions()
This will execute the request and perform a default search on any record(s) returned
@throw INVALID-OPERATION the data provider does not support reading records or the request / response API
*/
AbstractDataProviderRecordIterator requestSearchRecords(auto req, *hash<auto> where_cond,
*hash<auto> search_options) {
checkRead();
checkRequest();
return requestSearchRecordsImpl(req, where_cond, search_options);
}
#! Updates a single record matching the search options
/** @param set the hash of field data to set; will be processed by processFieldValues()
@param where_cond the search criteria; will be processed by processFieldValues()
@param search_options the search options; will be processed by validateSearchOptions()
@returns @ref True if the record was updated, @ref False if not (no record found)
@throw INVALID-OPERATION the data provider does not support record updating
@throw UPDATE-RECORDS-ERROR error updating records
*/
bool updateSingleRecord(hash<auto> set, hash<auto> where_cond, *hash<auto> search_options) {
checkUpdate();
search_options = validateSearchOptions(search_options);
on_error {
if ($1.err != "DUPLICATE-RECORD" && $1.err != "UPDATE-RECORDS-ERROR") {
rethrow "UPDATE-RECORDS-ERROR", sprintf("%s: %s", $1.err, $1.desc), $1.arg;
}
}
return updateSingleRecordImpl(processFieldValues(set, search_options),
processFieldValues(where_cond, search_options), search_options);
}
#! Updates zero or more records matching the search options
/** @param set the hash of field data to set
@param where_cond a hash for identifying the record(s) to be updated
@param search_options the search options; will be processed by validateSearchOptions()
@return the number of records updated
@throw INVALID-OPERATION the data provider does not support record updating
@throw UPDATE-RECORDS-ERROR error updating records
*/
int updateRecords(hash<auto> set, *hash<auto> where_cond, *hash<auto> search_options) {
checkUpdate();
search_options = validateSearchOptions(search_options);
on_error {
if ($1.err != "DUPLICATE-RECORD" && $1.err != "UPDATE-RECORDS-ERROR") {
rethrow "UPDATE-RECORDS-ERROR", sprintf("%s: %s", $1.err, $1.desc), $1.arg;
}
}
return updateRecordsImpl(processFieldValues(set, search_options),
processFieldValues(where_cond, search_options), search_options);
}
#! Deletes zero or more records
/**
@param where_cond a hash for identifying the record(s) to be deleted
@param search_options the search options; will be processed by validateSearchOptions()
@return the number of records deleted
@throw INVALID-OPERATION the data provider does not support record deletion
@throw DELETE-RECORDS-ERROR error deleting records
*/
int deleteRecords(*hash<auto> where_cond, *hash<auto> search_options) {
checkDelete();
search_options = validateSearchOptions(search_options);
on_error {
if ($1.err != "DELETE-RECORDS-ERROR") {
rethrow "DELETE-RECORDS-ERROR", sprintf("%s: %s", $1.err, $1.desc), $1.arg;
}
}
return deleteRecordsImpl(processFieldValues(where_cond, search_options), search_options);
}
#! Makes a request and returns the response
/** @param req the request to serialize and make according to the request type
@param request_options the request options; will be processed by validateRequestOptions()
@return the response to the request
@throw INVALID-OPERATION the data provider does not support the request API
@throw INVALID-REQUEST the request argument provided do not match the expected request type
*/
auto doRequest(auto req, *hash<auto> request_options) {
checkRequest();
*AbstractDataProviderType request_type = getRequestType();
if (request_type) {
try {
req = request_type.acceptsValue(req);
} catch (hash<ExceptionInfo> ex) {
rethrow "INVALID-REQUEST", sprintf("invalid request argument for request %y: %s: %s", getName(),
ex.err, ex.desc);
}
}
return doRequestImpl(req, validateRequestOptions(request_options));
}
#! Creates a new child data provider and returns it after adding as a child
/** @param name the name of the new child data provider
@param fields the fields for the new child data provider; must have at least one field
@param child_create_options the options for creating the new child data provider
@return the new child data provider
@throw INVALID-OPERATION thrown if the data provider does not support this API
@throw CREATE-CHILD-PROVIDER-ERROR error creating the child provider
@since DataProvider 2.0
*/
AbstractDataProvider createChildProvider(string name, hash<string, AbstractDataField> fields,
*hash<auto> child_create_options) {
checkCreateChild();
child_create_options = validateChildCreateOptions(child_create_options);
if (!fields) {
throw "CREATE-CHILD-PROVIDER-ERROR", "at least one field must be present in the field hash";
}
on_error if ($1.err != "CREATE-CHILD-PROVIDER-ERROR") {
rethrow "CREATE-CHILD-PROVIDER-ERROR", sprintf("%s: %s", $1.err, $1.desc), $1.arg;
}
return createChildProviderImpl(name, fields, child_create_options);
}
#! Deletes a child data provider
/** @param name the name of the new child data provider
@param child_delete_options the options for deleting a child data provider
@throw INVALID-OPERATION thrown if the data provider does not support this API
@throw DELETE-CHILD-PROVIDER-ERROR error creating the child provider
@since DataProvider 2.0
*/
deleteChildProvider(string name, *hash<auto> child_delete_options) {
checkDeleteChild();
child_delete_options = validateChildDeleteOptions(child_delete_options);
on_error if ($1.err != "DELETE-CHILD-PROVIDER-ERROR") {
rethrow "DELETE-CHILD-PROVIDER-ERROR", sprintf("%s: %s", $1.err, $1.desc), $1.arg;
}
return deleteChildProviderImpl(name, child_delete_options);
}
#! Creates a new field
/**
@param field the field to add
@param field_add_options the options for adding the new field
@throw INVALID-OPERATION thrown if the data provider does not support this API
@throw ADD-FIELD-ERROR error adding the field
@since DataProvider 2.0
*/
addField(AbstractDataField field, *hash<auto> field_add_options) {
checkAddField();
field_add_options = validateFieldAddOptions(field_add_options);
on_error if ($1.err != "ADD-FIELD-ERROR") {
rethrow "ADD-FIELD-ERROR", sprintf("%s: %s", $1.err, $1.desc), $1.arg;
}
addFieldImpl(field, field_add_options);
}
#! Updates an existing field
/** @param name the name of the current field to update
@param field the new definition of the field
@param field_update_options the options for adding the new field
@throw INVALID-OPERATION thrown if the data provider does not support this API
@throw UPDATE-FIELD-ERROR error adding the field
@since DataProvider 2.0
*/
updateField(string name, AbstractDataField field, *hash<auto> field_update_options) {
checkUpdateField();
field_update_options = validateFieldUpdateOptions(field_update_options);
on_error if ($1.err != "UPDATE-FIELD-ERROR") {
rethrow "UPDATE-FIELD-ERROR", sprintf("%s: %s", $1.err, $1.desc), $1.arg;
}
return updateFieldImpl(name, field, field_update_options);
}
#! Deletes an existing field
/** @param name the name of the field to delete
@param field_delete_options the options for deleting the new field
@throw INVALID-OPERATION thrown if the data provider does not support this API
@throw DELETE-FIELD-ERROR error adding the field
@since DataProvider 2.0
*/
deleteField(string name, *hash<auto> field_delete_options) {
checkDeleteField();
field_delete_options = validateFieldDeleteOptions(field_delete_options);
on_error if ($1.err != "DELETE-FIELD-ERROR") {
rethrow "DELETE-FIELD-ERROR", sprintf("%s: %s", $1.err, $1.desc), $1.arg;
}
return deleteFieldImpl(name, field_delete_options);
}
#! Returns the schema supporting this data provider
/** @return the schema supporting this data provider
@throw INVALID-OPERATION thrown if the data provider does not support this API
@since DataProvider 2.2
*/
object getSchemaObject() {
checkSchema();
return getSchemaObjectImpl();
}
#! Returns the description of a successful request message, if any
/** @return the request type for this provider
@throw INVALID-OPERATION the data provider does not support the request API
*/
*AbstractDataProviderType getRequestType() {
checkRequest();
return getRequestTypeImpl();
}
#! Returns the description of a response message, if this object represents a response message
/** @return the response type for this response message
@throw INVALID-OPERATION the data provider does not support the request API
*/
*AbstractDataProviderType getResponseType() {
checkRequest();
return getResponseTypeImpl();
}
#! Returns a hash of error responses, if any
/** @return a hash of error responses, if any, keyed by response code or string
@throw INVALID-OPERATION the data provider does not support the request API
*/
*hash<string, AbstractDataProviderType> getErrorResponseTypes() {
checkRequest();
return getErrorResponseTypesImpl();
}
#! Returns the type for the given error code
/** @param error_code the error code for the response; must be a known error code, or an \c UNKNOWN-ERROR-RESPONSE
exception is thrown
@return the type for the given error code
@throw INVALID-OPERATION the data provider does not support the request API
@throw UNKNOWN-ERROR-RESPONSE the error response given is not known
*/
AbstractDataProviderType getErrorResponseType(string error_code) {
checkRequest();
return getErrorResponseTypeImpl(error_code);
}
#! Returns a list of child data provider names, if any
/** @return a list of child data provider names, if any
*/
*list<string> getChildProviderNames() {
return getChildProviderNamesImpl();
}
#! Returns the given child provider or @ref nothing if the given child is unknown
/** @return the given child provider or @ref nothing if the given child is unknown
@throw INVALID-CHILD-PROVIDER unknown child provider
@see getChildProviderEx()
*/
*AbstractDataProvider getChildProvider(string name) {
return getChildProviderImpl(name);
}
#! Returns the given child provider or throws an exception if the given child is unknown
/** @return the given child provider or throws an exception if the given child is unknown
@throw INVALID-CHILD-PROVIDER unknown child provider
@see getChildProvider()
*/
AbstractDataProvider getChildProviderEx(string name) {
*AbstractDataProvider provider = getChildProviderImpl(name);
if (!provider) {
throw "INVALID-CHILD-PROVIDER", sprintf("provider %y is unknown; known children of %y: %y", name,
getName(), getChildProviderNames());
}
return provider;
}
#! Returns the given child provider from a \c "/" separated path string
/** throws an exception with unknown path elements
@param path a string giving a path to the target provider where child elements are separated by \c "/" characters
@return the target child provider; throws an exception if any element in the path is unknown
@throw INVALID-CHILD-PROVIDER unknown child provider
*/
AbstractDataProvider getChildProviderPath(string path) {
AbstractDataProvider provider = self;
map provider = provider.getChildProviderEx($1), path.split("/");
return provider;
}
#! Returns @ref True if the data provider supports transaction management
/** @return @ref True if the data provider supports transaction management, in which case commit() or rollback()
must be called to flush or discard data written to the data provider
*/
bool requiresTransactionManagement() {
return False;
}
#! Begins a transaction with a data provider
/** Has no effect if the data provider does not support transaction management
@see:
- commit()
- rollback()
@since DataProvider 1.2.2
*/
beginTransaction() {
}
#! Commits data written to the data provider
/** Has no effect if the data provider does not support transaction management
@see:
- beginTransaction()
- rollback()
*/
commit() {
}
#! Rolls back data written to the data provider
/** Has no effect if the data provider does not support transaction management
@see:
- beginTransaction()
- commit()
*/
rollback() {
}
#! Returns a bulk insert operation object for the data provider
/** @return a bulk insert operation object for the data provider
@throw INVALID-OPERATION the data provider does not support create operations
*/
AbstractDataProviderBulkOperation getBulkInserter() {
checkCreate();
return new DefaultBulkInserter(self);
}
#! Returns a bulk upsert operation object for the data provider
/** @return a bulk upsert operation object for the data provider
@throw INVALID-OPERATION the data provider does not support upsert operations
*/
AbstractDataProviderBulkOperation getBulkUpserter() {
checkUpsert();
return new DefaultBulkUpserter(self);
}
#! Returns custom data mapper runtime keys
/** @return custom data mapper runtime keys
This base method returns @ref nothing; reimplment in child classes to return a value
*/
*hash<string, hash<MapperRuntimeKeyInfo>> getMapperRuntimeKeys() {
# this method intentionally left empty
}
#! Ensures that the data provider supports read operations
/**
@throw INVALID-OPERATION the data provider does not support read operations
*/
checkRead() {
if (!supportsRead()) {
throw "INVALID-OPERATION", sprintf("data provider %y (type %y) does not support reading records",
getName(), self.className());
}
}
#! Ensures that the data provider supports record creation
/**
@throw INVALID-OPERATION the data provider does not support record creation
*/
checkCreate() {
if (!supportsCreate()) {
throw "INVALID-OPERATION", sprintf("data provider %y (type %y) does not support record creation",
getName(), self.className());
}
}
#! Ensures that the data provider supports record upserts
/**
@throw INVALID-OPERATION the data provider does not support upsert operations
*/
checkUpsert() {
if (!supportsUpsert()) {
throw "INVALID-OPERATION", sprintf("data provider %y (type %y) does not support record upserts",
getName(), self.className());
}
}
#! Ensures that the data provider supports record upserts
/**
@throw INVALID-OPERATION the data provider does not support record updating
*/
checkUpdate() {
if (!supportsUpdate()) {
throw "INVALID-OPERATION", sprintf("data provider %y (type %y) does not support record updating",
getName(), self.className());
}
}
#! Ensures that the data provider supports record deletion
/**
@throw INVALID-OPERATION the data provider does not support record deletion
*/
checkDelete() {
if (!supportsDelete()) {
throw "INVALID-OPERATION", sprintf("data provider %y (type %y) does not support record deletion",
getName(), self.className());
}
}
#! Ensures that the data provider supports the request API
/**