/
DatabaseObjects.cs
982 lines (929 loc) · 36.2 KB
/
DatabaseObjects.cs
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
// _________________________________________________________________________
//
// © Hi-Integrity Systems 2010. All rights reserved.
// www.hisystems.com.au - Toby Wicks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// _________________________________________________________________________
//
using System.Collections;
using System;
using System.Data;
namespace DatabaseObjects
{
/// --------------------------------------------------------------------------------
/// <summary>
/// Represents a collection of database records. Implements IDatabaseObjects and provides
/// the basic plumbing code required for the interface.
/// Attributes can be used to specify the database specific information using
/// class attributes DistinctFieldAttribute, TableAttribute, KeyFieldAttribute, ItemInstanceAttribute,
/// OrderByAttribute, SubsetAttribute and TableJoinAttribute.
/// </summary>
/// --------------------------------------------------------------------------------
public abstract class DatabaseObjects : IDatabaseObjects
{
internal const string DistinctFieldAutoIncrementsObsoleteWarningMessage = "Obsolete and replaced by DistinctFieldAutoAssignment to support both auto increment and automatically assigned globally unique identifiers.";
private Database pobjDatabase;
private DatabaseObject pobjParent;
/// <summary>
/// May optionally be set to the container object that this object is a child of.
/// </summary>
/// <remarks></remarks>
private RootContainer rootContainer;
private DatabaseObjectsUsingAttributesHelper pobjAttributeHelper;
/// --------------------------------------------------------------------------------
/// <summary>
/// Initializes a new DatabaseObjects with it's associated database.
/// </summary>
///
/// <param name="objDatabase">
/// The database that this collection is associated with.
/// </param>
/// --------------------------------------------------------------------------------
protected DatabaseObjects(Database objDatabase)
{
if (objDatabase == null)
throw new ArgumentNullException();
pobjDatabase = objDatabase;
pobjAttributeHelper = new DatabaseObjectsUsingAttributesHelper(this);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Initializes with it the associated root container and database.
/// </summary>
///
/// <param name="rootContainer">
/// The root object that this collection is associated with.
/// </param>
/// --------------------------------------------------------------------------------
protected DatabaseObjects(RootContainer rootContainer)
{
if (rootContainer == null)
throw new ArgumentNullException();
this.rootContainer = rootContainer;
pobjDatabase = rootContainer.Database;
pobjAttributeHelper = new DatabaseObjectsUsingAttributesHelper(this);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Initializes a new DatabaseObjects with it's associated parent object.
/// The Parent property can be used to access the parent variable passed into this constructor.
/// </summary>
///
/// <param name="objParent">
/// The parent object that this collection is associated with.
/// </param>
/// --------------------------------------------------------------------------------
protected DatabaseObjects(DatabaseObject objParent)
{
if (objParent == null)
throw new ArgumentNullException();
pobjDatabase = objParent.ParentDatabase;
pobjParent = objParent;
pobjAttributeHelper = new DatabaseObjectsUsingAttributesHelper(this);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns the parent object that this collection is associated with.
/// This property will return Nothing if the 'New(DatabaseObjects.Database)'
/// constructor is used.
/// </summary>
/// --------------------------------------------------------------------------------
protected internal DatabaseObject Parent
{
get
{
return pobjParent;
}
}
/// <summary>
/// Returns the root container object that this object is a child of.
/// </summary>
/// <remarks>
/// Traverses up the object heirarchy to find the root container class.
/// </remarks>
protected internal TRootContainer RootContainer<TRootContainer>() where TRootContainer : RootContainer
{
if (rootContainer != null)
return (TRootContainer)this.rootContainer;
else if (pobjParent != null)
return pobjParent.RootContainer<TRootContainer>();
else
return null;
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns the distinct value of the parent i.e. Parent.DistinctValue
/// Throws a NullReferenceException if there is no parent.
/// </summary>
/// <exception cref="NullReferenceException">Parent is nothing</exception>
/// --------------------------------------------------------------------------------
protected internal object ParentDistinctValue
{
get
{
return ((IDatabaseObject)this.Parent).DistinctValue;
}
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns the database associated with this collection/database table.
/// </summary>
/// --------------------------------------------------------------------------------
protected internal Database ParentDatabase
{
get
{
return pobjDatabase;
}
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an instance of an object from this collection using a distinct value as
/// specified by DistinctFieldName. If Subset has been implemented then the objDistinctValue
/// need only be unique within the subset specified, not the entire database table.
/// </summary>
///
/// <param name="objDistinctValue">
/// The value that uniquely identifies the object within this collection. This is the value
/// of the field defined by this collection's DistinctFieldName function.
/// </param>
///
/// <returns><see cref="IDatabaseObject" /> (DatabaseObjects.IDatabaseObject)</returns>
///
/// <example> Loads a product using a product ID of 123
/// <code>
/// Dim objProduct As Product = MyBase.Object(123)
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected IDatabaseObject Object(object objDistinctValue)
{
return this.ParentDatabase.Object(this, objDistinctValue);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an instance of an object from this collection using a distinct value as
/// specified by DistinctFieldName. If Subset has been implemented then the objDistinctValue
/// need only be unique within the subset specified, not the entire database table.
/// Returns Nothing/null if the distinct value does not exist in the database.
/// This feature is what differentiates DatabaseObjects.Object() from DatabaseObjects.ObjectIfExists().
/// </summary>
///
/// <param name="objDistinctValue">
/// The value that uniquely identifies the object within this collection. This is the value
/// of the field defined by this collection's DistinctFieldName function.
/// </param>
///
/// <returns><see cref="IDatabaseObject" /> (DatabaseObjects.IDatabaseObject)</returns>
///
/// <example> Loads a product using a product ID of 123
/// <code>
/// Dim objProduct As Product = MyBase.Object(123)
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected IDatabaseObject ObjectIfExists(object objDistinctValue)
{
return this.ParentDatabase.ObjectIfExists(this, objDistinctValue);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns the database fields for an object from the collection using a distinct value
/// (see IDatabaseObjects.DistinctFieldName). If the collection has implemented the
/// IDatabaseObjects.Subset function then the objDistinctValue need only be unique
/// within the collection's subset, not the entire database table.
/// This is typically used to interogate the database fields before loading the
/// object with a call to ObjectFromFieldValues.
/// This function is rarely used and generally the Object function suffices.
/// </summary>
///
/// <param name="objDistinctValue">
/// The value that uniquely identifies the object within the collection. This is the value
/// of the field defined by the collection's IDatabaseObjects.DistinctFieldName function.
/// </param>
///
/// <returns><see cref="IDatabaseObject" /> (DatabaseObjects.IDatabaseObject)</returns>
/// --------------------------------------------------------------------------------
protected SQL.SQLFieldValues ObjectFieldValues(object objDistinctValue)
{
return this.ParentDatabase.ObjectFieldValues(this, objDistinctValue);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns whether an object exists for the specified distinct value in the collection.
/// </summary>
///
/// <param name="objDistinctValue">
/// The value to search for in the collection. This is the value of the field defined
/// by the collection's IDatabaseObjects.DistinctFieldName function.
/// </param>
/// --------------------------------------------------------------------------------
///
protected bool ObjectExistsByDistinctValue(object objDistinctValue)
{
return this.ParentDatabase.ObjectExistsByDistinctValue(this, objDistinctValue);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Extracts the fields to save to the database from the objItem.SaveFields function.
/// The fields are then written to the database using either an SQL INSERT or UPDATE
/// depending on whether the object has already been saved.
/// </summary>
///
/// <param name="objItem">
/// The object to save to the database. The values saved to the database are extracted from the
/// SQLFieldValues object returned from IDatabaseObject.SaveFields.
/// </param>
/// --------------------------------------------------------------------------------
///
protected void ObjectSave(IDatabaseObject objItem)
{
this.ParentDatabase.ObjectSave(this, objItem);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an object using a unique key value.
/// The key must be unique within this collection. If the collection's DatabaseObjects.Subset
/// has been implemented then the key need only be unique within the subset specified, not the
/// entire database table.
/// </summary>
///
/// <param name="objKey">
/// The key that identifies the object with this collection. The key is the value of the field
/// defined by this collection's KeyFieldName.
/// </param>
///
/// <returns><see cref="IDatabaseObject" /> (DatabaseObjects.IDatabaseObject)</returns>
///
/// <example>
/// <code>
/// Default Public ReadOnly Property Item(ByVal strProductCode As String) As Product
/// Get
///
/// Return MyBase.ObjectByKey(strProductCode)
///
/// End Get
/// End Property
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected IDatabaseObject ObjectByKey(object objKey)
{
return this.ParentDatabase.ObjectByKey(this, objKey);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an object using a unique key value.
/// The key must be unique within this collection. If the collection's DatabaseObjects.Subset
/// has been implemented then the key need only be unique within the subset specified, not the
/// entire database table.
/// Returns Nothing/null if the object does exist with the specified key.
/// This feature is what differentiates DatabaseObjects.ObjectByKey() from DatabaseObjects.ObjectByKeyExists().
/// </summary>
///
/// <param name="objKey">
/// The key that identifies the object with this collection. The key is the value of the field
/// defined by this collection's KeyFieldName.
/// </param>
///
/// <returns><see cref="IDatabaseObject" /> (DatabaseObjects.IDatabaseObject)</returns>
///
/// <example>
/// <code>
/// Default Public ReadOnly Property Item(ByVal strProductCode As String) As Product
/// Get
///
/// Return MyBase.ObjectByKey(strProductCode)
///
/// End Get
/// End Property
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected IDatabaseObject ObjectByKeyIfExists(object objKey)
{
return this.ParentDatabase.ObjectByKeyIfExists(this, objKey);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// ObjectByOrdinalFirst returns the first object in the collection respectively
/// filtered and sorted by the collection's Subset and OrderBy values. It differs
/// from ObjectByOrdinal in that it only loads the first record from the database
/// table not the entire table.
/// </summary>
///
/// <returns><see cref="IDatabaseObject" /> (DatabaseObjects.IDatabaseObject)</returns>
///
/// <example>
/// <code>
/// 'Assuming this class is the Suppliers class
///
/// 'Ideal for loading default objects
/// Dim objDefaultSupplier As Supplier = MyBase.ObjectByOrdinalFirst
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected IDatabaseObject ObjectByOrdinalFirst()
{
return this.ParentDatabase.ObjectByOrdinalFirst(this);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns the last object in the collection respectively
/// filtered and sorted by the collection's Subset and OrderBy values. It differs
/// from ObjectByOrdinal in that it only loads the first record from the database
/// table not the entire table.
/// </summary>
///
/// <returns><see cref="IDatabaseObject" /> (DatabaseObjects.IDatabaseObject)</returns>
///
/// <example>
/// <code>
/// 'Assuming this class is the Suppliers class
///
/// 'Ideal for loading default objects
/// Dim objDefaultSupplier As Supplier = MyBase.ObjectByOrdinalFirst
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected IDatabaseObject ObjectByOrdinalLast()
{
return this.ParentDatabase.ObjectByOrdinalLast(this);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Deletes an object's database record. If this collection's Subset has been
/// implemented then the object must exist within the subset, otherwise the object
/// will not be deleted. If the object has not been saved to the database the function
/// will exit without executing an SQL DELETE command. After deleting the database
/// record the object is set to Nothing. The calling function should receive the
/// object ByRef for this to have any affect. Setting the object to Nothing
/// minimises the possibility of the deleted object being used in code after
/// ObjectDelete has been called.
/// </summary>
///
/// <param name="objItem">
/// The object to delete. The calling function should receive this object ByRef
/// as the object is set to Nothing after deletion.
/// </param>
///
/// <example>
/// <code>
/// Public Sub Delete(ByRef objProduct As Product)
///
/// MyBase.ObjectDelete(objProduct)
///
/// End Sub
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected void ObjectDelete(ref IDatabaseObject objItem)
{
this.ParentDatabase.ObjectDelete(this, ref objItem);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns whether the key exists within the collection. If this collection's Subset
/// has been set then only the subset is searched not the entire table.
/// </summary>
///
/// <param name="objKey">
/// The key value to search by.
/// </param>
///
/// <returns><see cref="Boolean" /> (System.Boolean)</returns>
///
/// <example>
/// <code>
/// Public Function Exists(ByVal strProductCode As String) As Boolean
///
/// Return MyBase.ObjectExists(strProductCode)
///
/// End Function
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected bool ObjectExists(object objKey)
{
return this.ParentDatabase.ObjectExists(this, objKey);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Loads an object from the current record of an IDataReader object.
/// </summary>
///
/// <param name="objReader">
/// The data to be copied into a new DatabaseObject object.
/// </param>
///
/// <returns><see cref="IDatabaseObject" /> (DatabaseObjects.IDatabaseObject)</returns>
/// --------------------------------------------------------------------------------
///
protected IDatabaseObject ObjectFromDataReader(IDataReader objReader)
{
return Database.ObjectFromDataReader(this, objReader);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Loads an object from the values contained in an SQLFieldValues object.
/// This function is generally used from within an DatabaseObject.Load function when
/// the TableJoins function has been implemented.
/// </summary>
///
/// <param name="objFieldValues">
/// The data container from which to load a new object.
/// </param>
///
/// <returns><see cref="IDatabaseObject" /> (DatabaseObjects.IDatabaseObject)</returns>
/// --------------------------------------------------------------------------------
///
protected IDatabaseObject ObjectFromFieldValues(SQL.SQLFieldValues objFieldValues)
{
return Database.ObjectFromFieldValues(this, objFieldValues);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an IList object containing the first n of the collection's associated child
/// objects. This function is useful when loading a set of objects for a subset or
/// for use with the IEnumerable interface.
/// </summary>
///
/// <param name="maxRecords">
/// The maximum number of records to return.
/// Zero returns all of the records.
/// </param>
///
/// <returns><see cref="Collections.IList" /> (System.Collections.IList)</returns>
///
/// <example>
/// <code>
/// 'Alternatively, the DatabaseObjectsEnumerable class can be used which
/// 'automatically incorporates an enumerator
/// Private Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
///
/// Return MyBase.ObjectsList(1000).GetEnumerator
///
/// End Function
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected IList ObjectsList(int maxRecords)
{
return this.ParentDatabase.ObjectsList(this, maxRecords);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an IList object containing all of this collection's objects. This
/// function is useful when loading a set of objects for a subset or for use with
/// the IEnumerable interface.
/// </summary>
///
/// <returns><see cref="Collections.IList" /> (System.Collections.IList)</returns>
///
/// <example>
/// <code>
/// 'Alternatively, the DatabaseObjectsEnumerable class can be used which
/// 'automatically incorporates an enumerator
/// Private Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
///
/// Return MyBase.ObjectsList.GetEnumerator
///
/// End Function
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected IList ObjectsList()
{
return this.ParentDatabase.ObjectsList(this);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an array of IDatabaseObject objects contained within this collection.
/// </summary>
/// --------------------------------------------------------------------------------
protected IDatabaseObject[] ObjectsArray()
{
return this.ParentDatabase.ObjectsArray(this);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an IDictionary object. Each key/value pair contains a key and
/// the object associated with the key.
/// </summary>
///
/// <returns><see cref="Collections.IDictionary" /> (System.Collections.IDictionary)</returns>
/// --------------------------------------------------------------------------------
///
protected IDictionary ObjectsDictionary()
{
return this.ParentDatabase.ObjectsDictionary(this);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns an IDictionary object. Each key/value pair contains a distinct
/// value and the object associated with the distinct value.
/// </summary>
///
/// <returns><see cref="Collections.IDictionary" /> (System.Collections.IDictionary)</returns>
/// --------------------------------------------------------------------------------
///
protected IDictionary ObjectsDictionaryByDistinctValue()
{
return this.ParentDatabase.ObjectsDictionaryByDistinctValue(this);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns the number of items in this collection. If this collection's Subset
/// has been implemented then this function returns the number of records within the
/// subset, not the entire table.
/// Also utilises the table joins so that any filters specified on the subset
/// can be used.
/// </summary>
///
/// <returns><see cref="Int32" /> (System.Int32)</returns>
///
/// <example>
/// <code>
/// 'Return the number of items in this collection.
/// Public ReadOnly Property Count() As Integer
/// Get
///
/// Return MyBase.ObjectsCount
///
/// End Get
/// End Property
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected int ObjectsCount()
{
return this.ParentDatabase.ObjectsCount(this);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Deletes all of the objects in this collection. If Subset has been implemented
/// then only the objects within the subset are deleted, not the table's entire
/// contents.
/// </summary>
/// --------------------------------------------------------------------------------
///
protected void ObjectsDeleteAll()
{
this.ParentDatabase.ObjectsDeleteAll(this);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Returns a collection of objects that match the specified search criteria.
/// This function utilises any subsets, ordering or table joins specified in this
/// collection. To add a set of conditions to the objSearchCriteria object with
/// higher precendance use the "Add(SQLConditions)" overloaded as this will wrap
/// the conditions within parentheses.
/// </summary>
///
/// <param name="objSearchCriteria">
/// The criteria to search for within this collection. To add set a of conditions with
/// with higher precendance use the "Add(SQLConditions)" overloaded function as this
/// will wrap the conditions within parentheses.
/// </param>
///
/// <returns><see cref="Collections.IList" /> (System.Collections.IList)</returns>
///
/// <remarks>
/// The following wildcard characters are used when using the LIKE operator (extract
/// from Microsoft Transact-SQL Reference):
///
/// <table width="659" border="1" cellspacing="1" cellpadding="4">
/// <tr>
/// <th width="16%" height="20">Wildcard character</th>
/// <th width="22%">Description</th>
/// <th width="62%">Example</th>
/// </tr>
/// <tr>
/// <td>%</td>
/// <td>Any string of zero or more characters.</td>
/// <td>WHERE title LIKE '%computer%' finds all book titles with the word
/// 'computer' anywhere in the book title.</td>
/// </tr>
/// <tr>
/// <td>_ (underscore)</td>
/// <td>Any single character.</td>
/// <td>WHERE au_fname LIKE '_ean' finds all four-letter first names that end
/// with ean (Dean, Sean, and so on).</td>
/// </tr>
/// </table>
/// </remarks>
///
/// <example>
/// <code>
/// Public Function Search(ByVal objSearchCriteria As Object, ByVal eType As SearchType) As IList
///
/// Dim objConditions As SQL.SQLConditions = New SQL.SQLConditions
///
/// Select Case eType
/// Case SearchType.DescriptionPrefix
/// objConditions.Add("ProductName", SQL.ComparisonOperator.Like, objSearchCriteria & "%")
/// Case SearchType.Description
/// objConditions.Add("ProductName", SQL.ComparisonOperator.Like, "%" & objSearchCriteria & "%")
/// End Select
///
/// Return MyBase.ObjectsSearch(objConditions)
///
/// End Function
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
///
protected IList ObjectsSearch(SQL.SQLConditions objSearchCriteria)
{
return this.ParentDatabase.ObjectsSearch(this, objSearchCriteria);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Should return whether the Distinct field as specified in the
/// associated collection's DatabaseObject.DistinctField is an identity field
/// (Autonumber in Microsoft Access) or is a unique identifier field.
/// If set to either value then the IDatabaseObject.DistinctValue value is
/// automatically set when a new object is saved.
/// </summary>
///
/// <example>
/// <code>
/// Protected Overrides Function DistinctFieldAutoAssignment() As SQL.FieldValueAutoAssignmentType
///
/// Return SQL.FieldValueAutoAssignmentType.AutoIncrement
///
/// End Function
/// </code>
/// </example>
protected virtual SQL.FieldValueAutoAssignmentType DistinctFieldAutoAssignment()
{
return pobjAttributeHelper.DistinctFieldAutoAssignment;
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Should return whether the Distinct field as specified in the
/// associated collection's DatabaseObject.DistinctField is an identity field
/// (Autonumber in Microsoft Access). If set to true, then the
/// DatabaseObject.DistinctValue value is set when a new object is saved.
/// </summary>
///
/// <example>
/// <code>
/// Protected Overrides Function DistinctFieldAutoIncrements() As Boolean
///
/// Return True
///
/// End Function
/// </code>
/// </example>
/// --------------------------------------------------------------------------------
[Obsolete(DatabaseObjects.DistinctFieldAutoIncrementsObsoleteWarningMessage)]
protected virtual bool DistinctFieldAutoIncrements()
{
//Indicates to defer logic to the DistinctFieldAutoAssignment function as this function is obsolete.
return false;
}
/// <summary>
/// Should return the field name that uniquely identifies each object
/// within the collection. Typically, this is the field name of an identity or auto
/// increment field. If the DatabaseObjects.SubSet function has been implemented
/// then the DistinctFieldName need only be unique within the subset not the
/// entire table. The DistinctFieldName and KeyFieldName can be identical. This
/// function should almost always be implemented.
/// </summary>
///
/// <example>
/// <code>
/// Protected Overrides Function DistinctFieldName() As String
///
/// Return "ProductID"
///
/// End Function
/// </code>
/// </example>
protected virtual string DistinctFieldName()
{
return pobjAttributeHelper.DistinctFieldName;
}
/// <summary>
/// This property should return the field name that uniquely identifies each object
/// within the collection. As opposed to the ordinal/index position, the key field
/// provides another method of accessing a particular object within the collection.
/// The key field must be unique within the collection. If the DatabaseObjects.Subset
/// function has been implemented then the key field only needs to be unique within
/// the specified subset, not the entire table. Implementing this function is optional.
/// </summary>
///
/// <example>
/// <code>
/// Protected Overrides Function KeyFieldName() As String
///
/// Return "ProductCode"
///
/// End Function
/// </code>
/// </example>
protected virtual string KeyFieldName()
{
return pobjAttributeHelper.KeyFieldName;
}
/// <summary>
/// Should return an SQLSelectOrderByFields object containing the list
/// of fields the collection will be sorted by. Just as with an SQL statement, the
/// order of the fields added to the collection indicates the group sorting. If
/// DatabaseObjects.TableJoins has been implemented then fields from the adjoining
/// table or tables can be utilized. The sort order is used by the ObjectByOrdinal,
/// ObjectByOrdinalFirst and ObjectsSearch functions.
/// Should return Nothing if no ordering is required.
/// Implementing this function is optional.
/// </summary>
///
/// <example>
/// <code>
/// Protected Overrides Function OrderBy() As SQL.SQLSelectOrderByFields
///
/// OrderBy = New SQL.SQLSelectOrderByFields
/// OrderBy.Add("ProductCode", SQL.OrderBy.Ascending)
///
/// End Function
/// </code>
/// </example>
protected virtual SQL.SQLSelectOrderByFields OrderBy()
{
return pobjAttributeHelper.OrderBy;
}
/// <summary>
/// Should return the conditions that define the collection's subset.
/// If the collection should include the entire table then this function should return Nothing.
/// Implementing this function is optional.
/// </summary>
///
/// <example>
/// <code>
/// Protected Overrides Function Subset() As SQL.SQLConditions
///
/// Dim objConditions As New SQL.SQLConditions
///
/// 'Only include products that are in group ID 1234
/// objConditions.Add("GroupID", SQL.ComparisonOperator.EqualTo, 1234)
///
/// Return objConditions
///
/// End Function
/// </code>
/// </example>
protected virtual SQL.SQLConditions Subset()
{
return pobjAttributeHelper.Subset;
}
/// <summary>
/// Should return an SQLSelectTableJoins object containing the table
/// or tables to be joined to the primary table. This function is useful in
/// optimising database loading speeds by allowing multiple tables to be joined into
/// one data set. The resultant data set can then be used to load
/// objects from the associated tables avoiding subsequent SQL calls. For a complete
/// example, see the demonstration program.
/// Should return Nothing if no table joins are required.
/// Implementing this function is optional.
/// </summary>
protected virtual SQL.SQLSelectTableJoins TableJoins(SQL.SQLSelectTable objPrimaryTable, SQL.SQLSelectTables objTables)
{
return pobjAttributeHelper.TableJoins(objPrimaryTable, objTables);
}
/// --------------------------------------------------------------------------------
/// <summary>
/// Should return the name of the table associated with this collection.
/// This function should almost always be implemented.
/// </summary>
///
/// <example>
/// <code>
/// Protected Overrides Function TableName() As String
///
/// Return "Products"
///
/// End Function
/// </code>
/// </example>
protected virtual string TableName()
{
return pobjAttributeHelper.TableName;
}
/// <summary>
/// Should return an instance of the class that is associated with this
/// collection of objects. The associated class must implement the IDatabaseObject
/// interface. Typically, a DatabaseObject (implements IDatabaseObject) instance is
/// returned from this function.
/// </summary>
///
/// <example>
/// <code>
/// Protected Overrides Function ItemInstance() As IDatabaseObject
///
/// Return New Product
///
/// End Function
/// </code>
/// </example>
protected virtual IDatabaseObject ItemInstance()
{
return pobjAttributeHelper.ItemInstance();
}
/// <summary>
/// Private implementation of interface for protected method.
/// Onforwards call to protected method.
/// </summary>
IDatabaseObject IDatabaseObjects.ItemInstance()
{
return ItemInstance();
}
/// <summary>
/// Private implementation of interface for protected method.
/// Onforwards call to protected method.
/// </summary>
SQL.SQLConditions IDatabaseObjects.Subset()
{
return Subset();
}
/// <summary>
/// Private implementation of interface for protected method.
/// Onforwards call to protected method.
/// </summary>
string IDatabaseObjects.TableName()
{
return TableName();
}
/// <summary>
/// Private implementation of interface for protected method.
/// Onforwards call to protected method.
/// </summary>
string IDatabaseObjects.KeyFieldName()
{
return KeyFieldName();
}
/// <summary>
/// Private implementation of interface for protected method.
/// Onforwards call to protected method.
/// </summary>
string IDatabaseObjects.DistinctFieldName()
{
return DistinctFieldName();
}
/// <summary>
/// Private implementation of interface for protected method.
/// Onforwards call to protected method.
/// </summary>
SQL.FieldValueAutoAssignmentType IDatabaseObjects.DistinctFieldAutoAssignment()
{
return DistinctFieldAutoAssignment();
}
/// <summary>
/// Private implementation of interface for protected method.
/// Onforwards call to protected method.
/// </summary>
bool IDatabaseObjects.DistinctFieldAutoIncrements()
{
#pragma warning disable 0618
return DistinctFieldAutoIncrements();
#pragma warning restore 0618
}
/// <summary>
/// Private implementation of interface for protected method.
/// Onforwards call to protected method.
/// </summary>
SQL.SQLSelectOrderByFields IDatabaseObjects.OrderBy()
{
return OrderBy();
}
/// <summary>
/// Private implementation of interface for protected method.
/// Onforwards call to protected method.
/// </summary>
SQL.SQLSelectTableJoins IDatabaseObjects.TableJoins(SQL.SQLSelectTable objPrimaryTable, SQL.SQLSelectTables objTables)
{
return TableJoins(objPrimaryTable, objTables);
}
}
}