Provide the interface for StoreAsset to report success or failure

avinationmerge
Tom Grimshaw 2010-06-28 04:02:33 -07:00
parent 7807d11807
commit a5a1df68c2
7 changed files with 16 additions and 7 deletions

View File

@ -38,7 +38,7 @@ namespace OpenSim.Data
{ {
public abstract AssetBase GetAsset(UUID uuid); public abstract AssetBase GetAsset(UUID uuid);
public abstract void StoreAsset(AssetBase asset); public abstract bool StoreAsset(AssetBase asset);
public abstract bool ExistsAsset(UUID uuid); public abstract bool ExistsAsset(UUID uuid);
public abstract List<AssetMetadata> FetchAssetMetadataSet(int start, int count); public abstract List<AssetMetadata> FetchAssetMetadataSet(int start, int count);

View File

@ -34,7 +34,7 @@ namespace OpenSim.Data
public interface IAssetDataPlugin : IPlugin public interface IAssetDataPlugin : IPlugin
{ {
AssetBase GetAsset(UUID uuid); AssetBase GetAsset(UUID uuid);
void StoreAsset(AssetBase asset); bool StoreAsset(AssetBase asset);
bool ExistsAsset(UUID uuid); bool ExistsAsset(UUID uuid);
List<AssetMetadata> FetchAssetMetadataSet(int start, int count); List<AssetMetadata> FetchAssetMetadataSet(int start, int count);
void Initialise(string connect); void Initialise(string connect);

View File

@ -143,7 +143,7 @@ namespace OpenSim.Data.MSSQL
/// Create asset in m_database /// Create asset in m_database
/// </summary> /// </summary>
/// <param name="asset">the asset</param> /// <param name="asset">the asset</param>
override public void StoreAsset(AssetBase asset) override public bool StoreAsset(AssetBase asset)
{ {
string sql = string sql =
@ -192,10 +192,12 @@ namespace OpenSim.Data.MSSQL
try try
{ {
command.ExecuteNonQuery(); command.ExecuteNonQuery();
return true;
} }
catch(Exception e) catch(Exception e)
{ {
m_log.Error("[ASSET DB]: Error storing item :" + e.Message); m_log.Error("[ASSET DB]: Error storing item :" + e.Message);
return false;
} }
} }
} }

View File

@ -153,7 +153,7 @@ namespace OpenSim.Data.MySQL
/// </summary> /// </summary>
/// <param name="asset">Asset UUID to create</param> /// <param name="asset">Asset UUID to create</param>
/// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks> /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks>
override public void StoreAsset(AssetBase asset) override public bool StoreAsset(AssetBase asset)
{ {
lock (m_dbLock) lock (m_dbLock)
{ {
@ -201,12 +201,14 @@ namespace OpenSim.Data.MySQL
cmd.Parameters.AddWithValue("?data", asset.Data); cmd.Parameters.AddWithValue("?data", asset.Data);
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
cmd.Dispose(); cmd.Dispose();
return true;
} }
} }
catch (Exception e) catch (Exception e)
{ {
m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset {0} with name \"{1}\". Error: {2}", m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset {0} with name \"{1}\". Error: {2}",
asset.FullID, asset.Name, e.Message); asset.FullID, asset.Name, e.Message);
return false;
} }
} }
} }

View File

@ -119,7 +119,7 @@ namespace OpenSim.Data.SQLite
/// Create an asset /// Create an asset
/// </summary> /// </summary>
/// <param name="asset">Asset Base</param> /// <param name="asset">Asset Base</param>
override public void StoreAsset(AssetBase asset) override public bool StoreAsset(AssetBase asset)
{ {
//m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString()); //m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString());
if (ExistsAsset(asset.FullID)) if (ExistsAsset(asset.FullID))
@ -141,6 +141,7 @@ namespace OpenSim.Data.SQLite
cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data));
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
return true;
} }
} }
} }
@ -161,6 +162,7 @@ namespace OpenSim.Data.SQLite
cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data));
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
return true;
} }
} }
} }

View File

@ -119,7 +119,7 @@ namespace OpenSim.Data.SQLiteLegacy
/// Create an asset /// Create an asset
/// </summary> /// </summary>
/// <param name="asset">Asset Base</param> /// <param name="asset">Asset Base</param>
override public void StoreAsset(AssetBase asset) override public bool StoreAsset(AssetBase asset)
{ {
//m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString()); //m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString());
if (ExistsAsset(asset.FullID)) if (ExistsAsset(asset.FullID))
@ -139,6 +139,7 @@ namespace OpenSim.Data.SQLiteLegacy
cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data));
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
return true;
} }
} }
} }
@ -157,6 +158,7 @@ namespace OpenSim.Data.SQLiteLegacy
cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data));
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
return true;
} }
} }
} }

View File

@ -54,9 +54,10 @@ namespace OpenSim.Tests.Common.Mock
return assets.Find(x=>x.FullID == uuid); return assets.Find(x=>x.FullID == uuid);
} }
public void StoreAsset(AssetBase asset) public bool StoreAsset(AssetBase asset)
{ {
assets.Add(asset); assets.Add(asset);
return true;
} }
public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) { return new List<AssetMetadata>(count); } public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) { return new List<AssetMetadata>(count); }