aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/NHibernateGridData.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-01-20 18:38:51 +0000
committerJustin Clarke Casey2009-01-20 18:38:51 +0000
commit37f7c5a0ea272761793e072f2439e5b8e5f30e13 (patch)
tree53199c878a8d509b1dc04274357c6e910f597f79 /OpenSim/Data/NHibernate/NHibernateGridData.cs
parent* Apply http://opensimulator.org/mantis/view.php?id=3012 (diff)
downloadopensim-SC_OLD-37f7c5a0ea272761793e072f2439e5b8e5f30e13.zip
opensim-SC_OLD-37f7c5a0ea272761793e072f2439e5b8e5f30e13.tar.gz
opensim-SC_OLD-37f7c5a0ea272761793e072f2439e5b8e5f30e13.tar.bz2
opensim-SC_OLD-37f7c5a0ea272761793e072f2439e5b8e5f30e13.tar.xz
* Apply http://opensimulator.org/mantis/view.php?id=3020
* Adds a grid db implementation and unit tests to the NHibernate module
Diffstat (limited to 'OpenSim/Data/NHibernate/NHibernateGridData.cs')
-rw-r--r--OpenSim/Data/NHibernate/NHibernateGridData.cs241
1 files changed, 241 insertions, 0 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateGridData.cs b/OpenSim/Data/NHibernate/NHibernateGridData.cs
new file mode 100644
index 0000000..912beca
--- /dev/null
+++ b/OpenSim/Data/NHibernate/NHibernateGridData.cs
@@ -0,0 +1,241 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28
29using System;
30using System.Collections.Generic;
31using System.Text;
32using log4net;
33using System.Reflection;
34using OpenSim.Framework;
35using NHibernate;
36using NHibernate.Criterion;
37using System.Collections;
38using OpenMetaverse;
39
40namespace OpenSim.Data.NHibernate
41{
42
43 /// <summary>
44 /// A GridData Interface to the NHibernate database
45 /// </summary>
46 public class NHibernateGridData : GridDataBase
47 {
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 public NHibernateManager manager;
50
51 public override void Initialise()
52 {
53 m_log.Info("[NHibernateGridData]: " + Name + " cannot be default-initialized!");
54 throw new PluginNotInitialisedException(Name);
55 }
56
57 public override void Initialise(string connect)
58 {
59 m_log.InfoFormat("[NHIBERNATE] Initializing NHibernateGridData");
60 manager = new NHibernateManager(connect, "GridStore");
61 }
62
63 /***********************************************************************
64 *
65 * Public Interface Functions
66 *
67 **********************************************************************/
68
69 public override void Dispose() { }
70
71 /// <summary>
72 /// The plugin being loaded
73 /// </summary>
74 /// <returns>A string containing the plugin name</returns>
75 public override string Name
76 {
77 get { return "NHibernate Grid Data Interface"; }
78 }
79
80 /// <summary>
81 /// The plugins version
82 /// </summary>
83 /// <returns>A string containing the plugin version</returns>
84 public override string Version
85 {
86 get
87 {
88 Module module = GetType().Module;
89 Version dllVersion = module.Assembly.GetName().Version;
90
91 return string.Format("{0}.{1}.{2}.{3}",
92 dllVersion.Major, dllVersion.Minor, dllVersion.Build, dllVersion.Revision);
93 }
94 }
95
96 public override bool AuthenticateSim(OpenMetaverse.UUID UUID, ulong regionHandle, string simrecvkey)
97 {
98 bool throwHissyFit = false; // Should be true by 1.0
99
100 if (throwHissyFit)
101 throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential.");
102
103 RegionProfileData data = GetProfileByUUID(UUID);
104
105 return (regionHandle == data.regionHandle && simrecvkey == data.regionSecret);
106 }
107
108 public override ReservationData GetReservationAtPoint(uint x, uint y)
109 {
110 throw new NotImplementedException();
111 }
112
113 public override DataResponse AddProfile(RegionProfileData profile)
114 {
115 if (manager.Load(typeof(RegionProfileData), profile.Uuid) == null)
116 {
117 manager.Save(profile);
118 return DataResponse.RESPONSE_OK;
119 }
120 else
121 {
122 return DataResponse.RESPONSE_ERROR;
123 }
124 }
125
126 public override DataResponse UpdateProfile(RegionProfileData profile)
127 {
128 if (manager.Load(typeof(RegionProfileData), profile.Uuid) != null)
129 {
130 manager.Update(profile);
131 return DataResponse.RESPONSE_OK;
132 }
133 else
134 {
135 return DataResponse.RESPONSE_ERROR;
136 }
137 }
138
139 public override DataResponse DeleteProfile(string uuid)
140 {
141 RegionProfileData regionProfileData = (RegionProfileData)manager.Load(typeof(RegionProfileData), new UUID(uuid));
142 if (regionProfileData != null)
143 {
144 manager.Delete(regionProfileData);
145 return DataResponse.RESPONSE_OK;
146 }
147 return DataResponse.RESPONSE_ERROR;
148 }
149
150 public override RegionProfileData GetProfileByUUID(OpenMetaverse.UUID UUID)
151 {
152 return (RegionProfileData)manager.Load(typeof(RegionProfileData), UUID);
153 }
154
155 public override RegionProfileData GetProfileByHandle(ulong regionHandle)
156 {
157 using (ISession session = manager.GetSession())
158 {
159 ICriteria criteria = session.CreateCriteria(typeof(RegionProfileData));
160 criteria.Add(Expression.Eq("RegionHandle", regionHandle));
161
162 IList regions = criteria.List();
163
164 if (regions.Count == 1)
165 {
166 return (RegionProfileData)regions[0];
167 }
168 else
169 {
170 return null;
171 }
172 }
173 }
174
175 public override RegionProfileData GetProfileByString(string regionName)
176 {
177
178 using (ISession session = manager.GetSession())
179 {
180 ICriteria criteria = session.CreateCriteria(typeof(RegionProfileData));
181 criteria.Add(Expression.Eq("RegionName", regionName));
182
183 IList regions = criteria.List();
184
185 if (regions.Count == 1)
186 {
187 return (RegionProfileData)regions[0];
188 }
189 else
190 {
191 return null;
192 }
193 }
194
195 }
196
197 public override RegionProfileData[] GetProfilesInRange(uint Xmin, uint Ymin, uint Xmax, uint Ymax)
198 {
199 using (ISession session = manager.GetSession())
200 {
201 ICriteria criteria = session.CreateCriteria(typeof(RegionProfileData));
202 criteria.Add(Expression.Ge("RegionLocX", Xmin));
203 criteria.Add(Expression.Ge("RegionLocY", Ymin));
204 criteria.Add(Expression.Le("RegionLocX", Xmax));
205 criteria.Add(Expression.Le("RegionLocY", Ymax));
206
207 IList regions = criteria.List();
208 RegionProfileData[] regionArray = new RegionProfileData[regions.Count];
209
210 for(int i=0;i<regionArray.Length;i++)
211 {
212 regionArray[i] = (RegionProfileData)regions[i];
213 }
214
215 return regionArray;
216 }
217 }
218
219 public override List<RegionProfileData> GetRegionsByName(string namePrefix, uint maxNum)
220 {
221 using (ISession session = manager.GetSession())
222 {
223 ICriteria criteria = session.CreateCriteria(typeof(RegionProfileData));
224 criteria.SetMaxResults((int)maxNum);
225
226 criteria.Add(Expression.Like("RegionName", namePrefix, MatchMode.Start));
227
228 IList regions = criteria.List();
229 List<RegionProfileData> regionList = new List<RegionProfileData>();
230
231 foreach (RegionProfileData regionProfileData in regions)
232 {
233 regionList.Add(regionProfileData);
234 }
235
236 return regionList;
237 }
238 }
239
240 }
241}