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/MSSQL/MSSQLXInventoryData.cs | 47 +++++--------------------- OpenSim/Data/MySQL/MySQLXInventoryData.cs | 51 +++++------------------------ OpenSim/Data/SQLite/SQLiteXInventoryData.cs | 42 ++++++------------------ 3 files changed, 28 insertions(+), 112 deletions(-) (limited to 'OpenSim/Data') diff --git a/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs index 97970af..9164ffe 100644 --- a/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs +++ b/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs @@ -122,7 +122,7 @@ namespace OpenSim.Data.MSSQL } } - public class MSSQLItemHandler : MSSQLGenericTableHandler + public class MSSQLItemHandler : MSSQLInventoryHandler { public MSSQLItemHandler(string c, string t, string m) : base(c, t, m) @@ -213,43 +213,9 @@ namespace OpenSim.Data.MSSQL 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(); - - string sql = "update inventoryfolders set version=version+1 where folderID = ?folderID"; - - using (SqlConnection conn = new SqlConnection(m_ConnectionString)) - { - using (SqlCommand cmd = new SqlCommand(sql, conn)) - { - conn.Open(); - - cmd.Parameters.AddWithValue("@folderID", folderID); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception) - { - return false; - } - } - } - - return true; - } } - public class MSSQLFolderHandler : MSSQLGenericTableHandler + public class MSSQLFolderHandler : MSSQLInventoryHandler { public MSSQLFolderHandler(string c, string t, string m) : base(c, t, m) @@ -296,13 +262,18 @@ namespace OpenSim.Data.MSSQL return true; } + } + + public class MSSQLInventoryHandler : MSSQLGenericTableHandler where T: class, new() + { + public MSSQLInventoryHandler(string c, string t, string m) : base(c, t, m) {} - private bool IncrementFolderVersion(UUID folderID) + 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(); diff --git a/OpenSim/Data/MySQL/MySQLXInventoryData.cs b/OpenSim/Data/MySQL/MySQLXInventoryData.cs index 7a3b5b4..c74033e 100644 --- a/OpenSim/Data/MySQL/MySQLXInventoryData.cs +++ b/OpenSim/Data/MySQL/MySQLXInventoryData.cs @@ -122,7 +122,7 @@ namespace OpenSim.Data.MySQL } } - public class MySqlItemHandler : MySQLGenericTableHandler + public class MySqlItemHandler : MySqlInventoryHandler { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -241,47 +241,9 @@ namespace OpenSim.Data.MySQL 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 (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) - { - dbcon.Open(); - - using (MySqlCommand cmd = new MySqlCommand()) - { - cmd.Connection = dbcon; - - cmd.CommandText = String.Format("update inventoryfolders set version=version+1 where folderID = ?folderID"); - cmd.Parameters.AddWithValue("?folderID", folderID); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception) - { - return false; - } - cmd.Dispose(); - } - - dbcon.Close(); - } - - return true; - } } - public class MySqlFolderHandler : MySQLGenericTableHandler + public class MySqlFolderHandler : MySqlInventoryHandler { // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -326,13 +288,18 @@ namespace OpenSim.Data.MySQL return true; } + } + + public class MySqlInventoryHandler : MySQLGenericTableHandler where T: class, new() + { + public MySqlInventoryHandler(string c, string t, string m) : base(c, t, m) {} - private bool IncrementFolderVersion(UUID folderID) + protected bool IncrementFolderVersion(UUID folderID) { return IncrementFolderVersion(folderID.ToString()); } - private bool IncrementFolderVersion(string folderID) + protected bool IncrementFolderVersion(string folderID) { // m_log.DebugFormat("[MYSQL FOLDER HANDLER]: Incrementing version on folder {0}", folderID); // Util.PrintCallStack(); 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