* Switching IAssetData to follow the new naming schema, removing the separate insert and update methods.

arthursv
Kunnis 2009-08-16 18:54:20 -05:00 committed by Melanie
parent c295354ea0
commit f1287cc7af
13 changed files with 73 additions and 95 deletions

View File

@ -36,15 +36,9 @@ namespace OpenSim.Data
{ {
public abstract class AssetDataBase : IAssetDataPlugin public abstract class AssetDataBase : IAssetDataPlugin
{ {
public virtual AssetBase FetchAsset(UUID uuid) public abstract AssetBase GetAsset(UUID uuid);
{
return FetchStoredAsset(uuid);
}
protected abstract AssetBase FetchStoredAsset(UUID uuid); public abstract void StoreAsset(AssetBase asset);
public abstract void CreateAsset(AssetBase asset);
public abstract void UpdateAsset(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

@ -33,9 +33,8 @@ namespace OpenSim.Data
{ {
public interface IAssetDataPlugin : IPlugin public interface IAssetDataPlugin : IPlugin
{ {
AssetBase FetchAsset(UUID uuid); AssetBase GetAsset(UUID uuid);
void CreateAsset(AssetBase asset); void StoreAsset(AssetBase asset);
void UpdateAsset(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

@ -122,7 +122,7 @@ namespace OpenSim.Data.MSSQL
/// </summary> /// </summary>
/// <param name="assetID">the asset UUID</param> /// <param name="assetID">the asset UUID</param>
/// <returns></returns> /// <returns></returns>
override protected AssetBase FetchStoredAsset(UUID assetID) override public AssetBase GetAsset(UUID assetID)
{ {
string sql = "SELECT * FROM assets WHERE id = @id"; string sql = "SELECT * FROM assets WHERE id = @id";
using (AutoClosingSqlCommand command = m_database.Query(sql)) using (AutoClosingSqlCommand command = m_database.Query(sql))
@ -152,7 +152,16 @@ 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 CreateAsset(AssetBase asset) override public void StoreAsset(AssetBase asset)
{
if (ExistsAsset(asset.FullID))
UpdateAsset(asset);
else
InsertAsset(asset);
}
private void InsertAsset(AssetBase asset)
{ {
if (ExistsAsset(asset.FullID)) if (ExistsAsset(asset.FullID))
{ {
@ -208,7 +217,7 @@ namespace OpenSim.Data.MSSQL
/// Update asset in m_database /// Update asset in m_database
/// </summary> /// </summary>
/// <param name="asset">the asset</param> /// <param name="asset">the asset</param>
override public void UpdateAsset(AssetBase asset) private void UpdateAsset(AssetBase asset)
{ {
string sql = @"UPDATE assets set id = @id, name = @name, description = @description, assetType = @assetType, string sql = @"UPDATE assets set id = @id, name = @name, description = @description, assetType = @assetType,
local = @local, temporary = @temporary, data = @data local = @local, temporary = @temporary, data = @data
@ -250,7 +259,7 @@ namespace OpenSim.Data.MSSQL
} }
} }
// Commented out since currently unused - this probably should be called in FetchAsset() // Commented out since currently unused - this probably should be called in GetAsset()
// private void UpdateAccessTime(AssetBase asset) // private void UpdateAccessTime(AssetBase asset)
// { // {
// using (AutoClosingSqlCommand cmd = m_database.Query("UPDATE assets SET access_time = @access_time WHERE id=@id")) // using (AutoClosingSqlCommand cmd = m_database.Query("UPDATE assets SET access_time = @access_time WHERE id=@id"))
@ -276,7 +285,7 @@ namespace OpenSim.Data.MSSQL
/// <returns>true if exist.</returns> /// <returns>true if exist.</returns>
override public bool ExistsAsset(UUID uuid) override public bool ExistsAsset(UUID uuid)
{ {
if (FetchAsset(uuid) != null) if (GetAsset(uuid) != null)
{ {
return true; return true;
} }

View File

@ -135,7 +135,7 @@ namespace OpenSim.Data.MySQL
/// <param name="assetID">Asset UUID to fetch</param> /// <param name="assetID">Asset UUID to fetch</param>
/// <returns>Return the asset</returns> /// <returns>Return the asset</returns>
/// <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 protected AssetBase FetchStoredAsset(UUID assetID) override public AssetBase GetAsset(UUID assetID)
{ {
AssetBase asset = null; AssetBase asset = null;
lock (_dbConnection) lock (_dbConnection)
@ -192,7 +192,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 CreateAsset(AssetBase asset) override public void StoreAsset(AssetBase asset)
{ {
lock (_dbConnection) lock (_dbConnection)
{ {
@ -284,15 +284,6 @@ namespace OpenSim.Data.MySQL
} }
/// <summary>
/// Update a asset in database, see <see cref="CreateAsset"/>
/// </summary>
/// <param name="asset">Asset UUID to update</param>
override public void UpdateAsset(AssetBase asset)
{
CreateAsset(asset);
}
/// <summary> /// <summary>
/// check if the asset UUID exist in database /// check if the asset UUID exist in database
/// </summary> /// </summary>

View File

@ -65,30 +65,24 @@ namespace OpenSim.Data.NHibernate
} }
override protected AssetBase FetchStoredAsset(UUID uuid) override public AssetBase GetAsset(UUID uuid)
{ {
return (AssetBase)manager.Get(typeof(AssetBase), uuid); return (AssetBase)manager.Get(typeof(AssetBase), uuid);
} }
private void Save(AssetBase asset) override public void StoreAsset(AssetBase asset)
{ {
AssetBase temp = (AssetBase)manager.Get(typeof(AssetBase), asset.FullID); AssetBase temp = (AssetBase)manager.Get(typeof(AssetBase), asset.FullID);
if (temp == null) if (temp == null)
{ {
m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID);
manager.Insert(asset); manager.Insert(asset);
} }
} else
{
override public void CreateAsset(AssetBase asset) m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID);
{ manager.Update(asset);
m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID); }
Save(asset);
}
override public void UpdateAsset(AssetBase asset)
{
m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID);
manager.Update(asset);
} }
// private void LogAssetLoad(AssetBase asset) // private void LogAssetLoad(AssetBase asset)
@ -107,7 +101,7 @@ namespace OpenSim.Data.NHibernate
override public bool ExistsAsset(UUID uuid) override public bool ExistsAsset(UUID uuid)
{ {
m_log.InfoFormat("[NHIBERNATE] ExistsAsset: {0}", uuid); m_log.InfoFormat("[NHIBERNATE] ExistsAsset: {0}", uuid);
return (FetchAsset(uuid) != null); return (GetAsset(uuid) != null);
} }
/// <summary> /// <summary>

View File

@ -90,7 +90,7 @@ namespace OpenSim.Data.SQLite
/// </summary> /// </summary>
/// <param name="uuid">UUID of ... ?</param> /// <param name="uuid">UUID of ... ?</param>
/// <returns>Asset base</returns> /// <returns>Asset base</returns>
override protected AssetBase FetchStoredAsset(UUID uuid) override public AssetBase GetAsset(UUID uuid)
{ {
lock (this) lock (this)
{ {
@ -119,12 +119,28 @@ 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 CreateAsset(AssetBase asset) override public void 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))
{ {
//m_log.Info("[ASSET DB]: Asset exists already, ignoring."); LogAssetLoad(asset);
lock (this)
{
using (SqliteCommand cmd = new SqliteCommand(UpdateAssetSQL, m_conn))
{
cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString()));
cmd.Parameters.Add(new SqliteParameter(":Name", asset.Name));
cmd.Parameters.Add(new SqliteParameter(":Description", asset.Description));
cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type));
cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local));
cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary));
cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data));
cmd.ExecuteNonQuery();
}
}
} }
else else
{ {
@ -146,31 +162,6 @@ namespace OpenSim.Data.SQLite
} }
} }
/// <summary>
/// Update an asset
/// </summary>
/// <param name="asset"></param>
override public void UpdateAsset(AssetBase asset)
{
LogAssetLoad(asset);
lock (this)
{
using (SqliteCommand cmd = new SqliteCommand(UpdateAssetSQL, m_conn))
{
cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString()));
cmd.Parameters.Add(new SqliteParameter(":Name", asset.Name));
cmd.Parameters.Add(new SqliteParameter(":Description", asset.Description));
cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type));
cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local));
cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary));
cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data));
cmd.ExecuteNonQuery();
}
}
}
/// <summary> /// <summary>
/// Some... logging functionnality /// Some... logging functionnality
/// </summary> /// </summary>

View File

@ -84,34 +84,34 @@ namespace OpenSim.Data.Tests
scrambler.Scramble(a2); scrambler.Scramble(a2);
scrambler.Scramble(a3); scrambler.Scramble(a3);
db.CreateAsset(a1); db.StoreAsset(a1);
db.CreateAsset(a2); db.StoreAsset(a2);
db.CreateAsset(a3); db.StoreAsset(a3);
AssetBase a1a = db.FetchAsset(uuid1); AssetBase a1a = db.GetAsset(uuid1);
Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
AssetBase a2a = db.FetchAsset(uuid2); AssetBase a2a = db.GetAsset(uuid2);
Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
AssetBase a3a = db.FetchAsset(uuid3); AssetBase a3a = db.GetAsset(uuid3);
Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
scrambler.Scramble(a1a); scrambler.Scramble(a1a);
scrambler.Scramble(a2a); scrambler.Scramble(a2a);
scrambler.Scramble(a3a); scrambler.Scramble(a3a);
db.UpdateAsset(a1a); db.StoreAsset(a1a);
db.UpdateAsset(a2a); db.StoreAsset(a2a);
db.UpdateAsset(a3a); db.StoreAsset(a3a);
AssetBase a1b = db.FetchAsset(uuid1); AssetBase a1b = db.GetAsset(uuid1);
Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a)); Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a));
AssetBase a2b = db.FetchAsset(uuid2); AssetBase a2b = db.GetAsset(uuid2);
Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a)); Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a));
AssetBase a3b = db.FetchAsset(uuid3); AssetBase a3b = db.GetAsset(uuid3);
Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a)); Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a));
Assert.That(db.ExistsAsset(uuid1), Is.True); Assert.That(db.ExistsAsset(uuid1), Is.True);

View File

@ -57,7 +57,7 @@ namespace OpenSim.Framework.Servers
protected override AssetBase GetAsset(UUID assetID) protected override AssetBase GetAsset(UUID assetID)
{ {
return m_assetProvider.FetchAsset(assetID); return m_assetProvider.GetAsset(assetID);
} }
} }
} }

View File

@ -57,7 +57,7 @@ namespace OpenSim.Framework.Servers
AssetBase asset = (AssetBase) xs.Deserialize(request); AssetBase asset = (AssetBase) xs.Deserialize(request);
m_log.InfoFormat("[REST]: Creating asset {0}", asset.FullID); m_log.InfoFormat("[REST]: Creating asset {0}", asset.FullID);
m_assetProvider.CreateAsset(asset); m_assetProvider.StoreAsset(asset);
return new byte[] {}; return new byte[] {};
} }

View File

@ -128,7 +128,7 @@ namespace OpenSim.Framework.Servers.Tests
IAssetDataPlugin assetDataPlugin = new TestAssetDataPlugin(); IAssetDataPlugin assetDataPlugin = new TestAssetDataPlugin();
handler = new GetAssetStreamHandler(assetDataPlugin); handler = new GetAssetStreamHandler(assetDataPlugin);
assetDataPlugin.CreateAsset(asset); assetDataPlugin.StoreAsset(asset);
return asset; return asset;
} }
} }

View File

@ -57,7 +57,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
metadata = null; metadata = null;
BackendResponse ret; BackendResponse ret;
AssetBase asset = m_assetProvider.FetchAsset(assetID); AssetBase asset = m_assetProvider.GetAsset(assetID);
if (asset == null) ret = BackendResponse.NotFound; if (asset == null) ret = BackendResponse.NotFound;
else else
@ -75,7 +75,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
assetData = null; assetData = null;
BackendResponse ret; BackendResponse ret;
AssetBase asset = m_assetProvider.FetchAsset(assetID); AssetBase asset = m_assetProvider.GetAsset(assetID);
if (asset == null) ret = BackendResponse.NotFound; if (asset == null) ret = BackendResponse.NotFound;
else else
@ -90,7 +90,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset) public BackendResponse TryFetchDataMetadata(UUID assetID, out AssetBase asset)
{ {
asset = m_assetProvider.FetchAsset(assetID); asset = m_assetProvider.GetAsset(assetID);
if (asset == null) return BackendResponse.NotFound; if (asset == null) return BackendResponse.NotFound;
@ -107,7 +107,7 @@ namespace OpenSim.Grid.AssetInventoryServer.Plugins.OpenSim
{ {
BackendResponse ret; BackendResponse ret;
m_assetProvider.CreateAsset(asset); m_assetProvider.StoreAsset(asset);
ret = BackendResponse.Success; ret = BackendResponse.Success;
m_server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, asset.FullID, asset.Data.Length, DateTime.Now); m_server.MetricsProvider.LogAssetCreate(EXTENSION_NAME, ret, asset.FullID, asset.Data.Length, DateTime.Now);

View File

@ -140,7 +140,7 @@ namespace OpenSim.Grid.AssetServer
protected void StoreAsset(AssetBase asset) protected void StoreAsset(AssetBase asset)
{ {
m_assetProvider.CreateAsset(asset); m_assetProvider.StoreAsset(asset);
} }
} }
} }

View File

@ -83,7 +83,7 @@ namespace OpenSim.Services.AssetService
if (!UUID.TryParse(id, out assetID)) if (!UUID.TryParse(id, out assetID))
return null; return null;
return m_Database.FetchAsset(assetID); return m_Database.GetAsset(assetID);
} }
public AssetMetadata GetMetadata(string id) public AssetMetadata GetMetadata(string id)
@ -93,7 +93,7 @@ namespace OpenSim.Services.AssetService
if (!UUID.TryParse(id, out assetID)) if (!UUID.TryParse(id, out assetID))
return null; return null;
AssetBase asset = m_Database.FetchAsset(assetID); AssetBase asset = m_Database.GetAsset(assetID);
return asset.Metadata; return asset.Metadata;
} }
@ -104,7 +104,7 @@ namespace OpenSim.Services.AssetService
if (!UUID.TryParse(id, out assetID)) if (!UUID.TryParse(id, out assetID))
return null; return null;
AssetBase asset = m_Database.FetchAsset(assetID); AssetBase asset = m_Database.GetAsset(assetID);
return asset.Data; return asset.Data;
} }
@ -117,7 +117,7 @@ namespace OpenSim.Services.AssetService
if (!UUID.TryParse(id, out assetID)) if (!UUID.TryParse(id, out assetID))
return false; return false;
AssetBase asset = m_Database.FetchAsset(assetID); AssetBase asset = m_Database.GetAsset(assetID);
//m_log.DebugFormat("[AssetService]: Got asset {0}", asset); //m_log.DebugFormat("[AssetService]: Got asset {0}", asset);
@ -129,7 +129,7 @@ namespace OpenSim.Services.AssetService
public string Store(AssetBase asset) public string Store(AssetBase asset)
{ {
//m_log.DebugFormat("[ASSET SERVICE]: Store asset {0} {1}", asset.Name, asset.ID); //m_log.DebugFormat("[ASSET SERVICE]: Store asset {0} {1}", asset.Name, asset.ID);
m_Database.CreateAsset(asset); m_Database.StoreAsset(asset);
return asset.ID; return asset.ID;
} }