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
| ///////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2015 by Charta Software B.V. //
// All rights reserved //
// //
// Version: 1.7.0.83525 //
// Web site: https://pascal.chartasoftware.com/ //
// //
// This code and information are provided "as is" without warranty of //
// any kind. Dissemination of this information or reproduction of //
// this material is strictly forbidden unless prior written permission //
// is obtained from Charta Software B.V.. //
// //
///////////////////////////////////////////////////////////////////////////
unit SimpleTable;
interface
uses
Boolean,
Collection.List,
DataMethod,
SimpleTable.Column,
Sql.Builder,
Sql.Statement.ResultSet,
Sql.Table,
WebSite.Table.Row.UriProducer;
type
TSimpleTable = class(TObject)
private
FTable: TSqlTable;
FRowUriProducer: TTableRowUriProducer;
procedure SetTable(const Value: TSqlTable);
procedure SetRowUriProducer(const Value: TTableRowUriProducer);
function GetRowDetailsEnabled(): TBoolean;
public
Columns: TList<TSimpleTableColumn>;
UpdateOperations: TUpdateMethods;
InitialUpdateOperations: TUpdateMethods;
InitialFilterEnabled: TBoolean;
UploadEnabled: TBoolean;
DefaultSortColumns: TList<TSqlOrderByExpression>;
OwnsTable: TBoolean;
constructor Create(); virtual;
destructor Destroy(); override;
property Table: TSqlTable read FTable write SetTable;
property RowUriProducer: TTableRowUriProducer read FRowUriProducer write SetRowUriProducer;
property RowDetailsEnabled: TBoolean read GetRowDetailsEnabled;
public
class function New(Table: TSqlTable; const Columns: array of TSimpleTableColumn; UpdateOperations: TUpdateMethods = DataMethods_AllUpdate): TSimpleTable;
class function NewWithSort(Table: TSqlTable; const Columns: array of TSimpleTableColumn; const SortOrder: array of TSqlOrderByExpressionBuilder; UpdateOperations: TUpdateMethods = DataMethods_AllUpdate): TSimpleTable;
class function NewDefault(Table: TSqlTable; UpdateOperations: TUpdateMethods = DataMethods_AllUpdate): TSimpleTable;
class function NewDefaultWithSort(Table: TSqlTable; const SortOrder: array of TSqlOrderByExpressionBuilder; UpdateOperations: TUpdateMethods = DataMethods_AllUpdate): TSimpleTable;
class function NewDefaultWithIdColumn(Table: TSqlTable; UpdateOperations: TUpdateMethods = DataMethods_AllUpdate; IdColumnOptions: TDataMethods = [TDataMethod.Read]): TSimpleTable;
end;
implementation
uses
Integer._32,
Object_.List,
Object_.Reference.Counter,
SimpleTable.RowUriProducer,
Sql.Table.Column;
{ TSimpleTable }
constructor TSimpleTable.Create();
begin
inherited Create();
Columns := TObjectList<TSimpleTableColumn>.Create();
DefaultSortColumns := TObjectList<TSqlOrderByExpression>.Create();
DefaultSortColumns.ElementManager := TReferenceCounter<TSqlOrderByExpression>.Create();
InitialUpdateOperations := [];
RowUriProducer := TSimpleTableRowDetailsUriProducer.Create();
end;
destructor TSimpleTable.Destroy();
begin
Columns.Free();
DefaultSortColumns.Free();
FRowUriProducer.ReleaseReference();
if OwnsTable then
Table.Free();
inherited Destroy();
end;
function TSimpleTable.GetRowDetailsEnabled(): TBoolean;
begin
Result := RowUriProducer is TSimpleTableRowDetailsUriProducer;
end;
class function TSimpleTable.New(Table: TSqlTable; const Columns: array of TSimpleTableColumn; UpdateOperations: TUpdateMethods): TSimpleTable;
var
i: TInteger32;
begin
Result := TSimpleTable.Create();
Result.Table := Table;
Result.UpdateOperations := UpdateOperations;
for i := 0 to High(Columns) do
Result.Columns.Add(Columns[i]);
end;
class function TSimpleTable.NewDefault(Table: TSqlTable; UpdateOperations: TUpdateMethods): TSimpleTable;
var
Column: TSqlTableColumn;
begin
Result := New(Table, [], UpdateOperations);
for Column in Table.Columns do
begin
if Table.DefaultHiddenColumns.Contains(Column) then
Result.Columns.Add(TSimpleTableColumn.Create(Column, []))
else
Result.Columns.Add(TSimpleTableColumn.Create(Column));
end;
end;
class function TSimpleTable.NewDefaultWithIdColumn(Table: TSqlTable; UpdateOperations: TUpdateMethods = DataMethods_AllUpdate; IdColumnOptions: TDataMethods = [TDataMethod.Read]): TSimpleTable;
begin
Result := NewDefault(Table, UpdateOperations);
Result.Columns[0].EnabledMethods := IdColumnOptions;
end;
class function TSimpleTable.NewDefaultWithSort(Table: TSqlTable; const SortOrder: array of TSqlOrderByExpressionBuilder; UpdateOperations: TUpdateMethods): TSimpleTable;
var
i: TInteger32;
begin
Result := TSimpleTable.NewDefault(Table, UpdateOperations);
for i := 0 to High(SortOrder) do
Result.DefaultSortColumns.Add(SortOrder[i].Expression);
end;
class function TSimpleTable.NewWithSort(Table: TSqlTable; const Columns: array of TSimpleTableColumn; const SortOrder: array of TSqlOrderByExpressionBuilder; UpdateOperations: TUpdateMethods): TSimpleTable;
var
i: TInteger32;
begin
Result := New(Table, Columns, UpdateOperations);
for i := 0 to High(SortOrder) do
Result.DefaultSortColumns.Add(SortOrder[i].Expression);
end;
procedure TSimpleTable.SetRowUriProducer(const Value: TTableRowUriProducer);
begin
if Value <> RowUriProducer then
begin
Value.AddReference();
RowUriProducer.ReleaseReference();
FRowUriProducer := Value;
end;
end;
procedure TSimpleTable.SetTable(const Value: TSqlTable);
begin
FTable := Value;
if (Table <> nil) and (Table.PrimaryKey = nil) and RowDetailsEnabled then
RowUriProducer := nil;
// if Table.PrimaryKey = nil then
// raise EException.Create('Cannot create a simple table for a table without a primary key: ' + Table.Identifier);
end;
end.
|