Check in the remaining bits to do Asset store via NHibernate. Still

need to work out auto table creation in a reasonable way.  Tommorrow
I'll work on getting the NHibernate bits in place to be able to put this
into the main tree.
0.6.0-stable
Sean Dague 2008-04-03 20:59:20 +00:00
parent 4f174fbf57
commit cd4348738a
2 changed files with 36 additions and 35 deletions

View File

@ -47,6 +47,7 @@ namespace OpenSim.Data.NHibernate
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Configuration cfg;
private ISessionFactory factory;
public override void Initialise()
@ -54,7 +55,7 @@ namespace OpenSim.Data.NHibernate
// TODO: hard coding for sqlite based stuff to begin with, just making it easier to test
// This is stubbing for now, it will become dynamic later and support different db backends
Configuration cfg = new Configuration();
cfg = new Configuration();
cfg.SetProperty(Environment.ConnectionProvider,
"NHibernate.Connection.DriverConnectionProvider");
cfg.SetProperty(Environment.Dialect,
@ -65,48 +66,49 @@ namespace OpenSim.Data.NHibernate
"URI=file:Asset.db,version=3");
cfg.AddAssembly("OpenSim.Data.NHibernate");
// HbmSerializer.Default.Validate = true;
HbmSerializer.Default.Validate = true;
// using ( System.IO.MemoryStream stream =
// HbmSerializer.Default.Serialize(System.Reflection.Assembly.GetExecutingAssembly()))
// cfg.AddInputStream(stream);
// new SchemaExport(cfg).Create(true, true);
factory = cfg.BuildSessionFactory();
factory = cfg.BuildSessionFactory();
}
override public AssetBase FetchAsset(LLUUID uuid)
{
return null;
using(ISession session = factory.OpenSession()) {
try {
return session.Load(typeof(AssetBase), uuid.ToString()) as AssetBase;
} catch {
return null;
}
}
}
override public void CreateAsset(AssetBase asset)
override public void CreateAsset(AssetBase asset)
{
ISession session = null;
ITransaction transaction = null;
try {
session = factory.OpenSession();
transaction = session.BeginTransaction();
session.SaveOrUpdate(asset);
// CRUD operations here (with the session)
transaction.Commit();
}
catch {
if(transaction != null)
transaction.Rollback();
throw; // Don't trap the exception
}
finally {
if(session != null)
session.Close();
if (!ExistsAsset(asset.FullID)) {
using(ISession session = factory.OpenSession()) {
using(ITransaction transaction = session.BeginTransaction()) {
session.Save(asset);
transaction.Commit();
}
}
}
}
override public void UpdateAsset(AssetBase asset)
{
if (ExistsAsset(asset.FullID)) {
using(ISession session = factory.OpenSession()) {
using(ITransaction transaction = session.BeginTransaction()) {
session.Update(asset);
transaction.Commit();
}
}
}
}
private void LogAssetLoad(AssetBase asset)
@ -124,7 +126,7 @@ namespace OpenSim.Data.NHibernate
override public bool ExistsAsset(LLUUID uuid)
{
return false;
return (FetchAsset(uuid) != null) ? true : false;
}
public void DeleteAsset(LLUUID uuid)

View File

@ -1,16 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="OpenSim.Framework.AssetBase, OpenSim.Framework" table="Assets">
<class name="OpenSim.Framework.AssetBase, OpenSim.Framework" table="Assets" lazy="false">
<id name="ID" column="UUID" type="String" length="36" >
<generator class="assigned" />
</id>
<property name="Type" type="integer" />
<property name="InvType" type="integer" />
<property name="Name" type="String" length="50" />
<property name="Description" type="String" length="50" />
<property name="Local" type="boolean" />
<property name="Temporary" type="boolean" />
<property name="Type" type="SByte" />
<property name="InvType" type="SByte" />
<property name="Name" type="String" length="50" />
<property name="Description" type="String" length="50" />
<property name="Local" type="boolean" />
<property name="Temporary" type="boolean" />
<property name="Data" type="binary" />
</class>
</hibernate-mapping>