Updated MySQL connection management to use the MySQL connection pooling. This should accommodate various timeout problems that exist with the current connection pool code in a more general and standard way.

This commit is contained in:
Master ScienceSim
2010-02-04 13:19:30 -08:00
committed by John Hurliman
parent 5f1f5c29e9
commit e1b5c61247
15 changed files with 2261 additions and 2660 deletions

View File

@@ -38,16 +38,21 @@ namespace OpenSim.Data.MySQL
public class MySqlUserAccountData : MySqlFramework, IUserAccountData
{
private string m_Realm;
private List<string> m_ColumnNames = null;
// private int m_LastExpire = 0;
private List<string> m_ColumnNames;
// private string m_connectionString;
public MySqlUserAccountData(string connectionString, string realm)
: base(connectionString)
{
m_Realm = realm;
m_connectionString = connectionString;
Migration m = new Migration(m_Connection, GetType().Assembly, "UserStore");
m.Update();
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
Migration m = new Migration(dbcon, GetType().Assembly, "UserStore");
m.Update();
}
}
public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query)
@@ -64,49 +69,49 @@ namespace OpenSim.Data.MySQL
if (scopeID != UUID.Zero)
command += " and ScopeID = ?scopeID";
MySqlCommand cmd = new MySqlCommand(command);
cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
IDataReader result = ExecuteReader(cmd);
if (result.Read())
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
ret.PrincipalID = principalID;
UUID scope;
UUID.TryParse(result["ScopeID"].ToString(), out scope);
ret.ScopeID = scope;
dbcon.Open();
MySqlCommand cmd = new MySqlCommand(command, dbcon);
if (m_ColumnNames == null)
cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
IDataReader result = cmd.ExecuteReader();
if (result.Read())
{
m_ColumnNames = new List<string>();
ret.PrincipalID = principalID;
UUID scope;
UUID.TryParse(result["ScopeID"].ToString(), out scope);
ret.ScopeID = scope;
DataTable schemaTable = result.GetSchemaTable();
foreach (DataRow row in schemaTable.Rows)
m_ColumnNames.Add(row["ColumnName"].ToString());
if (m_ColumnNames == null)
{
m_ColumnNames = new List<string>();
DataTable schemaTable = result.GetSchemaTable();
foreach (DataRow row in schemaTable.Rows)
m_ColumnNames.Add(row["ColumnName"].ToString());
}
foreach (string s in m_ColumnNames)
{
if (s == "UUID")
continue;
if (s == "ScopeID")
continue;
ret.Data[s] = result[s].ToString();
}
return ret;
}
foreach (string s in m_ColumnNames)
else
{
if (s == "UUID")
continue;
if (s == "ScopeID")
continue;
ret.Data[s] = result[s].ToString();
return null;
}
result.Close();
CloseReaderCommand(cmd);
return ret;
}
result.Close();
CloseReaderCommand(cmd);
return null;
}
public bool Store(UserAccountData data)
@@ -118,61 +123,60 @@ namespace OpenSim.Data.MySQL
string[] fields = new List<string>(data.Data.Keys).ToArray();
MySqlCommand cmd = new MySqlCommand();
string update = "update `"+m_Realm+"` set ";
bool first = true;
foreach (string field in fields)
using (MySqlCommand cmd = new MySqlCommand())
{
if (!first)
update += ", ";
update += "`" + field + "` = ?"+field;
string update = "update `" + m_Realm + "` set ";
bool first = true;
foreach (string field in fields)
{
if (!first)
update += ", ";
update += "`" + field + "` = ?" + field;
first = false;
first = false;
cmd.Parameters.AddWithValue("?"+field, data.Data[field]);
}
cmd.Parameters.AddWithValue("?" + field, data.Data[field]);
}
update += " where UUID = ?principalID";
update += " where UUID = ?principalID";
if (data.ScopeID != UUID.Zero)
update += " and ScopeID = ?scopeID";
if (data.ScopeID != UUID.Zero)
update += " and ScopeID = ?scopeID";
cmd.CommandText = update;
cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString());
cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString());
if (ExecuteNonQuery(cmd) < 1)
{
string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" +
String.Join("`, `", fields) +
"`) values (?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")";
cmd.CommandText = insert;
cmd.CommandText = update;
cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString());
cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString());
if (ExecuteNonQuery(cmd) < 1)
{
cmd.Dispose();
return false;
string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" +
String.Join("`, `", fields) +
"`) values (?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")";
cmd.CommandText = insert;
if (ExecuteNonQuery(cmd) < 1)
{
cmd.Dispose();
return false;
}
}
}
cmd.Dispose();
return true;
}
public bool SetDataItem(UUID principalID, string item, string value)
{
MySqlCommand cmd = new MySqlCommand("update `" + m_Realm +
"` set `" + item + "` = ?" + item + " where UUID = ?UUID");
using (MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + "` set `" +
item + "` = ?" + item + " where UUID = ?UUID"))
{
cmd.Parameters.AddWithValue("?" + item, value);
cmd.Parameters.AddWithValue("?UUID", principalID.ToString());
cmd.Parameters.AddWithValue("?"+item, value);
cmd.Parameters.AddWithValue("?UUID", principalID.ToString());
if (ExecuteNonQuery(cmd) > 0)
return true;
if (ExecuteNonQuery(cmd) > 0)
return true;
}
return false;
}