aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/NHibernateEstateData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/NHibernate/NHibernateEstateData.cs168
1 files changed, 0 insertions, 168 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateEstateData.cs b/OpenSim/Data/NHibernate/NHibernateEstateData.cs
deleted file mode 100644
index 5c5be9f..0000000
--- a/OpenSim/Data/NHibernate/NHibernateEstateData.cs
+++ /dev/null
@@ -1,168 +0,0 @@
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 OpenSimulator 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
28using System.Reflection;
29using log4net;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Region.Framework.Interfaces;
33using NHibernate;
34using NHibernate.Criterion;
35using System.Collections;
36using System;
37
38namespace OpenSim.Data.NHibernate
39{
40 /// <summary>
41 /// A User storage interface for the DB4o database system
42 /// </summary>
43 public class NHibernateEstateData : IEstateDataStore
44 {
45
46 #region Fields
47
48 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49
50 private NHibernateManager manager;
51 public NHibernateManager Manager
52 {
53 get
54 {
55 return manager;
56 }
57 }
58
59 public string Name
60 {
61 get { return "NHibernateEstateData"; }
62 }
63
64 public string Version
65 {
66 get { return "0.1"; }
67 }
68
69 #endregion
70
71 #region Startup and shutdown.
72
73 public void Initialise()
74 {
75 m_log.Info("[NHIBERNATE]: " + Name + " cannot be default-initialized!");
76 throw new PluginNotInitialisedException(Name);
77 }
78
79 public void Initialise(string connect)
80 {
81
82 m_log.InfoFormat("[NHIBERNATE] Initializing " + Name + ".");
83 manager = new NHibernateManager(connect, "EstateStore");
84 }
85
86 public void Dispose() { }
87
88 #endregion
89
90 #region IEstateDataStore Members
91
92 public EstateSettings LoadEstateSettings(UUID regionID)
93 {
94 EstateRegionLink link = LoadEstateRegionLink(regionID);
95
96 // Ensure that estate settings exist for the link
97 if (link != null)
98 {
99 if (manager.GetWithStatefullSession(typeof(EstateSettings), link.EstateID) == null)
100 {
101 // Delete broken link
102 manager.Delete(link);
103 link = null;
104 }
105 }
106
107 // If estate link does not exist create estate settings and link it to region.
108 if (link == null)
109 {
110 EstateSettings estateSettings = new EstateSettings();
111 //estateSettings.EstateOwner = UUID.Random();
112 //estateSettings.BlockDwell = false;
113 object identifier = manager.Insert(estateSettings);
114
115 if (identifier == null)
116 {
117 // Saving failed. Error is logged in the manager.
118 return null;
119 }
120
121 uint estateID = (uint)identifier;
122 link = new EstateRegionLink();
123 link.EstateRegionLinkID = UUID.Random();
124 link.RegionID = regionID;
125 link.EstateID = estateID;
126 manager.InsertWithStatefullSession(link);
127 }
128
129 // Load estate settings according to the existing or created link.
130 return (EstateSettings)manager.GetWithStatefullSession(typeof(EstateSettings), link.EstateID);
131 }
132
133 public void StoreEstateSettings(EstateSettings estateSettings)
134 {
135 // Estates are always updated when stored.
136 // Insert is always done via. load method as with the current API
137 // this is explicitly the only way to create region link.
138 manager.UpdateWithStatefullSession(estateSettings);
139 }
140
141 #endregion
142
143 #region Private Utility Methods
144 private EstateRegionLink LoadEstateRegionLink(UUID regionID)
145 {
146 ICriteria criteria = manager.GetSession().CreateCriteria(typeof(EstateRegionLink));
147 criteria.Add(Expression.Eq("RegionID", regionID));
148 IList links = criteria.List();
149
150 // Fail fast if more than one estate links exist
151 if (links.Count > 1)
152 {
153 m_log.Error("[NHIBERNATE]: Region had more than one estate linked: " + regionID);
154 throw new Exception("[NHIBERNATE]: Region had more than one estate linked: " + regionID);
155 }
156
157 if (links.Count == 1)
158 {
159 return (EstateRegionLink)links[0];
160 }
161 else
162 {
163 return null;
164 }
165 }
166 #endregion
167 }
168}