From aec5f0ceed08b3ac9f94752a7d18ffe73d5abbf2 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Fri, 18 Jul 2008 15:06:24 +0000 Subject: found a better pattern for SaveOrUpdate with nhibernate cleaned up the asset path a bit --- OpenSim/Data/NHibernate/NHibernateAssetData.cs | 45 ++++++++++++++++---------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'OpenSim/Data/NHibernate/NHibernateAssetData.cs') diff --git a/OpenSim/Data/NHibernate/NHibernateAssetData.cs b/OpenSim/Data/NHibernate/NHibernateAssetData.cs index eb4e14c..488cae4 100644 --- a/OpenSim/Data/NHibernate/NHibernateAssetData.cs +++ b/OpenSim/Data/NHibernate/NHibernateAssetData.cs @@ -26,6 +26,7 @@ */ using System; +using System.Collections; using System.IO; using System.Reflection; using System.Text.RegularExpressions; @@ -33,6 +34,7 @@ using libsecondlife; using log4net; using NHibernate; using NHibernate.Cfg; +using NHibernate.Expression; using NHibernate.Mapping.Attributes; using NHibernate.Tool.hbm2ddl; using OpenSim.Framework; @@ -105,36 +107,45 @@ namespace OpenSim.Data.NHibernate { return session.Load(typeof(AssetBase), uuid) as AssetBase; } + catch (ObjectNotFoundException e) + { + m_log.ErrorFormat("[NHIBERNATE] no such asset {0}", uuid); + return null; + } catch (Exception e) { - m_log.Error("[NHIBERNATE] issue loading asset", e); + m_log.Error("[NHIBERNATE] unexpected exception: ", e); return null; } } - override public void CreateAsset(AssetBase asset) + private void Save(AssetBase asset) { - if (!ExistsAsset(asset.FullID)) + try + { + AssetBase a = session.Load(typeof(AssetBase), asset.FullID) as AssetBase; + } + catch (ObjectNotFoundException e) + { + session.Save(asset); + session.Flush(); + } + catch (Exception e) { - m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID); - using (ITransaction transaction = session.BeginTransaction()) - { - session.Save(asset); - transaction.Commit(); - } + m_log.Error("[NHIBERNATE] issue saving asset", e); } } + override public void CreateAsset(AssetBase asset) + { + m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID); + Save(asset); + } + override public void UpdateAsset(AssetBase asset) { - if (ExistsAsset(asset.FullID)) - { - using (ITransaction transaction = session.BeginTransaction()) - { - session.Update(asset); - transaction.Commit(); - } - } + m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID); + Save(asset); } // private void LogAssetLoad(AssetBase asset) -- cgit v1.1