aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/PGSQL/PGSQLGroupsData.cs
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-11-03 21:44:39 +1000
committerDavid Walter Seikel2016-11-03 21:44:39 +1000
commit134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch)
tree216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Data/PGSQL/PGSQLGroupsData.cs
parentMore changing to production grid. Double oops. (diff)
downloadopensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip
opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz
opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2
opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Data/PGSQL/PGSQLGroupsData.cs')
-rwxr-xr-xOpenSim/Data/PGSQL/PGSQLGroupsData.cs485
1 files changed, 485 insertions, 0 deletions
diff --git a/OpenSim/Data/PGSQL/PGSQLGroupsData.cs b/OpenSim/Data/PGSQL/PGSQLGroupsData.cs
new file mode 100755
index 0000000..e257e7c
--- /dev/null
+++ b/OpenSim/Data/PGSQL/PGSQLGroupsData.cs
@@ -0,0 +1,485 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Reflection;
32using OpenSim.Framework;
33using OpenMetaverse;
34using log4net;
35using Npgsql;
36
37namespace OpenSim.Data.PGSQL
38{
39 public class PGSQLGroupsData : IGroupsData
40 {
41 private PGSqlGroupsGroupsHandler m_Groups;
42 private PGSqlGroupsMembershipHandler m_Membership;
43 private PGSqlGroupsRolesHandler m_Roles;
44 private PGSqlGroupsRoleMembershipHandler m_RoleMembership;
45 private PGSqlGroupsInvitesHandler m_Invites;
46 private PGSqlGroupsNoticesHandler m_Notices;
47 private PGSqlGroupsPrincipalsHandler m_Principals;
48
49 public PGSQLGroupsData(string connectionString, string realm)
50 {
51 m_Groups = new PGSqlGroupsGroupsHandler(connectionString, realm + "_groups", realm + "_Store");
52 m_Membership = new PGSqlGroupsMembershipHandler(connectionString, realm + "_membership");
53 m_Roles = new PGSqlGroupsRolesHandler(connectionString, realm + "_roles");
54 m_RoleMembership = new PGSqlGroupsRoleMembershipHandler(connectionString, realm + "_rolemembership");
55 m_Invites = new PGSqlGroupsInvitesHandler(connectionString, realm + "_invites");
56 m_Notices = new PGSqlGroupsNoticesHandler(connectionString, realm + "_notices");
57 m_Principals = new PGSqlGroupsPrincipalsHandler(connectionString, realm + "_principals");
58 }
59
60 #region groups table
61 public bool StoreGroup(GroupData data)
62 {
63 return m_Groups.Store(data);
64 }
65
66 public GroupData RetrieveGroup(UUID groupID)
67 {
68 GroupData[] groups = m_Groups.Get("GroupID", groupID.ToString());
69 if (groups.Length > 0)
70 return groups[0];
71
72 return null;
73 }
74
75 public GroupData RetrieveGroup(string name)
76 {
77 GroupData[] groups = m_Groups.Get("Name", name);
78 if (groups.Length > 0)
79 return groups[0];
80
81 return null;
82 }
83
84 public GroupData[] RetrieveGroups(string pattern)
85 {
86
87 if (string.IsNullOrEmpty(pattern)) // True for where clause
88 {
89 pattern = " 1 ORDER BY lower(\"Name\") LIMIT 100";
90
91 return m_Groups.Get(pattern);
92 }
93 else
94 {
95 pattern = " \"ShowInList\" = 1 AND lower(\"Name\") LIKE lower('%" + pattern + "%') ORDER BY lower(\"Name\") LIMIT 100";
96
97 return m_Groups.Get(pattern, new NpgsqlParameter("pattern", pattern));
98 }
99 }
100
101 public bool DeleteGroup(UUID groupID)
102 {
103 return m_Groups.Delete("GroupID", groupID.ToString());
104 }
105
106 public int GroupsCount()
107 {
108 return (int)m_Groups.GetCount(" \"Location\" = \"\"");
109 }
110
111 #endregion
112
113 #region membership table
114 public MembershipData[] RetrieveMembers(UUID groupID)
115 {
116 return m_Membership.Get("GroupID", groupID.ToString());
117 }
118
119 public MembershipData RetrieveMember(UUID groupID, string pricipalID)
120 {
121 MembershipData[] m = m_Membership.Get(new string[] { "GroupID", "PrincipalID" },
122 new string[] { groupID.ToString(), pricipalID });
123 if (m != null && m.Length > 0)
124 return m[0];
125
126 return null;
127 }
128
129 public MembershipData[] RetrieveMemberships(string pricipalID)
130 {
131 return m_Membership.Get("PrincipalID", pricipalID.ToString());
132 }
133
134 public bool StoreMember(MembershipData data)
135 {
136 return m_Membership.Store(data);
137 }
138
139 public bool DeleteMember(UUID groupID, string pricipalID)
140 {
141 return m_Membership.Delete(new string[] { "GroupID", "PrincipalID" },
142 new string[] { groupID.ToString(), pricipalID });
143 }
144
145 public int MemberCount(UUID groupID)
146 {
147 return (int)m_Membership.GetCount("GroupID", groupID.ToString());
148 }
149 #endregion
150
151 #region roles table
152 public bool StoreRole(RoleData data)
153 {
154 return m_Roles.Store(data);
155 }
156
157 public RoleData RetrieveRole(UUID groupID, UUID roleID)
158 {
159 RoleData[] data = m_Roles.Get(new string[] { "GroupID", "RoleID" },
160 new string[] { groupID.ToString(), roleID.ToString() });
161
162 if (data != null && data.Length > 0)
163 return data[0];
164
165 return null;
166 }
167
168 public RoleData[] RetrieveRoles(UUID groupID)
169 {
170 //return m_Roles.RetrieveRoles(groupID);
171 return m_Roles.Get("GroupID", groupID.ToString());
172 }
173
174 public bool DeleteRole(UUID groupID, UUID roleID)
175 {
176 return m_Roles.Delete(new string[] { "GroupID", "RoleID" },
177 new string[] { groupID.ToString(), roleID.ToString() });
178 }
179
180 public int RoleCount(UUID groupID)
181 {
182 return (int)m_Roles.GetCount("GroupID", groupID.ToString());
183 }
184
185
186 #endregion
187
188 #region rolememberhip table
189 public RoleMembershipData[] RetrieveRolesMembers(UUID groupID)
190 {
191 RoleMembershipData[] data = m_RoleMembership.Get("GroupID", groupID.ToString());
192
193 return data;
194 }
195
196 public RoleMembershipData[] RetrieveRoleMembers(UUID groupID, UUID roleID)
197 {
198 RoleMembershipData[] data = m_RoleMembership.Get(new string[] { "GroupID", "RoleID" },
199 new string[] { groupID.ToString(), roleID.ToString() });
200
201 return data;
202 }
203
204 public RoleMembershipData[] RetrieveMemberRoles(UUID groupID, string principalID)
205 {
206 RoleMembershipData[] data = m_RoleMembership.Get(new string[] { "GroupID", "PrincipalID" },
207 new string[] { groupID.ToString(), principalID.ToString() });
208
209 return data;
210 }
211
212 public RoleMembershipData RetrieveRoleMember(UUID groupID, UUID roleID, string principalID)
213 {
214 RoleMembershipData[] data = m_RoleMembership.Get(new string[] { "GroupID", "RoleID", "PrincipalID" },
215 new string[] { groupID.ToString(), roleID.ToString(), principalID.ToString() });
216
217 if (data != null && data.Length > 0)
218 return data[0];
219
220 return null;
221 }
222
223 public int RoleMemberCount(UUID groupID, UUID roleID)
224 {
225 return (int)m_RoleMembership.GetCount(new string[] { "GroupID", "RoleID" },
226 new string[] { groupID.ToString(), roleID.ToString() });
227 }
228
229 public bool StoreRoleMember(RoleMembershipData data)
230 {
231 return m_RoleMembership.Store(data);
232 }
233
234 public bool DeleteRoleMember(RoleMembershipData data)
235 {
236 return m_RoleMembership.Delete(new string[] { "GroupID", "RoleID", "PrincipalID"},
237 new string[] { data.GroupID.ToString(), data.RoleID.ToString(), data.PrincipalID });
238 }
239
240 public bool DeleteMemberAllRoles(UUID groupID, string principalID)
241 {
242 return m_RoleMembership.Delete(new string[] { "GroupID", "PrincipalID" },
243 new string[] { groupID.ToString(), principalID });
244 }
245
246 #endregion
247
248 #region principals table
249 public bool StorePrincipal(PrincipalData data)
250 {
251 return m_Principals.Store(data);
252 }
253
254 public PrincipalData RetrievePrincipal(string principalID)
255 {
256 PrincipalData[] p = m_Principals.Get("PrincipalID", principalID);
257 if (p != null && p.Length > 0)
258 return p[0];
259
260 return null;
261 }
262
263 public bool DeletePrincipal(string principalID)
264 {
265 return m_Principals.Delete("PrincipalID", principalID);
266 }
267 #endregion
268
269 #region invites table
270
271 public bool StoreInvitation(InvitationData data)
272 {
273 return m_Invites.Store(data);
274 }
275
276 public InvitationData RetrieveInvitation(UUID inviteID)
277 {
278 InvitationData[] invites = m_Invites.Get("InviteID", inviteID.ToString());
279
280 if (invites != null && invites.Length > 0)
281 return invites[0];
282
283 return null;
284 }
285
286 public InvitationData RetrieveInvitation(UUID groupID, string principalID)
287 {
288 InvitationData[] invites = m_Invites.Get(new string[] { "GroupID", "PrincipalID" },
289 new string[] { groupID.ToString(), principalID });
290
291 if (invites != null && invites.Length > 0)
292 return invites[0];
293
294 return null;
295 }
296
297 public bool DeleteInvite(UUID inviteID)
298 {
299 return m_Invites.Delete("InviteID", inviteID.ToString());
300 }
301
302 public void DeleteOldInvites()
303 {
304 m_Invites.DeleteOld();
305 }
306
307 #endregion
308
309 #region notices table
310
311 public bool StoreNotice(NoticeData data)
312 {
313 return m_Notices.Store(data);
314 }
315
316 public NoticeData RetrieveNotice(UUID noticeID)
317 {
318 NoticeData[] notices = m_Notices.Get("NoticeID", noticeID.ToString());
319
320 if (notices != null && notices.Length > 0)
321 return notices[0];
322
323 return null;
324 }
325
326 public NoticeData[] RetrieveNotices(UUID groupID)
327 {
328 NoticeData[] notices = m_Notices.Get("GroupID", groupID.ToString());
329
330 return notices;
331 }
332
333 public bool DeleteNotice(UUID noticeID)
334 {
335 return m_Notices.Delete("NoticeID", noticeID.ToString());
336 }
337
338 public void DeleteOldNotices()
339 {
340 m_Notices.DeleteOld();
341 }
342
343 #endregion
344
345 #region combinations
346 public MembershipData RetrievePrincipalGroupMembership(string principalID, UUID groupID)
347 {
348 // TODO
349 return null;
350 }
351 public MembershipData[] RetrievePrincipalGroupMemberships(string principalID)
352 {
353 // TODO
354 return null;
355 }
356
357 #endregion
358 }
359
360 public class PGSqlGroupsGroupsHandler : PGSQLGenericTableHandler<GroupData>
361 {
362 protected override Assembly Assembly
363 {
364 // WARNING! Moving migrations to this assembly!!!
365 get { return GetType().Assembly; }
366 }
367
368 public PGSqlGroupsGroupsHandler(string connectionString, string realm, string store)
369 : base(connectionString, realm, store)
370 {
371 }
372
373 }
374
375 public class PGSqlGroupsMembershipHandler : PGSQLGenericTableHandler<MembershipData>
376 {
377 protected override Assembly Assembly
378 {
379 // WARNING! Moving migrations to this assembly!!!
380 get { return GetType().Assembly; }
381 }
382
383 public PGSqlGroupsMembershipHandler(string connectionString, string realm)
384 : base(connectionString, realm, string.Empty)
385 {
386 }
387
388 }
389
390 public class PGSqlGroupsRolesHandler : PGSQLGenericTableHandler<RoleData>
391 {
392 protected override Assembly Assembly
393 {
394 // WARNING! Moving migrations to this assembly!!!
395 get { return GetType().Assembly; }
396 }
397
398 public PGSqlGroupsRolesHandler(string connectionString, string realm)
399 : base(connectionString, realm, string.Empty)
400 {
401 }
402
403 }
404
405 public class PGSqlGroupsRoleMembershipHandler : PGSQLGenericTableHandler<RoleMembershipData>
406 {
407 protected override Assembly Assembly
408 {
409 // WARNING! Moving migrations to this assembly!!!
410 get { return GetType().Assembly; }
411 }
412
413 public PGSqlGroupsRoleMembershipHandler(string connectionString, string realm)
414 : base(connectionString, realm, string.Empty)
415 {
416 }
417
418 }
419
420 public class PGSqlGroupsInvitesHandler : PGSQLGenericTableHandler<InvitationData>
421 {
422 protected override Assembly Assembly
423 {
424 // WARNING! Moving migrations to this assembly!!!
425 get { return GetType().Assembly; }
426 }
427
428 public PGSqlGroupsInvitesHandler(string connectionString, string realm)
429 : base(connectionString, realm, string.Empty)
430 {
431 }
432
433 public void DeleteOld()
434 {
435
436 using (NpgsqlCommand cmd = new NpgsqlCommand())
437 {
438 cmd.CommandText = String.Format("delete from {0} where \"TMStamp\" < CURRENT_DATE - INTERVAL '2 week'", m_Realm);
439
440 ExecuteNonQuery(cmd);
441 }
442
443 }
444 }
445
446 public class PGSqlGroupsNoticesHandler : PGSQLGenericTableHandler<NoticeData>
447 {
448 protected override Assembly Assembly
449 {
450 // WARNING! Moving migrations to this assembly!!!
451 get { return GetType().Assembly; }
452 }
453
454 public PGSqlGroupsNoticesHandler(string connectionString, string realm)
455 : base(connectionString, realm, string.Empty)
456 {
457 }
458
459 public void DeleteOld()
460 {
461
462 using (NpgsqlCommand cmd = new NpgsqlCommand())
463 {
464 cmd.CommandText = String.Format("delete from {0} where \"TMStamp\" < CURRENT_DATE - INTERVAL '2 week'", m_Realm);
465
466 ExecuteNonQuery(cmd);
467 }
468
469 }
470 }
471
472 public class PGSqlGroupsPrincipalsHandler : PGSQLGenericTableHandler<PrincipalData>
473 {
474 protected override Assembly Assembly
475 {
476 // WARNING! Moving migrations to this assembly!!!
477 get { return GetType().Assembly; }
478 }
479
480 public PGSqlGroupsPrincipalsHandler(string connectionString, string realm)
481 : base(connectionString, realm, string.Empty)
482 {
483 }
484 }
485}