From e263368656ee4aa2d939790012233e0793c63868 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 15 Nov 2012 03:29:55 +0000 Subject: [PATCH] Implement folder version updating for the sqlite inventory plugin --- .../Data/SQLite/SQLiteGenericTableHandler.cs | 10 +- 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 917a0a1504..9fbeb100ce 100644 --- a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs +++ b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs @@ -120,12 +120,12 @@ namespace OpenSim.Data.SQLite } } - public T[] Get(string field, string key) + public virtual T[] Get(string field, string key) { return Get(new string[] { field }, new string[] { key }); } - public T[] Get(string[] fields, string[] keys) + public virtual T[] Get(string[] fields, string[] keys) { if (fields.Length != keys.Length) return new T[0]; @@ -213,7 +213,7 @@ namespace OpenSim.Data.SQLite return result.ToArray(); } - public T[] Get(string where) + public virtual T[] Get(string where) { using (SqliteCommand cmd = new SqliteCommand()) { @@ -226,7 +226,7 @@ namespace OpenSim.Data.SQLite } } - public bool Store(T row) + public virtual bool Store(T row) { using (SqliteCommand cmd = new SqliteCommand()) { @@ -270,7 +270,7 @@ namespace OpenSim.Data.SQLite return Delete(new string[] { field }, new string[] { key }); } - public bool Delete(string[] fields, string[] keys) + public virtual bool Delete(string[] fields, string[] keys) { if (fields.Length != keys.Length) return false; diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs index 8eb1a63996..87eb31eb0f 100644 --- a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs +++ b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs @@ -137,16 +137,72 @@ namespace OpenSim.Data.SQLite { } + public override bool Store(XInventoryItem item) + { + if (!base.Store(item)) + return false; + + IncrementFolderVersion(item.parentFolderID); + + return true; + } + + public override bool Delete(string field, string val) + { + XInventoryItem[] retrievedItems = Get(new string[] { field }, new string[] { val }); + if (retrievedItems.Length == 0) + return false; + + if (!base.Delete(field, val)) + return false; + + // Don't increment folder version here since Delete(string, string) calls Delete(string[], string[]) +// IncrementFolderVersion(retrievedItems[0].parentFolderID); + + return true; + } + + public override bool Delete(string[] fields, string[] vals) + { + XInventoryItem[] retrievedItems = Get(fields, vals); + if (retrievedItems.Length == 0) + return false; + + if (!base.Delete(fields, vals)) + return false; + + HashSet deletedItemFolderUUIDs = new HashSet(); + + Array.ForEach(retrievedItems, i => deletedItemFolderUUIDs.Add(i.parentFolderID)); + + foreach (UUID deletedItemFolderUUID in deletedItemFolderUUIDs) + IncrementFolderVersion(deletedItemFolderUUID); + + return true; + } + public bool MoveItem(string id, string newParent) { + XInventoryItem[] retrievedItems = Get(new string[] { "inventoryID" }, new string[] { id }); + if (retrievedItems.Length == 0) + return false; + + UUID oldParent = retrievedItems[0].parentFolderID; + using (SqliteCommand cmd = new SqliteCommand()) { cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where inventoryID = :InventoryID", m_Realm); cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParent)); cmd.Parameters.Add(new SqliteParameter(":InventoryID", id)); - return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true; + if (ExecuteNonQuery(cmd, m_Connection) == 0) + return false; } + + IncrementFolderVersion(oldParent); + IncrementFolderVersion(newParent); + + return true; } public XInventoryItem[] GetActiveGestures(UUID principalID) @@ -187,6 +243,34 @@ namespace OpenSim.Data.SQLite return perms; } + + private bool IncrementFolderVersion(UUID folderID) + { + return IncrementFolderVersion(folderID.ToString()); + } + + private bool IncrementFolderVersion(string folderID) + { +// m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID); +// Util.PrintCallStack(); + + using (SqliteCommand cmd = new SqliteCommand()) + { + cmd.CommandText = "update inventoryfolders set version=version+1 where folderID = ?folderID"; + cmd.Parameters.Add(new SqliteParameter(":folderID", folderID)); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception) + { + return false; + } + } + + return true; + } } public class SqliteFolderHandler : SQLiteGenericTableHandler @@ -196,16 +280,67 @@ namespace OpenSim.Data.SQLite { } + public override bool Store(XInventoryFolder folder) + { + if (!base.Store(folder)) + return false; + + IncrementFolderVersion(folder.parentFolderID); + + return true; + } + public bool MoveFolder(string id, string newParentFolderID) { + XInventoryFolder[] folders = Get(new string[] { "folderID" }, new string[] { id }); + + if (folders.Length == 0) + return false; + + UUID oldParentFolderUUID = folders[0].parentFolderID; + using (SqliteCommand cmd = new SqliteCommand()) { cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where folderID = :FolderID", m_Realm); cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParentFolderID)); cmd.Parameters.Add(new SqliteParameter(":FolderID", id)); - return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true; + if (ExecuteNonQuery(cmd, m_Connection) == 0) + return false; } + + IncrementFolderVersion(oldParentFolderUUID); + IncrementFolderVersion(newParentFolderID); + + return true; + } + + private bool IncrementFolderVersion(UUID folderID) + { + return IncrementFolderVersion(folderID.ToString()); + } + + private bool IncrementFolderVersion(string folderID) + { +// m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID); +// Util.PrintCallStack(); + + using (SqliteCommand cmd = new SqliteCommand()) + { + cmd.CommandText = "update inventoryfolders set version=version+1 where folderID = ?folderID"; + cmd.Parameters.Add(new SqliteParameter(":folderID", folderID)); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception) + { + return false; + } + } + + return true; } } } \ No newline at end of file