aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MSSQL/MSSQLXInventoryData.cs')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLXInventoryData.cs305
1 files changed, 0 insertions, 305 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs
deleted file mode 100644
index bfef682..0000000
--- a/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs
+++ /dev/null
@@ -1,305 +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;
30using System.Collections.Generic;
31using System.Data;
32using OpenMetaverse;
33using OpenSim.Framework;
34using System.Data.SqlClient;
35using System.Reflection;
36using System.Text;
37using log4net;
38
39namespace OpenSim.Data.MSSQL
40{
41 public class MSSQLXInventoryData : IXInventoryData
42 {
43// private static readonly ILog m_log = LogManager.GetLogger(
44// MethodBase.GetCurrentMethod().DeclaringType);
45
46 private MSSQLFolderHandler m_Folders;
47 private MSSQLItemHandler m_Items;
48
49 public MSSQLXInventoryData(string conn, string realm)
50 {
51 m_Folders = new MSSQLFolderHandler(
52 conn, "inventoryfolders", "InventoryStore");
53 m_Items = new MSSQLItemHandler(
54 conn, "inventoryitems", String.Empty);
55 }
56
57 public XInventoryFolder[] GetFolders(string[] fields, string[] vals)
58 {
59 return m_Folders.Get(fields, vals);
60 }
61
62 public XInventoryItem[] GetItems(string[] fields, string[] vals)
63 {
64 return m_Items.Get(fields, vals);
65 }
66
67 public bool StoreFolder(XInventoryFolder folder)
68 {
69 if (folder.folderName.Length > 64)
70 folder.folderName = folder.folderName.Substring(0, 64);
71 return m_Folders.Store(folder);
72 }
73
74 public bool StoreItem(XInventoryItem item)
75 {
76 if (item.inventoryName.Length > 64)
77 item.inventoryName = item.inventoryName.Substring(0, 64);
78 if (item.inventoryDescription.Length > 128)
79 item.inventoryDescription = item.inventoryDescription.Substring(0, 128);
80
81 return m_Items.Store(item);
82 }
83
84 public bool DeleteFolders(string field, string val)
85 {
86 return m_Folders.Delete(field, val);
87 }
88
89 public bool DeleteFolders(string[] fields, string[] vals)
90 {
91 return m_Folders.Delete(fields, vals);
92 }
93
94 public bool DeleteItems(string field, string val)
95 {
96 return m_Items.Delete(field, val);
97 }
98
99 public bool DeleteItems(string[] fields, string[] vals)
100 {
101 return m_Items.Delete(fields, vals);
102 }
103
104 public bool MoveItem(string id, string newParent)
105 {
106 return m_Items.MoveItem(id, newParent);
107 }
108
109 public bool MoveFolder(string id, string newParent)
110 {
111 return m_Folders.MoveFolder(id, newParent);
112 }
113
114 public XInventoryItem[] GetActiveGestures(UUID principalID)
115 {
116 return m_Items.GetActiveGestures(principalID);
117 }
118
119 public int GetAssetPermissions(UUID principalID, UUID assetID)
120 {
121 return m_Items.GetAssetPermissions(principalID, assetID);
122 }
123 }
124
125 public class MSSQLItemHandler : MSSQLInventoryHandler<XInventoryItem>
126 {
127 public MSSQLItemHandler(string c, string t, string m) :
128 base(c, t, m)
129 {
130 }
131
132 public bool MoveItem(string id, string newParent)
133 {
134 XInventoryItem[] retrievedItems = Get(new string[] { "inventoryID" }, new string[] { id });
135 if (retrievedItems.Length == 0)
136 return false;
137
138 UUID oldParent = retrievedItems[0].parentFolderID;
139
140 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
141 {
142 using (SqlCommand cmd = new SqlCommand())
143 {
144
145 cmd.CommandText = String.Format("update {0} set parentFolderID = @ParentFolderID where inventoryID = @InventoryID", m_Realm);
146 cmd.Parameters.Add(m_database.CreateParameter("@ParentFolderID", newParent));
147 cmd.Parameters.Add(m_database.CreateParameter("@InventoryID", id));
148 cmd.Connection = conn;
149 conn.Open();
150
151 if (cmd.ExecuteNonQuery() == 0)
152 return false;
153 }
154 }
155
156 IncrementFolderVersion(oldParent);
157 IncrementFolderVersion(newParent);
158
159 return true;
160 }
161
162 public XInventoryItem[] GetActiveGestures(UUID principalID)
163 {
164 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
165 {
166 using (SqlCommand cmd = new SqlCommand())
167 {
168 cmd.CommandText = String.Format("select * from inventoryitems where avatarId = @uuid and assetType = @type and flags = 1", m_Realm);
169
170 cmd.Parameters.Add(m_database.CreateParameter("@uuid", principalID.ToString()));
171 cmd.Parameters.Add(m_database.CreateParameter("@type", (int)AssetType.Gesture));
172 cmd.Connection = conn;
173 conn.Open();
174 return DoQuery(cmd);
175 }
176 }
177 }
178
179 public int GetAssetPermissions(UUID principalID, UUID assetID)
180 {
181 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
182 {
183 using (SqlCommand cmd = new SqlCommand())
184 {
185 cmd.CommandText = String.Format("select bit_or(inventoryCurrentPermissions) as inventoryCurrentPermissions from inventoryitems where avatarID = @PrincipalID and assetID = @AssetID group by assetID", m_Realm);
186 cmd.Parameters.Add(m_database.CreateParameter("@PrincipalID", principalID.ToString()));
187 cmd.Parameters.Add(m_database.CreateParameter("@AssetID", assetID.ToString()));
188 cmd.Connection = conn;
189 conn.Open();
190 using (SqlDataReader reader = cmd.ExecuteReader())
191 {
192
193 int perms = 0;
194
195 if (reader.Read())
196 {
197 perms = Convert.ToInt32(reader["inventoryCurrentPermissions"]);
198 }
199
200 return perms;
201 }
202
203 }
204 }
205 }
206
207 public override bool Store(XInventoryItem item)
208 {
209 if (!base.Store(item))
210 return false;
211
212 IncrementFolderVersion(item.parentFolderID);
213
214 return true;
215 }
216 }
217
218 public class MSSQLFolderHandler : MSSQLInventoryHandler<XInventoryFolder>
219 {
220 public MSSQLFolderHandler(string c, string t, string m) :
221 base(c, t, m)
222 {
223 }
224
225 public bool MoveFolder(string id, string newParentFolderID)
226 {
227 XInventoryFolder[] folders = Get(new string[] { "folderID" }, new string[] { id });
228
229 if (folders.Length == 0)
230 return false;
231
232 UUID oldParentFolderUUID = folders[0].parentFolderID;
233
234 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
235 {
236 using (SqlCommand cmd = new SqlCommand())
237 {
238
239 cmd.CommandText = String.Format("update {0} set parentFolderID = @ParentFolderID where folderID = @folderID", m_Realm);
240 cmd.Parameters.Add(m_database.CreateParameter("@ParentFolderID", newParentFolderID));
241 cmd.Parameters.Add(m_database.CreateParameter("@folderID", id));
242 cmd.Connection = conn;
243 conn.Open();
244
245 if (cmd.ExecuteNonQuery() == 0)
246 return false;
247 }
248 }
249
250 IncrementFolderVersion(oldParentFolderUUID);
251 IncrementFolderVersion(newParentFolderID);
252
253 return true;
254 }
255
256 public override bool Store(XInventoryFolder folder)
257 {
258 if (!base.Store(folder))
259 return false;
260
261 IncrementFolderVersion(folder.parentFolderID);
262
263 return true;
264 }
265 }
266
267 public class MSSQLInventoryHandler<T> : MSSQLGenericTableHandler<T> where T: class, new()
268 {
269 public MSSQLInventoryHandler(string c, string t, string m) : base(c, t, m) {}
270
271 protected bool IncrementFolderVersion(UUID folderID)
272 {
273 return IncrementFolderVersion(folderID.ToString());
274 }
275
276 protected bool IncrementFolderVersion(string folderID)
277 {
278// m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID);
279// Util.PrintCallStack();
280
281 string sql = "update inventoryfolders set version=version+1 where folderID = @folderID";
282
283 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
284 {
285 using (SqlCommand cmd = new SqlCommand(sql, conn))
286 {
287 conn.Open();
288
289 cmd.Parameters.AddWithValue("@folderID", folderID);
290
291 try
292 {
293 cmd.ExecuteNonQuery();
294 }
295 catch (Exception)
296 {
297 return false;
298 }
299 }
300 }
301
302 return true;
303 }
304 }
305} \ No newline at end of file