aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL')
-rw-r--r--OpenSim/Data/MySQL/MySQLGenericTableHandler.cs6
-rw-r--r--OpenSim/Data/MySQL/MySQLXInventoryData.cs138
-rw-r--r--OpenSim/Data/MySQL/Properties/AssemblyInfo.cs2
3 files changed, 137 insertions, 9 deletions
diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
index da8e958..995c6a5 100644
--- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
+++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
@@ -219,6 +219,8 @@ namespace OpenSim.Data.MySQL
219 219
220 public virtual bool Store(T row) 220 public virtual bool Store(T row)
221 { 221 {
222// m_log.DebugFormat("[MYSQL GENERIC TABLE HANDLER]: Store(T row) invoked");
223
222 using (MySqlCommand cmd = new MySqlCommand()) 224 using (MySqlCommand cmd = new MySqlCommand())
223 { 225 {
224 string query = ""; 226 string query = "";
@@ -273,6 +275,10 @@ namespace OpenSim.Data.MySQL
273 275
274 public virtual bool Delete(string[] fields, string[] keys) 276 public virtual bool Delete(string[] fields, string[] keys)
275 { 277 {
278// m_log.DebugFormat(
279// "[MYSQL GENERIC TABLE HANDLER]: Delete(string[] fields, string[] keys) invoked with {0}:{1}",
280// string.Join(",", fields), string.Join(",", keys));
281
276 if (fields.Length != keys.Length) 282 if (fields.Length != keys.Length)
277 return false; 283 return false;
278 284
diff --git a/OpenSim/Data/MySQL/MySQLXInventoryData.cs b/OpenSim/Data/MySQL/MySQLXInventoryData.cs
index caf18a4..c74033e 100644
--- a/OpenSim/Data/MySQL/MySQLXInventoryData.cs
+++ b/OpenSim/Data/MySQL/MySQLXInventoryData.cs
@@ -26,9 +26,10 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using System.Data; 30using System.Data;
31using System.Linq;
30using System.Reflection; 32using System.Reflection;
31using System.Collections.Generic;
32using log4net; 33using log4net;
33using MySql.Data.MySqlClient; 34using MySql.Data.MySqlClient;
34using OpenMetaverse; 35using OpenMetaverse;
@@ -41,12 +42,12 @@ namespace OpenSim.Data.MySQL
41 /// </summary> 42 /// </summary>
42 public class MySQLXInventoryData : IXInventoryData 43 public class MySQLXInventoryData : IXInventoryData
43 { 44 {
44 private MySQLGenericTableHandler<XInventoryFolder> m_Folders; 45 private MySqlFolderHandler m_Folders;
45 private MySqlItemHandler m_Items; 46 private MySqlItemHandler m_Items;
46 47
47 public MySQLXInventoryData(string conn, string realm) 48 public MySQLXInventoryData(string conn, string realm)
48 { 49 {
49 m_Folders = new MySQLGenericTableHandler<XInventoryFolder>( 50 m_Folders = new MySqlFolderHandler(
50 conn, "inventoryfolders", "InventoryStore"); 51 conn, "inventoryfolders", "InventoryStore");
51 m_Items = new MySqlItemHandler( 52 m_Items = new MySqlItemHandler(
52 conn, "inventoryitems", String.Empty); 53 conn, "inventoryitems", String.Empty);
@@ -105,6 +106,11 @@ namespace OpenSim.Data.MySQL
105 return m_Items.MoveItem(id, newParent); 106 return m_Items.MoveItem(id, newParent);
106 } 107 }
107 108
109 public bool MoveFolder(string id, string newParent)
110 {
111 return m_Folders.MoveFolder(id, newParent);
112 }
113
108 public XInventoryItem[] GetActiveGestures(UUID principalID) 114 public XInventoryItem[] GetActiveGestures(UUID principalID)
109 { 115 {
110 return m_Items.GetActiveGestures(principalID); 116 return m_Items.GetActiveGestures(principalID);
@@ -116,24 +122,71 @@ namespace OpenSim.Data.MySQL
116 } 122 }
117 } 123 }
118 124
119 public class MySqlItemHandler : MySQLGenericTableHandler<XInventoryItem> 125 public class MySqlItemHandler : MySqlInventoryHandler<XInventoryItem>
120 { 126 {
127// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
128
121 public MySqlItemHandler(string c, string t, string m) : 129 public MySqlItemHandler(string c, string t, string m) :
122 base(c, t, m) 130 base(c, t, m)
123 { 131 {
124 } 132 }
125 133
134 public override bool Delete(string field, string val)
135 {
136 XInventoryItem[] retrievedItems = Get(new string[] { field }, new string[] { val });
137 if (retrievedItems.Length == 0)
138 return false;
139
140 if (!base.Delete(field, val))
141 return false;
142
143 // Don't increment folder version here since Delete(string, string) calls Delete(string[], string[])
144// IncrementFolderVersion(retrievedItems[0].parentFolderID);
145
146 return true;
147 }
148
149 public override bool Delete(string[] fields, string[] vals)
150 {
151 XInventoryItem[] retrievedItems = Get(fields, vals);
152 if (retrievedItems.Length == 0)
153 return false;
154
155 if (!base.Delete(fields, vals))
156 return false;
157
158 HashSet<UUID> deletedItemFolderUUIDs = new HashSet<UUID>();
159
160 Array.ForEach<XInventoryItem>(retrievedItems, i => deletedItemFolderUUIDs.Add(i.parentFolderID));
161
162 foreach (UUID deletedItemFolderUUID in deletedItemFolderUUIDs)
163 IncrementFolderVersion(deletedItemFolderUUID);
164
165 return true;
166 }
167
126 public bool MoveItem(string id, string newParent) 168 public bool MoveItem(string id, string newParent)
127 { 169 {
170 XInventoryItem[] retrievedItems = Get(new string[] { "inventoryID" }, new string[] { id });
171 if (retrievedItems.Length == 0)
172 return false;
173
174 UUID oldParent = retrievedItems[0].parentFolderID;
175
128 using (MySqlCommand cmd = new MySqlCommand()) 176 using (MySqlCommand cmd = new MySqlCommand())
129 { 177 {
130
131 cmd.CommandText = String.Format("update {0} set parentFolderID = ?ParentFolderID where inventoryID = ?InventoryID", m_Realm); 178 cmd.CommandText = String.Format("update {0} set parentFolderID = ?ParentFolderID where inventoryID = ?InventoryID", m_Realm);
132 cmd.Parameters.AddWithValue("?ParentFolderID", newParent); 179 cmd.Parameters.AddWithValue("?ParentFolderID", newParent);
133 cmd.Parameters.AddWithValue("?InventoryID", id); 180 cmd.Parameters.AddWithValue("?InventoryID", id);
134 181
135 return ExecuteNonQuery(cmd) == 0 ? false : true; 182 if (ExecuteNonQuery(cmd) == 0)
183 return false;
136 } 184 }
185
186 IncrementFolderVersion(oldParent);
187 IncrementFolderVersion(newParent);
188
189 return true;
137 } 190 }
138 191
139 public XInventoryItem[] GetActiveGestures(UUID principalID) 192 public XInventoryItem[] GetActiveGestures(UUID principalID)
@@ -184,6 +237,73 @@ namespace OpenSim.Data.MySQL
184 if (!base.Store(item)) 237 if (!base.Store(item))
185 return false; 238 return false;
186 239
240 IncrementFolderVersion(item.parentFolderID);
241
242 return true;
243 }
244 }
245
246 public class MySqlFolderHandler : MySqlInventoryHandler<XInventoryFolder>
247 {
248// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
249
250 public MySqlFolderHandler(string c, string t, string m) :
251 base(c, t, m)
252 {
253 }
254
255 public bool MoveFolder(string id, string newParentFolderID)
256 {
257 XInventoryFolder[] folders = Get(new string[] { "folderID" }, new string[] { id });
258
259 if (folders.Length == 0)
260 return false;
261
262 UUID oldParentFolderUUID = folders[0].parentFolderID;
263
264 using (MySqlCommand cmd = new MySqlCommand())
265 {
266 cmd.CommandText
267 = String.Format(
268 "update {0} set parentFolderID = ?ParentFolderID where folderID = ?folderID", m_Realm);
269 cmd.Parameters.AddWithValue("?ParentFolderID", newParentFolderID);
270 cmd.Parameters.AddWithValue("?folderID", id);
271
272 if (ExecuteNonQuery(cmd) == 0)
273 return false;
274 }
275
276 IncrementFolderVersion(oldParentFolderUUID);
277 IncrementFolderVersion(newParentFolderID);
278
279 return true;
280 }
281
282 public override bool Store(XInventoryFolder folder)
283 {
284 if (!base.Store(folder))
285 return false;
286
287 IncrementFolderVersion(folder.parentFolderID);
288
289 return true;
290 }
291 }
292
293 public class MySqlInventoryHandler<T> : MySQLGenericTableHandler<T> where T: class, new()
294 {
295 public MySqlInventoryHandler(string c, string t, string m) : base(c, t, m) {}
296
297 protected bool IncrementFolderVersion(UUID folderID)
298 {
299 return IncrementFolderVersion(folderID.ToString());
300 }
301
302 protected bool IncrementFolderVersion(string folderID)
303 {
304// m_log.DebugFormat("[MYSQL FOLDER HANDLER]: Incrementing version on folder {0}", folderID);
305// Util.PrintCallStack();
306
187 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 307 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
188 { 308 {
189 dbcon.Open(); 309 dbcon.Open();
@@ -193,7 +313,7 @@ namespace OpenSim.Data.MySQL
193 cmd.Connection = dbcon; 313 cmd.Connection = dbcon;
194 314
195 cmd.CommandText = String.Format("update inventoryfolders set version=version+1 where folderID = ?folderID"); 315 cmd.CommandText = String.Format("update inventoryfolders set version=version+1 where folderID = ?folderID");
196 cmd.Parameters.AddWithValue("?folderID", item.parentFolderID.ToString()); 316 cmd.Parameters.AddWithValue("?folderID", folderID);
197 317
198 try 318 try
199 { 319 {
@@ -205,9 +325,11 @@ namespace OpenSim.Data.MySQL
205 } 325 }
206 cmd.Dispose(); 326 cmd.Dispose();
207 } 327 }
328
208 dbcon.Close(); 329 dbcon.Close();
209 } 330 }
331
210 return true; 332 return true;
211 } 333 }
212 } 334 }
213} 335} \ No newline at end of file
diff --git a/OpenSim/Data/MySQL/Properties/AssemblyInfo.cs b/OpenSim/Data/MySQL/Properties/AssemblyInfo.cs
index c28829c..ab3fe36 100644
--- a/OpenSim/Data/MySQL/Properties/AssemblyInfo.cs
+++ b/OpenSim/Data/MySQL/Properties/AssemblyInfo.cs
@@ -61,5 +61,5 @@ using System.Runtime.InteropServices;
61// You can specify all the values or you can default the Revision and Build Numbers 61// You can specify all the values or you can default the Revision and Build Numbers
62// by using the '*' as shown below: 62// by using the '*' as shown below:
63 63
64[assembly : AssemblyVersion("0.6.5.*")] 64[assembly : AssemblyVersion("0.7.5.*")]
65[assembly : AssemblyFileVersion("0.6.5.0")] 65[assembly : AssemblyFileVersion("0.6.5.0")]