-
Notifications
You must be signed in to change notification settings - Fork 2
/
IFastDaoReader.cs
237 lines (217 loc) · 14.5 KB
/
IFastDaoReader.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
// Copyright (c) 2004-2010 Azavea, Inc.
//
// 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.
using System.Collections.Generic;
using Azavea.Open.DAO.Criteria;
using Azavea.Open.DAO.Criteria.Grouping;
using Azavea.Open.DAO.Criteria.Joins;
namespace Azavea.Open.DAO
{
/// <summary>
/// This interface defines the "query" methods of FastDAO.
/// </summary>
/// <typeparam name="T">The type of object that can be written.</typeparam>
public interface IFastDaoReader<T> : IFastDaoBase<T> where T : class, new()
{
/// <summary>
/// Returns all objects of the given type.
/// </summary>
/// <returns>A list of objects, or an empty list (not null).</returns>
IList<T> Get();
/// <summary>
/// Returns all objects of the given type.
/// </summary>
/// <param name="transaction">The transaction to do this as part of. May be null.</param>
/// <returns>A list of objects, or an empty list (not null).</returns>
IList<T> Get(ITransaction transaction);
/// <summary>
/// Queries for objects where the property matches the given value.
/// </summary>
/// <param name="propertyName">Property or Field on the object you want to match a value.</param>
/// <param name="propertyValue">Value that the Property or Field should have.</param>
/// <returns>All objects that match the criteria, or an empty list (not null).</returns>
IList<T> Get(string propertyName, object propertyValue);
/// <summary>
/// Queries for objects where the property matches the given value.
/// </summary>
/// <param name="transaction">The transaction to do this as part of. May be null.</param>
/// <param name="propertyName">Property or Field on the object you want to match a value.</param>
/// <param name="propertyValue">Value that the Property or Field should have.</param>
/// <returns>All objects that match the criteria, or an empty list (not null).</returns>
IList<T> Get(ITransaction transaction, string propertyName, object propertyValue);
/// <summary>
/// Queries and returns objects of the specified type matching the criteria.
/// </summary>
/// <param name="crit">The criteria that you wish the objects to match. You can also
/// specify a start/limit, ordering, etc.</param>
/// <returns>A list of objects, or an empty list (not null).</returns>
IList<T> Get(DaoCriteria crit);
/// <summary>
/// Queries and returns objects of the specified type matching the criteria.
/// </summary>
/// <param name="transaction">The transaction to do this as part of. May be null.</param>
/// <param name="crit">The criteria that you wish the objects to match. You can also
/// specify a start/limit, ordering, etc.</param>
/// <returns>A list of objects, or an empty list (not null).</returns>
IList<T> Get(ITransaction transaction, DaoCriteria crit);
/// <summary>
/// Performs a join, or the nearest possible equivilent depending on the data sources
/// involved, and returns the results. If you aren't familiar with joins, do some reading
/// online. This should behave like a "normal" database SQL join on all data sources.
///
/// When "joining" DAOs that are operating on different data sources, or data sources
/// with no inherent join support (flat files for example), joins will be performed
/// using the "PseudoJoiner" class, see that class for more details.
/// </summary>
/// <param name="crit">An object describing how to join the two DAOs. Includes any
/// criteria that apply to the right or left DAO.</param>
/// <param name="rightDao">The other DAO we are joining against.</param>
/// <typeparam name="R">The type of object returned by the other DAO.</typeparam>
/// <returns>A list of JoinResults, containing the matching objects from each DAO. This is similar
/// to the way that </returns>
List<JoinResult<T, R>> Get<R>(DaoJoinCriteria crit, IFastDaoReader<R> rightDao) where R : class, new();
/// <summary>
/// Performs a join, or the nearest possible equivilent depending on the data sources
/// involved, and returns the results. If you aren't familiar with joins, do some reading
/// online. This should behave like a "normal" database SQL join on all data sources.
///
/// When "joining" DAOs that are operating on different data sources, or data sources
/// with no inherent join support (flat files for example), joins will be performed
/// using the "PseudoJoiner" class, see that class for more details.
/// </summary>
/// <param name="transaction">The transaction to do this as part of. May be null.</param>
/// <param name="crit">An object describing how to join the two DAOs. Includes any
/// criteria that apply to the right or left DAO.</param>
/// <param name="rightDao">The other DAO we are joining against.</param>
/// <typeparam name="R">The type of object returned by the other DAO.</typeparam>
/// <returns>A list of JoinResults, containing the matching objects from each DAO. This is similar
/// to the way that </returns>
List<JoinResult<T, R>> Get<R>(ITransaction transaction, DaoJoinCriteria crit, IFastDaoReader<R> rightDao) where R : class, new();
/// <summary>
/// Returns the number of objects of the specified type matching the given criteria.
/// </summary>
/// <param name="crit">The criteria that you wish the objects to match. Start/limit and order are ignored.</param>
/// <returns>The number of objects that match the criteria.</returns>
int GetCount(DaoCriteria crit);
/// <summary>
/// Returns the number of objects of the specified type matching the given criteria.
/// </summary>
/// <param name="transaction">The transaction to do this as part of. May be null.</param>
/// <param name="crit">The criteria that you wish the objects to match. Start/limit and order are ignored.</param>
/// <returns>The number of objects that match the criteria.</returns>
int GetCount(ITransaction transaction, DaoCriteria crit);
/// <summary>
/// Returns the number of objects of the specified type matching the given criteria,
/// aggregated by the given grouping expressions. This matches "GROUP BY" behavior
/// in SQL.
/// </summary>
/// <param name="crit">The criteria that you wish the objects to match. Start/limit and order are ignored.</param>
/// <param name="groupExpressions">The fields/expressions to aggregate on when counting.</param>
/// <returns>The number of objects that match the criteria, plus the values of those objects
/// for the fields that were aggregated on.</returns>
List<GroupCountResult> GetCount(DaoCriteria crit, ICollection<AbstractGroupExpression> groupExpressions);
/// <summary>
/// Returns the number of objects of the specified type matching the given criteria,
/// aggregated by the given grouping expressions. This matches "GROUP BY" behavior
/// in SQL.
/// </summary>
/// <param name="transaction">The transaction to do this as part of. May be null.</param>
/// <param name="crit">The criteria that you wish the objects to match. Start/limit and order are ignored.</param>
/// <param name="groupExpressions">The fields/expressions to aggregate on when counting.</param>
/// <returns>The number of objects that match the criteria, plus the values of those objects
/// for the fields that were aggregated on.</returns>
List<GroupCountResult> GetCount(ITransaction transaction, DaoCriteria crit, ICollection<AbstractGroupExpression> groupExpressions);
/// <summary>
/// Performs a join using the given join criteria and returns the number of rows that
/// result from the join.
/// </summary>
/// <typeparam name="R">The type of object returned by the other DAO.</typeparam>
/// <param name="crit">An object describing how to join the two DAOs. Includes any
/// criteria that apply to the right or left DAO.</param>
/// <param name="rightDao">The other DAO we are joining against.</param>
/// <returns>The number of join results that matched the criteria.</returns>
int GetCount<R>(DaoJoinCriteria crit, IFastDaoReader<R> rightDao) where R : class, new();
/// <summary>
/// Performs a join using the given join criteria and returns the number of rows that
/// result from the join.
/// </summary>
/// <typeparam name="R">The type of object returned by the other DAO.</typeparam>
/// <param name="transaction">The transaction to do this as part of. May be null.</param>
/// <param name="crit">An object describing how to join the two DAOs. Includes any
/// criteria that apply to the right or left DAO.</param>
/// <param name="rightDao">The other DAO we are joining against.</param>
/// <returns>The number of join results that matched the criteria.</returns>
int GetCount<R>(ITransaction transaction, DaoJoinCriteria crit, IFastDaoReader<R> rightDao) where R : class, new();
/// <summary>
/// Queries for objects where the property matches the given value.
/// </summary>
/// <param name="propName">Property or Field on the object you want to match a value.</param>
/// <param name="val">Value that the Property or Field should have.</param>
/// <returns>The first object that matches the criteria.</returns>
T GetFirst(string propName, object val);
/// <summary>
/// Queries for objects where the property matches the given value.
/// </summary>
/// <param name="transaction">The transaction to do this as part of. May be null.</param>
/// <param name="propName">Property or Field on the object you want to match a value.</param>
/// <param name="val">Value that the Property or Field should have.</param>
/// <returns>The first object that matches the criteria.</returns>
T GetFirst(ITransaction transaction, string propName, object val);
/// <summary>
/// Queries for objects, similar to Get, except that this iterates over the resulting
/// records and invokes the specified delegate for each one. This allows processing of much
/// larger result sets since it doesn't attempt to load all the objects into memory at once.
/// </summary>
/// <typeparam name="P">The type of the 'parameters' object taken by the delegate.</typeparam>
/// <param name="criteria">Any criteria for the query. May be null for "all records".</param>
/// <param name="invokeMe">The method to invoke for each object returned by the query.</param>
/// <param name="parameters">Any parameters that you want to pass to the invokeMe method.
/// This may be null.</param>
/// <param name="desc">Description of the loop for logging purposes.</param>
/// <returns>The number of objects iterated over.</returns>
int Iterate<P>(DaoCriteria criteria, DaoIterationDelegate<T, P> invokeMe,
P parameters, string desc);
/// <summary>
/// Queries for objects, similar to Get, except that this iterates over the resulting
/// records and invokes the specified delegate for each one. This allows processing of much
/// larger result sets since it doesn't attempt to load all the objects into memory at once.
/// </summary>
/// <typeparam name="P">The type of the 'parameters' object taken by the delegate.</typeparam>
/// <param name="transaction">The transaction to do this as part of. May be null.</param>
/// <param name="criteria">Any criteria for the query. May be null for "all records".</param>
/// <param name="invokeMe">The method to invoke for each object returned by the query.</param>
/// <param name="parameters">Any parameters that you want to pass to the invokeMe method.
/// This may be null.</param>
/// <param name="desc">Description of the loop for logging purposes.</param>
/// <returns>The number of objects iterated over.</returns>
int Iterate<P>(ITransaction transaction, DaoCriteria criteria, DaoIterationDelegate<T, P> invokeMe,
P parameters, string desc);
/// <summary>
/// Gets a single value off the data object based on the
/// name of the field/property.
/// </summary>
/// <param name="dataObject">The object to get a value off of.</param>
/// <param name="fieldName">The name of the field/property to get the value of.</param>
/// <returns>The value.</returns>
object GetValueFromObject(T dataObject, string fieldName);
}
}