refactor: move common inventory folder version update code to parent class in mysql, mssql and sqlite database plugins

connector_plugin
Justin Clark-Casey (justincc) 2012-11-15 04:01:30 +00:00
parent 16dd94b956
commit 350cd58e5e
3 changed files with 28 additions and 112 deletions

View File

@ -122,7 +122,7 @@ namespace OpenSim.Data.MSSQL
} }
} }
public class MSSQLItemHandler : MSSQLGenericTableHandler<XInventoryItem> public class MSSQLItemHandler : MSSQLInventoryHandler<XInventoryItem>
{ {
public MSSQLItemHandler(string c, string t, string m) : public MSSQLItemHandler(string c, string t, string m) :
base(c, t, m) base(c, t, m)
@ -213,43 +213,9 @@ namespace OpenSim.Data.MSSQL
return true; 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<XInventoryFolder> public class MSSQLFolderHandler : MSSQLInventoryHandler<XInventoryFolder>
{ {
public MSSQLFolderHandler(string c, string t, string m) : public MSSQLFolderHandler(string c, string t, string m) :
base(c, t, m) base(c, t, m)
@ -296,13 +262,18 @@ namespace OpenSim.Data.MSSQL
return true; return true;
} }
}
private bool IncrementFolderVersion(UUID folderID) public class MSSQLInventoryHandler<T> : MSSQLGenericTableHandler<T> where T: class, new()
{
public MSSQLInventoryHandler(string c, string t, string m) : base(c, t, m) {}
protected bool IncrementFolderVersion(UUID folderID)
{ {
return IncrementFolderVersion(folderID.ToString()); 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); // m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID);
// Util.PrintCallStack(); // Util.PrintCallStack();

View File

@ -122,7 +122,7 @@ namespace OpenSim.Data.MySQL
} }
} }
public class MySqlItemHandler : MySQLGenericTableHandler<XInventoryItem> public class MySqlItemHandler : MySqlInventoryHandler<XInventoryItem>
{ {
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -241,47 +241,9 @@ namespace OpenSim.Data.MySQL
return true; 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<XInventoryFolder> public class MySqlFolderHandler : MySqlInventoryHandler<XInventoryFolder>
{ {
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -326,13 +288,18 @@ namespace OpenSim.Data.MySQL
return true; return true;
} }
}
private bool IncrementFolderVersion(UUID folderID) public class MySqlInventoryHandler<T> : MySQLGenericTableHandler<T> where T: class, new()
{
public MySqlInventoryHandler(string c, string t, string m) : base(c, t, m) {}
protected bool IncrementFolderVersion(UUID folderID)
{ {
return IncrementFolderVersion(folderID.ToString()); 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); // m_log.DebugFormat("[MYSQL FOLDER HANDLER]: Incrementing version on folder {0}", folderID);
// Util.PrintCallStack(); // Util.PrintCallStack();

View File

@ -130,7 +130,7 @@ namespace OpenSim.Data.SQLite
} }
} }
public class SqliteItemHandler : SQLiteGenericTableHandler<XInventoryItem> public class SqliteItemHandler : SqliteInventoryHandler<XInventoryItem>
{ {
public SqliteItemHandler(string c, string t, string m) : public SqliteItemHandler(string c, string t, string m) :
base(c, t, m) base(c, t, m)
@ -243,37 +243,9 @@ namespace OpenSim.Data.SQLite
return perms; 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<XInventoryFolder> public class SqliteFolderHandler : SqliteInventoryHandler<XInventoryFolder>
{ {
public SqliteFolderHandler(string c, string t, string m) : public SqliteFolderHandler(string c, string t, string m) :
base(c, t, m) base(c, t, m)
@ -315,12 +287,18 @@ namespace OpenSim.Data.SQLite
return true; return true;
} }
private bool IncrementFolderVersion(UUID folderID) }
public class SqliteInventoryHandler<T> : SQLiteGenericTableHandler<T> 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()); 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); // m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID);
// Util.PrintCallStack(); // Util.PrintCallStack();