aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/NHibernateInventoryData.cs
diff options
context:
space:
mode:
authorJohn Hurliman2009-10-19 16:52:27 -0700
committerJohn Hurliman2009-10-19 16:52:27 -0700
commitfdce1be3db287bed901332b90ba57165e201d3fc (patch)
tree8f0792e4c4ac4c14a50559f8439573740a7b3326 /OpenSim/Data/NHibernate/NHibernateInventoryData.cs
parentMerge branch 'prioritization' of ssh://opensimulator.org/var/git/opensim into... (diff)
downloadopensim-SC_OLD-fdce1be3db287bed901332b90ba57165e201d3fc.zip
opensim-SC_OLD-fdce1be3db287bed901332b90ba57165e201d3fc.tar.gz
opensim-SC_OLD-fdce1be3db287bed901332b90ba57165e201d3fc.tar.bz2
opensim-SC_OLD-fdce1be3db287bed901332b90ba57165e201d3fc.tar.xz
* Removed OpenSim.Data.NHibernate
* Replaced calls to ThreadPool.QueueUserWorkItem() with ThreadPool.UnsafeQueueUserWorkItem() since OpenSim does not use Code Access Security sandboxing
Diffstat (limited to 'OpenSim/Data/NHibernate/NHibernateInventoryData.cs')
-rw-r--r--OpenSim/Data/NHibernate/NHibernateInventoryData.cs382
1 files changed, 0 insertions, 382 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs
deleted file mode 100644
index 130be7e..0000000
--- a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs
+++ /dev/null
@@ -1,382 +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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using log4net;
32using NHibernate;
33using NHibernate.Criterion;
34using OpenMetaverse;
35using OpenSim.Framework;
36
37namespace OpenSim.Data.NHibernate
38{
39 public class NHibernateInventoryData: IInventoryDataPlugin
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 private NHibernateManager manager;
44 public NHibernateManager Manager
45 {
46 get
47 {
48 return manager;
49 }
50 }
51
52 /// <summary>
53 /// The plugin being loaded
54 /// </summary>
55 /// <returns>A string containing the plugin name</returns>
56 public string Name
57 {
58 get { return "NHibernate Inventory Data Interface"; }
59 }
60
61 /// <summary>
62 /// The plugins version
63 /// </summary>
64 /// <returns>A string containing the plugin version</returns>
65 public string Version
66 {
67 get
68 {
69 Module module = GetType().Module;
70 // string dllName = module.Assembly.ManifestModule.Name;
71 Version dllVersion = module.Assembly.GetName().Version;
72
73
74 return
75 string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build,
76 dllVersion.Revision);
77 }
78 }
79
80 public void Initialise()
81 {
82 m_log.Info("[NHibernateInventoryData]: " + Name + " cannot be default-initialized!");
83 throw new PluginNotInitialisedException (Name);
84 }
85
86 /// <summary>
87 /// Initialises the interface
88 /// </summary>
89 public void Initialise(string connect)
90 {
91 m_log.InfoFormat("[NHIBERNATE] Initializing NHibernateInventoryData");
92 manager = new NHibernateManager(connect, "InventoryStore");
93 }
94
95 /// <summary>
96 /// Closes the interface
97 /// </summary>
98 public void Dispose()
99 {
100 }
101
102 /*****************************************************************
103 *
104 * Basic CRUD operations on Data
105 *
106 ****************************************************************/
107
108 // READ
109
110 /// <summary>
111 /// Returns an inventory item by its UUID
112 /// </summary>
113 /// <param name="item">The UUID of the item to be returned</param>
114 /// <returns>A class containing item information</returns>
115 public InventoryItemBase getInventoryItem(UUID item)
116 {
117 try
118 {
119 m_log.InfoFormat("[NHIBERNATE] getInventoryItem {0}", item);
120 return (InventoryItemBase)manager.Get(typeof(InventoryItemBase), item);
121 }
122 catch
123 {
124 m_log.ErrorFormat("Couldn't find inventory item: {0}", item);
125 return null;
126 }
127 }
128
129 /// <summary>
130 /// Creates a new inventory item based on item
131 /// </summary>
132 /// <param name="item">The item to be created</param>
133 public void addInventoryItem(InventoryItemBase item)
134 {
135 if (!ExistsItem(item.ID))
136 {
137 manager.Insert(item);
138 }
139 else
140 {
141 m_log.ErrorFormat("[NHIBERNATE] Attempted to add Inventory Item {0} that already exists, updating instead", item.ID);
142 updateInventoryItem(item);
143 }
144 }
145
146 /// <summary>
147 /// Updates an inventory item with item (updates based on ID)
148 /// </summary>
149 /// <param name="item">The updated item</param>
150 public void updateInventoryItem(InventoryItemBase item)
151 {
152 if (ExistsItem(item.ID))
153 {
154 manager.Update(item);
155 }
156 else
157 {
158 m_log.ErrorFormat("[NHIBERNATE] Attempted to add Inventory Item {0} that already exists", item.ID);
159 }
160 }
161
162 /// <summary>
163 ///
164 /// </summary>
165 /// <param name="item"></param>
166 public void deleteInventoryItem(UUID itemID)
167 {
168 InventoryItemBase item = (InventoryItemBase)manager.Get(typeof(InventoryItemBase), itemID);
169 if (item != null)
170 {
171 manager.Delete(item);
172 }
173 else
174 {
175 m_log.ErrorFormat("[NHIBERNATE] Error deleting InventoryItemBase {0}", itemID);
176 }
177
178 }
179
180 public InventoryItemBase queryInventoryItem(UUID itemID)
181 {
182 return null;
183 }
184
185 public InventoryFolderBase queryInventoryFolder(UUID folderID)
186 {
187 return null;
188 }
189
190 /// <summary>
191 /// Returns an inventory folder by its UUID
192 /// </summary>
193 /// <param name="folder">The UUID of the folder to be returned</param>
194 /// <returns>A class containing folder information</returns>
195 public InventoryFolderBase getInventoryFolder(UUID folder)
196 {
197 try
198 {
199 return (InventoryFolderBase)manager.Get(typeof(InventoryFolderBase), folder);
200 }
201 catch
202 {
203 m_log.ErrorFormat("[NHIBERNATE] Couldn't find inventory item: {0}", folder);
204 return null;
205 }
206 }
207
208 /// <summary>
209 /// Creates a new inventory folder based on folder
210 /// </summary>
211 /// <param name="folder">The folder to be created</param>
212 public void addInventoryFolder(InventoryFolderBase folder)
213 {
214 if (!ExistsFolder(folder.ID))
215 {
216 manager.Insert(folder);
217 }
218 else
219 {
220 m_log.ErrorFormat("[NHIBERNATE] Attempted to add Inventory Folder {0} that already exists, updating instead", folder.ID);
221 updateInventoryFolder(folder);
222 }
223 }
224
225 /// <summary>
226 /// Updates an inventory folder with folder (updates based on ID)
227 /// </summary>
228 /// <param name="folder">The updated folder</param>
229 public void updateInventoryFolder(InventoryFolderBase folder)
230 {
231 if (ExistsFolder(folder.ID))
232 {
233 manager.Update(folder);
234 }
235 else
236 {
237 m_log.ErrorFormat("[NHIBERNATE] Attempted to add Inventory Folder {0} that already exists", folder.ID);
238 }
239 }
240
241 /// <summary>
242 ///
243 /// </summary>
244 /// <param name="folder"></param>
245 public void deleteInventoryFolder(UUID folderID)
246 {
247 InventoryFolderBase item = (InventoryFolderBase)manager.Get(typeof(InventoryFolderBase), folderID);
248 if (item != null)
249 {
250 manager.Delete(item);
251 }
252 else
253 {
254 m_log.ErrorFormat("[NHIBERNATE] Error deleting InventoryFolderBase {0}", folderID);
255 }
256 manager.Delete(folderID);
257 }
258
259 // useful private methods
260 private bool ExistsItem(UUID uuid)
261 {
262 return (getInventoryItem(uuid) != null) ? true : false;
263 }
264
265 private bool ExistsFolder(UUID uuid)
266 {
267 return (getInventoryFolder(uuid) != null) ? true : false;
268 }
269
270 public void Shutdown()
271 {
272 // TODO: DataSet commit
273 }
274
275 // Move seems to be just update
276
277 public void moveInventoryFolder(InventoryFolderBase folder)
278 {
279 updateInventoryFolder(folder);
280 }
281
282 public void moveInventoryItem(InventoryItemBase item)
283 {
284 updateInventoryItem(item);
285 }
286
287
288
289 /// <summary>
290 /// Returns a list of inventory items contained within the specified folder
291 /// </summary>
292 /// <param name="folderID">The UUID of the target folder</param>
293 /// <returns>A List of InventoryItemBase items</returns>
294 public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
295 {
296 // try {
297 ICriteria criteria = manager.GetSession().CreateCriteria(typeof(InventoryItemBase));
298 criteria.Add(Expression.Eq("Folder", folderID));
299 List<InventoryItemBase> list = new List<InventoryItemBase>();
300 foreach (InventoryItemBase item in criteria.List())
301 {
302 list.Add(item);
303 }
304 return list;
305 // }
306 // catch
307 // {
308 // return new List<InventoryItemBase>();
309 // }
310 }
311
312 public List<InventoryFolderBase> getUserRootFolders(UUID user)
313 {
314 return new List<InventoryFolderBase>();
315 }
316
317 // see InventoryItemBase.getUserRootFolder
318 public InventoryFolderBase getUserRootFolder(UUID user)
319 {
320 ICriteria criteria = manager.GetSession().CreateCriteria(typeof(InventoryFolderBase));
321 criteria.Add(Expression.Eq("ParentID", UUID.Zero));
322 criteria.Add(Expression.Eq("Owner", user));
323 foreach (InventoryFolderBase folder in criteria.List())
324 {
325 return folder;
326 }
327 m_log.ErrorFormat("No Inventory Root Folder Found for: {0}", user);
328 return null;
329 }
330
331 /// <summary>
332 /// Append a list of all the child folders of a parent folder
333 /// </summary>
334 /// <param name="folders">list where folders will be appended</param>
335 /// <param name="parentID">ID of parent</param>
336 private void getInventoryFolders(ref List<InventoryFolderBase> folders, UUID parentID)
337 {
338 ICriteria criteria = manager.GetSession().CreateCriteria(typeof(InventoryFolderBase));
339 criteria.Add(Expression.Eq("ParentID", parentID));
340 foreach (InventoryFolderBase item in criteria.List())
341 {
342 folders.Add(item);
343 }
344 }
345
346 /// <summary>
347 /// Returns a list of inventory folders contained in the folder 'parentID'
348 /// </summary>
349 /// <param name="parentID">The folder to get subfolders for</param>
350 /// <returns>A list of inventory folders</returns>
351 public List<InventoryFolderBase> getInventoryFolders(UUID parentID)
352 {
353 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
354 getInventoryFolders(ref folders, parentID);
355 return folders;
356 }
357
358 // See IInventoryDataPlugin
359 public List<InventoryFolderBase> getFolderHierarchy(UUID parentID)
360 {
361 if (parentID == UUID.Zero)
362 {
363 // Zero UUID is not a real parent folder.
364 return new List<InventoryFolderBase>();
365 }
366
367 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
368
369 getInventoryFolders(ref folders, parentID);
370
371 for (int i = 0; i < folders.Count; i++)
372 getInventoryFolders(ref folders, folders[i].ID);
373
374 return folders;
375 }
376
377 public List<InventoryItemBase> fetchActiveGestures (UUID avatarID)
378 {
379 return null;
380 }
381 }
382}