diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Data/MSSQL/MSSQLAssetData.cs | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC_OLD-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Data/MSSQL/MSSQLAssetData.cs')
-rw-r--r-- | OpenSim/Data/MSSQL/MSSQLAssetData.cs | 289 |
1 files changed, 0 insertions, 289 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLAssetData.cs b/OpenSim/Data/MSSQL/MSSQLAssetData.cs deleted file mode 100644 index c7488d8..0000000 --- a/OpenSim/Data/MSSQL/MSSQLAssetData.cs +++ /dev/null | |||
@@ -1,289 +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 | |||
28 | using System; | ||
29 | using System.Data; | ||
30 | using System.Data.SqlClient; | ||
31 | using System.Reflection; | ||
32 | using System.Collections.Generic; | ||
33 | using OpenMetaverse; | ||
34 | using log4net; | ||
35 | using OpenSim.Framework; | ||
36 | |||
37 | namespace OpenSim.Data.MSSQL | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// A MSSQL Interface for the Asset server | ||
41 | /// </summary> | ||
42 | public class MSSQLAssetData : AssetDataBase | ||
43 | { | ||
44 | private const string _migrationStore = "AssetStore"; | ||
45 | |||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | private long m_ticksToEpoch; | ||
48 | /// <summary> | ||
49 | /// Database manager | ||
50 | /// </summary> | ||
51 | private MSSQLManager m_database; | ||
52 | private string m_connectionString; | ||
53 | |||
54 | #region IPlugin Members | ||
55 | |||
56 | override public void Dispose() { } | ||
57 | |||
58 | /// <summary> | ||
59 | /// <para>Initialises asset interface</para> | ||
60 | /// </summary> | ||
61 | // [Obsolete("Cannot be default-initialized!")] | ||
62 | override public void Initialise() | ||
63 | { | ||
64 | m_log.Info("[MSSQLAssetData]: " + Name + " cannot be default-initialized!"); | ||
65 | throw new PluginNotInitialisedException(Name); | ||
66 | } | ||
67 | |||
68 | /// <summary> | ||
69 | /// Initialises asset interface | ||
70 | /// </summary> | ||
71 | /// <para> | ||
72 | /// a string instead of file, if someone writes the support | ||
73 | /// </para> | ||
74 | /// <param name="connectionString">connect string</param> | ||
75 | override public void Initialise(string connectionString) | ||
76 | { | ||
77 | m_ticksToEpoch = new System.DateTime(1970, 1, 1).Ticks; | ||
78 | |||
79 | m_database = new MSSQLManager(connectionString); | ||
80 | m_connectionString = connectionString; | ||
81 | |||
82 | //New migration to check for DB changes | ||
83 | m_database.CheckMigration(_migrationStore); | ||
84 | } | ||
85 | |||
86 | /// <summary> | ||
87 | /// Database provider version. | ||
88 | /// </summary> | ||
89 | override public string Version | ||
90 | { | ||
91 | get { return m_database.getVersion(); } | ||
92 | } | ||
93 | |||
94 | /// <summary> | ||
95 | /// The name of this DB provider. | ||
96 | /// </summary> | ||
97 | override public string Name | ||
98 | { | ||
99 | get { return "MSSQL Asset storage engine"; } | ||
100 | } | ||
101 | |||
102 | #endregion | ||
103 | |||
104 | #region IAssetDataPlugin Members | ||
105 | |||
106 | /// <summary> | ||
107 | /// Fetch Asset from m_database | ||
108 | /// </summary> | ||
109 | /// <param name="assetID">the asset UUID</param> | ||
110 | /// <returns></returns> | ||
111 | override public AssetBase GetAsset(UUID assetID) | ||
112 | { | ||
113 | string sql = "SELECT * FROM assets WHERE id = @id"; | ||
114 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | ||
115 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
116 | { | ||
117 | cmd.Parameters.Add(m_database.CreateParameter("id", assetID)); | ||
118 | conn.Open(); | ||
119 | using (SqlDataReader reader = cmd.ExecuteReader()) | ||
120 | { | ||
121 | if (reader.Read()) | ||
122 | { | ||
123 | AssetBase asset = new AssetBase( | ||
124 | DBGuid.FromDB(reader["id"]), | ||
125 | (string)reader["name"], | ||
126 | Convert.ToSByte(reader["assetType"]), | ||
127 | reader["creatorid"].ToString() | ||
128 | ); | ||
129 | // Region Main | ||
130 | asset.Description = (string)reader["description"]; | ||
131 | asset.Local = Convert.ToBoolean(reader["local"]); | ||
132 | asset.Temporary = Convert.ToBoolean(reader["temporary"]); | ||
133 | asset.Flags = (AssetFlags)(Convert.ToInt32(reader["asset_flags"])); | ||
134 | asset.Data = (byte[])reader["data"]; | ||
135 | return asset; | ||
136 | } | ||
137 | return null; // throw new Exception("No rows to return"); | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | |||
142 | /// <summary> | ||
143 | /// Create asset in m_database | ||
144 | /// </summary> | ||
145 | /// <param name="asset">the asset</param> | ||
146 | override public void StoreAsset(AssetBase asset) | ||
147 | { | ||
148 | |||
149 | string sql = | ||
150 | @"IF EXISTS(SELECT * FROM assets WHERE id=@id) | ||
151 | UPDATE assets set name = @name, description = @description, assetType = @assetType, | ||
152 | local = @local, temporary = @temporary, creatorid = @creatorid, data = @data | ||
153 | WHERE id=@id | ||
154 | ELSE | ||
155 | INSERT INTO assets | ||
156 | ([id], [name], [description], [assetType], [local], | ||
157 | [temporary], [create_time], [access_time], [creatorid], [asset_flags], [data]) | ||
158 | VALUES | ||
159 | (@id, @name, @description, @assetType, @local, | ||
160 | @temporary, @create_time, @access_time, @creatorid, @asset_flags, @data)"; | ||
161 | |||
162 | string assetName = asset.Name; | ||
163 | if (asset.Name.Length > 64) | ||
164 | { | ||
165 | assetName = asset.Name.Substring(0, 64); | ||
166 | m_log.Warn("[ASSET DB]: Name field truncated from " + asset.Name.Length + " to " + assetName.Length + " characters on add"); | ||
167 | } | ||
168 | |||
169 | string assetDescription = asset.Description; | ||
170 | if (asset.Description.Length > 64) | ||
171 | { | ||
172 | assetDescription = asset.Description.Substring(0, 64); | ||
173 | m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add"); | ||
174 | } | ||
175 | |||
176 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | ||
177 | using (SqlCommand command = new SqlCommand(sql, conn)) | ||
178 | { | ||
179 | int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000); | ||
180 | command.Parameters.Add(m_database.CreateParameter("id", asset.FullID)); | ||
181 | command.Parameters.Add(m_database.CreateParameter("name", assetName)); | ||
182 | command.Parameters.Add(m_database.CreateParameter("description", assetDescription)); | ||
183 | command.Parameters.Add(m_database.CreateParameter("assetType", asset.Type)); | ||
184 | command.Parameters.Add(m_database.CreateParameter("local", asset.Local)); | ||
185 | command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary)); | ||
186 | command.Parameters.Add(m_database.CreateParameter("access_time", now)); | ||
187 | command.Parameters.Add(m_database.CreateParameter("create_time", now)); | ||
188 | command.Parameters.Add(m_database.CreateParameter("asset_flags", (int)asset.Flags)); | ||
189 | command.Parameters.Add(m_database.CreateParameter("creatorid", asset.Metadata.CreatorID)); | ||
190 | command.Parameters.Add(m_database.CreateParameter("data", asset.Data)); | ||
191 | conn.Open(); | ||
192 | try | ||
193 | { | ||
194 | command.ExecuteNonQuery(); | ||
195 | } | ||
196 | catch(Exception e) | ||
197 | { | ||
198 | m_log.Error("[ASSET DB]: Error storing item :" + e.Message); | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | |||
203 | |||
204 | // Commented out since currently unused - this probably should be called in GetAsset() | ||
205 | // private void UpdateAccessTime(AssetBase asset) | ||
206 | // { | ||
207 | // using (AutoClosingSqlCommand cmd = m_database.Query("UPDATE assets SET access_time = @access_time WHERE id=@id")) | ||
208 | // { | ||
209 | // int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000); | ||
210 | // cmd.Parameters.AddWithValue("@id", asset.FullID.ToString()); | ||
211 | // cmd.Parameters.AddWithValue("@access_time", now); | ||
212 | // try | ||
213 | // { | ||
214 | // cmd.ExecuteNonQuery(); | ||
215 | // } | ||
216 | // catch (Exception e) | ||
217 | // { | ||
218 | // m_log.Error(e.ToString()); | ||
219 | // } | ||
220 | // } | ||
221 | // } | ||
222 | |||
223 | /// <summary> | ||
224 | /// Check if asset exist in m_database | ||
225 | /// </summary> | ||
226 | /// <param name="uuid"></param> | ||
227 | /// <returns>true if exist.</returns> | ||
228 | override public bool ExistsAsset(UUID uuid) | ||
229 | { | ||
230 | if (GetAsset(uuid) != null) | ||
231 | { | ||
232 | return true; | ||
233 | } | ||
234 | return false; | ||
235 | } | ||
236 | |||
237 | /// <summary> | ||
238 | /// Returns a list of AssetMetadata objects. The list is a subset of | ||
239 | /// the entire data set offset by <paramref name="start" /> containing | ||
240 | /// <paramref name="count" /> elements. | ||
241 | /// </summary> | ||
242 | /// <param name="start">The number of results to discard from the total data set.</param> | ||
243 | /// <param name="count">The number of rows the returned list should contain.</param> | ||
244 | /// <returns>A list of AssetMetadata objects.</returns> | ||
245 | public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count) | ||
246 | { | ||
247 | List<AssetMetadata> retList = new List<AssetMetadata>(count); | ||
248 | string sql = @"WITH OrderedAssets AS | ||
249 | ( | ||
250 | SELECT id, name, description, assetType, temporary, creatorid, | ||
251 | RowNumber = ROW_NUMBER() OVER (ORDER BY id) | ||
252 | FROM assets | ||
253 | ) | ||
254 | SELECT * | ||
255 | FROM OrderedAssets | ||
256 | WHERE RowNumber BETWEEN @start AND @stop;"; | ||
257 | |||
258 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | ||
259 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
260 | { | ||
261 | cmd.Parameters.Add(m_database.CreateParameter("start", start)); | ||
262 | cmd.Parameters.Add(m_database.CreateParameter("stop", start + count - 1)); | ||
263 | conn.Open(); | ||
264 | using (SqlDataReader reader = cmd.ExecuteReader()) | ||
265 | { | ||
266 | while (reader.Read()) | ||
267 | { | ||
268 | AssetMetadata metadata = new AssetMetadata(); | ||
269 | metadata.FullID = DBGuid.FromDB(reader["id"]); | ||
270 | metadata.Name = (string)reader["name"]; | ||
271 | metadata.Description = (string)reader["description"]; | ||
272 | metadata.Type = Convert.ToSByte(reader["assetType"]); | ||
273 | metadata.Temporary = Convert.ToBoolean(reader["temporary"]); | ||
274 | metadata.CreatorID = (string)reader["creatorid"]; | ||
275 | retList.Add(metadata); | ||
276 | } | ||
277 | } | ||
278 | } | ||
279 | |||
280 | return retList; | ||
281 | } | ||
282 | |||
283 | public override bool Delete(string id) | ||
284 | { | ||
285 | return false; | ||
286 | } | ||
287 | #endregion | ||
288 | } | ||
289 | } | ||