aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/NHibernateUserData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/NHibernate/NHibernateUserData.cs157
1 files changed, 60 insertions, 97 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateUserData.cs b/OpenSim/Data/NHibernate/NHibernateUserData.cs
index 2bec02c..0fb297f 100644
--- a/OpenSim/Data/NHibernate/NHibernateUserData.cs
+++ b/OpenSim/Data/NHibernate/NHibernateUserData.cs
@@ -51,6 +51,7 @@ namespace OpenSim.Data.NHibernate
51 51
52 private Configuration cfg; 52 private Configuration cfg;
53 private ISessionFactory factory; 53 private ISessionFactory factory;
54 private ISession session;
54 55
55 public override void Initialise(string connect) 56 public override void Initialise(string connect)
56 { 57 {
@@ -75,7 +76,8 @@ namespace OpenSim.Data.NHibernate
75 cfg.AddAssembly("OpenSim.Data.NHibernate"); 76 cfg.AddAssembly("OpenSim.Data.NHibernate");
76 77
77 factory = cfg.BuildSessionFactory(); 78 factory = cfg.BuildSessionFactory();
78 79 session = factory.OpenSession();
80
79 // This actually does the roll forward assembly stuff 81 // This actually does the roll forward assembly stuff
80 Assembly assem = GetType().Assembly; 82 Assembly assem = GetType().Assembly;
81 Migration m = new Migration((System.Data.Common.DbConnection)factory.ConnectionProvider.GetConnection(), assem, dialect, "UserStore"); 83 Migration m = new Migration((System.Data.Common.DbConnection)factory.ConnectionProvider.GetConnection(), assem, dialect, "UserStore");
@@ -87,10 +89,7 @@ namespace OpenSim.Data.NHibernate
87 UserProfileData user = null; 89 UserProfileData user = null;
88 try 90 try
89 { 91 {
90 using (ISession session = factory.OpenSession()) 92 user = session.Load(typeof(UserProfileData), uuid) as UserProfileData;
91 {
92 user = session.Load(typeof(UserProfileData), uuid) as UserProfileData;
93 }
94 } 93 }
95 catch (Exception) {} 94 catch (Exception) {}
96 95
@@ -101,11 +100,9 @@ namespace OpenSim.Data.NHibernate
101 { 100 {
102 UserProfileData user; 101 UserProfileData user;
103 // TODO: I'm sure I'll have to do something silly here 102 // TODO: I'm sure I'll have to do something silly here
104 using (ISession session = factory.OpenSession()) 103 user = session.Load(typeof(UserProfileData), uuid) as UserProfileData;
105 { 104 user.CurrentAgent = GetAgentByUUID(uuid);
106 user = session.Load(typeof(UserProfileData), uuid) as UserProfileData; 105
107 user.CurrentAgent = GetAgentByUUID(uuid);
108 }
109 return user; 106 return user;
110 } 107 }
111 108
@@ -113,16 +110,10 @@ namespace OpenSim.Data.NHibernate
113 { 110 {
114 if (!ExistsUser(profile.ID)) 111 if (!ExistsUser(profile.ID))
115 { 112 {
116 using (ISession session = factory.OpenSession()) 113 session.Save(profile);
117 { 114 SetAgentData(profile.ID, profile.CurrentAgent);
118 using (ITransaction transaction = session.BeginTransaction()) 115 // TODO: save agent
119 { 116 session.Transaction.Commit();
120 session.Save(profile);
121 SetAgentData(profile.ID, profile.CurrentAgent, session);
122 // TODO: save agent
123 transaction.Commit();
124 }
125 }
126 } 117 }
127 else 118 else
128 { 119 {
@@ -131,7 +122,7 @@ namespace OpenSim.Data.NHibernate
131 } 122 }
132 } 123 }
133 124
134 private static void SetAgentData(LLUUID uuid, UserAgentData agent, ISession session) 125 private void SetAgentData(LLUUID uuid, UserAgentData agent)
135 { 126 {
136 if (agent == null) 127 if (agent == null)
137 { 128 {
@@ -140,14 +131,12 @@ namespace OpenSim.Data.NHibernate
140 else 131 else
141 { 132 {
142 UserAgentData old = session.Load(typeof(UserAgentData), uuid) as UserAgentData; 133 UserAgentData old = session.Load(typeof(UserAgentData), uuid) as UserAgentData;
143 if (old == null) 134 if (old != null)
144 { 135 {
145 session.Save(agent); 136 session.Delete(old);
146 }
147 else
148 {
149 session.Update(agent);
150 } 137 }
138
139 session.Save(agent);
151 } 140 }
152 141
153 } 142 }
@@ -155,16 +144,10 @@ namespace OpenSim.Data.NHibernate
155 { 144 {
156 if (ExistsUser(profile.ID)) 145 if (ExistsUser(profile.ID))
157 { 146 {
158 using (ISession session = factory.OpenSession()) 147 session.Update(profile);
159 { 148 SetAgentData(profile.ID, profile.CurrentAgent);
160 using (ITransaction transaction = session.BeginTransaction()) 149 session.Transaction.Commit();
161 { 150 return true;
162 session.Update(profile);
163 SetAgentData(profile.ID, profile.CurrentAgent, session);
164 transaction.Commit();
165 return true;
166 }
167 }
168 } 151 }
169 else 152 else
170 { 153 {
@@ -176,36 +159,27 @@ namespace OpenSim.Data.NHibernate
176 159
177 override public void AddNewUserAgent(UserAgentData agent) 160 override public void AddNewUserAgent(UserAgentData agent)
178 { 161 {
179 using (ISession session = factory.OpenSession()) 162 UserAgentData old = session.Load(typeof(UserAgentData), agent.ProfileID) as UserAgentData;
180 { 163
181 using (ITransaction transaction = session.BeginTransaction()) 164 if (old == null) {
182 { 165 session.Save(agent);
183 session.Save(agent); 166 session.Transaction.Commit();
184 transaction.Commit(); 167 } else {
185 } 168 UpdateUserAgent(agent);
186 } 169 }
187 } 170 }
188 171
189 public void UpdateUserAgent(UserAgentData agent) 172 public void UpdateUserAgent(UserAgentData agent)
190 { 173 {
191 using (ISession session = factory.OpenSession()) 174 session.Update(agent);
192 { 175 session.Transaction.Commit();
193 using (ITransaction transaction = session.BeginTransaction())
194 {
195 session.Update(agent);
196 transaction.Commit();
197 }
198 }
199 } 176 }
200 177
201 override public UserAgentData GetAgentByUUID(LLUUID uuid) 178 override public UserAgentData GetAgentByUUID(LLUUID uuid)
202 { 179 {
203 try 180 try
204 { 181 {
205 using (ISession session = factory.OpenSession()) 182 return session.Load(typeof(UserAgentData), uuid) as UserAgentData;
206 {
207 return session.Load(typeof(UserAgentData), uuid) as UserAgentData;
208 }
209 } 183 }
210 catch 184 catch
211 { 185 {
@@ -215,18 +189,15 @@ namespace OpenSim.Data.NHibernate
215 189
216 override public UserProfileData GetUserByName(string fname, string lname) 190 override public UserProfileData GetUserByName(string fname, string lname)
217 { 191 {
218 using (ISession session = factory.OpenSession()) 192 ICriteria criteria = session.CreateCriteria(typeof(UserProfileData));
193 criteria.Add(Expression.Eq("FirstName", fname));
194 criteria.Add(Expression.Eq("SurName", lname));
195 foreach (UserProfileData profile in criteria.List())
219 { 196 {
220 ICriteria criteria = session.CreateCriteria(typeof(UserProfileData)); 197 profile.CurrentAgent = GetAgentByUUID(profile.ID);
221 criteria.Add(Expression.Eq("FirstName", fname)); 198 return profile;
222 criteria.Add(Expression.Eq("SurName", lname));
223 foreach (UserProfileData profile in criteria.List())
224 {
225 profile.CurrentAgent = GetAgentByUUID(profile.ID);
226 return profile;
227 }
228 return null;
229 } 199 }
200 return null;
230 } 201 }
231 202
232 override public UserAgentData GetAgentByName(string fname, string lname) 203 override public UserAgentData GetAgentByName(string fname, string lname)
@@ -247,19 +218,16 @@ namespace OpenSim.Data.NHibernate
247 218
248 if (querysplit.Length == 2) 219 if (querysplit.Length == 2)
249 { 220 {
250 using (ISession session = factory.OpenSession()) 221 ICriteria criteria = session.CreateCriteria(typeof(UserProfileData));
222 criteria.Add(Expression.Like("FirstName", querysplit[0]));
223 criteria.Add(Expression.Like("SurName", querysplit[1]));
224 foreach (UserProfileData profile in criteria.List())
251 { 225 {
252 ICriteria criteria = session.CreateCriteria(typeof(UserProfileData)); 226 AvatarPickerAvatar user = new AvatarPickerAvatar();
253 criteria.Add(Expression.Like("FirstName", querysplit[0])); 227 user.AvatarID = profile.ID;
254 criteria.Add(Expression.Like("SurName", querysplit[1])); 228 user.firstName = profile.FirstName;
255 foreach (UserProfileData profile in criteria.List()) 229 user.lastName = profile.SurName;
256 { 230 results.Add(user);
257 AvatarPickerAvatar user = new AvatarPickerAvatar();
258 user.AvatarID = profile.ID;
259 user.firstName = profile.FirstName;
260 user.lastName = profile.SurName;
261 results.Add(user);
262 }
263 } 231 }
264 } 232 }
265 return results; 233 return results;
@@ -281,20 +249,17 @@ namespace OpenSim.Data.NHibernate
281 { 249 {
282 AvatarAppearance appearance; 250 AvatarAppearance appearance;
283 // TODO: I'm sure I'll have to do something silly here 251 // TODO: I'm sure I'll have to do something silly here
284 using (ISession session = factory.OpenSession()) 252 appearance = session.Load(typeof(AvatarAppearance), user) as AvatarAppearance;
285 { 253
286 appearance = session.Load(typeof(AvatarAppearance), user) as AvatarAppearance;
287 }
288 return appearance; 254 return appearance;
289 } 255 }
290 256
291 private bool ExistsAppearance(LLUUID uuid) 257 private bool ExistsAppearance(LLUUID uuid)
292 { 258 {
293 AvatarAppearance appearance; 259 AvatarAppearance appearance;
294 using (ISession session = factory.OpenSession()) 260
295 { 261 appearance = session.Load(typeof(AvatarAppearance), uuid) as AvatarAppearance;
296 appearance = session.Load(typeof(AvatarAppearance), uuid) as AvatarAppearance; 262
297 }
298 return (appearance == null) ? false : true; 263 return (appearance == null) ? false : true;
299 } 264 }
300 265
@@ -302,20 +267,18 @@ namespace OpenSim.Data.NHibernate
302 public override void UpdateUserAppearance(LLUUID user, AvatarAppearance appearance) 267 public override void UpdateUserAppearance(LLUUID user, AvatarAppearance appearance)
303 { 268 {
304 bool exists = ExistsAppearance(user); 269 bool exists = ExistsAppearance(user);
305 using (ISession session = factory.OpenSession()) 270
271 using (ITransaction transaction = session.BeginTransaction())
306 { 272 {
307 using (ITransaction transaction = session.BeginTransaction()) 273 if (exists)
274 {
275 session.Update(appearance);
276 }
277 else
308 { 278 {
309 if (exists) 279 session.Save(appearance);
310 {
311 session.Update(appearance);
312 }
313 else
314 {
315 session.Save(appearance);
316 }
317 transaction.Commit();
318 } 280 }
281 transaction.Commit();
319 } 282 }
320 } 283 }
321 284