diff options
author | Fernando Oliveira | 2013-10-12 16:33:45 -0500 |
---|---|---|
committer | fernando | 2013-10-12 16:33:45 -0500 |
commit | ff8a76825841533bdc5d534b6f58b2ab964ea6c6 (patch) | |
tree | 4ddde40916db04c1506486c9e7ba88b37f53e23e /OpenSim/Data/PGSQL/PGSQLGroupsData.cs | |
parent | * pushing test (diff) | |
download | opensim-SC_OLD-ff8a76825841533bdc5d534b6f58b2ab964ea6c6.zip opensim-SC_OLD-ff8a76825841533bdc5d534b6f58b2ab964ea6c6.tar.gz opensim-SC_OLD-ff8a76825841533bdc5d534b6f58b2ab964ea6c6.tar.bz2 opensim-SC_OLD-ff8a76825841533bdc5d534b6f58b2ab964ea6c6.tar.xz |
Fernando Oliveira's Postgress SQL Server Data Connector as a single commit.
* Added PostGreSQL support
* Added MySQL/MySQLXGroupData.cs
* PostgreSQL data access implementation
* PostgreSQL dll binarie and RegionStore.migrations
* Migrations Scripts from MSSQL to POSTGRES
* Postgres SQL Type fixes
* Postgres SQL Connection string
* Data type issues
* more fixes
* tests and +tests
* UUID x string - FIGHT!
* Fixed PG types to internal csharp types
* More data type fix (PostgreSQL fields are case sensitive) :(
* more field case sensitive fixes
* changed the migration files to be case sensitive for fields.
* fixed fields case
* finished converting, now search for hidden bugs.
* some more fixes
* bool type fixed
* more case fixes;
* creatorID case fixed
* case fields fixed
* fixed default now() for TMStamp fields with don't allow nulls.
* fix case sensitve for Region name and Estate name
* fixed case for names for search
* fix class name Error
* Bug fixed on select and migrations
* Un-Reverting my change due to Postgres issue with the ILIKE function
* Fixed some issued for Diva Distro
* Fixes for integration with Diva Distro
* Added System.Core to prebuild.xml for PG project
* Configured to make DIff for Push to OpenSim Project
* Diffs only to PostgreSQL mods.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/PGSQL/PGSQLGroupsData.cs | 481 |
1 files changed, 481 insertions, 0 deletions
diff --git a/OpenSim/Data/PGSQL/PGSQLGroupsData.cs b/OpenSim/Data/PGSQL/PGSQLGroupsData.cs new file mode 100644 index 0000000..ed75b63 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLGroupsData.cs | |||
@@ -0,0 +1,481 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using Npgsql; | ||
35 | |||
36 | namespace OpenSim.Data.PGSQL | ||
37 | { | ||
38 | public class PGSQLGroupsData : IGroupsData | ||
39 | { | ||
40 | private PGSqlGroupsGroupsHandler m_Groups; | ||
41 | private PGSqlGroupsMembershipHandler m_Membership; | ||
42 | private PGSqlGroupsRolesHandler m_Roles; | ||
43 | private PGSqlGroupsRoleMembershipHandler m_RoleMembership; | ||
44 | private PGSqlGroupsInvitesHandler m_Invites; | ||
45 | private PGSqlGroupsNoticesHandler m_Notices; | ||
46 | private PGSqlGroupsPrincipalsHandler m_Principals; | ||
47 | |||
48 | public PGSQLGroupsData(string connectionString, string realm) | ||
49 | { | ||
50 | m_Groups = new PGSqlGroupsGroupsHandler(connectionString, realm + "_groups", realm + "_Store"); | ||
51 | m_Membership = new PGSqlGroupsMembershipHandler(connectionString, realm + "_membership"); | ||
52 | m_Roles = new PGSqlGroupsRolesHandler(connectionString, realm + "_roles"); | ||
53 | m_RoleMembership = new PGSqlGroupsRoleMembershipHandler(connectionString, realm + "_rolemembership"); | ||
54 | m_Invites = new PGSqlGroupsInvitesHandler(connectionString, realm + "_invites"); | ||
55 | m_Notices = new PGSqlGroupsNoticesHandler(connectionString, realm + "_notices"); | ||
56 | m_Principals = new PGSqlGroupsPrincipalsHandler(connectionString, realm + "_principals"); | ||
57 | } | ||
58 | |||
59 | #region groups table | ||
60 | public bool StoreGroup(GroupData data) | ||
61 | { | ||
62 | return m_Groups.Store(data); | ||
63 | } | ||
64 | |||
65 | public GroupData RetrieveGroup(UUID groupID) | ||
66 | { | ||
67 | GroupData[] groups = m_Groups.Get("GroupID", groupID.ToString()); | ||
68 | if (groups.Length > 0) | ||
69 | return groups[0]; | ||
70 | |||
71 | return null; | ||
72 | } | ||
73 | |||
74 | public GroupData RetrieveGroup(string name) | ||
75 | { | ||
76 | GroupData[] groups = m_Groups.Get("Name", name); | ||
77 | if (groups.Length > 0) | ||
78 | return groups[0]; | ||
79 | |||
80 | return null; | ||
81 | } | ||
82 | |||
83 | public GroupData[] RetrieveGroups(string pattern) | ||
84 | { | ||
85 | if (string.IsNullOrEmpty(pattern)) // True for where clause | ||
86 | pattern = " true ORDER BY lower(\"Name\") LIMIT 100"; | ||
87 | else | ||
88 | pattern = string.Format(" lower(\"Name\") LIKE lower('%{0}%') ORDER BY lower(\"Name\") LIMIT 100", pattern); | ||
89 | |||
90 | return m_Groups.Get(pattern); | ||
91 | } | ||
92 | |||
93 | public bool DeleteGroup(UUID groupID) | ||
94 | { | ||
95 | return m_Groups.Delete("GroupID", groupID.ToString()); | ||
96 | } | ||
97 | |||
98 | public int GroupsCount() | ||
99 | { | ||
100 | return (int)m_Groups.GetCount(" \"Location\" = \"\""); | ||
101 | } | ||
102 | |||
103 | #endregion | ||
104 | |||
105 | #region membership table | ||
106 | public MembershipData[] RetrieveMembers(UUID groupID) | ||
107 | { | ||
108 | return m_Membership.Get("GroupID", groupID.ToString()); | ||
109 | } | ||
110 | |||
111 | public MembershipData RetrieveMember(UUID groupID, string pricipalID) | ||
112 | { | ||
113 | MembershipData[] m = m_Membership.Get(new string[] { "GroupID", "PrincipalID" }, | ||
114 | new string[] { groupID.ToString(), pricipalID }); | ||
115 | if (m != null && m.Length > 0) | ||
116 | return m[0]; | ||
117 | |||
118 | return null; | ||
119 | } | ||
120 | |||
121 | public MembershipData[] RetrieveMemberships(string pricipalID) | ||
122 | { | ||
123 | return m_Membership.Get("PrincipalID", pricipalID.ToString()); | ||
124 | } | ||
125 | |||
126 | public bool StoreMember(MembershipData data) | ||
127 | { | ||
128 | return m_Membership.Store(data); | ||
129 | } | ||
130 | |||
131 | public bool DeleteMember(UUID groupID, string pricipalID) | ||
132 | { | ||
133 | return m_Membership.Delete(new string[] { "GroupID", "PrincipalID" }, | ||
134 | new string[] { groupID.ToString(), pricipalID }); | ||
135 | } | ||
136 | |||
137 | public int MemberCount(UUID groupID) | ||
138 | { | ||
139 | return (int)m_Membership.GetCount("GroupID", groupID.ToString()); | ||
140 | } | ||
141 | #endregion | ||
142 | |||
143 | #region roles table | ||
144 | public bool StoreRole(RoleData data) | ||
145 | { | ||
146 | return m_Roles.Store(data); | ||
147 | } | ||
148 | |||
149 | public RoleData RetrieveRole(UUID groupID, UUID roleID) | ||
150 | { | ||
151 | RoleData[] data = m_Roles.Get(new string[] { "GroupID", "RoleID" }, | ||
152 | new string[] { groupID.ToString(), roleID.ToString() }); | ||
153 | |||
154 | if (data != null && data.Length > 0) | ||
155 | return data[0]; | ||
156 | |||
157 | return null; | ||
158 | } | ||
159 | |||
160 | public RoleData[] RetrieveRoles(UUID groupID) | ||
161 | { | ||
162 | //return m_Roles.RetrieveRoles(groupID); | ||
163 | return m_Roles.Get("GroupID", groupID.ToString()); | ||
164 | } | ||
165 | |||
166 | public bool DeleteRole(UUID groupID, UUID roleID) | ||
167 | { | ||
168 | return m_Roles.Delete(new string[] { "GroupID", "RoleID" }, | ||
169 | new string[] { groupID.ToString(), roleID.ToString() }); | ||
170 | } | ||
171 | |||
172 | public int RoleCount(UUID groupID) | ||
173 | { | ||
174 | return (int)m_Roles.GetCount("GroupID", groupID.ToString()); | ||
175 | } | ||
176 | |||
177 | |||
178 | #endregion | ||
179 | |||
180 | #region rolememberhip table | ||
181 | public RoleMembershipData[] RetrieveRolesMembers(UUID groupID) | ||
182 | { | ||
183 | RoleMembershipData[] data = m_RoleMembership.Get("GroupID", groupID.ToString()); | ||
184 | |||
185 | return data; | ||
186 | } | ||
187 | |||
188 | public RoleMembershipData[] RetrieveRoleMembers(UUID groupID, UUID roleID) | ||
189 | { | ||
190 | RoleMembershipData[] data = m_RoleMembership.Get(new string[] { "GroupID", "RoleID" }, | ||
191 | new string[] { groupID.ToString(), roleID.ToString() }); | ||
192 | |||
193 | return data; | ||
194 | } | ||
195 | |||
196 | public RoleMembershipData[] RetrieveMemberRoles(UUID groupID, string principalID) | ||
197 | { | ||
198 | RoleMembershipData[] data = m_RoleMembership.Get(new string[] { "GroupID", "PrincipalID" }, | ||
199 | new string[] { groupID.ToString(), principalID.ToString() }); | ||
200 | |||
201 | return data; | ||
202 | } | ||
203 | |||
204 | public RoleMembershipData RetrieveRoleMember(UUID groupID, UUID roleID, string principalID) | ||
205 | { | ||
206 | RoleMembershipData[] data = m_RoleMembership.Get(new string[] { "GroupID", "RoleID", "PrincipalID" }, | ||
207 | new string[] { groupID.ToString(), roleID.ToString(), principalID.ToString() }); | ||
208 | |||
209 | if (data != null && data.Length > 0) | ||
210 | return data[0]; | ||
211 | |||
212 | return null; | ||
213 | } | ||
214 | |||
215 | public int RoleMemberCount(UUID groupID, UUID roleID) | ||
216 | { | ||
217 | return (int)m_RoleMembership.GetCount(new string[] { "GroupID", "RoleID" }, | ||
218 | new string[] { groupID.ToString(), roleID.ToString() }); | ||
219 | } | ||
220 | |||
221 | public bool StoreRoleMember(RoleMembershipData data) | ||
222 | { | ||
223 | return m_RoleMembership.Store(data); | ||
224 | } | ||
225 | |||
226 | public bool DeleteRoleMember(RoleMembershipData data) | ||
227 | { | ||
228 | return m_RoleMembership.Delete(new string[] { "GroupID", "RoleID", "PrincipalID"}, | ||
229 | new string[] { data.GroupID.ToString(), data.RoleID.ToString(), data.PrincipalID }); | ||
230 | } | ||
231 | |||
232 | public bool DeleteMemberAllRoles(UUID groupID, string principalID) | ||
233 | { | ||
234 | return m_RoleMembership.Delete(new string[] { "GroupID", "PrincipalID" }, | ||
235 | new string[] { groupID.ToString(), principalID }); | ||
236 | } | ||
237 | |||
238 | #endregion | ||
239 | |||
240 | #region principals table | ||
241 | public bool StorePrincipal(PrincipalData data) | ||
242 | { | ||
243 | return m_Principals.Store(data); | ||
244 | } | ||
245 | |||
246 | public PrincipalData RetrievePrincipal(string principalID) | ||
247 | { | ||
248 | PrincipalData[] p = m_Principals.Get("PrincipalID", principalID); | ||
249 | if (p != null && p.Length > 0) | ||
250 | return p[0]; | ||
251 | |||
252 | return null; | ||
253 | } | ||
254 | |||
255 | public bool DeletePrincipal(string principalID) | ||
256 | { | ||
257 | return m_Principals.Delete("PrincipalID", principalID); | ||
258 | } | ||
259 | #endregion | ||
260 | |||
261 | #region invites table | ||
262 | |||
263 | public bool StoreInvitation(InvitationData data) | ||
264 | { | ||
265 | return m_Invites.Store(data); | ||
266 | } | ||
267 | |||
268 | public InvitationData RetrieveInvitation(UUID inviteID) | ||
269 | { | ||
270 | InvitationData[] invites = m_Invites.Get("InviteID", inviteID.ToString()); | ||
271 | |||
272 | if (invites != null && invites.Length > 0) | ||
273 | return invites[0]; | ||
274 | |||
275 | return null; | ||
276 | } | ||
277 | |||
278 | public InvitationData RetrieveInvitation(UUID groupID, string principalID) | ||
279 | { | ||
280 | InvitationData[] invites = m_Invites.Get(new string[] { "GroupID", "PrincipalID" }, | ||
281 | new string[] { groupID.ToString(), principalID }); | ||
282 | |||
283 | if (invites != null && invites.Length > 0) | ||
284 | return invites[0]; | ||
285 | |||
286 | return null; | ||
287 | } | ||
288 | |||
289 | public bool DeleteInvite(UUID inviteID) | ||
290 | { | ||
291 | return m_Invites.Delete("InviteID", inviteID.ToString()); | ||
292 | } | ||
293 | |||
294 | public void DeleteOldInvites() | ||
295 | { | ||
296 | m_Invites.DeleteOld(); | ||
297 | } | ||
298 | |||
299 | #endregion | ||
300 | |||
301 | #region notices table | ||
302 | |||
303 | public bool StoreNotice(NoticeData data) | ||
304 | { | ||
305 | return m_Notices.Store(data); | ||
306 | } | ||
307 | |||
308 | public NoticeData RetrieveNotice(UUID noticeID) | ||
309 | { | ||
310 | NoticeData[] notices = m_Notices.Get("NoticeID", noticeID.ToString()); | ||
311 | |||
312 | if (notices != null && notices.Length > 0) | ||
313 | return notices[0]; | ||
314 | |||
315 | return null; | ||
316 | } | ||
317 | |||
318 | public NoticeData[] RetrieveNotices(UUID groupID) | ||
319 | { | ||
320 | NoticeData[] notices = m_Notices.Get("GroupID", groupID.ToString()); | ||
321 | |||
322 | return notices; | ||
323 | } | ||
324 | |||
325 | public bool DeleteNotice(UUID noticeID) | ||
326 | { | ||
327 | return m_Notices.Delete("NoticeID", noticeID.ToString()); | ||
328 | } | ||
329 | |||
330 | public void DeleteOldNotices() | ||
331 | { | ||
332 | m_Notices.DeleteOld(); | ||
333 | } | ||
334 | |||
335 | #endregion | ||
336 | |||
337 | #region combinations | ||
338 | public MembershipData RetrievePrincipalGroupMembership(string principalID, UUID groupID) | ||
339 | { | ||
340 | // TODO | ||
341 | return null; | ||
342 | } | ||
343 | public MembershipData[] RetrievePrincipalGroupMemberships(string principalID) | ||
344 | { | ||
345 | // TODO | ||
346 | return null; | ||
347 | } | ||
348 | |||
349 | #endregion | ||
350 | } | ||
351 | |||
352 | public class PGSqlGroupsGroupsHandler : PGSQLGenericTableHandler<GroupData> | ||
353 | { | ||
354 | protected override Assembly Assembly | ||
355 | { | ||
356 | // WARNING! Moving migrations to this assembly!!! | ||
357 | get { return GetType().Assembly; } | ||
358 | } | ||
359 | |||
360 | public PGSqlGroupsGroupsHandler(string connectionString, string realm, string store) | ||
361 | : base(connectionString, realm, store) | ||
362 | { | ||
363 | } | ||
364 | |||
365 | } | ||
366 | |||
367 | public class PGSqlGroupsMembershipHandler : PGSQLGenericTableHandler<MembershipData> | ||
368 | { | ||
369 | protected override Assembly Assembly | ||
370 | { | ||
371 | // WARNING! Moving migrations to this assembly!!! | ||
372 | get { return GetType().Assembly; } | ||
373 | } | ||
374 | |||
375 | public PGSqlGroupsMembershipHandler(string connectionString, string realm) | ||
376 | : base(connectionString, realm, string.Empty) | ||
377 | { | ||
378 | } | ||
379 | |||
380 | } | ||
381 | |||
382 | public class PGSqlGroupsRolesHandler : PGSQLGenericTableHandler<RoleData> | ||
383 | { | ||
384 | protected override Assembly Assembly | ||
385 | { | ||
386 | // WARNING! Moving migrations to this assembly!!! | ||
387 | get { return GetType().Assembly; } | ||
388 | } | ||
389 | |||
390 | public PGSqlGroupsRolesHandler(string connectionString, string realm) | ||
391 | : base(connectionString, realm, string.Empty) | ||
392 | { | ||
393 | } | ||
394 | |||
395 | } | ||
396 | |||
397 | public class PGSqlGroupsRoleMembershipHandler : PGSQLGenericTableHandler<RoleMembershipData> | ||
398 | { | ||
399 | protected override Assembly Assembly | ||
400 | { | ||
401 | // WARNING! Moving migrations to this assembly!!! | ||
402 | get { return GetType().Assembly; } | ||
403 | } | ||
404 | |||
405 | public PGSqlGroupsRoleMembershipHandler(string connectionString, string realm) | ||
406 | : base(connectionString, realm, string.Empty) | ||
407 | { | ||
408 | } | ||
409 | |||
410 | } | ||
411 | |||
412 | public class PGSqlGroupsInvitesHandler : PGSQLGenericTableHandler<InvitationData> | ||
413 | { | ||
414 | protected override Assembly Assembly | ||
415 | { | ||
416 | // WARNING! Moving migrations to this assembly!!! | ||
417 | get { return GetType().Assembly; } | ||
418 | } | ||
419 | |||
420 | public PGSqlGroupsInvitesHandler(string connectionString, string realm) | ||
421 | : base(connectionString, realm, string.Empty) | ||
422 | { | ||
423 | } | ||
424 | |||
425 | public void DeleteOld() | ||
426 | { | ||
427 | uint now = (uint)Util.UnixTimeSinceEpoch(); | ||
428 | |||
429 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
430 | { | ||
431 | cmd.CommandText = String.Format("delete from {0} where \"TMStamp\" < :tstamp", m_Realm); | ||
432 | cmd.Parameters.AddWithValue("tstamp", now - 14 * 24 * 60 * 60); // > 2 weeks old | ||
433 | |||
434 | ExecuteNonQuery(cmd); | ||
435 | } | ||
436 | |||
437 | } | ||
438 | } | ||
439 | |||
440 | public class PGSqlGroupsNoticesHandler : PGSQLGenericTableHandler<NoticeData> | ||
441 | { | ||
442 | protected override Assembly Assembly | ||
443 | { | ||
444 | // WARNING! Moving migrations to this assembly!!! | ||
445 | get { return GetType().Assembly; } | ||
446 | } | ||
447 | |||
448 | public PGSqlGroupsNoticesHandler(string connectionString, string realm) | ||
449 | : base(connectionString, realm, string.Empty) | ||
450 | { | ||
451 | } | ||
452 | |||
453 | public void DeleteOld() | ||
454 | { | ||
455 | uint now = (uint)Util.UnixTimeSinceEpoch(); | ||
456 | |||
457 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
458 | { | ||
459 | cmd.CommandText = String.Format("delete from {0} where \"TMStamp\" < :tstamp", m_Realm); | ||
460 | cmd.Parameters.AddWithValue("tstamp", now - 14 * 24 * 60 * 60); // > 2 weeks old | ||
461 | |||
462 | ExecuteNonQuery(cmd); | ||
463 | } | ||
464 | |||
465 | } | ||
466 | } | ||
467 | |||
468 | public class PGSqlGroupsPrincipalsHandler : PGSQLGenericTableHandler<PrincipalData> | ||
469 | { | ||
470 | protected override Assembly Assembly | ||
471 | { | ||
472 | // WARNING! Moving migrations to this assembly!!! | ||
473 | get { return GetType().Assembly; } | ||
474 | } | ||
475 | |||
476 | public PGSqlGroupsPrincipalsHandler(string connectionString, string realm) | ||
477 | : base(connectionString, realm, string.Empty) | ||
478 | { | ||
479 | } | ||
480 | } | ||
481 | } | ||