aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorSean Dague2008-07-18 15:06:24 +0000
committerSean Dague2008-07-18 15:06:24 +0000
commitaec5f0ceed08b3ac9f94752a7d18ffe73d5abbf2 (patch)
treeb977e0a529d3012d9de7b1674d1664d2c4f6f852
parent* refactor: break out sog loading code into two parts so that post-deserializ... (diff)
downloadopensim-SC_OLD-aec5f0ceed08b3ac9f94752a7d18ffe73d5abbf2.zip
opensim-SC_OLD-aec5f0ceed08b3ac9f94752a7d18ffe73d5abbf2.tar.gz
opensim-SC_OLD-aec5f0ceed08b3ac9f94752a7d18ffe73d5abbf2.tar.bz2
opensim-SC_OLD-aec5f0ceed08b3ac9f94752a7d18ffe73d5abbf2.tar.xz
found a better pattern for SaveOrUpdate with nhibernate
cleaned up the asset path a bit
-rw-r--r--OpenSim/Data/NHibernate/NHibernateAssetData.cs45
-rw-r--r--OpenSim/Data/NHibernate/NHibernateRegionData.cs56
2 files changed, 49 insertions, 52 deletions
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 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections;
29using System.IO; 30using System.IO;
30using System.Reflection; 31using System.Reflection;
31using System.Text.RegularExpressions; 32using System.Text.RegularExpressions;
@@ -33,6 +34,7 @@ using libsecondlife;
33using log4net; 34using log4net;
34using NHibernate; 35using NHibernate;
35using NHibernate.Cfg; 36using NHibernate.Cfg;
37using NHibernate.Expression;
36using NHibernate.Mapping.Attributes; 38using NHibernate.Mapping.Attributes;
37using NHibernate.Tool.hbm2ddl; 39using NHibernate.Tool.hbm2ddl;
38using OpenSim.Framework; 40using OpenSim.Framework;
@@ -105,36 +107,45 @@ namespace OpenSim.Data.NHibernate
105 { 107 {
106 return session.Load(typeof(AssetBase), uuid) as AssetBase; 108 return session.Load(typeof(AssetBase), uuid) as AssetBase;
107 } 109 }
110 catch (ObjectNotFoundException e)
111 {
112 m_log.ErrorFormat("[NHIBERNATE] no such asset {0}", uuid);
113 return null;
114 }
108 catch (Exception e) 115 catch (Exception e)
109 { 116 {
110 m_log.Error("[NHIBERNATE] issue loading asset", e); 117 m_log.Error("[NHIBERNATE] unexpected exception: ", e);
111 return null; 118 return null;
112 } 119 }
113 } 120 }
114 121
115 override public void CreateAsset(AssetBase asset) 122 private void Save(AssetBase asset)
116 { 123 {
117 if (!ExistsAsset(asset.FullID)) 124 try
125 {
126 AssetBase a = session.Load(typeof(AssetBase), asset.FullID) as AssetBase;
127 }
128 catch (ObjectNotFoundException e)
129 {
130 session.Save(asset);
131 session.Flush();
132 }
133 catch (Exception e)
118 { 134 {
119 m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID); 135 m_log.Error("[NHIBERNATE] issue saving asset", e);
120 using (ITransaction transaction = session.BeginTransaction())
121 {
122 session.Save(asset);
123 transaction.Commit();
124 }
125 } 136 }
126 } 137 }
127 138
139 override public void CreateAsset(AssetBase asset)
140 {
141 m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID);
142 Save(asset);
143 }
144
128 override public void UpdateAsset(AssetBase asset) 145 override public void UpdateAsset(AssetBase asset)
129 { 146 {
130 if (ExistsAsset(asset.FullID)) 147 m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID);
131 { 148 Save(asset);
132 using (ITransaction transaction = session.BeginTransaction())
133 {
134 session.Update(asset);
135 transaction.Commit();
136 }
137 }
138 } 149 }
139 150
140 // private void LogAssetLoad(AssetBase asset) 151 // private void LogAssetLoad(AssetBase asset)
diff --git a/OpenSim/Data/NHibernate/NHibernateRegionData.cs b/OpenSim/Data/NHibernate/NHibernateRegionData.cs
index 3d2d0e6..40861ae 100644
--- a/OpenSim/Data/NHibernate/NHibernateRegionData.cs
+++ b/OpenSim/Data/NHibernate/NHibernateRegionData.cs
@@ -114,31 +114,25 @@ namespace OpenSim.Data.NHibernate
114 return null; 114 return null;
115 } 115 }
116 116
117 // This looks inefficient, but it turns out that it isn't
118 // based on trial runs with nhibernate 1.2
117 private void SaveOrUpdate(SceneObjectPart p) 119 private void SaveOrUpdate(SceneObjectPart p)
118 { 120 {
119 try 121 try
120 { 122 {
121 ICriteria criteria = session.CreateCriteria(typeof(SceneObjectPart)); 123 SceneObjectPart old = session.Load(typeof(SceneObjectPart), p.UUID) as SceneObjectPart;
122 criteria.Add(Expression.Eq("UUID", p.UUID)); 124 session.Evict(old);
123 ArrayList l = (ArrayList)criteria.List(); 125 session.Update(p);
124 if (l.Count < 1) 126 m_log.InfoFormat("[NHIBERNATE] updating object {0}", p.UUID);
125 { 127 }
126 session.Save(p); 128 catch (ObjectNotFoundException e)
127 } 129 {
128 else if (l.Count == 1) 130 m_log.InfoFormat("[NHIBERNATE] saving object {0}", p.UUID);
129 { 131 session.Save(p);
130 SceneObjectPart old = (SceneObjectPart)l[0];
131 session.Evict(old);
132 session.Update(p);
133 }
134 else
135 {
136 m_log.Error("Not unique");
137 }
138 } 132 }
139 catch (Exception e) 133 catch (Exception e)
140 { 134 {
141 m_log.Error("[NHIBERNATE] issue saving prim", e); 135 m_log.Error("[NHIBERNATE] issue saving part", e);
142 } 136 }
143 } 137 }
144 138
@@ -146,23 +140,15 @@ namespace OpenSim.Data.NHibernate
146 { 140 {
147 try 141 try
148 { 142 {
149 ICriteria criteria = session.CreateCriteria(typeof(Terrain)); 143 Terrain old = session.Load(typeof(Terrain), t.RegionID) as Terrain;
150 criteria.Add(Expression.Eq("RegionID", t.RegionID)); 144 session.Evict(old);
151 ArrayList l = (ArrayList)criteria.List(); 145 session.Update(t);
152 if (l.Count < 1) 146 session.Flush();
153 { 147 }
154 session.Save(t); 148 catch (ObjectNotFoundException e)
155 } 149 {
156 else if (l.Count == 1) 150 session.Save(t);
157 { 151 session.Flush();
158 Terrain old = (Terrain)l[0];
159 session.Evict(old);
160 session.Update(t);
161 }
162 else
163 {
164 m_log.Error("Not unique");
165 }
166 } 152 }
167 catch (Exception e) 153 catch (Exception e)
168 { 154 {