found a better pattern for SaveOrUpdate with nhibernate
cleaned up the asset path a bit0.6.0-stable
parent
f8721c3c1c
commit
aec5f0ceed
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
private void Save(AssetBase asset)
|
||||
{
|
||||
try
|
||||
{
|
||||
AssetBase a = session.Load(typeof(AssetBase), asset.FullID) as AssetBase;
|
||||
}
|
||||
catch (ObjectNotFoundException e)
|
||||
{
|
||||
session.Save(asset);
|
||||
session.Flush();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[NHIBERNATE] issue saving asset", e);
|
||||
}
|
||||
}
|
||||
|
||||
override public void CreateAsset(AssetBase asset)
|
||||
{
|
||||
if (!ExistsAsset(asset.FullID))
|
||||
{
|
||||
m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID);
|
||||
using (ITransaction transaction = session.BeginTransaction())
|
||||
{
|
||||
session.Save(asset);
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
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)
|
||||
|
|
|
@ -114,31 +114,25 @@ namespace OpenSim.Data.NHibernate
|
|||
return null;
|
||||
}
|
||||
|
||||
// This looks inefficient, but it turns out that it isn't
|
||||
// based on trial runs with nhibernate 1.2
|
||||
private void SaveOrUpdate(SceneObjectPart p)
|
||||
{
|
||||
try
|
||||
{
|
||||
ICriteria criteria = session.CreateCriteria(typeof(SceneObjectPart));
|
||||
criteria.Add(Expression.Eq("UUID", p.UUID));
|
||||
ArrayList l = (ArrayList)criteria.List();
|
||||
if (l.Count < 1)
|
||||
{
|
||||
session.Save(p);
|
||||
}
|
||||
else if (l.Count == 1)
|
||||
{
|
||||
SceneObjectPart old = (SceneObjectPart)l[0];
|
||||
session.Evict(old);
|
||||
session.Update(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Error("Not unique");
|
||||
}
|
||||
SceneObjectPart old = session.Load(typeof(SceneObjectPart), p.UUID) as SceneObjectPart;
|
||||
session.Evict(old);
|
||||
session.Update(p);
|
||||
m_log.InfoFormat("[NHIBERNATE] updating object {0}", p.UUID);
|
||||
}
|
||||
catch (ObjectNotFoundException e)
|
||||
{
|
||||
m_log.InfoFormat("[NHIBERNATE] saving object {0}", p.UUID);
|
||||
session.Save(p);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_log.Error("[NHIBERNATE] issue saving prim", e);
|
||||
m_log.Error("[NHIBERNATE] issue saving part", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,23 +140,15 @@ namespace OpenSim.Data.NHibernate
|
|||
{
|
||||
try
|
||||
{
|
||||
ICriteria criteria = session.CreateCriteria(typeof(Terrain));
|
||||
criteria.Add(Expression.Eq("RegionID", t.RegionID));
|
||||
ArrayList l = (ArrayList)criteria.List();
|
||||
if (l.Count < 1)
|
||||
{
|
||||
session.Save(t);
|
||||
}
|
||||
else if (l.Count == 1)
|
||||
{
|
||||
Terrain old = (Terrain)l[0];
|
||||
session.Evict(old);
|
||||
session.Update(t);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_log.Error("Not unique");
|
||||
}
|
||||
Terrain old = session.Load(typeof(Terrain), t.RegionID) as Terrain;
|
||||
session.Evict(old);
|
||||
session.Update(t);
|
||||
session.Flush();
|
||||
}
|
||||
catch (ObjectNotFoundException e)
|
||||
{
|
||||
session.Save(t);
|
||||
session.Flush();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue