From 75c880a6f3631a527b532773a8a493309a96028e Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 9 Nov 2012 00:59:18 +0000 Subject: Update parent inventory folder version numbers when folders are moved/created/deleted to match version numbers cached by viewers. This is done in the way that one would expect (e.g. moving a folder increments version number on both source and destination parent folders). This should hopefully improve viewer reuse of its cached inventory information. Currently MySQL only but will be implement for SQLite/MSSQL if there are no issues. --- OpenSim/Data/SQLite/SQLiteXInventoryData.cs | 30 ++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'OpenSim/Data/SQLite/SQLiteXInventoryData.cs') diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs index 1f36986..75f8c87 100644 --- a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs +++ b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs @@ -47,7 +47,7 @@ namespace OpenSim.Data.SQLite { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private SQLiteGenericTableHandler m_Folders; + private SqliteFolderHandler m_Folders; private SqliteItemHandler m_Items; public SQLiteXInventoryData(string conn, string realm) @@ -55,7 +55,7 @@ namespace OpenSim.Data.SQLite if (Util.IsWindows()) Util.LoadArchSpecificWindowsDll("sqlite3.dll"); - m_Folders = new SQLiteGenericTableHandler( + m_Folders = new SqliteFolderHandler( conn, "inventoryfolders", "XInventoryStore"); m_Items = new SqliteItemHandler( conn, "inventoryitems", String.Empty); @@ -114,6 +114,11 @@ namespace OpenSim.Data.SQLite return m_Items.MoveItem(id, newParent); } + public bool MoveFolder(string id, string newParent) + { + return m_Folders.MoveFolder(id, newParent); + } + public XInventoryItem[] GetActiveGestures(UUID principalID) { return m_Items.GetActiveGestures(principalID); @@ -177,4 +182,23 @@ namespace OpenSim.Data.SQLite return perms; } } -} + + public class SqliteFolderHandler : SQLiteGenericTableHandler + { + public SqliteFolderHandler(string c, string t, string m) : + base(c, t, m) + { + } + + public bool MoveFolder(string id, string newParentFolderID) + { + 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; + } + } +} \ No newline at end of file -- cgit v1.1 From 94da908813e42c328572bc5da2ddc41b6664b59c Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Wed, 14 Nov 2012 04:45:59 +0000 Subject: More consistently dispose of SqliteCommand in OpenSim.Data.SQLite where possible. Not doing SQLiteInventoryStore since this is no longer used and should disappear in the future. --- OpenSim/Data/SQLite/SQLiteXInventoryData.cs | 51 ++++++++++++++++------------- 1 file changed, 29 insertions(+), 22 deletions(-) (limited to 'OpenSim/Data/SQLite/SQLiteXInventoryData.cs') diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs index 75f8c87..8eb1a63 100644 --- a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs +++ b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs @@ -139,35 +139,41 @@ namespace OpenSim.Data.SQLite public bool MoveItem(string id, string newParent) { - 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)); + 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; + return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true; + } } public XInventoryItem[] GetActiveGestures(UUID principalID) { - SqliteCommand cmd = new SqliteCommand(); - cmd.CommandText = String.Format("select * from inventoryitems where avatarId = :uuid and assetType = :type and flags = 1", m_Realm); + using (SqliteCommand cmd = new SqliteCommand()) + { + cmd.CommandText = String.Format("select * from inventoryitems where avatarId = :uuid and assetType = :type and flags = 1", m_Realm); - cmd.Parameters.Add(new SqliteParameter(":uuid", principalID.ToString())); - cmd.Parameters.Add(new SqliteParameter(":type", (int)AssetType.Gesture)); + cmd.Parameters.Add(new SqliteParameter(":uuid", principalID.ToString())); + cmd.Parameters.Add(new SqliteParameter(":type", (int)AssetType.Gesture)); - return DoQuery(cmd); + return DoQuery(cmd); + } } public int GetAssetPermissions(UUID principalID, UUID assetID) { - SqliteCommand cmd = new SqliteCommand(); + IDataReader reader; - cmd.CommandText = String.Format("select inventoryCurrentPermissions from inventoryitems where avatarID = :PrincipalID and assetID = :AssetID", m_Realm); - cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString())); - cmd.Parameters.Add(new SqliteParameter(":AssetID", assetID.ToString())); + using (SqliteCommand cmd = new SqliteCommand()) + { + cmd.CommandText = String.Format("select inventoryCurrentPermissions from inventoryitems where avatarID = :PrincipalID and assetID = :AssetID", m_Realm); + cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString())); + cmd.Parameters.Add(new SqliteParameter(":AssetID", assetID.ToString())); - IDataReader reader = ExecuteReader(cmd, m_Connection); + reader = ExecuteReader(cmd, m_Connection); + } int perms = 0; @@ -192,13 +198,14 @@ namespace OpenSim.Data.SQLite public bool MoveFolder(string id, string newParentFolderID) { - 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)); + 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; + return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true; + } } } } \ No newline at end of file -- cgit v1.1 From 1aa027123982b710313ea0e15efe7fc85db1c9ea Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 15 Nov 2012 03:29:55 +0000 Subject: Implement folder version updating for the sqlite inventory plugin --- OpenSim/Data/SQLite/SQLiteXInventoryData.cs | 139 +++++++++++++++++++++++++++- 1 file changed, 137 insertions(+), 2 deletions(-) (limited to 'OpenSim/Data/SQLite/SQLiteXInventoryData.cs') 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 { } + 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 -- cgit v1.1 From 350cd58e5e52b88651035bcba19010807bff7870 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 15 Nov 2012 04:01:30 +0000 Subject: refactor: move common inventory folder version update code to parent class in mysql, mssql and sqlite database plugins --- OpenSim/Data/SQLite/SQLiteXInventoryData.cs | 42 +++++++---------------------- 1 file changed, 10 insertions(+), 32 deletions(-) (limited to 'OpenSim/Data/SQLite/SQLiteXInventoryData.cs') diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs index 87eb31e..2a0a8f6 100644 --- a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs +++ b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs @@ -130,7 +130,7 @@ namespace OpenSim.Data.SQLite } } - public class SqliteItemHandler : SQLiteGenericTableHandler + public class SqliteItemHandler : SqliteInventoryHandler { public SqliteItemHandler(string c, string t, string m) : base(c, t, m) @@ -243,37 +243,9 @@ 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 + public class SqliteFolderHandler : SqliteInventoryHandler { public SqliteFolderHandler(string c, string t, string m) : base(c, t, m) @@ -315,12 +287,18 @@ namespace OpenSim.Data.SQLite return true; } - private bool IncrementFolderVersion(UUID folderID) + } + + public class SqliteInventoryHandler : SQLiteGenericTableHandler where T: class, new() + { + public SqliteInventoryHandler(string c, string t, string m) : base(c, t, m) {} + + protected bool IncrementFolderVersion(UUID folderID) { return IncrementFolderVersion(folderID.ToString()); } - private bool IncrementFolderVersion(string folderID) + protected bool IncrementFolderVersion(string folderID) { // m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID); // Util.PrintCallStack(); -- cgit v1.1