Apply patch from bug #1606 -- Documentation for Data/Null, Data/Base. Thanks kerunix_Flan!

0.6.0-stable
Jeff Ames 2008-06-26 20:20:30 +00:00
parent 9fae975a53
commit d96caaa14e
8 changed files with 382 additions and 16 deletions

View File

@ -32,6 +32,9 @@ using OpenSim.Framework;
namespace OpenSim.Data.Base
{
/// <summary>
///
/// </summary>
public class AppearanceRowMapper : BaseRowMapper<AvatarAppearance>
{
public AppearanceRowMapper(BaseSchema schema, AvatarAppearance obj)
@ -40,6 +43,9 @@ namespace OpenSim.Data.Base
}
}
/// <summary>
///
/// </summary>
public class AppearanceTableMapper : BaseTableMapper<AppearanceRowMapper, Guid>
{
public AppearanceTableMapper(BaseDatabaseConnector database, string tableName)
@ -186,28 +192,55 @@ namespace OpenSim.Data.Base
}
/// <summary>
///
/// </summary>
/// <param name="userID"></param>
/// <param name="appearance"></param>
/// <returns></returns>
public bool Add(Guid userID, AvatarAppearance appearance)
{
AppearanceRowMapper mapper = CreateRowMapper(appearance);
return Add(mapper);
}
/// <summary>
///
/// </summary>
/// <param name="userID"></param>
/// <param name="appearance"></param>
/// <returns></returns>
public bool Update(Guid userID, AvatarAppearance appearance)
{
AppearanceRowMapper mapper = CreateRowMapper(appearance);
return Update(appearance.Owner.UUID, mapper);
}
/// <summary>
///
/// </summary>
/// <param name="appearance"></param>
/// <returns></returns>
protected AppearanceRowMapper CreateRowMapper(AvatarAppearance appearance)
{
return new AppearanceRowMapper(m_schema, appearance);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected AppearanceRowMapper CreateRowMapper()
{
return CreateRowMapper(new AvatarAppearance());
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
/// <param name="appearance"></param>
/// <returns></returns>
protected AppearanceRowMapper FromReader(BaseDataReader reader, AvatarAppearance appearance)
{
AppearanceRowMapper mapper = CreateRowMapper(appearance);
@ -215,6 +248,11 @@ namespace OpenSim.Data.Base
return mapper;
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
/// <returns></returns>
public override AppearanceRowMapper FromReader(BaseDataReader reader)
{
AppearanceRowMapper mapper = CreateRowMapper();
@ -222,6 +260,12 @@ namespace OpenSim.Data.Base
return mapper;
}
/// <summary>
///
/// </summary>
/// <param name="presenceID"></param>
/// <param name="val"></param>
/// <returns></returns>
public bool TryGetValue(Guid presenceID, out AvatarAppearance val)
{
AppearanceRowMapper mapper;

View File

@ -31,25 +31,47 @@ using System.IO;
namespace OpenSim.Data.Base
{
/// <summary>
///
/// </summary>
public abstract class BaseDataReader
{
private readonly IDataReader m_source;
/// <summary>
///
/// </summary>
/// <param name="source"></param>
public BaseDataReader(IDataReader source)
{
m_source = source;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public object Get(string name)
{
return m_source[name];
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public ushort GetUShort(string name)
{
return (ushort)m_source.GetInt32(m_source.GetOrdinal(name));
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public byte GetByte(string name)
{
int ordinal = m_source.GetOrdinal(name);
@ -57,16 +79,31 @@ namespace OpenSim.Data.Base
return value;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public sbyte GetSByte(string name)
{
return (sbyte)m_source.GetInt16(m_source.GetOrdinal(name));
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public float GetFloat(string name)
{
return m_source.GetFloat(m_source.GetOrdinal(name));
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public byte[] GetBytes(string name)
{
int ordinal = m_source.GetOrdinal(name);
@ -94,6 +131,11 @@ namespace OpenSim.Data.Base
return memStream.ToArray();
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public string GetString(string name)
{
int ordinal = m_source.GetOrdinal(name);
@ -107,21 +149,40 @@ namespace OpenSim.Data.Base
return (string)value;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool Read()
{
return m_source.Read();
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public virtual Guid GetGuid(string name)
{
return m_source.GetGuid(m_source.GetOrdinal(name));
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public UInt32 GetUInt32(string name)
{
return (UInt32)GetInt32(name);
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private Int32 GetInt32(string name)
{
int ordinal = m_source.GetOrdinal(name);
@ -129,6 +190,11 @@ namespace OpenSim.Data.Base
return int32;
}
/// <summary>
///
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public Int64 GetInt64(string name)
{
int ordinal = m_source.GetOrdinal(name);

View File

@ -32,10 +32,17 @@ using System.Data.Common;
namespace OpenSim.Data.Base
{
/// <summary>
///
/// </summary>
public abstract class BaseDatabaseConnector
{
protected string m_connectionString;
/// <summary>
///
/// </summary>
/// <param name="connectionString"></param>
public BaseDatabaseConnector(string connectionString)
{
m_connectionString = connectionString;
@ -44,6 +51,14 @@ namespace OpenSim.Data.Base
public abstract DbConnection GetNewConnection();
public abstract string CreateParamName(string fieldName);
/// <summary>
///
/// </summary>
/// <param name="mapper"></param>
/// <param name="connection"></param>
/// <param name="fieldName"></param>
/// <param name="key"></param>
/// <returns></returns>
public DbCommand CreateSelectCommand(BaseTableMapper mapper, DbConnection connection, string fieldName, object key)
{
string table = mapper.TableName;
@ -61,6 +76,14 @@ namespace OpenSim.Data.Base
return command;
}
/// <summary>
///
/// </summary>
/// <param name="mapper"></param>
/// <param name="command"></param>
/// <param name="fieldName"></param>
/// <param name="key"></param>
/// <returns></returns>
public string CreateCondition(BaseTableMapper mapper, DbCommand command, string fieldName, object key)
{
string keyFieldParamName = mapper.CreateParamName(fieldName);
@ -73,6 +96,14 @@ namespace OpenSim.Data.Base
return String.Format("{0}={1}", fieldName, keyFieldParamName);
}
/// <summary>
///
/// </summary>
/// <param name="mapper"></param>
/// <param name="connection"></param>
/// <param name="rowMapper"></param>
/// <param name="primaryKey"></param>
/// <returns></returns>
public DbCommand CreateUpdateCommand(BaseTableMapper mapper, DbConnection connection, object rowMapper, object primaryKey)
{
string table = mapper.TableName;
@ -105,6 +136,13 @@ namespace OpenSim.Data.Base
return command;
}
/// <summary>
///
/// </summary>
/// <param name="mapper"></param>
/// <param name="connection"></param>
/// <param name="obj"></param>
/// <returns></returns>
public DbCommand CreateInsertCommand(BaseTableMapper mapper, DbConnection connection, object obj)
{
string table = mapper.TableName;
@ -132,6 +170,11 @@ namespace OpenSim.Data.Base
return command;
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public virtual object ConvertToDbType(object value)
{
return value;

View File

@ -34,11 +34,17 @@ namespace OpenSim.Data.Base
public delegate TField ObjectGetAccessor<TObj, TField>(TObj obj);
public delegate void ObjectSetAccessor<TObj, TField>(TObj obj, TField value);
/// <summary>
///
/// </summary>
public abstract class BaseFieldMapper
{
private readonly BaseTableMapper m_tableMapper;
private readonly string m_fieldName;
/// <summary>
///
/// </summary>
public string FieldName
{
get { return m_fieldName; }
@ -46,6 +52,9 @@ namespace OpenSim.Data.Base
protected Type m_valueType;
/// <summary>
///
/// </summary>
public Type ValueType
{
get { return m_valueType; }
@ -53,6 +62,12 @@ namespace OpenSim.Data.Base
public abstract object GetParamValue(object obj);
/// <summary>
///
/// </summary>
/// <param name="tableMapper"></param>
/// <param name="fieldName"></param>
/// <param name="valueType"></param>
public BaseFieldMapper(BaseTableMapper tableMapper, string fieldName, Type valueType)
{
m_fieldName = fieldName;
@ -62,6 +77,13 @@ namespace OpenSim.Data.Base
public abstract void SetPropertyFromReader(object mapper, BaseDataReader reader);
/// <summary>
///
/// </summary>
/// <param name="command"></param>
/// <param name="fieldNames"></param>
/// <param name="fieldName"></param>
/// <param name="value"></param>
public void RawAddParam(DbCommand command, List<string> fieldNames, string fieldName, object value)
{
string paramName = m_tableMapper.CreateParamName(fieldName);
@ -74,6 +96,13 @@ namespace OpenSim.Data.Base
command.Parameters.Add(param);
}
/// <summary>
///
/// </summary>
/// <typeparam name="TObj"></typeparam>
/// <param name="obj"></param>
/// <param name="command"></param>
/// <param name="fieldNames"></param>
public virtual void ExpandField<TObj>(TObj obj, DbCommand command, List<string> fieldNames)
{
string fieldName = FieldName;
@ -82,6 +111,11 @@ namespace OpenSim.Data.Base
RawAddParam(command, fieldNames, fieldName, m_tableMapper.ConvertToDbType(value));
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
/// <returns></returns>
protected virtual object GetValue(BaseDataReader reader)
{
object value;
@ -130,6 +164,11 @@ namespace OpenSim.Data.Base
}
}
/// <summary>
///
/// </summary>
/// <typeparam name="TObject"></typeparam>
/// <typeparam name="TField"></typeparam>
public class ObjectField<TObject, TField> : BaseFieldMapper
{
private readonly ObjectGetAccessor<TObject, TField> m_fieldGetAccessor;
@ -157,6 +196,13 @@ namespace OpenSim.Data.Base
}
/// <summary>
///
/// </summary>
/// <param name="tableMapper"></param>
/// <param name="fieldName"></param>
/// <param name="rowMapperGetAccessor"></param>
/// <param name="rowMapperSetAccessor"></param>
public ObjectField(BaseTableMapper tableMapper, string fieldName, ObjectGetAccessor<TObject, TField> rowMapperGetAccessor,
ObjectSetAccessor<TObject, TField> rowMapperSetAccessor)
: base(tableMapper, fieldName, typeof(TField))

View File

@ -27,27 +27,46 @@
namespace OpenSim.Data.Base
{
/// <summary>
///
/// </summary>
public abstract class BaseRowMapper
{
public abstract void FillObject(BaseDataReader reader);
}
/// <summary>
///
/// </summary>
/// <typeparam name="TObj"></typeparam>
public class BaseRowMapper<TObj> : BaseRowMapper
{
private readonly BaseSchema m_schema;
private readonly TObj m_obj;
/// <summary>
///
/// </summary>
public TObj Object
{
get { return m_obj; }
}
/// <summary>
///
/// </summary>
/// <param name="schema"></param>
/// <param name="obj"></param>
public BaseRowMapper(BaseSchema schema, TObj obj)
{
m_schema = schema;
m_obj = obj;
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
public override void FillObject(BaseDataReader reader)
{
foreach (BaseFieldMapper fieldMapper in m_schema.Fields.Values)

View File

@ -29,16 +29,26 @@ using System.Collections.Generic;
namespace OpenSim.Data.Base
{
/// <summary>
///
/// </summary>
public class BaseSchema
{
protected BaseTableMapper m_tableMapper;
protected Dictionary<string, BaseFieldMapper> m_mappings;
/// <summary>
///
/// </summary>
public Dictionary<string, BaseFieldMapper> Fields
{
get { return m_mappings; }
}
/// <summary>
///
/// </summary>
/// <param name="tableMapper"></param>
public BaseSchema(BaseTableMapper tableMapper)
{
m_mappings = new Dictionary<string, BaseFieldMapper>();
@ -46,13 +56,29 @@ namespace OpenSim.Data.Base
}
}
/// <summary>
///
/// </summary>
/// <typeparam name="TObj"></typeparam>
public class BaseSchema<TObj> : BaseSchema
{
/// <summary>
///
/// </summary>
/// <param name="tableMapper"></param>
public BaseSchema(BaseTableMapper tableMapper)
: base(tableMapper)
{
}
/// <summary>
///
/// </summary>
/// <typeparam name="TField"></typeparam>
/// <param name="fieldName"></param>
/// <param name="rowMapperGetAccessor"></param>
/// <param name="rowMapperSetAccessor"></param>
/// <returns></returns>
public ObjectField<TObj, TField> AddMapping<TField>(string fieldName,
ObjectGetAccessor<TObj, TField> rowMapperGetAccessor,
ObjectSetAccessor<TObj, TField> rowMapperSetAccessor)

View File

@ -31,11 +31,18 @@ using System.Data.Common;
namespace OpenSim.Data.Base
{
/// <summary>
///
/// </summary>
public abstract class BaseTableMapper
{
private readonly BaseDatabaseConnector m_database;
private readonly object m_syncRoot = new object();
/// <summary>
///
/// </summary>
/// <param name="action"></param>
protected void WithConnection(Action<DbConnection> action)
{
lock (m_syncRoot)
@ -74,59 +81,124 @@ namespace OpenSim.Data.Base
get { return m_keyFieldMapper; }
}
/// <summary>
///
/// </summary>
/// <param name="database"></param>
/// <param name="tableName"></param>
public BaseTableMapper(BaseDatabaseConnector database, string tableName)
{
m_database = database;
m_tableName = tableName.ToLower(); // Stupid MySQL hack.
}
/// <summary>
///
/// </summary>
/// <param name="fieldName"></param>
/// <returns></returns>
public string CreateParamName(string fieldName)
{
return m_database.CreateParamName(fieldName);
}
/// <summary>
///
/// </summary>
/// <param name="connection"></param>
/// <param name="fieldName"></param>
/// <param name="primaryKey"></param>
/// <returns></returns>
protected DbCommand CreateSelectCommand(DbConnection connection, string fieldName, object primaryKey)
{
return m_database.CreateSelectCommand(this, connection, fieldName, primaryKey);
}
/// <summary>
///
/// </summary>
/// <param name="command"></param>
/// <param name="fieldName"></param>
/// <param name="key"></param>
/// <returns></returns>
public string CreateCondition(DbCommand command, string fieldName, object key)
{
return m_database.CreateCondition(this, command, fieldName, key);
}
/// <summary>
///
/// </summary>
/// <param name="connection"></param>
/// <param name="obj"></param>
/// <returns></returns>
public DbCommand CreateInsertCommand(DbConnection connection, object obj)
{
return m_database.CreateInsertCommand(this, connection, obj);
}
/// <summary>
///
/// </summary>
/// <param name="connection"></param>
/// <param name="rowMapper"></param>
/// <param name="primaryKey"></param>
/// <returns></returns>
public DbCommand CreateUpdateCommand(DbConnection connection, object rowMapper, object primaryKey)
{
return m_database.CreateUpdateCommand(this, connection, rowMapper, primaryKey);
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public object ConvertToDbType(object value)
{
return m_database.ConvertToDbType(value);
}
/// <summary>
///
/// </summary>
/// <param name="reader"></param>
/// <returns></returns>
protected virtual BaseDataReader CreateReader(IDataReader reader)
{
return m_database.CreateReader(reader);
}
}
/// <summary>
///
/// </summary>
/// <typeparam name="TRowMapper"></typeparam>
/// <typeparam name="TPrimaryKey"></typeparam>
public abstract class BaseTableMapper<TRowMapper, TPrimaryKey> : BaseTableMapper
{
/// <summary>
///
/// </summary>
/// <param name="database"></param>
/// <param name="tableName"></param>
public BaseTableMapper(BaseDatabaseConnector database, string tableName)
: base(database, tableName)
{
}
// HACK: This is a temporary function used by TryGetValue().
// Due to a bug in mono 1.2.6, delegate blocks cannot contain
// a using block. This has been fixed in SVN, so the next
// mono release should work.
/// <summary>
/// HACK: This is a temporary function used by TryGetValue().
/// Due to a bug in mono 1.2.6, delegate blocks cannot contain
/// a using block. This has been fixed in SVN, so the next
/// mono release should work.
/// </summary>
/// <param name="connection"></param>
/// <param name="primaryKey"></param>
/// <param name="result"></param>
/// <param name="success"></param>
private void TryGetConnectionValue(DbConnection connection, TPrimaryKey primaryKey, ref TRowMapper result, ref bool success)
{
using (
@ -148,6 +220,12 @@ namespace OpenSim.Data.Base
}
}
/// <summary>
///
/// </summary>
/// <param name="primaryKey"></param>
/// <param name="value"></param>
/// <returns></returns>
public bool TryGetValue(TPrimaryKey primaryKey, out TRowMapper value)
{
TRowMapper result = default(TRowMapper);
@ -163,10 +241,15 @@ namespace OpenSim.Data.Base
return success;
}
// HACK: This is a temporary function used by Remove().
// Due to a bug in mono 1.2.6, delegate blocks cannot contain
// a using block. This has been fixed in SVN, so the next
// mono release should work.
/// <summary>
/// HACK: This is a temporary function used by Remove().
/// Due to a bug in mono 1.2.6, delegate blocks cannot contain
/// a using block. This has been fixed in SVN, so the next
/// mono release should work.
/// </summary>
/// <param name="connection"></param>
/// <param name="id"></param>
/// <param name="deleted"></param>
protected virtual void TryDelete(DbConnection connection, TPrimaryKey id, ref int deleted)
{
using (
@ -177,6 +260,11 @@ namespace OpenSim.Data.Base
}
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual bool Remove(TPrimaryKey id)
{
int deleted = 0;
@ -196,6 +284,13 @@ namespace OpenSim.Data.Base
}
}
/// <summary>
///
/// </summary>
/// <param name="connection"></param>
/// <param name="fieldName"></param>
/// <param name="primaryKey"></param>
/// <returns></returns>
public DbCommand CreateDeleteCommand(DbConnection connection, string fieldName, TPrimaryKey primaryKey)
{
string table = TableName;
@ -213,10 +308,18 @@ namespace OpenSim.Data.Base
return command;
}
// HACK: This is a temporary function used by Update().
// Due to a bug in mono 1.2.6, delegate blocks cannot contain
// a using block. This has been fixed in SVN, so the next
// mono release should work.
/// <summary>
/// HACK: This is a temporary function used by Update().
/// Due to a bug in mono 1.2.6, delegate blocks cannot contain
/// a using block. This has been fixed in SVN, so the next
/// mono release should work.
/// </summary>
/// <param name="connection"></param>
/// <param name="primaryKey"></param>
/// <param name="value"></param>
/// <param name="updated"></param>
protected void TryUpdate(DbConnection connection, TPrimaryKey primaryKey, TRowMapper value, ref int updated)
{
using (DbCommand command = CreateUpdateCommand(connection, value, primaryKey))
@ -225,6 +328,12 @@ namespace OpenSim.Data.Base
}
}
/// <summary>
///
/// </summary>
/// <param name="primaryKey"></param>
/// <param name="value"></param>
/// <returns></returns>
public virtual bool Update(TPrimaryKey primaryKey, TRowMapper value)
{
int updated = 0;
@ -244,10 +353,15 @@ namespace OpenSim.Data.Base
}
}
// HACK: This is a temporary function used by Add().
// Due to a bug in mono 1.2.6, delegate blocks cannot contain
// a using block. This has been fixed in SVN, so the next
// mono release should work.
/// <summary>
/// HACK: This is a temporary function used by Add().
/// Due to a bug in mono 1.2.6, delegate blocks cannot contain
/// a using block. This has been fixed in SVN, so the next
/// mono release should work.
/// </summary>
/// <param name="connection"></param>
/// <param name="value"></param>
/// <param name="added"></param>
protected void TryAdd(DbConnection connection, TRowMapper value, ref int added)
{
using (DbCommand command = CreateInsertCommand(connection, value))
@ -256,6 +370,11 @@ namespace OpenSim.Data.Base
}
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public virtual bool Add(TRowMapper value)
{
int added = 0;

View File

@ -33,6 +33,9 @@ using OpenSim.Region.Environment.Scenes;
namespace OpenSim.Data.Null
{
/// <summary>
/// NULL DataStore, do not store anything
/// </summary>
public class NullDataStore : IRegionDataStore
{
public void Initialise(string dbfile, bool persistPrimInventories)