diff options
author | Justin Clark-Casey (justincc) | 2012-11-15 03:29:55 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-11-15 03:29:55 +0000 |
commit | 1aa027123982b710313ea0e15efe7fc85db1c9ea (patch) | |
tree | 75106a9369d6453eaa96fb4a1b2093ccf231fb72 /OpenSim/Data/SQLite | |
parent | Handle Map block requests on a separate thread rather than the main packet ha... (diff) | |
download | opensim-SC_OLD-1aa027123982b710313ea0e15efe7fc85db1c9ea.zip opensim-SC_OLD-1aa027123982b710313ea0e15efe7fc85db1c9ea.tar.gz opensim-SC_OLD-1aa027123982b710313ea0e15efe7fc85db1c9ea.tar.bz2 opensim-SC_OLD-1aa027123982b710313ea0e15efe7fc85db1c9ea.tar.xz |
Implement folder version updating for the sqlite inventory plugin
Diffstat (limited to 'OpenSim/Data/SQLite')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs | 10 | ||||
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteXInventoryData.cs | 139 |
2 files changed, 142 insertions, 7 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs index 917a0a1..9fbeb10 100644 --- a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs +++ b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs | |||
@@ -120,12 +120,12 @@ namespace OpenSim.Data.SQLite | |||
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | public T[] Get(string field, string key) | 123 | public virtual T[] Get(string field, string key) |
124 | { | 124 | { |
125 | return Get(new string[] { field }, new string[] { key }); | 125 | return Get(new string[] { field }, new string[] { key }); |
126 | } | 126 | } |
127 | 127 | ||
128 | public T[] Get(string[] fields, string[] keys) | 128 | public virtual T[] Get(string[] fields, string[] keys) |
129 | { | 129 | { |
130 | if (fields.Length != keys.Length) | 130 | if (fields.Length != keys.Length) |
131 | return new T[0]; | 131 | return new T[0]; |
@@ -213,7 +213,7 @@ namespace OpenSim.Data.SQLite | |||
213 | return result.ToArray(); | 213 | return result.ToArray(); |
214 | } | 214 | } |
215 | 215 | ||
216 | public T[] Get(string where) | 216 | public virtual T[] Get(string where) |
217 | { | 217 | { |
218 | using (SqliteCommand cmd = new SqliteCommand()) | 218 | using (SqliteCommand cmd = new SqliteCommand()) |
219 | { | 219 | { |
@@ -226,7 +226,7 @@ namespace OpenSim.Data.SQLite | |||
226 | } | 226 | } |
227 | } | 227 | } |
228 | 228 | ||
229 | public bool Store(T row) | 229 | public virtual bool Store(T row) |
230 | { | 230 | { |
231 | using (SqliteCommand cmd = new SqliteCommand()) | 231 | using (SqliteCommand cmd = new SqliteCommand()) |
232 | { | 232 | { |
@@ -270,7 +270,7 @@ namespace OpenSim.Data.SQLite | |||
270 | return Delete(new string[] { field }, new string[] { key }); | 270 | return Delete(new string[] { field }, new string[] { key }); |
271 | } | 271 | } |
272 | 272 | ||
273 | public bool Delete(string[] fields, string[] keys) | 273 | public virtual bool Delete(string[] fields, string[] keys) |
274 | { | 274 | { |
275 | if (fields.Length != keys.Length) | 275 | if (fields.Length != keys.Length) |
276 | return false; | 276 | return false; |
diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs index 8eb1a63..87eb31e 100644 --- a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs +++ b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs | |||
@@ -137,16 +137,72 @@ namespace OpenSim.Data.SQLite | |||
137 | { | 137 | { |
138 | } | 138 | } |
139 | 139 | ||
140 | public override bool Store(XInventoryItem item) | ||
141 | { | ||
142 | if (!base.Store(item)) | ||
143 | return false; | ||
144 | |||
145 | IncrementFolderVersion(item.parentFolderID); | ||
146 | |||
147 | return true; | ||
148 | } | ||
149 | |||
150 | public override bool Delete(string field, string val) | ||
151 | { | ||
152 | XInventoryItem[] retrievedItems = Get(new string[] { field }, new string[] { val }); | ||
153 | if (retrievedItems.Length == 0) | ||
154 | return false; | ||
155 | |||
156 | if (!base.Delete(field, val)) | ||
157 | return false; | ||
158 | |||
159 | // Don't increment folder version here since Delete(string, string) calls Delete(string[], string[]) | ||
160 | // IncrementFolderVersion(retrievedItems[0].parentFolderID); | ||
161 | |||
162 | return true; | ||
163 | } | ||
164 | |||
165 | public override bool Delete(string[] fields, string[] vals) | ||
166 | { | ||
167 | XInventoryItem[] retrievedItems = Get(fields, vals); | ||
168 | if (retrievedItems.Length == 0) | ||
169 | return false; | ||
170 | |||
171 | if (!base.Delete(fields, vals)) | ||
172 | return false; | ||
173 | |||
174 | HashSet<UUID> deletedItemFolderUUIDs = new HashSet<UUID>(); | ||
175 | |||
176 | Array.ForEach<XInventoryItem>(retrievedItems, i => deletedItemFolderUUIDs.Add(i.parentFolderID)); | ||
177 | |||
178 | foreach (UUID deletedItemFolderUUID in deletedItemFolderUUIDs) | ||
179 | IncrementFolderVersion(deletedItemFolderUUID); | ||
180 | |||
181 | return true; | ||
182 | } | ||
183 | |||
140 | public bool MoveItem(string id, string newParent) | 184 | public bool MoveItem(string id, string newParent) |
141 | { | 185 | { |
186 | XInventoryItem[] retrievedItems = Get(new string[] { "inventoryID" }, new string[] { id }); | ||
187 | if (retrievedItems.Length == 0) | ||
188 | return false; | ||
189 | |||
190 | UUID oldParent = retrievedItems[0].parentFolderID; | ||
191 | |||
142 | using (SqliteCommand cmd = new SqliteCommand()) | 192 | using (SqliteCommand cmd = new SqliteCommand()) |
143 | { | 193 | { |
144 | cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where inventoryID = :InventoryID", m_Realm); | 194 | cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where inventoryID = :InventoryID", m_Realm); |
145 | cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParent)); | 195 | cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParent)); |
146 | cmd.Parameters.Add(new SqliteParameter(":InventoryID", id)); | 196 | cmd.Parameters.Add(new SqliteParameter(":InventoryID", id)); |
147 | 197 | ||
148 | return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true; | 198 | if (ExecuteNonQuery(cmd, m_Connection) == 0) |
199 | return false; | ||
149 | } | 200 | } |
201 | |||
202 | IncrementFolderVersion(oldParent); | ||
203 | IncrementFolderVersion(newParent); | ||
204 | |||
205 | return true; | ||
150 | } | 206 | } |
151 | 207 | ||
152 | public XInventoryItem[] GetActiveGestures(UUID principalID) | 208 | public XInventoryItem[] GetActiveGestures(UUID principalID) |
@@ -187,6 +243,34 @@ namespace OpenSim.Data.SQLite | |||
187 | 243 | ||
188 | return perms; | 244 | return perms; |
189 | } | 245 | } |
246 | |||
247 | private bool IncrementFolderVersion(UUID folderID) | ||
248 | { | ||
249 | return IncrementFolderVersion(folderID.ToString()); | ||
250 | } | ||
251 | |||
252 | private bool IncrementFolderVersion(string folderID) | ||
253 | { | ||
254 | // m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID); | ||
255 | // Util.PrintCallStack(); | ||
256 | |||
257 | using (SqliteCommand cmd = new SqliteCommand()) | ||
258 | { | ||
259 | cmd.CommandText = "update inventoryfolders set version=version+1 where folderID = ?folderID"; | ||
260 | cmd.Parameters.Add(new SqliteParameter(":folderID", folderID)); | ||
261 | |||
262 | try | ||
263 | { | ||
264 | cmd.ExecuteNonQuery(); | ||
265 | } | ||
266 | catch (Exception) | ||
267 | { | ||
268 | return false; | ||
269 | } | ||
270 | } | ||
271 | |||
272 | return true; | ||
273 | } | ||
190 | } | 274 | } |
191 | 275 | ||
192 | public class SqliteFolderHandler : SQLiteGenericTableHandler<XInventoryFolder> | 276 | public class SqliteFolderHandler : SQLiteGenericTableHandler<XInventoryFolder> |
@@ -196,16 +280,67 @@ namespace OpenSim.Data.SQLite | |||
196 | { | 280 | { |
197 | } | 281 | } |
198 | 282 | ||
283 | public override bool Store(XInventoryFolder folder) | ||
284 | { | ||
285 | if (!base.Store(folder)) | ||
286 | return false; | ||
287 | |||
288 | IncrementFolderVersion(folder.parentFolderID); | ||
289 | |||
290 | return true; | ||
291 | } | ||
292 | |||
199 | public bool MoveFolder(string id, string newParentFolderID) | 293 | public bool MoveFolder(string id, string newParentFolderID) |
200 | { | 294 | { |
295 | XInventoryFolder[] folders = Get(new string[] { "folderID" }, new string[] { id }); | ||
296 | |||
297 | if (folders.Length == 0) | ||
298 | return false; | ||
299 | |||
300 | UUID oldParentFolderUUID = folders[0].parentFolderID; | ||
301 | |||
201 | using (SqliteCommand cmd = new SqliteCommand()) | 302 | using (SqliteCommand cmd = new SqliteCommand()) |
202 | { | 303 | { |
203 | cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where folderID = :FolderID", m_Realm); | 304 | cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where folderID = :FolderID", m_Realm); |
204 | cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParentFolderID)); | 305 | cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParentFolderID)); |
205 | cmd.Parameters.Add(new SqliteParameter(":FolderID", id)); | 306 | cmd.Parameters.Add(new SqliteParameter(":FolderID", id)); |
206 | 307 | ||
207 | return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true; | 308 | if (ExecuteNonQuery(cmd, m_Connection) == 0) |
309 | return false; | ||
208 | } | 310 | } |
311 | |||
312 | IncrementFolderVersion(oldParentFolderUUID); | ||
313 | IncrementFolderVersion(newParentFolderID); | ||
314 | |||
315 | return true; | ||
316 | } | ||
317 | |||
318 | private bool IncrementFolderVersion(UUID folderID) | ||
319 | { | ||
320 | return IncrementFolderVersion(folderID.ToString()); | ||
321 | } | ||
322 | |||
323 | private bool IncrementFolderVersion(string folderID) | ||
324 | { | ||
325 | // m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID); | ||
326 | // Util.PrintCallStack(); | ||
327 | |||
328 | using (SqliteCommand cmd = new SqliteCommand()) | ||
329 | { | ||
330 | cmd.CommandText = "update inventoryfolders set version=version+1 where folderID = ?folderID"; | ||
331 | cmd.Parameters.Add(new SqliteParameter(":folderID", folderID)); | ||
332 | |||
333 | try | ||
334 | { | ||
335 | cmd.ExecuteNonQuery(); | ||
336 | } | ||
337 | catch (Exception) | ||
338 | { | ||
339 | return false; | ||
340 | } | ||
341 | } | ||
342 | |||
343 | return true; | ||
209 | } | 344 | } |
210 | } | 345 | } |
211 | } \ No newline at end of file | 346 | } \ No newline at end of file |