[Opensim-dev] further db thoughts
Laurent B.
grumly57 at hotmail.com
Mon Jan 14 16:06:42 UTC 2008
Hi back,
Well I managed to get something running with Asset server (partially... because I need to implement a Save operation that would update or insert depending on the asset to exist or not - The asset server is trying to insert existing assets, which leads to a key violation during insert) .
I had to add a Set accessor to Schema in TableMapper, put an empty constructor to the DatabaseMapper (which I specialized with a SQLiteDatabaseMapper) so it can be instanciated using the current plugin pattern, then add a ConnectionString property. Does it makes sense ?
Although I managed to get something running, I think I am not finish catching up with this pattern. I suppose it is a question of habits. I struggled to get things correctly setup and instanciated, while trying to avoid to change too much things :)
Laurent.
From: grumly57 at hotmail.comTo: opensim-dev at lists.berlios.deDate: Mon, 14 Jan 2008 14:31:21 +0100Subject: Re: [Opensim-dev] further db thoughts
This is just what I needed :-) a piece of code + some guidance. Elegant does not mean "simple"... However, this is a very interresting approach.I will to get Assets persistence working this way. Thanks a lot,Laurent.
From: stefan at tribalmedia.seTo: opensim-dev at lists.berlios.deDate: Mon, 14 Jan 2008 11:31:50 +0100Subject: Re: [Opensim-dev] further db thoughts
---
Stefan, It would be motivating if you could provide a sample about how the TribalMedia data framework should work. Could that be done by implementing the very simple asset server as an example ? I propose we would make it work, make tests, comment and try to improve it, then it may serve as a baseline for the other db stuff ?
---
*doh*
I'll just post the code; but beware, it doesn't work, it's just to show you how stuff would interact
(Also, the code could probably be cleaner...)
What to look for:
* how the Schema is created and populated
* how the m_keyFieldMapper (that is used to extract primary key from queries) is initialized
* how the FromReader passes on to FillObject() - the function that will use the Schema to populate the RowMapper (and the PrimitiveBaseShape)
* How the CRUD and CreateRowMapper functions are really just there to get a cleaner interface for the caller.
/Stefan
---
using System;
namespace TribalMedia.Framework.Data{ public class PrimitiveBaseShapeRowMapper : RowMapper<PrimitiveBaseShape> { public Guid SceneObjectPartId;
public PrimitiveBaseShapeRowMapper(Schema schema, PrimitiveBaseShape obj) : base(schema, obj) { } }
public class PrimitiveBaseShapeTableMapper : TableMapper<PrimitiveBaseShapeRowMapper, Guid> { public PrimitiveBaseShapeTableMapper(DbConnectionPool connection, string tableName) : base(connection, tableName) { RowMapperSchema<PrimitiveBaseShapeRowMapper> rowMapperSchema = new RowMapperSchema<PrimitiveBaseShapeRowMapper>(); m_schema = rowMapperSchema;
m_keyFieldMapper = rowMapperSchema.AddMapping<Guid>("SceneObjectPartId", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.SceneObjectPartId; }, delegate(PrimitiveBaseShapeRowMapper shape, Guid value) { shape.SceneObjectPartId = value; });
rowMapperSchema.AddMapping<byte>("PCode", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PCode; }, delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PCode = value; });
rowMapperSchema.AddMapping<ushort>("PathBegin", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathBegin; }, delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.PathBegin = value; });
rowMapperSchema.AddMapping<ushort>("PathEnd", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathEnd; }, delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.PathEnd = value; });
rowMapperSchema.AddMapping<byte>("PathScaleX", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathScaleX; }, delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathScaleX = value; });
rowMapperSchema.AddMapping<byte>("PathScaleY", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathScaleY; }, delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathScaleY = value; });
rowMapperSchema.AddMapping<byte>("PathShearX", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathShearX; }, delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathShearX = value; });
rowMapperSchema.AddMapping<byte>("PathShearY", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathShearY; }, delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathShearY = value; });
rowMapperSchema.AddMapping<ushort>("ProfileBegin", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileBegin; }, delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileBegin = value; });
rowMapperSchema.AddMapping<ushort>("ProfileEnd", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileEnd; }, delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileEnd = value; });
rowMapperSchema.AddMapping<BluedogVector3>("Scale", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.Scale; }, delegate(PrimitiveBaseShapeRowMapper shape, BluedogVector3 value) { shape.Object.Scale = value; });
rowMapperSchema.AddMapping<sbyte>("PathTaperX", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTaperX; }, delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTaperX = value; });
rowMapperSchema.AddMapping<sbyte>("PathTaperY", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTaperY; }, delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTaperY = value; });
rowMapperSchema.AddMapping<sbyte>("PathTwist", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTwist; }, delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTwist = value; });
rowMapperSchema.AddMapping<sbyte>("PathRadiusOffset", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathRadiusOffset; }, delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathRadiusOffset = value; });
rowMapperSchema.AddMapping<byte>("PathRevolutions", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathRevolutions; }, delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathRevolutions = value; });
rowMapperSchema.AddMapping<sbyte>("PathTwistBegin", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathTwistBegin; }, delegate(PrimitiveBaseShapeRowMapper shape, sbyte value) { shape.Object.PathTwistBegin = value; });
rowMapperSchema.AddMapping<byte>("PathCurve", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.PathCurve; }, delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.PathCurve = value; });
rowMapperSchema.AddMapping<byte>("ProfileCurve", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileCurve; }, delegate(PrimitiveBaseShapeRowMapper shape, byte value) { shape.Object.ProfileCurve = value; });
rowMapperSchema.AddMapping<ushort>("ProfileHollow", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ProfileHollow; }, delegate(PrimitiveBaseShapeRowMapper shape, ushort value) { shape.Object.ProfileHollow = value; });
rowMapperSchema.AddMapping<byte[]>("TextureEntry", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.TextureEntry; }, delegate(PrimitiveBaseShapeRowMapper shape, byte[] value) { shape.Object.TextureEntry = value; });
rowMapperSchema.AddMapping<byte[]>("ExtraParams", delegate(PrimitiveBaseShapeRowMapper shape) { return shape.Object.ExtraParams; }, delegate(PrimitiveBaseShapeRowMapper shape, byte[] value) { shape.Object.ExtraParams = value; }); }
public override PrimitiveBaseShapeRowMapper FromReader(DataReader reader) { PrimitiveBaseShape shape = new PrimitiveBaseShape();
PrimitiveBaseShapeRowMapper mapper = new PrimitiveBaseShapeRowMapper(m_schema, shape); mapper.FillObject( reader );
return mapper; }
public bool Update(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape) { PrimitiveBaseShapeRowMapper mapper = CreateRowMapper(sceneObjectPartId, primitiveBaseShape); return Update(sceneObjectPartId, mapper); }
public bool Add(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape) { PrimitiveBaseShapeRowMapper mapper = CreateRowMapper(sceneObjectPartId, primitiveBaseShape); return Add(mapper); }
private PrimitiveBaseShapeRowMapper CreateRowMapper(Guid sceneObjectPartId, PrimitiveBaseShape primitiveBaseShape) { PrimitiveBaseShapeRowMapper mapper = new PrimitiveBaseShapeRowMapper( m_schema, primitiveBaseShape ); mapper.SceneObjectPartId = sceneObjectPartId; return mapper; } }}
Téléchargez gratuitement Messenger 2008
_________________________________________________________________
Votre contact a choisi Hotmail, l'e-mail nouvelle génération. Créez un compte.
http://www.windowslive.fr/hotmail/default.asp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://opensimulator.org/pipermail/opensim-dev/attachments/20080114/ce09a93b/attachment-0001.html>
More information about the Opensim-dev
mailing list