[Opensim-dev] nhibernate progress, baby steps

Sean Dague sean at dague.net
Thu Apr 3 12:42:01 UTC 2008


I've starting baby steps in building an OpenSim.Data.NHibernate driver
(I'm very close to getting NHiberate + Mono + SQLite working).  I did
look at Impalah's work here, but that created a lot of intermediary
objects that I wanted to avoid.  After chatting with Stephan yesterday,
wanted to give people a flavor of how this works, as we'll need to make
a few changes in the base to make our objects NHibernate friendly.

It turns out the NHibernate + Mono + SQLite is actually the hardest
thing to get working, as NHibernate 1.2.1 doesn't have an SQLite driver
that works with Mono.  Step one was to write one, which I've done.  Once
this is proofed out a bit more we'll need to do an import of NHibernate
1.2.1 branch into opensim-libs and add in the driver.  I'll also be
submitting the driver upstream to NHibernate in a hopes we could get a
1.2.2 with it included so we don't have to keep our own tree here.

My first test case here is Assets.  Asset storage is easy, as we just
store AssetBase.  It's 8 fields, which include an LLUUID, a Blob, and
some other types, which also makes it good at testing we can do all the
types we need to do.

AssetBase is what I call a "naked object".  Today all access is done via
direct attribute modification, which is actually worst practice in the
area.  For NHibernate to work correctly we need to have all our storable
data objects use Properties for data modification.  Honestly, we should
have been doing this anyway.  We're going to break Grid Comms
compatibility when we make this change, because the default
serialization of AssetBase will change.

Once this is done you create a mapping file.  This is an embedded
resource of OpenSim.Data.NHibernate.  The AssetBase mapping file is
here:
http://opensimulator.org/hg/opensim-trunk/file/8566c030a9bf/OpenSim/Data/NHibernate/Resources/AssetBase.hbm.xml

http://opensimulator.org/hg/opensim-trunk/file/8566c030a9bf/OpenSim/Data/NHibernate/NHibernateAssetData.cs
is the Asset Store work in progress.  It should just save assets right
now (though there is a transaction bug with sqlite I need to sort out).

In order to have this code work for a different database you just change
the driver declaration lines in 60 - 65 (can be done via runtime
config).  Any of the ~20 databases supported by NHibernate could then be
used instead.  Lines 68 - 71 gives you automatic db creation.  It does a
drop/create each time it is run, so is something we'll only want for
initial create, not used every time.

Right now I'm fighting with a transaction bug with SQLite, which I've
got a few ideas on how to get around.  Once that's fixed on store, I'll
fill out the rest of the asset implementation.  My goal is to be running
my Asset db on NHibernate + SQLite by end of the week, and to have all
that work in tree so others can kick the tires.

There are plenty of unanswered questions here, but having finally gotten
my head wrapped around the space, I really like the direction this is
headed.  The fact that NHibernate is also an actively developed project,
and things like automatic schema upgrades are coming in the future (they
already exist in Hibernate, the java project that NHibernate is based
on), is something we'll definitely want to take advantage of.

     -Sean

-- 
__________________________________________________________________

Sean Dague                                       Mid-Hudson Valley
sean at dague dot net                            Linux Users Group
http://dague.net                                 http://mhvlug.org

There is no silver bullet.  Plus, werewolves make better neighbors
than zombies, and they tend to keep the vampire population down.
__________________________________________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://opensimulator.org/pipermail/opensim-dev/attachments/20080403/8ae54fe3/attachment-0001.pgp>


More information about the Opensim-dev mailing list