diff options
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLXAssetData.cs')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLXAssetData.cs | 113 |
1 files changed, 66 insertions, 47 deletions
diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs index af7e876..9f9c9cf 100644 --- a/OpenSim/Data/MySQL/MySQLXAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs | |||
@@ -97,6 +97,7 @@ namespace OpenSim.Data.MySQL | |||
97 | dbcon.Open(); | 97 | dbcon.Open(); |
98 | Migration m = new Migration(dbcon, Assembly, "XAssetStore"); | 98 | Migration m = new Migration(dbcon, Assembly, "XAssetStore"); |
99 | m.Update(); | 99 | m.Update(); |
100 | dbcon.Close(); | ||
100 | } | 101 | } |
101 | } | 102 | } |
102 | 103 | ||
@@ -130,6 +131,7 @@ namespace OpenSim.Data.MySQL | |||
130 | // m_log.DebugFormat("[MYSQL XASSET DATA]: Looking for asset {0}", assetID); | 131 | // m_log.DebugFormat("[MYSQL XASSET DATA]: Looking for asset {0}", assetID); |
131 | 132 | ||
132 | AssetBase asset = null; | 133 | AssetBase asset = null; |
134 | int accessTime = 0; | ||
133 | 135 | ||
134 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | 136 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
135 | { | 137 | { |
@@ -140,7 +142,6 @@ namespace OpenSim.Data.MySQL | |||
140 | dbcon)) | 142 | dbcon)) |
141 | { | 143 | { |
142 | cmd.Parameters.AddWithValue("?ID", assetID.ToString()); | 144 | cmd.Parameters.AddWithValue("?ID", assetID.ToString()); |
143 | |||
144 | try | 145 | try |
145 | { | 146 | { |
146 | using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | 147 | using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) |
@@ -159,23 +160,7 @@ namespace OpenSim.Data.MySQL | |||
159 | 160 | ||
160 | asset.Temporary = Convert.ToBoolean(dbReader["Temporary"]); | 161 | asset.Temporary = Convert.ToBoolean(dbReader["Temporary"]); |
161 | asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["AssetFlags"]); | 162 | asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["AssetFlags"]); |
162 | 163 | accessTime = (int)dbReader["AccessTime"]; | |
163 | if (m_enableCompression) | ||
164 | { | ||
165 | using (GZipStream decompressionStream = new GZipStream(new MemoryStream(asset.Data), CompressionMode.Decompress)) | ||
166 | { | ||
167 | MemoryStream outputStream = new MemoryStream(); | ||
168 | WebUtil.CopyStream(decompressionStream, outputStream, int.MaxValue); | ||
169 | // int compressedLength = asset.Data.Length; | ||
170 | asset.Data = outputStream.ToArray(); | ||
171 | |||
172 | // m_log.DebugFormat( | ||
173 | // "[XASSET DB]: Decompressed {0} {1} to {2} bytes from {3}", | ||
174 | // asset.ID, asset.Name, asset.Data.Length, compressedLength); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | UpdateAccessTime(asset.Metadata, (int)dbReader["AccessTime"]); | ||
179 | } | 164 | } |
180 | } | 165 | } |
181 | } | 166 | } |
@@ -184,9 +169,38 @@ namespace OpenSim.Data.MySQL | |||
184 | m_log.Error(string.Format("[MYSQL XASSET DATA]: Failure fetching asset {0}", assetID), e); | 169 | m_log.Error(string.Format("[MYSQL XASSET DATA]: Failure fetching asset {0}", assetID), e); |
185 | } | 170 | } |
186 | } | 171 | } |
172 | dbcon.Close(); | ||
187 | } | 173 | } |
188 | 174 | ||
189 | return asset; | 175 | if(asset == null) |
176 | return asset; | ||
177 | |||
178 | if(accessTime > 0) | ||
179 | { | ||
180 | try | ||
181 | { | ||
182 | UpdateAccessTime(asset.Metadata, accessTime); | ||
183 | } | ||
184 | catch { } | ||
185 | } | ||
186 | |||
187 | if (m_enableCompression && asset.Data != null) | ||
188 | { | ||
189 | using(MemoryStream ms = new MemoryStream(asset.Data)) | ||
190 | using(GZipStream decompressionStream = new GZipStream(ms, CompressionMode.Decompress)) | ||
191 | { | ||
192 | using(MemoryStream outputStream = new MemoryStream()) | ||
193 | { | ||
194 | decompressionStream.CopyTo(outputStream, int.MaxValue); | ||
195 | // int compressedLength = asset.Data.Length; | ||
196 | asset.Data = outputStream.ToArray(); | ||
197 | } | ||
198 | // m_log.DebugFormat( | ||
199 | // "[XASSET DB]: Decompressed {0} {1} to {2} bytes from {3}", | ||
200 | // asset.ID, asset.Name, asset.Data.Length, compressedLength); | ||
201 | } | ||
202 | } | ||
203 | return asset; | ||
190 | } | 204 | } |
191 | 205 | ||
192 | /// <summary> | 206 | /// <summary> |
@@ -209,7 +223,7 @@ namespace OpenSim.Data.MySQL | |||
209 | { | 223 | { |
210 | assetName = asset.Name.Substring(0, AssetBase.MAX_ASSET_NAME); | 224 | assetName = asset.Name.Substring(0, AssetBase.MAX_ASSET_NAME); |
211 | m_log.WarnFormat( | 225 | m_log.WarnFormat( |
212 | "[XASSET DB]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add", | 226 | "[XASSET DB]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add", |
213 | asset.Name, asset.ID, asset.Name.Length, assetName.Length); | 227 | asset.Name, asset.ID, asset.Name.Length, assetName.Length); |
214 | } | 228 | } |
215 | 229 | ||
@@ -218,7 +232,7 @@ namespace OpenSim.Data.MySQL | |||
218 | { | 232 | { |
219 | assetDescription = asset.Description.Substring(0, AssetBase.MAX_ASSET_DESC); | 233 | assetDescription = asset.Description.Substring(0, AssetBase.MAX_ASSET_DESC); |
220 | m_log.WarnFormat( | 234 | m_log.WarnFormat( |
221 | "[XASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add", | 235 | "[XASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add", |
222 | asset.Description, asset.ID, asset.Description.Length, assetDescription.Length); | 236 | asset.Description, asset.ID, asset.Description.Length, assetDescription.Length); |
223 | } | 237 | } |
224 | 238 | ||
@@ -303,6 +317,7 @@ namespace OpenSim.Data.MySQL | |||
303 | 317 | ||
304 | transaction.Commit(); | 318 | transaction.Commit(); |
305 | } | 319 | } |
320 | dbcon.Close(); | ||
306 | } | 321 | } |
307 | } | 322 | } |
308 | 323 | ||
@@ -341,9 +356,10 @@ namespace OpenSim.Data.MySQL | |||
341 | catch (Exception) | 356 | catch (Exception) |
342 | { | 357 | { |
343 | m_log.ErrorFormat( | 358 | m_log.ErrorFormat( |
344 | "[XASSET MYSQL DB]: Failure updating access_time for asset {0} with name {1}", | 359 | "[XASSET MYSQL DB]: Failure updating access_time for asset {0} with name {1}", |
345 | assetMetadata.ID, assetMetadata.Name); | 360 | assetMetadata.ID, assetMetadata.Name); |
346 | } | 361 | } |
362 | dbcon.Close(); | ||
347 | } | 363 | } |
348 | } | 364 | } |
349 | 365 | ||
@@ -440,38 +456,41 @@ namespace OpenSim.Data.MySQL | |||
440 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | 456 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
441 | { | 457 | { |
442 | dbcon.Open(); | 458 | dbcon.Open(); |
443 | MySqlCommand cmd = new MySqlCommand("SELECT Name, Description, AccessTime, AssetType, Temporary, ID, AssetFlags, CreatorID FROM XAssetsMeta LIMIT ?start, ?count", dbcon); | 459 | using(MySqlCommand cmd = new MySqlCommand("SELECT Name, Description, AccessTime, AssetType, Temporary, ID, AssetFlags, CreatorID FROM XAssetsMeta LIMIT ?start, ?count",dbcon)) |
444 | cmd.Parameters.AddWithValue("?start", start); | ||
445 | cmd.Parameters.AddWithValue("?count", count); | ||
446 | |||
447 | try | ||
448 | { | 460 | { |
449 | using (MySqlDataReader dbReader = cmd.ExecuteReader()) | 461 | cmd.Parameters.AddWithValue("?start",start); |
462 | cmd.Parameters.AddWithValue("?count", count); | ||
463 | |||
464 | try | ||
450 | { | 465 | { |
451 | while (dbReader.Read()) | 466 | using (MySqlDataReader dbReader = cmd.ExecuteReader()) |
452 | { | 467 | { |
453 | AssetMetadata metadata = new AssetMetadata(); | 468 | while (dbReader.Read()) |
454 | metadata.Name = (string)dbReader["Name"]; | 469 | { |
455 | metadata.Description = (string)dbReader["Description"]; | 470 | AssetMetadata metadata = new AssetMetadata(); |
456 | metadata.Type = (sbyte)dbReader["AssetType"]; | 471 | metadata.Name = (string)dbReader["Name"]; |
457 | metadata.Temporary = Convert.ToBoolean(dbReader["Temporary"]); // Not sure if this is correct. | 472 | metadata.Description = (string)dbReader["Description"]; |
458 | metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["AssetFlags"]); | 473 | metadata.Type = (sbyte)dbReader["AssetType"]; |
459 | metadata.FullID = DBGuid.FromDB(dbReader["ID"]); | 474 | metadata.Temporary = Convert.ToBoolean(dbReader["Temporary"]); // Not sure if this is correct. |
460 | metadata.CreatorID = dbReader["CreatorID"].ToString(); | 475 | metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["AssetFlags"]); |
476 | metadata.FullID = DBGuid.FromDB(dbReader["ID"]); | ||
477 | metadata.CreatorID = dbReader["CreatorID"].ToString(); | ||
461 | 478 | ||
462 | // We'll ignore this for now - it appears unused! | 479 | // We'll ignore this for now - it appears unused! |
463 | // metadata.SHA1 = dbReader["hash"]); | 480 | // metadata.SHA1 = dbReader["hash"]); |
464 | 481 | ||
465 | UpdateAccessTime(metadata, (int)dbReader["AccessTime"]); | 482 | UpdateAccessTime(metadata, (int)dbReader["AccessTime"]); |
466 | 483 | ||
467 | retList.Add(metadata); | 484 | retList.Add(metadata); |
485 | } | ||
468 | } | 486 | } |
469 | } | 487 | } |
488 | catch (Exception e) | ||
489 | { | ||
490 | m_log.Error("[XASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString()); | ||
491 | } | ||
470 | } | 492 | } |
471 | catch (Exception e) | 493 | dbcon.Close(); |
472 | { | ||
473 | m_log.Error("[XASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString()); | ||
474 | } | ||
475 | } | 494 | } |
476 | 495 | ||
477 | return retList; | 496 | return retList; |
@@ -490,9 +509,9 @@ namespace OpenSim.Data.MySQL | |||
490 | cmd.Parameters.AddWithValue("?ID", id); | 509 | cmd.Parameters.AddWithValue("?ID", id); |
491 | cmd.ExecuteNonQuery(); | 510 | cmd.ExecuteNonQuery(); |
492 | } | 511 | } |
493 | |||
494 | // TODO: How do we deal with data from deleted assets? Probably not easily reapable unless we | 512 | // TODO: How do we deal with data from deleted assets? Probably not easily reapable unless we |
495 | // keep a reference count (?) | 513 | // keep a reference count (?) |
514 | dbcon.Close(); | ||
496 | } | 515 | } |
497 | 516 | ||
498 | return true; | 517 | return true; |
@@ -500,4 +519,4 @@ namespace OpenSim.Data.MySQL | |||
500 | 519 | ||
501 | #endregion | 520 | #endregion |
502 | } | 521 | } |
503 | } \ No newline at end of file | 522 | } |