comparison Source/DataAccess/SprocQuery.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Collections;
3
4 using BLToolkit.Data;
5
6 namespace BLToolkit.DataAccess
7 {
8 public class SprocQuery : DataAccessorBase
9 {
10 #region Constructors
11
12 public SprocQuery()
13 {
14 }
15
16 public SprocQuery(DbManager dbManager)
17 : base(dbManager)
18 {
19 }
20
21 public SprocQuery(DbManager dbManager, bool dispose)
22 : base(dbManager, dispose)
23 {
24 }
25
26 #endregion
27
28 #region SelectByKey
29
30 public virtual object SelectByKey(DbManager db, Type type, params object[] key)
31 {
32 return db
33 .SetSpCommand(GetSpName(type, "SelectByKey"), key)
34 .ExecuteObject(type);
35 }
36
37 public virtual object SelectByKey(Type type, params object[] key)
38 {
39 DbManager db = GetDbManager();
40
41 try
42 {
43 return SelectByKey(db, type, key);
44 }
45 finally
46 {
47 Dispose(db);
48 }
49 }
50
51 public virtual T SelectByKey<T>(DbManager db, params object[] key)
52 {
53 return db
54 .SetSpCommand(GetSpName(typeof(T), "SelectByKey"), key)
55 .ExecuteObject<T>();
56 }
57
58 public virtual T SelectByKey<T>(params object[] key)
59 {
60 DbManager db = GetDbManager();
61
62 try
63 {
64 return SelectByKey<T>(db, key);
65 }
66 finally
67 {
68 Dispose(db);
69 }
70 }
71
72 #endregion
73
74 #region SelectAll
75
76 public virtual ArrayList SelectAll(DbManager db, Type type)
77 {
78 return db
79 .SetSpCommand(GetSpName(type, "SelectAll"))
80 .ExecuteList(type);
81 }
82
83 public virtual IList SelectAll(DbManager db, IList list, Type type)
84 {
85 return db
86 .SetSpCommand(GetSpName(type, "SelectAll"))
87 .ExecuteList(list, type);
88 }
89
90 public virtual ArrayList SelectAll(Type type)
91 {
92 DbManager db = GetDbManager();
93
94 try
95 {
96 return SelectAll(db, type);
97 }
98 finally
99 {
100 Dispose(db);
101 }
102 }
103
104 public virtual IList SelectAll(IList list, Type type)
105 {
106 DbManager db = GetDbManager();
107
108 try
109 {
110 return SelectAll(db, list, type);
111 }
112 finally
113 {
114 Dispose(db);
115 }
116 }
117
118 public virtual System.Collections.Generic.List<T> SelectAll<T>(DbManager db)
119 {
120 return db
121 .SetSpCommand(GetSpName(typeof(T), "SelectAll"))
122 .ExecuteList<T>();
123 }
124
125 public virtual L SelectAll<L,T>(DbManager db, L list)
126 where L : System.Collections.Generic.IList<T>
127 {
128 return db
129 .SetSpCommand(GetSpName(typeof(T), "SelectAll"))
130 .ExecuteList<L,T>(list);
131 }
132
133 public virtual L SelectAll<L, T>(DbManager db)
134 where L : System.Collections.Generic.IList<T>, new()
135 {
136 return SelectAll<L, T>(db, new L());
137 }
138
139 public virtual System.Collections.Generic.List<T> SelectAll<T>()
140 {
141 DbManager db = GetDbManager();
142
143 try
144 {
145 return SelectAll<T>(db);
146 }
147 finally
148 {
149 Dispose(db);
150 }
151 }
152
153 public virtual L SelectAll<L,T>(L list)
154 where L : System.Collections.Generic.IList<T>
155 {
156 DbManager db = GetDbManager();
157
158 try
159 {
160 return SelectAll<L,T>(db, list);
161 }
162 finally
163 {
164 Dispose(db);
165 }
166 }
167
168 public virtual L SelectAll<L,T>()
169 where L : System.Collections.Generic.IList<T>, new()
170 {
171 return SelectAll<L,T>(new L());
172 }
173
174 #endregion
175
176 #region Insert
177
178 public virtual void Insert(DbManager db, object obj)
179 {
180 db
181 .SetSpCommand(
182 GetSpName(obj.GetType(), "Insert"),
183 db.CreateParameters(obj))
184 .ExecuteNonQuery();
185 }
186
187 public virtual void Insert(object obj)
188 {
189 var db = GetDbManager();
190
191 try
192 {
193 Insert(db, obj);
194 }
195 finally
196 {
197 Dispose(db);
198 }
199 }
200
201 #endregion
202
203 #region Update
204
205 public virtual int Update(DbManager db, object obj)
206 {
207 return db
208 .SetSpCommand(
209 GetSpName(obj.GetType(), "Update"),
210 db.CreateParameters(obj))
211 .ExecuteNonQuery();
212 }
213
214 public virtual int Update(object obj)
215 {
216 DbManager db = GetDbManager();
217
218 try
219 {
220 return Update(db, obj);
221 }
222 finally
223 {
224 Dispose(db);
225 }
226 }
227
228 #endregion
229
230 #region DeleteByKey
231
232 public virtual int DeleteByKey(DbManager db, Type type, params object[] key)
233 {
234 return db
235 .SetSpCommand(GetSpName(type, "Delete"), key)
236 .ExecuteNonQuery();
237 }
238
239 public virtual int DeleteByKey(Type type, params object[] key)
240 {
241 DbManager db = GetDbManager();
242
243 try
244 {
245 return DeleteByKey(db, type, key);
246 }
247 finally
248 {
249 Dispose(db);
250 }
251 }
252
253 #endregion
254
255 #region Delete
256
257 public virtual int Delete(DbManager db, object obj)
258 {
259 return db
260 .SetSpCommand(
261 GetSpName(obj.GetType(), "Delete"),
262 db.CreateParameters(obj))
263 .ExecuteNonQuery();
264 }
265
266 public virtual int Delete(object obj)
267 {
268 DbManager db = GetDbManager();
269
270 try
271 {
272 return Delete(db, obj);
273 }
274 finally
275 {
276 Dispose(db);
277 }
278 }
279
280 #endregion
281 }
282 }