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/PGSQL/PGSQLAssetData.cs | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/PGSQL/PGSQLAssetData.cs (renamed from OpenSim/Data/MSSQL/MSSQLAssetData.cs) | 137 |
1 files changed, 82 insertions, 55 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLAssetData.cs b/OpenSim/Data/PGSQL/PGSQLAssetData.cs index c7488d8..5d8b0a2 100644 --- a/OpenSim/Data/MSSQL/MSSQLAssetData.cs +++ b/OpenSim/Data/PGSQL/PGSQLAssetData.cs | |||
@@ -27,19 +27,20 @@ | |||
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Data; | 29 | using System.Data; |
30 | using System.Data.SqlClient; | ||
31 | using System.Reflection; | 30 | using System.Reflection; |
32 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
33 | using OpenMetaverse; | 32 | using OpenMetaverse; |
34 | using log4net; | 33 | using log4net; |
35 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | using Npgsql; | ||
36 | using NpgsqlTypes; | ||
36 | 37 | ||
37 | namespace OpenSim.Data.MSSQL | 38 | namespace OpenSim.Data.PGSQL |
38 | { | 39 | { |
39 | /// <summary> | 40 | /// <summary> |
40 | /// A MSSQL Interface for the Asset server | 41 | /// A PGSQL Interface for the Asset server |
41 | /// </summary> | 42 | /// </summary> |
42 | public class MSSQLAssetData : AssetDataBase | 43 | public class PGSQLAssetData : AssetDataBase |
43 | { | 44 | { |
44 | private const string _migrationStore = "AssetStore"; | 45 | private const string _migrationStore = "AssetStore"; |
45 | 46 | ||
@@ -48,9 +49,14 @@ namespace OpenSim.Data.MSSQL | |||
48 | /// <summary> | 49 | /// <summary> |
49 | /// Database manager | 50 | /// Database manager |
50 | /// </summary> | 51 | /// </summary> |
51 | private MSSQLManager m_database; | 52 | private PGSQLManager m_database; |
52 | private string m_connectionString; | 53 | private string m_connectionString; |
53 | 54 | ||
55 | protected virtual Assembly Assembly | ||
56 | { | ||
57 | get { return GetType().Assembly; } | ||
58 | } | ||
59 | |||
54 | #region IPlugin Members | 60 | #region IPlugin Members |
55 | 61 | ||
56 | override public void Dispose() { } | 62 | override public void Dispose() { } |
@@ -61,7 +67,7 @@ namespace OpenSim.Data.MSSQL | |||
61 | // [Obsolete("Cannot be default-initialized!")] | 67 | // [Obsolete("Cannot be default-initialized!")] |
62 | override public void Initialise() | 68 | override public void Initialise() |
63 | { | 69 | { |
64 | m_log.Info("[MSSQLAssetData]: " + Name + " cannot be default-initialized!"); | 70 | m_log.Info("[PGSQLAssetData]: " + Name + " cannot be default-initialized!"); |
65 | throw new PluginNotInitialisedException(Name); | 71 | throw new PluginNotInitialisedException(Name); |
66 | } | 72 | } |
67 | 73 | ||
@@ -76,7 +82,7 @@ namespace OpenSim.Data.MSSQL | |||
76 | { | 82 | { |
77 | m_ticksToEpoch = new System.DateTime(1970, 1, 1).Ticks; | 83 | m_ticksToEpoch = new System.DateTime(1970, 1, 1).Ticks; |
78 | 84 | ||
79 | m_database = new MSSQLManager(connectionString); | 85 | m_database = new PGSQLManager(connectionString); |
80 | m_connectionString = connectionString; | 86 | m_connectionString = connectionString; |
81 | 87 | ||
82 | //New migration to check for DB changes | 88 | //New migration to check for DB changes |
@@ -96,7 +102,7 @@ namespace OpenSim.Data.MSSQL | |||
96 | /// </summary> | 102 | /// </summary> |
97 | override public string Name | 103 | override public string Name |
98 | { | 104 | { |
99 | get { return "MSSQL Asset storage engine"; } | 105 | get { return "PGSQL Asset storage engine"; } |
100 | } | 106 | } |
101 | 107 | ||
102 | #endregion | 108 | #endregion |
@@ -110,13 +116,13 @@ namespace OpenSim.Data.MSSQL | |||
110 | /// <returns></returns> | 116 | /// <returns></returns> |
111 | override public AssetBase GetAsset(UUID assetID) | 117 | override public AssetBase GetAsset(UUID assetID) |
112 | { | 118 | { |
113 | string sql = "SELECT * FROM assets WHERE id = @id"; | 119 | string sql = "SELECT * FROM assets WHERE id = :id"; |
114 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | 120 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) |
115 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 121 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) |
116 | { | 122 | { |
117 | cmd.Parameters.Add(m_database.CreateParameter("id", assetID)); | 123 | cmd.Parameters.Add(m_database.CreateParameter("id", assetID)); |
118 | conn.Open(); | 124 | conn.Open(); |
119 | using (SqlDataReader reader = cmd.ExecuteReader()) | 125 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) |
120 | { | 126 | { |
121 | if (reader.Read()) | 127 | if (reader.Read()) |
122 | { | 128 | { |
@@ -147,34 +153,38 @@ namespace OpenSim.Data.MSSQL | |||
147 | { | 153 | { |
148 | 154 | ||
149 | string sql = | 155 | string sql = |
150 | @"IF EXISTS(SELECT * FROM assets WHERE id=@id) | 156 | @"UPDATE assets set name = :name, description = :description, " + "\"assetType\" " + @" = :assetType, |
151 | UPDATE assets set name = @name, description = @description, assetType = @assetType, | 157 | local = :local, temporary = :temporary, creatorid = :creatorid, data = :data |
152 | local = @local, temporary = @temporary, creatorid = @creatorid, data = @data | 158 | WHERE id=:id; |
153 | WHERE id=@id | 159 | |
154 | ELSE | 160 | INSERT INTO assets |
155 | INSERT INTO assets | 161 | (id, name, description, " + "\"assetType\" " + @", local, |
156 | ([id], [name], [description], [assetType], [local], | 162 | temporary, create_time, access_time, creatorid, asset_flags, data) |
157 | [temporary], [create_time], [access_time], [creatorid], [asset_flags], [data]) | 163 | Select :id, :name, :description, :assetType, :local, |
158 | VALUES | 164 | :temporary, :create_time, :access_time, :creatorid, :asset_flags, :data |
159 | (@id, @name, @description, @assetType, @local, | 165 | Where not EXISTS(SELECT * FROM assets WHERE id=:id) |
160 | @temporary, @create_time, @access_time, @creatorid, @asset_flags, @data)"; | 166 | "; |
161 | 167 | ||
162 | string assetName = asset.Name; | 168 | string assetName = asset.Name; |
163 | if (asset.Name.Length > 64) | 169 | if (asset.Name.Length > AssetBase.MAX_ASSET_NAME) |
164 | { | 170 | { |
165 | assetName = asset.Name.Substring(0, 64); | 171 | assetName = asset.Name.Substring(0, AssetBase.MAX_ASSET_NAME); |
166 | m_log.Warn("[ASSET DB]: Name field truncated from " + asset.Name.Length + " to " + assetName.Length + " characters on add"); | 172 | m_log.WarnFormat( |
173 | "[ASSET DB]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
174 | asset.Name, asset.ID, asset.Name.Length, assetName.Length); | ||
167 | } | 175 | } |
168 | 176 | ||
169 | string assetDescription = asset.Description; | 177 | string assetDescription = asset.Description; |
170 | if (asset.Description.Length > 64) | 178 | if (asset.Description.Length > AssetBase.MAX_ASSET_DESC) |
171 | { | 179 | { |
172 | assetDescription = asset.Description.Substring(0, 64); | 180 | assetDescription = asset.Description.Substring(0, AssetBase.MAX_ASSET_DESC); |
173 | m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add"); | 181 | m_log.WarnFormat( |
182 | "[ASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
183 | asset.Description, asset.ID, asset.Description.Length, assetDescription.Length); | ||
174 | } | 184 | } |
175 | 185 | ||
176 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | 186 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) |
177 | using (SqlCommand command = new SqlCommand(sql, conn)) | 187 | using (NpgsqlCommand command = new NpgsqlCommand(sql, conn)) |
178 | { | 188 | { |
179 | int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000); | 189 | int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000); |
180 | command.Parameters.Add(m_database.CreateParameter("id", asset.FullID)); | 190 | command.Parameters.Add(m_database.CreateParameter("id", asset.FullID)); |
@@ -195,7 +205,7 @@ namespace OpenSim.Data.MSSQL | |||
195 | } | 205 | } |
196 | catch(Exception e) | 206 | catch(Exception e) |
197 | { | 207 | { |
198 | m_log.Error("[ASSET DB]: Error storing item :" + e.Message); | 208 | m_log.Error("[ASSET DB]: Error storing item :" + e.Message + " sql "+sql); |
199 | } | 209 | } |
200 | } | 210 | } |
201 | } | 211 | } |
@@ -204,11 +214,11 @@ namespace OpenSim.Data.MSSQL | |||
204 | // Commented out since currently unused - this probably should be called in GetAsset() | 214 | // Commented out since currently unused - this probably should be called in GetAsset() |
205 | // private void UpdateAccessTime(AssetBase asset) | 215 | // private void UpdateAccessTime(AssetBase asset) |
206 | // { | 216 | // { |
207 | // using (AutoClosingSqlCommand cmd = m_database.Query("UPDATE assets SET access_time = @access_time WHERE id=@id")) | 217 | // using (AutoClosingSqlCommand cmd = m_database.Query("UPDATE assets SET access_time = :access_time WHERE id=:id")) |
208 | // { | 218 | // { |
209 | // int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000); | 219 | // int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000); |
210 | // cmd.Parameters.AddWithValue("@id", asset.FullID.ToString()); | 220 | // cmd.Parameters.AddWithValue(":id", asset.FullID.ToString()); |
211 | // cmd.Parameters.AddWithValue("@access_time", now); | 221 | // cmd.Parameters.AddWithValue(":access_time", now); |
212 | // try | 222 | // try |
213 | // { | 223 | // { |
214 | // cmd.ExecuteNonQuery(); | 224 | // cmd.ExecuteNonQuery(); |
@@ -221,17 +231,38 @@ namespace OpenSim.Data.MSSQL | |||
221 | // } | 231 | // } |
222 | 232 | ||
223 | /// <summary> | 233 | /// <summary> |
224 | /// Check if asset exist in m_database | 234 | /// Check if the assets exist in the database. |
225 | /// </summary> | 235 | /// </summary> |
226 | /// <param name="uuid"></param> | 236 | /// <param name="uuids">The assets' IDs</param> |
227 | /// <returns>true if exist.</returns> | 237 | /// <returns>For each asset: true if it exists, false otherwise</returns> |
228 | override public bool ExistsAsset(UUID uuid) | 238 | public override bool[] AssetsExist(UUID[] uuids) |
229 | { | 239 | { |
230 | if (GetAsset(uuid) != null) | 240 | if (uuids.Length == 0) |
241 | return new bool[0]; | ||
242 | |||
243 | HashSet<UUID> exist = new HashSet<UUID>(); | ||
244 | |||
245 | string ids = "'" + string.Join("','", uuids) + "'"; | ||
246 | string sql = string.Format("SELECT id FROM assets WHERE id IN ({0})", ids); | ||
247 | |||
248 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
249 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
231 | { | 250 | { |
232 | return true; | 251 | conn.Open(); |
252 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
253 | { | ||
254 | while (reader.Read()) | ||
255 | { | ||
256 | UUID id = DBGuid.FromDB(reader["id"]); | ||
257 | exist.Add(id); | ||
258 | } | ||
259 | } | ||
233 | } | 260 | } |
234 | return false; | 261 | |
262 | bool[] results = new bool[uuids.Length]; | ||
263 | for (int i = 0; i < uuids.Length; i++) | ||
264 | results[i] = exist.Contains(uuids[i]); | ||
265 | return results; | ||
235 | } | 266 | } |
236 | 267 | ||
237 | /// <summary> | 268 | /// <summary> |
@@ -245,23 +276,19 @@ namespace OpenSim.Data.MSSQL | |||
245 | public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count) | 276 | public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count) |
246 | { | 277 | { |
247 | List<AssetMetadata> retList = new List<AssetMetadata>(count); | 278 | List<AssetMetadata> retList = new List<AssetMetadata>(count); |
248 | string sql = @"WITH OrderedAssets AS | 279 | string sql = @" SELECT id, name, description, " + "\"assetType\"" + @", temporary, creatorid |
249 | ( | 280 | FROM assets |
250 | SELECT id, name, description, assetType, temporary, creatorid, | 281 | order by id |
251 | RowNumber = ROW_NUMBER() OVER (ORDER BY id) | 282 | limit :stop |
252 | FROM assets | 283 | offset :start;"; |
253 | ) | ||
254 | SELECT * | ||
255 | FROM OrderedAssets | ||
256 | WHERE RowNumber BETWEEN @start AND @stop;"; | ||
257 | 284 | ||
258 | using (SqlConnection conn = new SqlConnection(m_connectionString)) | 285 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) |
259 | using (SqlCommand cmd = new SqlCommand(sql, conn)) | 286 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) |
260 | { | 287 | { |
261 | cmd.Parameters.Add(m_database.CreateParameter("start", start)); | 288 | cmd.Parameters.Add(m_database.CreateParameter("start", start)); |
262 | cmd.Parameters.Add(m_database.CreateParameter("stop", start + count - 1)); | 289 | cmd.Parameters.Add(m_database.CreateParameter("stop", start + count - 1)); |
263 | conn.Open(); | 290 | conn.Open(); |
264 | using (SqlDataReader reader = cmd.ExecuteReader()) | 291 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) |
265 | { | 292 | { |
266 | while (reader.Read()) | 293 | while (reader.Read()) |
267 | { | 294 | { |