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 static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Configuration cfg;
private ISessionFactory factory; private ISessionFactory factory;
public override void Initialise() 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 // 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 // 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, cfg.SetProperty(Environment.ConnectionProvider,
"NHibernate.Connection.DriverConnectionProvider"); "NHibernate.Connection.DriverConnectionProvider");
cfg.SetProperty(Environment.Dialect, cfg.SetProperty(Environment.Dialect,
@ -65,48 +66,49 @@ namespace OpenSim.Data.NHibernate
"URI=file:Asset.db,version=3"); "URI=file:Asset.db,version=3");
cfg.AddAssembly("OpenSim.Data.NHibernate"); cfg.AddAssembly("OpenSim.Data.NHibernate");
// HbmSerializer.Default.Validate = true; HbmSerializer.Default.Validate = true;
// using ( System.IO.MemoryStream stream = // using ( System.IO.MemoryStream stream =
// HbmSerializer.Default.Serialize(System.Reflection.Assembly.GetExecutingAssembly())) // HbmSerializer.Default.Serialize(System.Reflection.Assembly.GetExecutingAssembly()))
// cfg.AddInputStream(stream); // cfg.AddInputStream(stream);
// new SchemaExport(cfg).Create(true, true); // new SchemaExport(cfg).Create(true, true);
factory = cfg.BuildSessionFactory(); factory = cfg.BuildSessionFactory();
} }
override public AssetBase FetchAsset(LLUUID uuid) 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; if (!ExistsAsset(asset.FullID)) {
ITransaction transaction = null; using(ISession session = factory.OpenSession()) {
try { using(ITransaction transaction = session.BeginTransaction()) {
session = factory.OpenSession(); session.Save(asset);
transaction = session.BeginTransaction(); transaction.Commit();
}
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();
} }
} }
override public void UpdateAsset(AssetBase asset) 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) private void LogAssetLoad(AssetBase asset)
@ -124,7 +126,7 @@ namespace OpenSim.Data.NHibernate
override public bool ExistsAsset(LLUUID uuid) override public bool ExistsAsset(LLUUID uuid)
{ {
return false; return (FetchAsset(uuid) != null) ? true : false;
} }
public void DeleteAsset(LLUUID uuid) public void DeleteAsset(LLUUID uuid)

View File

@ -1,16 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <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" > <id name="ID" column="UUID" type="String" length="36" >
<generator class="assigned" /> <generator class="assigned" />
</id> </id>
<property name="Type" type="integer" /> <property name="Type" type="SByte" />
<property name="InvType" type="integer" /> <property name="InvType" type="SByte" />
<property name="Name" type="String" length="50" /> <property name="Name" type="String" length="50" />
<property name="Description" type="String" length="50" /> <property name="Description" type="String" length="50" />
<property name="Local" type="boolean" /> <property name="Local" type="boolean" />
<property name="Temporary" type="boolean" /> <property name="Temporary" type="boolean" />
<property name="Data" type="binary" /> <property name="Data" type="binary" />
</class> </class>
</hibernate-mapping> </hibernate-mapping>