* Some morw work on specializing the database framework for OpenSim

ThreadPoolClientBranch
lbsa71 2008-01-15 10:15:39 +00:00
parent 492e72b21a
commit 47c6529523
5 changed files with 40 additions and 18 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Text;
using libsecondlife;
using TribalMedia.Framework.Data;
@ -15,7 +16,7 @@ namespace OpenSim.Framework.Data
{
}
public override void ExpandField<TObj>(TObj obj, System.Data.Common.DbCommand command, List<string> fieldNames)
public override void ExpandField<TObj>(TObj obj, DbCommand command, List<string> fieldNames)
{
string fieldName = FieldName;
object value = GetParamValue(obj);

View File

@ -0,0 +1,17 @@
using System.Data;
using TribalMedia.Framework.Data;
namespace OpenSim.Framework.Data
{
public abstract class OpenSimTableMapper<TRowMapper, TPrimaryKey> : ObjectTableMapper<TRowMapper, TPrimaryKey>
{
public OpenSimTableMapper(DatabaseMapper database, string tableName) : base(database, tableName)
{
}
protected override DataReader CreateReader(IDataReader reader)
{
return new OpenSimDataReader(reader);
}
}
}

View File

@ -14,7 +14,7 @@ namespace OpenSim.Framework.Data
}
}
public class PrimitiveBaseShapeTableMapper : ObjectTableMapper<PrimitiveBaseShapeRowMapper, Guid>
public class PrimitiveBaseShapeTableMapper : OpenSimTableMapper<PrimitiveBaseShapeRowMapper, Guid>
{
public PrimitiveBaseShapeTableMapper(DatabaseMapper connection, string tableName)
: base(connection, tableName)
@ -140,4 +140,4 @@ namespace OpenSim.Framework.Data
return mapper;
}
}
}
}

View File

@ -32,8 +32,8 @@ namespace TribalMedia.Framework.Data
{
public abstract class ObjectTableMapper<TRowMapper, TPrimaryKey> : TableMapper
{
public ObjectTableMapper(DatabaseMapper connectionPool, string tableName)
: base(connectionPool, tableName)
public ObjectTableMapper(DatabaseMapper database, string tableName)
: base(database, tableName)
{
}
@ -52,7 +52,7 @@ namespace TribalMedia.Framework.Data
{
if (reader.Read())
{
result = FromReader(new DataReader(reader));
result = FromReader( CreateReader(reader));
success = true;
}
else
@ -67,8 +67,7 @@ namespace TribalMedia.Framework.Data
return success;
}
public virtual bool Remove(TPrimaryKey id)
{
int deleted = 0;

View File

@ -33,14 +33,14 @@ namespace TribalMedia.Framework.Data
{
public abstract class TableMapper
{
private readonly DatabaseMapper m_connectionPool;
private readonly DatabaseMapper m_database;
private readonly object m_syncRoot = new object();
protected void WithConnection(Action<DbConnection> action)
{
lock (m_syncRoot)
{
DbConnection m_connection = m_connectionPool.GetNewConnection();
DbConnection m_connection = m_database.GetNewConnection();
if (m_connection.State != ConnectionState.Open)
{
@ -74,40 +74,45 @@ namespace TribalMedia.Framework.Data
get { return m_keyFieldMapper; }
}
public TableMapper(DatabaseMapper connectionPool, string tableName)
public TableMapper(DatabaseMapper database, string tableName)
{
m_connectionPool = connectionPool;
m_database = database;
m_tableName = tableName.ToLower(); // Stupid MySQL hack.
}
public string CreateParamName(string fieldName)
{
return m_connectionPool.CreateParamName(fieldName);
return m_database.CreateParamName(fieldName);
}
protected DbCommand CreateSelectCommand(DbConnection connection, string fieldName, object primaryKey)
{
return m_connectionPool.CreateSelectCommand(this, connection, fieldName, primaryKey);
return m_database.CreateSelectCommand(this, connection, fieldName, primaryKey);
}
public string CreateCondition(DbCommand command, string fieldName, object key)
{
return m_connectionPool.CreateCondition(this, command, fieldName, key);
return m_database.CreateCondition(this, command, fieldName, key);
}
public DbCommand CreateInsertCommand(DbConnection connection, object obj)
{
return m_connectionPool.CreateInsertCommand(this, connection, obj);
return m_database.CreateInsertCommand(this, connection, obj);
}
public DbCommand CreateUpdateCommand(DbConnection connection, object rowMapper, object primaryKey)
{
return m_connectionPool.CreateUpdateCommand(this, connection, rowMapper, primaryKey);
return m_database.CreateUpdateCommand(this, connection, rowMapper, primaryKey);
}
public object ConvertToDbType(object value)
{
return m_connectionPool.ConvertToDbType(value);
return m_database.ConvertToDbType(value);
}
protected virtual DataReader CreateReader(IDataReader reader)
{
return new DataReader(reader);
}
}
}