AvatarStore. Untested, but complete

slimupdates
Melanie 2010-01-04 02:52:43 +00:00
parent 791c6188fd
commit 6e8d94685d
4 changed files with 64 additions and 16 deletions

View File

@ -43,5 +43,7 @@ namespace OpenSim.Data
{
AvatarBaseData[] Get(string field, string val);
bool Store(AvatarBaseData data);
bool Delete(UUID principalID, string name);
bool Delete(string field, string val);
}
}

View File

@ -95,12 +95,12 @@ namespace OpenSim.Data.MySQL
}
}
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];
@ -184,7 +184,7 @@ namespace OpenSim.Data.MySQL
return result.ToArray();
}
public T[] Get(string where)
public virtual T[] Get(string where)
{
MySqlCommand cmd = new MySqlCommand();
@ -196,7 +196,7 @@ namespace OpenSim.Data.MySQL
return DoQuery(cmd);
}
public bool Store(T row)
public virtual bool Store(T row)
{
MySqlCommand cmd = new MySqlCommand();
@ -234,7 +234,7 @@ namespace OpenSim.Data.MySQL
return false;
}
public bool Delete(string field, string val)
public virtual bool Delete(string field, string val)
{
MySqlCommand cmd = new MySqlCommand();

View File

@ -0,0 +1,5 @@
BEGIN;
CREATE TABLE Avatars (PrincipalID CHAR(36) NOT NULL, Name VARCHAR(32) NOT NULL, Value VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY(PrincipalID, Name), KEY(PrincipalID));
COMMIT;

View File

@ -53,45 +53,86 @@ namespace OpenSim.Services.AvatarService
public AvatarData GetAvatar(UUID principalID)
{
AvatarBaseData[] av = m_Database.Get("PrincipalID", principalID.ToString());
if (av.Length == 0)
return null;
AvatarData ret = new AvatarData();
ret.AvatarType = Convert.ToInt32(av[0].Data["AvatarType"]);
ret.Data = new Dictionary<string,string>();
av[0].Data.Remove("AvatarType");
ret.Data = av[0].Data;
foreach (AvatarBaseData b in av)
{
if (b.Data["Name"] == "AvatarType")
ret.AvatarType = Convert.ToInt32(b.Data["Value"]);
else
ret.Data[b.Data["Name"]] = b.Data["Value"];
}
return ret;
}
public bool SetAvatar(UUID principalID, AvatarData avatar)
{
m_Database.Delete("PrincipalID", principalID.ToString());
AvatarBaseData av = new AvatarBaseData();
av.Data = new Dictionary<string,string>();
av.PrincipalID = principalID;
av.Data = avatar.Data;
av.Data["AvatarType"] = avatar.AvatarType.ToString();
av.Data["Name"] = "AvatarType";
av.Data["Value"] = avatar.AvatarType.ToString();
return m_Database.Store(av);
if (!m_Database.Store(av))
return false;
foreach (KeyValuePair<string,string> kvp in avatar.Data)
{
av.Data["Name"] = kvp.Key;
av.Data["Value"] = kvp.Value;
if (!m_Database.Store(av))
{
m_Database.Delete("PrincipalID", principalID.ToString());
return false;
}
}
return true;
}
public bool ResetAvatar(UUID principalID)
{
return false;
return m_Database.Delete("PrincipalID", principalID.ToString());
}
public bool SetItems(UUID principalID, string[] names, string[] values)
{
AvatarBaseData av = new AvatarBaseData();
av.Data = new Dictionary<string,string>();
av.PrincipalID = principalID;
if (names.Length != values.Length)
return false;
for (int i = 0 ; i < names.Length ; i++)
{
av.Data["Name"] = names[i];
av.Data["Value"] = values[i];
if (!m_Database.Store(av))
return false;
}
return true;
}
public bool RemoveItems(UUID principalID, string[] names)
{
return false;
foreach (string name in names)
{
m_Database.Delete(principalID, name);
}
return true;
}
}
}