diff options
author | Melanie | 2009-10-22 07:12:10 +0100 |
---|---|---|
committer | Melanie | 2009-10-22 07:12:10 +0100 |
commit | c4969d47d9bbc22b37054451cd31451ca8d8c78a (patch) | |
tree | 788e3b034254bcf068ca950ee97a78b6aa07b386 /OpenSim/Data/NHibernate/NHibernateUserData.cs | |
parent | Merge branch 'master' into vehicles (diff) | |
parent | Remove the "mel_t" from version string (diff) | |
download | opensim-SC_OLD-c4969d47d9bbc22b37054451cd31451ca8d8c78a.zip opensim-SC_OLD-c4969d47d9bbc22b37054451cd31451ca8d8c78a.tar.gz opensim-SC_OLD-c4969d47d9bbc22b37054451cd31451ca8d8c78a.tar.bz2 opensim-SC_OLD-c4969d47d9bbc22b37054451cd31451ca8d8c78a.tar.xz |
Merge branch 'master' into vehicles
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateUserData.cs | 461 |
1 files changed, 0 insertions, 461 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateUserData.cs b/OpenSim/Data/NHibernate/NHibernateUserData.cs deleted file mode 100644 index 1b0c4c9..0000000 --- a/OpenSim/Data/NHibernate/NHibernateUserData.cs +++ /dev/null | |||
@@ -1,461 +0,0 @@ | |||
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.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using log4net; | ||
31 | using NHibernate; | ||
32 | using NHibernate.Criterion; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | |||
36 | namespace OpenSim.Data.NHibernate | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// A User storage interface for the DB4o database system | ||
40 | /// </summary> | ||
41 | public class NHibernateUserData : UserDataBase | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | private NHibernateManager manager; | ||
46 | public NHibernateManager Manager | ||
47 | { | ||
48 | get | ||
49 | { | ||
50 | return manager; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | public override void Initialise() | ||
55 | { | ||
56 | m_log.Info("[NHibernateUserData]: " + Name + " cannot be default-initialized!"); | ||
57 | throw new PluginNotInitialisedException (Name); | ||
58 | } | ||
59 | |||
60 | public override void Initialise(string connect) | ||
61 | { | ||
62 | m_log.InfoFormat("[NHIBERNATE] Initializing NHibernateUserData"); | ||
63 | manager = new NHibernateManager(connect, "UserStore"); | ||
64 | } | ||
65 | |||
66 | private bool ExistsUser(UUID uuid) | ||
67 | { | ||
68 | UserProfileData user = null; | ||
69 | |||
70 | m_log.InfoFormat("[NHIBERNATE] ExistsUser; {0}", uuid); | ||
71 | user = (UserProfileData)manager.Get(typeof(UserProfileData), uuid); | ||
72 | |||
73 | if (user == null) | ||
74 | { | ||
75 | m_log.InfoFormat("[NHIBERNATE] User with given UUID does not exist {0} ", uuid); | ||
76 | return false; | ||
77 | } | ||
78 | |||
79 | return true; | ||
80 | |||
81 | } | ||
82 | |||
83 | override public UserProfileData GetUserByUUID(UUID uuid) | ||
84 | { | ||
85 | UserProfileData user; | ||
86 | m_log.InfoFormat("[NHIBERNATE] GetUserByUUID: {0} ", uuid); | ||
87 | |||
88 | user = (UserProfileData)manager.Get(typeof(UserProfileData), uuid); | ||
89 | if (user != null) | ||
90 | { | ||
91 | UserAgentData agent = GetAgentByUUID(uuid); | ||
92 | if (agent != null) | ||
93 | { | ||
94 | user.CurrentAgent = agent; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | return user; | ||
99 | } | ||
100 | |||
101 | override public void AddNewUserProfile(UserProfileData profile) | ||
102 | { | ||
103 | if (profile.ID == UUID.Zero) | ||
104 | { | ||
105 | m_log.ErrorFormat("[NHIBERNATE] Attempted to add User {0} {1} with zero UUID, throwintg exception as this is programming error ", profile.FirstName, profile.SurName); | ||
106 | return; | ||
107 | } | ||
108 | |||
109 | if (!ExistsUser(profile.ID)) | ||
110 | { | ||
111 | m_log.InfoFormat("[NHIBERNATE] AddNewUserProfile {0}", profile.ID); | ||
112 | manager.Insert(profile); | ||
113 | // Agent should not be saved according to BasicUserTest.T015_UserPersistency() | ||
114 | // SetAgentData(profile.ID, profile.CurrentAgent); | ||
115 | |||
116 | } | ||
117 | else | ||
118 | { | ||
119 | m_log.ErrorFormat("[NHIBERNATE] Attempted to add User {0} {1} that already exists, updating instead", profile.FirstName, profile.SurName); | ||
120 | UpdateUserProfile(profile); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | /* | ||
125 | private void SetAgentData(UUID uuid, UserAgentData agent) | ||
126 | { | ||
127 | UserAgentData old = (UserAgentData)manager.Load(typeof(UserAgentData), uuid); | ||
128 | if (old != null) | ||
129 | { | ||
130 | m_log.InfoFormat("[NHIBERNATE] SetAgentData deleting old: {0} ",uuid); | ||
131 | manager.Delete(old); | ||
132 | } | ||
133 | if (agent != null) | ||
134 | { | ||
135 | m_log.InfoFormat("[NHIBERNATE] SetAgentData: {0} ", agent.ProfileID); | ||
136 | manager.Save(agent); | ||
137 | } | ||
138 | } | ||
139 | */ | ||
140 | |||
141 | override public bool UpdateUserProfile(UserProfileData profile) | ||
142 | { | ||
143 | if (ExistsUser(profile.ID)) | ||
144 | { | ||
145 | manager.Update(profile); | ||
146 | // Agent should not be saved according to BasicUserTest.T015_UserPersistency() | ||
147 | // SetAgentData(profile.ID, profile.CurrentAgent); | ||
148 | return true; | ||
149 | } | ||
150 | else | ||
151 | { | ||
152 | m_log.ErrorFormat("[NHIBERNATE] Attempted to update User {0} {1} that doesn't exist, updating instead", profile.FirstName, profile.SurName); | ||
153 | AddNewUserProfile(profile); | ||
154 | return true; | ||
155 | } | ||
156 | } | ||
157 | |||
158 | override public void AddNewUserAgent(UserAgentData agent) | ||
159 | { | ||
160 | if (agent.ProfileID == UUID.Zero) | ||
161 | { | ||
162 | m_log.ErrorFormat("[NHIBERNATE] Attempted to add new user agent with zero user id. Agent session id: {0}", agent.SessionID); | ||
163 | return; | ||
164 | } | ||
165 | |||
166 | if (agent.SessionID == UUID.Zero) | ||
167 | { | ||
168 | m_log.ErrorFormat("[NHIBERNATE] Attempted to add new user agent with zero session id. User profile id: {0}", agent.SessionID); | ||
169 | return; | ||
170 | } | ||
171 | |||
172 | |||
173 | UserAgentData old = (UserAgentData)manager.Get(typeof(UserAgentData), agent.ProfileID); | ||
174 | if (old != null) | ||
175 | { | ||
176 | manager.Delete(old); | ||
177 | } | ||
178 | |||
179 | manager.Insert(agent); | ||
180 | |||
181 | } | ||
182 | |||
183 | public void UpdateUserAgent(UserAgentData agent) | ||
184 | { | ||
185 | m_log.InfoFormat("[NHIBERNATE] UpdateUserAgent: {0} ", agent.ProfileID); | ||
186 | manager.Update(agent); | ||
187 | } | ||
188 | |||
189 | override public UserAgentData GetAgentByUUID(UUID uuid) | ||
190 | { | ||
191 | m_log.InfoFormat("[NHIBERNATE] GetAgentByUUID: {0} ", uuid); | ||
192 | return (UserAgentData)manager.Get(typeof(UserAgentData), uuid); | ||
193 | } | ||
194 | |||
195 | override public UserProfileData GetUserByName(string fname, string lname) | ||
196 | { | ||
197 | m_log.InfoFormat("[NHIBERNATE] GetUserByName: {0} {1} ", fname, lname); | ||
198 | ICriteria criteria = manager.GetSession().CreateCriteria(typeof(UserProfileData)); | ||
199 | criteria.Add(Expression.Eq("FirstName", fname)); | ||
200 | criteria.Add(Expression.Eq("SurName", lname)); | ||
201 | foreach (UserProfileData profile in criteria.List()) | ||
202 | { | ||
203 | profile.CurrentAgent = GetAgentByUUID(profile.ID); | ||
204 | return profile; | ||
205 | } | ||
206 | return null; | ||
207 | } | ||
208 | |||
209 | override public UserAgentData GetAgentByName(string fname, string lname) | ||
210 | { | ||
211 | return GetUserByName(fname, lname).CurrentAgent; | ||
212 | } | ||
213 | |||
214 | override public UserAgentData GetAgentByName(string name) | ||
215 | { | ||
216 | return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]); | ||
217 | } | ||
218 | |||
219 | override public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) | ||
220 | { | ||
221 | List<AvatarPickerAvatar> results = new List<AvatarPickerAvatar>(); | ||
222 | string[] querysplit; | ||
223 | querysplit = query.Split(' '); | ||
224 | |||
225 | if (querysplit.Length == 2) | ||
226 | { | ||
227 | ICriteria criteria = manager.GetSession().CreateCriteria(typeof(UserProfileData)); | ||
228 | criteria.Add(Expression.Like("FirstName", querysplit[0])); | ||
229 | criteria.Add(Expression.Like("SurName", querysplit[1])); | ||
230 | foreach (UserProfileData profile in criteria.List()) | ||
231 | { | ||
232 | AvatarPickerAvatar user = new AvatarPickerAvatar(); | ||
233 | user.AvatarID = profile.ID; | ||
234 | user.firstName = profile.FirstName; | ||
235 | user.lastName = profile.SurName; | ||
236 | results.Add(user); | ||
237 | } | ||
238 | } | ||
239 | return results; | ||
240 | } | ||
241 | |||
242 | // TODO: actually implement these | ||
243 | public override void StoreWebLoginKey(UUID agentID, UUID webLoginKey) | ||
244 | { | ||
245 | UserProfileData user=GetUserByUUID(agentID); | ||
246 | user.WebLoginKey = webLoginKey; | ||
247 | UpdateUserProfile(user); | ||
248 | return; | ||
249 | } | ||
250 | |||
251 | public override void AddNewUserFriend(UUID ownerId, UUID friendId, uint perms) | ||
252 | { | ||
253 | if (!FriendRelationExists(ownerId,friendId)) | ||
254 | { | ||
255 | manager.Insert(new UserFriend(UUID.Random(), ownerId, friendId, perms)); | ||
256 | } | ||
257 | if (!FriendRelationExists(friendId, ownerId)) | ||
258 | { | ||
259 | manager.Insert(new UserFriend(UUID.Random(), friendId, ownerId, perms)); | ||
260 | } | ||
261 | return; | ||
262 | } | ||
263 | |||
264 | private bool FriendRelationExists(UUID ownerId, UUID friendId) | ||
265 | { | ||
266 | using (ISession session = manager.GetSession()) | ||
267 | { | ||
268 | ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); | ||
269 | criteria.Add(Expression.Eq("OwnerID", ownerId)); | ||
270 | criteria.Add(Expression.Eq("FriendID", friendId)); | ||
271 | return criteria.List().Count > 0; | ||
272 | } | ||
273 | } | ||
274 | |||
275 | public override void RemoveUserFriend(UUID ownerId, UUID friendId) | ||
276 | { | ||
277 | using (ISession session = manager.GetSession()) | ||
278 | { | ||
279 | using (ITransaction transaction = session.BeginTransaction()) | ||
280 | { | ||
281 | |||
282 | { | ||
283 | ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); | ||
284 | criteria.Add(Expression.Eq("OwnerID", ownerId)); | ||
285 | criteria.Add(Expression.Eq("FriendID", friendId)); | ||
286 | |||
287 | foreach (UserFriend userFriend in criteria.List()) | ||
288 | { | ||
289 | session.Delete(userFriend); | ||
290 | } | ||
291 | } | ||
292 | |||
293 | { | ||
294 | ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); | ||
295 | criteria.Add(Expression.Eq("OwnerID", friendId)); | ||
296 | criteria.Add(Expression.Eq("FriendID", ownerId)); | ||
297 | |||
298 | foreach (UserFriend userFriend in criteria.List()) | ||
299 | { | ||
300 | session.Delete(userFriend); | ||
301 | } | ||
302 | } | ||
303 | |||
304 | transaction.Commit(); | ||
305 | } | ||
306 | } | ||
307 | return; | ||
308 | } | ||
309 | |||
310 | |||
311 | public override void UpdateUserFriendPerms(UUID ownerId, UUID friendId, uint perms) | ||
312 | { | ||
313 | using (ISession session = manager.GetSession()) | ||
314 | { | ||
315 | using (ITransaction transaction = session.BeginTransaction()) | ||
316 | { | ||
317 | { | ||
318 | ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); | ||
319 | criteria.Add(Expression.Eq("OwnerID", ownerId)); | ||
320 | criteria.Add(Expression.Eq("FriendID", friendId)); | ||
321 | |||
322 | foreach (UserFriend userFriend in criteria.List()) | ||
323 | { | ||
324 | userFriend.FriendPermissions = perms; | ||
325 | session.Update(userFriend); | ||
326 | } | ||
327 | } | ||
328 | transaction.Commit(); | ||
329 | } | ||
330 | } | ||
331 | return; | ||
332 | } | ||
333 | |||
334 | public override List<FriendListItem> GetUserFriendList(UUID ownerId) | ||
335 | { | ||
336 | List<FriendListItem> friendList=new List<FriendListItem>(); | ||
337 | Dictionary<UUID, FriendListItem> friendListItemDictionary = new Dictionary<UUID, FriendListItem>(); | ||
338 | |||
339 | using (ISession session = manager.GetSession()) | ||
340 | { | ||
341 | ICriteria criteria = session.CreateCriteria(typeof(UserFriend)); | ||
342 | criteria.Add(Expression.Or( | ||
343 | Expression.Eq("OwnerID", ownerId), | ||
344 | Expression.Eq("FriendID", ownerId) | ||
345 | )); | ||
346 | |||
347 | foreach (UserFriend userFriend in criteria.List()) | ||
348 | { | ||
349 | if (userFriend.OwnerID == ownerId) | ||
350 | { | ||
351 | FriendListItem friendListItem = new FriendListItem(); | ||
352 | friendListItem.FriendListOwner = userFriend.OwnerID; | ||
353 | friendListItem.Friend = userFriend.FriendID; | ||
354 | friendListItem.FriendPerms = userFriend.FriendPermissions; | ||
355 | friendListItemDictionary.Add(userFriend.FriendID, friendListItem); | ||
356 | friendList.Add(friendListItem); | ||
357 | } | ||
358 | } | ||
359 | |||
360 | // Reading permissions to other direction | ||
361 | foreach (UserFriend userFriend in criteria.List()) | ||
362 | { | ||
363 | if (userFriend.FriendID == ownerId) | ||
364 | { | ||
365 | //Ignore if there is no reverse relation existing. | ||
366 | //if (friendListItemDictionary.ContainsKey(userFriend.OwnerID)) | ||
367 | { | ||
368 | FriendListItem friendListItem = friendListItemDictionary[userFriend.OwnerID]; | ||
369 | friendListItem.FriendListOwnerPerms = userFriend.FriendPermissions; | ||
370 | } | ||
371 | } | ||
372 | } | ||
373 | |||
374 | } | ||
375 | |||
376 | return friendList; | ||
377 | } | ||
378 | |||
379 | |||
380 | public override Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> friendsIds) | ||
381 | { | ||
382 | Dictionary<UUID, FriendRegionInfo> friendRegionInfos=new Dictionary<UUID, FriendRegionInfo>(); | ||
383 | |||
384 | foreach (UUID friendId in friendsIds) | ||
385 | { | ||
386 | UserAgentData agent=GetAgentByUUID(friendId); | ||
387 | if (agent != null) | ||
388 | { | ||
389 | FriendRegionInfo fri = new FriendRegionInfo(); | ||
390 | fri.isOnline = agent.AgentOnline; | ||
391 | fri.regionHandle = agent.Handle; | ||
392 | |||
393 | friendRegionInfos[friendId] = fri; | ||
394 | } | ||
395 | } | ||
396 | |||
397 | return friendRegionInfos; | ||
398 | } | ||
399 | |||
400 | public override bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return true; } | ||
401 | public override bool InventoryTransferRequest(UUID from, UUID to, UUID inventory) { return true; } | ||
402 | |||
403 | /// Appearance | ||
404 | /// TODO: stubs for now to get us to a compiling state gently | ||
405 | public override AvatarAppearance GetUserAppearance(UUID user) | ||
406 | { | ||
407 | return (AvatarAppearance)manager.Get(typeof(AvatarAppearance), user); | ||
408 | } | ||
409 | |||
410 | private bool ExistsAppearance(UUID uuid) | ||
411 | { | ||
412 | AvatarAppearance appearance = (AvatarAppearance)manager.Get(typeof(AvatarAppearance), uuid); | ||
413 | if (appearance == null) | ||
414 | { | ||
415 | return false; | ||
416 | } | ||
417 | |||
418 | return true; | ||
419 | } | ||
420 | |||
421 | |||
422 | public override void UpdateUserAppearance(UUID user, AvatarAppearance appearance) | ||
423 | { | ||
424 | if (appearance == null) | ||
425 | return; | ||
426 | |||
427 | appearance.Owner = user; | ||
428 | |||
429 | bool exists = ExistsAppearance(user); | ||
430 | if (exists) | ||
431 | { | ||
432 | manager.Update(appearance); | ||
433 | } | ||
434 | else | ||
435 | { | ||
436 | manager.Insert(appearance); | ||
437 | } | ||
438 | } | ||
439 | |||
440 | public override void ResetAttachments(UUID userID) | ||
441 | { | ||
442 | } | ||
443 | |||
444 | public override void LogoutUsers(UUID regionID) | ||
445 | { | ||
446 | } | ||
447 | |||
448 | public override string Name { | ||
449 | get { return "NHibernate"; } | ||
450 | } | ||
451 | |||
452 | public override string Version { | ||
453 | get { return "0.1"; } | ||
454 | } | ||
455 | |||
456 | public override void Dispose() | ||
457 | { | ||
458 | |||
459 | } | ||
460 | } | ||
461 | } | ||