diff options
author | Jeff Ames | 2008-05-14 06:09:39 +0000 |
---|---|---|
committer | Jeff Ames | 2008-05-14 06:09:39 +0000 |
commit | b7a0855c3afea27f207655fca25651b19b41636a (patch) | |
tree | d049510e51b337a82ebbf88e197b3141511d9155 /OpenSim/Data/NHibernate/NHibernateUserData.cs | |
parent | Applied Patch mantis 1220. Implements llGetStartParameter. Thanks! (diff) | |
download | opensim-SC-b7a0855c3afea27f207655fca25651b19b41636a.zip opensim-SC-b7a0855c3afea27f207655fca25651b19b41636a.tar.gz opensim-SC-b7a0855c3afea27f207655fca25651b19b41636a.tar.bz2 opensim-SC-b7a0855c3afea27f207655fca25651b19b41636a.tar.xz |
More formatting cleanup. Minor refactoring.
Diffstat (limited to 'OpenSim/Data/NHibernate/NHibernateUserData.cs')
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateUserData.cs | 107 |
1 files changed, 72 insertions, 35 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateUserData.cs b/OpenSim/Data/NHibernate/NHibernateUserData.cs index 2c84ef9..43d8c32 100644 --- a/OpenSim/Data/NHibernate/NHibernateUserData.cs +++ b/OpenSim/Data/NHibernate/NHibernateUserData.cs | |||
@@ -56,7 +56,8 @@ namespace OpenSim.Data.NHibernate | |||
56 | { | 56 | { |
57 | char[] split = {';'}; | 57 | char[] split = {';'}; |
58 | string[] parts = connect.Split(split, 3); | 58 | string[] parts = connect.Split(split, 3); |
59 | if (parts.Length != 3) { | 59 | if (parts.Length != 3) |
60 | { | ||
60 | // TODO: make this a real exception type | 61 | // TODO: make this a real exception type |
61 | throw new Exception("Malformed Inventory connection string '" + connect + "'"); | 62 | throw new Exception("Malformed Inventory connection string '" + connect + "'"); |
62 | } | 63 | } |
@@ -87,15 +88,22 @@ namespace OpenSim.Data.NHibernate | |||
87 | { | 88 | { |
88 | string regex = @"no such table: UserProfiles"; | 89 | string regex = @"no such table: UserProfiles"; |
89 | Regex RE = new Regex(regex, RegexOptions.Multiline); | 90 | Regex RE = new Regex(regex, RegexOptions.Multiline); |
90 | try { | 91 | try |
91 | using (ISession session = factory.OpenSession()) { | 92 | { |
93 | using (ISession session = factory.OpenSession()) | ||
94 | { | ||
92 | session.Load(typeof(UserProfileData), LLUUID.Zero); | 95 | session.Load(typeof(UserProfileData), LLUUID.Zero); |
93 | } | 96 | } |
94 | } catch (ObjectNotFoundException) { | 97 | } |
98 | catch (ObjectNotFoundException) | ||
99 | { | ||
95 | // yes, we know it's not there, but that's ok | 100 | // yes, we know it's not there, but that's ok |
96 | } catch (ADOException e) { | 101 | } |
102 | catch (ADOException e) | ||
103 | { | ||
97 | Match m = RE.Match(e.ToString()); | 104 | Match m = RE.Match(e.ToString()); |
98 | if (m.Success) { | 105 | if (m.Success) |
106 | { | ||
99 | // We don't have this table, so create it. | 107 | // We don't have this table, so create it. |
100 | new SchemaExport(cfg).Create(true, true); | 108 | new SchemaExport(cfg).Create(true, true); |
101 | } | 109 | } |
@@ -105,12 +113,15 @@ namespace OpenSim.Data.NHibernate | |||
105 | private bool ExistsUser(LLUUID uuid) | 113 | private bool ExistsUser(LLUUID uuid) |
106 | { | 114 | { |
107 | UserProfileData user = null; | 115 | UserProfileData user = null; |
108 | try { | 116 | try |
109 | using (ISession session = factory.OpenSession()) { | 117 | { |
118 | using (ISession session = factory.OpenSession()) | ||
119 | { | ||
110 | user = session.Load(typeof(UserProfileData), uuid) as UserProfileData; | 120 | user = session.Load(typeof(UserProfileData), uuid) as UserProfileData; |
111 | } | 121 | } |
112 | // BUG: CATCHALL IS BAD. | 122 | // BUG: CATCHALL IS BAD. |
113 | } catch (Exception) {} | 123 | } |
124 | catch (Exception) {} | ||
114 | 125 | ||
115 | return (user != null); | 126 | return (user != null); |
116 | } | 127 | } |
@@ -119,7 +130,8 @@ namespace OpenSim.Data.NHibernate | |||
119 | { | 130 | { |
120 | UserProfileData user; | 131 | UserProfileData user; |
121 | // TODO: I'm sure I'll have to do something silly here | 132 | // TODO: I'm sure I'll have to do something silly here |
122 | using (ISession session = factory.OpenSession()) { | 133 | using (ISession session = factory.OpenSession()) |
134 | { | ||
123 | user = session.Load(typeof(UserProfileData), uuid) as UserProfileData; | 135 | user = session.Load(typeof(UserProfileData), uuid) as UserProfileData; |
124 | user.CurrentAgent = GetAgentByUUID(uuid); | 136 | user.CurrentAgent = GetAgentByUUID(uuid); |
125 | } | 137 | } |
@@ -128,16 +140,21 @@ namespace OpenSim.Data.NHibernate | |||
128 | 140 | ||
129 | override public void AddNewUserProfile(UserProfileData profile) | 141 | override public void AddNewUserProfile(UserProfileData profile) |
130 | { | 142 | { |
131 | if (!ExistsUser(profile.ID)) { | 143 | if (!ExistsUser(profile.ID)) |
132 | using (ISession session = factory.OpenSession()) { | 144 | { |
133 | using (ITransaction transaction = session.BeginTransaction()) { | 145 | using (ISession session = factory.OpenSession()) |
146 | { | ||
147 | using (ITransaction transaction = session.BeginTransaction()) | ||
148 | { | ||
134 | session.Save(profile); | 149 | session.Save(profile); |
135 | SetAgentData(profile.ID, profile.CurrentAgent, session); | 150 | SetAgentData(profile.ID, profile.CurrentAgent, session); |
136 | // TODO: save agent | 151 | // TODO: save agent |
137 | transaction.Commit(); | 152 | transaction.Commit(); |
138 | } | 153 | } |
139 | } | 154 | } |
140 | } else { | 155 | } |
156 | else | ||
157 | { | ||
141 | m_log.ErrorFormat("Attempted to add User {0} {1} that already exists, updating instead", profile.FirstName, profile.SurName); | 158 | m_log.ErrorFormat("Attempted to add User {0} {1} that already exists, updating instead", profile.FirstName, profile.SurName); |
142 | UpdateUserProfile(profile); | 159 | UpdateUserProfile(profile); |
143 | } | 160 | } |
@@ -165,16 +182,21 @@ namespace OpenSim.Data.NHibernate | |||
165 | } | 182 | } |
166 | override public bool UpdateUserProfile(UserProfileData profile) | 183 | override public bool UpdateUserProfile(UserProfileData profile) |
167 | { | 184 | { |
168 | if (ExistsUser(profile.ID)) { | 185 | if (ExistsUser(profile.ID)) |
169 | using (ISession session = factory.OpenSession()) { | 186 | { |
170 | using (ITransaction transaction = session.BeginTransaction()) { | 187 | using (ISession session = factory.OpenSession()) |
188 | { | ||
189 | using (ITransaction transaction = session.BeginTransaction()) | ||
190 | { | ||
171 | session.Update(profile); | 191 | session.Update(profile); |
172 | SetAgentData(profile.ID, profile.CurrentAgent, session); | 192 | SetAgentData(profile.ID, profile.CurrentAgent, session); |
173 | transaction.Commit(); | 193 | transaction.Commit(); |
174 | return true; | 194 | return true; |
175 | } | 195 | } |
176 | } | 196 | } |
177 | } else { | 197 | } |
198 | else | ||
199 | { | ||
178 | m_log.ErrorFormat("Attempted to update User {0} {1} that doesn't exist, updating instead", profile.FirstName, profile.SurName); | 200 | m_log.ErrorFormat("Attempted to update User {0} {1} that doesn't exist, updating instead", profile.FirstName, profile.SurName); |
179 | AddNewUserProfile(profile); | 201 | AddNewUserProfile(profile); |
180 | return true; | 202 | return true; |
@@ -183,8 +205,10 @@ namespace OpenSim.Data.NHibernate | |||
183 | 205 | ||
184 | override public void AddNewUserAgent(UserAgentData agent) | 206 | override public void AddNewUserAgent(UserAgentData agent) |
185 | { | 207 | { |
186 | using (ISession session = factory.OpenSession()) { | 208 | using (ISession session = factory.OpenSession()) |
187 | using (ITransaction transaction = session.BeginTransaction()) { | 209 | { |
210 | using (ITransaction transaction = session.BeginTransaction()) | ||
211 | { | ||
188 | session.Save(agent); | 212 | session.Save(agent); |
189 | transaction.Commit(); | 213 | transaction.Commit(); |
190 | } | 214 | } |
@@ -193,30 +217,35 @@ namespace OpenSim.Data.NHibernate | |||
193 | 217 | ||
194 | public void UpdateUserAgent(UserAgentData agent) | 218 | public void UpdateUserAgent(UserAgentData agent) |
195 | { | 219 | { |
196 | using (ISession session = factory.OpenSession()) { | 220 | using (ISession session = factory.OpenSession()) |
197 | using (ITransaction transaction = session.BeginTransaction()) { | 221 | { |
222 | using (ITransaction transaction = session.BeginTransaction()) | ||
223 | { | ||
198 | session.Update(agent); | 224 | session.Update(agent); |
199 | transaction.Commit(); | 225 | transaction.Commit(); |
200 | } | 226 | } |
201 | } | 227 | } |
202 | } | 228 | } |
203 | 229 | ||
204 | |||
205 | |||
206 | override public UserAgentData GetAgentByUUID(LLUUID uuid) | 230 | override public UserAgentData GetAgentByUUID(LLUUID uuid) |
207 | { | 231 | { |
208 | try { | 232 | try |
209 | using (ISession session = factory.OpenSession()) { | 233 | { |
234 | using (ISession session = factory.OpenSession()) | ||
235 | { | ||
210 | return session.Load(typeof(UserAgentData), uuid) as UserAgentData; | 236 | return session.Load(typeof(UserAgentData), uuid) as UserAgentData; |
211 | } | 237 | } |
212 | } catch { | 238 | } |
239 | catch | ||
240 | { | ||
213 | return null; | 241 | return null; |
214 | } | 242 | } |
215 | } | 243 | } |
216 | 244 | ||
217 | override public UserProfileData GetUserByName(string fname, string lname) | 245 | override public UserProfileData GetUserByName(string fname, string lname) |
218 | { | 246 | { |
219 | using (ISession session = factory.OpenSession()) { | 247 | using (ISession session = factory.OpenSession()) |
248 | { | ||
220 | ICriteria criteria = session.CreateCriteria(typeof(UserProfileData)); | 249 | ICriteria criteria = session.CreateCriteria(typeof(UserProfileData)); |
221 | criteria.Add(Expression.Eq("FirstName", fname)); | 250 | criteria.Add(Expression.Eq("FirstName", fname)); |
222 | criteria.Add(Expression.Eq("SurName", lname)); | 251 | criteria.Add(Expression.Eq("SurName", lname)); |
@@ -247,7 +276,8 @@ namespace OpenSim.Data.NHibernate | |||
247 | 276 | ||
248 | if (querysplit.Length == 2) | 277 | if (querysplit.Length == 2) |
249 | { | 278 | { |
250 | using (ISession session = factory.OpenSession()) { | 279 | using (ISession session = factory.OpenSession()) |
280 | { | ||
251 | ICriteria criteria = session.CreateCriteria(typeof(UserProfileData)); | 281 | ICriteria criteria = session.CreateCriteria(typeof(UserProfileData)); |
252 | criteria.Add(Expression.Like("FirstName", querysplit[0])); | 282 | criteria.Add(Expression.Like("FirstName", querysplit[0])); |
253 | criteria.Add(Expression.Like("SurName", querysplit[1])); | 283 | criteria.Add(Expression.Like("SurName", querysplit[1])); |
@@ -280,7 +310,8 @@ namespace OpenSim.Data.NHibernate | |||
280 | { | 310 | { |
281 | UserAppearance appearance; | 311 | UserAppearance appearance; |
282 | // TODO: I'm sure I'll have to do something silly here | 312 | // TODO: I'm sure I'll have to do something silly here |
283 | using (ISession session = factory.OpenSession()) { | 313 | using (ISession session = factory.OpenSession()) |
314 | { | ||
284 | appearance = session.Load(typeof(UserAppearance), user) as UserAppearance; | 315 | appearance = session.Load(typeof(UserAppearance), user) as UserAppearance; |
285 | } | 316 | } |
286 | return appearance; | 317 | return appearance; |
@@ -289,7 +320,8 @@ namespace OpenSim.Data.NHibernate | |||
289 | private bool ExistsAppearance(LLUUID uuid) | 320 | private bool ExistsAppearance(LLUUID uuid) |
290 | { | 321 | { |
291 | UserAppearance appearance; | 322 | UserAppearance appearance; |
292 | using (ISession session = factory.OpenSession()) { | 323 | using (ISession session = factory.OpenSession()) |
324 | { | ||
293 | appearance = session.Load(typeof(UserAppearance), uuid) as UserAppearance; | 325 | appearance = session.Load(typeof(UserAppearance), uuid) as UserAppearance; |
294 | } | 326 | } |
295 | return (appearance == null) ? false : true; | 327 | return (appearance == null) ? false : true; |
@@ -299,11 +331,16 @@ namespace OpenSim.Data.NHibernate | |||
299 | override public void UpdateUserAppearance(LLUUID user, UserAppearance appearance) | 331 | override public void UpdateUserAppearance(LLUUID user, UserAppearance appearance) |
300 | { | 332 | { |
301 | bool exists = ExistsAppearance(user); | 333 | bool exists = ExistsAppearance(user); |
302 | using (ISession session = factory.OpenSession()) { | 334 | using (ISession session = factory.OpenSession()) |
303 | using (ITransaction transaction = session.BeginTransaction()) { | 335 | { |
304 | if (exists) { | 336 | using (ITransaction transaction = session.BeginTransaction()) |
337 | { | ||
338 | if (exists) | ||
339 | { | ||
305 | session.Update(appearance); | 340 | session.Update(appearance); |
306 | } else { | 341 | } |
342 | else | ||
343 | { | ||
307 | session.Save(appearance); | 344 | session.Save(appearance); |
308 | } | 345 | } |
309 | transaction.Commit(); | 346 | transaction.Commit(); |