diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateEstateData.cs | 322 |
1 files changed, 161 insertions, 161 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateEstateData.cs b/OpenSim/Data/NHibernate/NHibernateEstateData.cs index 59896dd..3d74135 100644 --- a/OpenSim/Data/NHibernate/NHibernateEstateData.cs +++ b/OpenSim/Data/NHibernate/NHibernateEstateData.cs | |||
@@ -1,161 +1,161 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System.Reflection; | 28 | using System.Reflection; |
29 | using log4net; | 29 | using log4net; |
30 | using OpenMetaverse; | 30 | using OpenMetaverse; |
31 | using OpenSim.Framework; | 31 | using OpenSim.Framework; |
32 | using OpenSim.Region.Framework.Interfaces; | 32 | using OpenSim.Region.Framework.Interfaces; |
33 | using NHibernate; | 33 | using NHibernate; |
34 | using NHibernate.Criterion; | 34 | using NHibernate.Criterion; |
35 | using System.Collections; | 35 | using System.Collections; |
36 | using System; | 36 | using System; |
37 | 37 | ||
38 | namespace OpenSim.Data.NHibernate | 38 | namespace OpenSim.Data.NHibernate |
39 | { | 39 | { |
40 | /// <summary> | 40 | /// <summary> |
41 | /// A User storage interface for the DB4o database system | 41 | /// A User storage interface for the DB4o database system |
42 | /// </summary> | 42 | /// </summary> |
43 | public class NHibernateEstateData : IEstateDataStore | 43 | public class NHibernateEstateData : IEstateDataStore |
44 | { | 44 | { |
45 | 45 | ||
46 | #region Fields | 46 | #region Fields |
47 | 47 | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
49 | 49 | ||
50 | public NHibernateManager manager; | 50 | public NHibernateManager manager; |
51 | 51 | ||
52 | public string Name | 52 | public string Name |
53 | { | 53 | { |
54 | get { return "NHibernateEstateData"; } | 54 | get { return "NHibernateEstateData"; } |
55 | } | 55 | } |
56 | 56 | ||
57 | public string Version | 57 | public string Version |
58 | { | 58 | { |
59 | get { return "0.1"; } | 59 | get { return "0.1"; } |
60 | } | 60 | } |
61 | 61 | ||
62 | #endregion | 62 | #endregion |
63 | 63 | ||
64 | #region Startup and shutdown. | 64 | #region Startup and shutdown. |
65 | 65 | ||
66 | public void Initialise() | 66 | public void Initialise() |
67 | { | 67 | { |
68 | m_log.Info("[NHIBERNATE]: " + Name + " cannot be default-initialized!"); | 68 | m_log.Info("[NHIBERNATE]: " + Name + " cannot be default-initialized!"); |
69 | throw new PluginNotInitialisedException(Name); | 69 | throw new PluginNotInitialisedException(Name); |
70 | } | 70 | } |
71 | 71 | ||
72 | public void Initialise(string connect) | 72 | public void Initialise(string connect) |
73 | { | 73 | { |
74 | 74 | ||
75 | m_log.InfoFormat("[NHIBERNATE] Initializing " + Name + "."); | 75 | m_log.InfoFormat("[NHIBERNATE] Initializing " + Name + "."); |
76 | manager = new NHibernateManager(connect, "EstateStore"); | 76 | manager = new NHibernateManager(connect, "EstateStore"); |
77 | } | 77 | } |
78 | 78 | ||
79 | public void Dispose() { } | 79 | public void Dispose() { } |
80 | 80 | ||
81 | #endregion | 81 | #endregion |
82 | 82 | ||
83 | #region IEstateDataStore Members | 83 | #region IEstateDataStore Members |
84 | 84 | ||
85 | public EstateSettings LoadEstateSettings(UUID regionID) | 85 | public EstateSettings LoadEstateSettings(UUID regionID) |
86 | { | 86 | { |
87 | EstateRegionLink link = LoadEstateRegionLink(regionID); | 87 | EstateRegionLink link = LoadEstateRegionLink(regionID); |
88 | 88 | ||
89 | // Ensure that estate settings exist for the link | 89 | // Ensure that estate settings exist for the link |
90 | if (link != null) | 90 | if (link != null) |
91 | { | 91 | { |
92 | if (manager.Load(typeof(EstateSettings), link.EstateID) == null) | 92 | if (manager.Load(typeof(EstateSettings), link.EstateID) == null) |
93 | { | 93 | { |
94 | // Delete broken link | 94 | // Delete broken link |
95 | manager.Delete(link); | 95 | manager.Delete(link); |
96 | link = null; | 96 | link = null; |
97 | } | 97 | } |
98 | } | 98 | } |
99 | 99 | ||
100 | // If estate link does not exist create estate settings and link it to region. | 100 | // If estate link does not exist create estate settings and link it to region. |
101 | if (link == null) | 101 | if (link == null) |
102 | { | 102 | { |
103 | EstateSettings estateSettings = new EstateSettings(); | 103 | EstateSettings estateSettings = new EstateSettings(); |
104 | //estateSettings.EstateOwner = UUID.Random(); | 104 | //estateSettings.EstateOwner = UUID.Random(); |
105 | //estateSettings.BlockDwell = false; | 105 | //estateSettings.BlockDwell = false; |
106 | object identifier = manager.Insert(estateSettings); | 106 | object identifier = manager.Insert(estateSettings); |
107 | 107 | ||
108 | if (identifier == null) | 108 | if (identifier == null) |
109 | { | 109 | { |
110 | // Saving failed. Error is logged in the manager. | 110 | // Saving failed. Error is logged in the manager. |
111 | return null; | 111 | return null; |
112 | } | 112 | } |
113 | 113 | ||
114 | uint estateID = (uint)identifier; | 114 | uint estateID = (uint)identifier; |
115 | link = new EstateRegionLink(); | 115 | link = new EstateRegionLink(); |
116 | link.EstateRegionLinkID = UUID.Random(); | 116 | link.EstateRegionLinkID = UUID.Random(); |
117 | link.RegionID = regionID; | 117 | link.RegionID = regionID; |
118 | link.EstateID = estateID; | 118 | link.EstateID = estateID; |
119 | manager.Insert(link); | 119 | manager.Insert(link); |
120 | } | 120 | } |
121 | 121 | ||
122 | // Load estate settings according to the existing or created link. | 122 | // Load estate settings according to the existing or created link. |
123 | return (EstateSettings)manager.Load(typeof(EstateSettings), link.EstateID); | 123 | return (EstateSettings)manager.Load(typeof(EstateSettings), link.EstateID); |
124 | } | 124 | } |
125 | 125 | ||
126 | public void StoreEstateSettings(EstateSettings estateSettings) | 126 | public void StoreEstateSettings(EstateSettings estateSettings) |
127 | { | 127 | { |
128 | // Estates are always updated when stored. | 128 | // Estates are always updated when stored. |
129 | // Insert is always done via. load method as with the current API | 129 | // Insert is always done via. load method as with the current API |
130 | // this is explicitly the only way to create region link. | 130 | // this is explicitly the only way to create region link. |
131 | manager.Update(estateSettings); | 131 | manager.Update(estateSettings); |
132 | } | 132 | } |
133 | 133 | ||
134 | #endregion | 134 | #endregion |
135 | 135 | ||
136 | #region Private Utility Methods | 136 | #region Private Utility Methods |
137 | private EstateRegionLink LoadEstateRegionLink(UUID regionID) | 137 | private EstateRegionLink LoadEstateRegionLink(UUID regionID) |
138 | { | 138 | { |
139 | ICriteria criteria = manager.GetSession().CreateCriteria(typeof(EstateRegionLink)); | 139 | ICriteria criteria = manager.GetSession().CreateCriteria(typeof(EstateRegionLink)); |
140 | criteria.Add(Expression.Eq("RegionID", regionID)); | 140 | criteria.Add(Expression.Eq("RegionID", regionID)); |
141 | IList links = criteria.List(); | 141 | IList links = criteria.List(); |
142 | 142 | ||
143 | // Fail fast if more than one estate links exist | 143 | // Fail fast if more than one estate links exist |
144 | if (links.Count > 1) | 144 | if (links.Count > 1) |
145 | { | 145 | { |
146 | m_log.Error("[NHIBERNATE]: Region had more than one estate linked: " + regionID); | 146 | m_log.Error("[NHIBERNATE]: Region had more than one estate linked: " + regionID); |
147 | throw new Exception("[NHIBERNATE]: Region had more than one estate linked: " + regionID); | 147 | throw new Exception("[NHIBERNATE]: Region had more than one estate linked: " + regionID); |
148 | } | 148 | } |
149 | 149 | ||
150 | if (links.Count == 1) | 150 | if (links.Count == 1) |
151 | { | 151 | { |
152 | return (EstateRegionLink)links[0]; | 152 | return (EstateRegionLink)links[0]; |
153 | } | 153 | } |
154 | else | 154 | else |
155 | { | 155 | { |
156 | return null; | 156 | return null; |
157 | } | 157 | } |
158 | } | 158 | } |
159 | #endregion | 159 | #endregion |
160 | } | 160 | } |
161 | } | 161 | } |