getting close on saving prims via nhibernate

0.6.0-stable
Sean Dague 2008-07-16 21:27:59 +00:00
parent 44d0b7c724
commit 6adac3bd5a
2 changed files with 36 additions and 7 deletions

View File

@ -34,6 +34,7 @@ using libsecondlife;
using log4net; using log4net;
using NHibernate; using NHibernate;
using NHibernate.Cfg; using NHibernate.Cfg;
using NHibernate.Expression;
using NHibernate.Mapping.Attributes; using NHibernate.Mapping.Attributes;
using NHibernate.Tool.hbm2ddl; using NHibernate.Tool.hbm2ddl;
using OpenSim.Framework; using OpenSim.Framework;
@ -123,12 +124,15 @@ namespace OpenSim.Data.NHibernate
{ {
try try
{ {
m_log.InfoFormat("Storing part {0}", part.UUID);
session.SaveOrUpdate(part); session.SaveOrUpdate(part);
session.Flush();
} }
catch (Exception e) catch (Exception e)
{ {
m_log.Error("Can't save: ", e); m_log.Error("Can't save: ", e);
} }
} }
} }
@ -151,8 +155,33 @@ namespace OpenSim.Data.NHibernate
/// <returns>List of loaded groups</returns> /// <returns>List of loaded groups</returns>
public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID) public List<SceneObjectGroup> LoadObjects(LLUUID regionUUID)
{ {
List<SceneObjectGroup> prims = new List<SceneObjectGroup>(); Dictionary<LLUUID, SceneObjectGroup> SOG = new Dictionary<LLUUID, SceneObjectGroup>();
return prims; List<SceneObjectGroup> ret = new List<SceneObjectGroup>();
ICriteria criteria = session.CreateCriteria(typeof(SceneObjectPart));
criteria.Add(Expression.Eq("RegionID", regionUUID));
criteria.AddOrder( Order.Asc("ParentID") );
foreach (SceneObjectPart p in criteria.List())
{
// root part
if (p.UUID == p.ParentUUID)
{
SceneObjectGroup group = new SceneObjectGroup();
group.AddPart(p);
group.RootPart = p;
SOG.Add(p.ParentUUID, group);
}
else
{
SOG[p.ParentUUID].AddPart(p);
}
}
foreach (SceneObjectGroup g in SOG.Values)
{
ret.Add(g);
}
return ret;
} }
/// <summary> /// <summary>
@ -215,7 +244,7 @@ namespace OpenSim.Data.NHibernate
/// </summary> /// </summary>
public void Shutdown() public void Shutdown()
{ {
session.Flush();
} }
/// <summary> /// <summary>

View File

@ -1,7 +1,7 @@
<?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.Region.Environment.Scenes.SceneObjectPart, OpenSim.Region.Environment" table="Prims" lazy="false"> <class name="OpenSim.Region.Environment.Scenes.SceneObjectPart, OpenSim.Region.Environment" table="Prims" lazy="false">
<id name="UUID" column="ID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate"> <id name="UUID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate">
<generator class="assigned" /> <generator class="assigned" />
</id> </id>
<property name="ParentID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" /> <property name="ParentID" type="OpenSim.Data.NHibernate.LLUUIDUserType, OpenSim.Data.NHibernate" />
@ -56,9 +56,9 @@
</property> </property>
<property name="SitTargetPositionLL" type="OpenSim.Data.NHibernate.LLVector3UserType, OpenSim.Data.NHibernate" > <property name="SitTargetPositionLL" type="OpenSim.Data.NHibernate.LLVector3UserType, OpenSim.Data.NHibernate" >
<column name="SitTargetPosX" /> <column name="SitTargetOffsetX" />
<column name="SitTargetPosY" /> <column name="SitTargetOffsetY" />
<column name="SitTargetPosZ" /> <column name="SitTargetOffsetZ" />
</property> </property>
<property name="RotationOffset" type="OpenSim.Data.NHibernate.LLQuaternionUserType, OpenSim.Data.NHibernate" > <property name="RotationOffset" type="OpenSim.Data.NHibernate.LLQuaternionUserType, OpenSim.Data.NHibernate" >