From f1287cc7af7da26910c5cba456a8c35b6454d815 Mon Sep 17 00:00:00 2001 From: Kunnis Date: Sun, 16 Aug 2009 18:54:20 -0500 Subject: * Switching IAssetData to follow the new naming schema, removing the separate insert and update methods. --- OpenSim/Data/AssetDataBase.cs | 10 ++---- OpenSim/Data/IAssetData.cs | 5 ++- OpenSim/Data/MSSQL/MSSQLAssetData.cs | 19 ++++++++--- OpenSim/Data/MySQL/MySQLAssetData.cs | 13 ++----- OpenSim/Data/NHibernate/NHibernateAssetData.cs | 24 +++++-------- OpenSim/Data/SQLite/SQLiteAssetData.cs | 47 +++++++++++--------------- OpenSim/Data/Tests/BasicAssetTest.cs | 24 ++++++------- 7 files changed, 60 insertions(+), 82 deletions(-) (limited to 'OpenSim/Data') diff --git a/OpenSim/Data/AssetDataBase.cs b/OpenSim/Data/AssetDataBase.cs index f723ebf..5deb44e 100644 --- a/OpenSim/Data/AssetDataBase.cs +++ b/OpenSim/Data/AssetDataBase.cs @@ -36,15 +36,9 @@ namespace OpenSim.Data { public abstract class AssetDataBase : IAssetDataPlugin { - public virtual AssetBase FetchAsset(UUID uuid) - { - return FetchStoredAsset(uuid); - } - - protected abstract AssetBase FetchStoredAsset(UUID uuid); + public abstract AssetBase GetAsset(UUID uuid); - public abstract void CreateAsset(AssetBase asset); - public abstract void UpdateAsset(AssetBase asset); + public abstract void StoreAsset(AssetBase asset); public abstract bool ExistsAsset(UUID uuid); public abstract List FetchAssetMetadataSet(int start, int count); diff --git a/OpenSim/Data/IAssetData.cs b/OpenSim/Data/IAssetData.cs index d13732b..2149bca 100644 --- a/OpenSim/Data/IAssetData.cs +++ b/OpenSim/Data/IAssetData.cs @@ -33,9 +33,8 @@ namespace OpenSim.Data { public interface IAssetDataPlugin : IPlugin { - AssetBase FetchAsset(UUID uuid); - void CreateAsset(AssetBase asset); - void UpdateAsset(AssetBase asset); + AssetBase GetAsset(UUID uuid); + void StoreAsset(AssetBase asset); bool ExistsAsset(UUID uuid); List FetchAssetMetadataSet(int start, int count); void Initialise(string connect); diff --git a/OpenSim/Data/MSSQL/MSSQLAssetData.cs b/OpenSim/Data/MSSQL/MSSQLAssetData.cs index a542584..d193cf5 100644 --- a/OpenSim/Data/MSSQL/MSSQLAssetData.cs +++ b/OpenSim/Data/MSSQL/MSSQLAssetData.cs @@ -122,7 +122,7 @@ namespace OpenSim.Data.MSSQL /// /// the asset UUID /// - override protected AssetBase FetchStoredAsset(UUID assetID) + override public AssetBase GetAsset(UUID assetID) { string sql = "SELECT * FROM assets WHERE id = @id"; using (AutoClosingSqlCommand command = m_database.Query(sql)) @@ -152,7 +152,16 @@ namespace OpenSim.Data.MSSQL /// Create asset in m_database /// /// the asset - 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)) { @@ -208,7 +217,7 @@ namespace OpenSim.Data.MSSQL /// Update asset in m_database /// /// the asset - override public void UpdateAsset(AssetBase asset) + private void UpdateAsset(AssetBase asset) { string sql = @"UPDATE assets set id = @id, name = @name, description = @description, assetType = @assetType, 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) // { // using (AutoClosingSqlCommand cmd = m_database.Query("UPDATE assets SET access_time = @access_time WHERE id=@id")) @@ -276,7 +285,7 @@ namespace OpenSim.Data.MSSQL /// true if exist. override public bool ExistsAsset(UUID uuid) { - if (FetchAsset(uuid) != null) + if (GetAsset(uuid) != null) { return true; } diff --git a/OpenSim/Data/MySQL/MySQLAssetData.cs b/OpenSim/Data/MySQL/MySQLAssetData.cs index 0865083..1b4377a 100644 --- a/OpenSim/Data/MySQL/MySQLAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLAssetData.cs @@ -135,7 +135,7 @@ namespace OpenSim.Data.MySQL /// Asset UUID to fetch /// Return the asset /// On failure : throw an exception and attempt to reconnect to database - override protected AssetBase FetchStoredAsset(UUID assetID) + override public AssetBase GetAsset(UUID assetID) { AssetBase asset = null; lock (_dbConnection) @@ -192,7 +192,7 @@ namespace OpenSim.Data.MySQL /// /// Asset UUID to create /// On failure : Throw an exception and attempt to reconnect to database - override public void CreateAsset(AssetBase asset) + override public void StoreAsset(AssetBase asset) { lock (_dbConnection) { @@ -285,15 +285,6 @@ namespace OpenSim.Data.MySQL } /// - /// Update a asset in database, see - /// - /// Asset UUID to update - override public void UpdateAsset(AssetBase asset) - { - CreateAsset(asset); - } - - /// /// check if the asset UUID exist in database /// /// The asset UUID diff --git a/OpenSim/Data/NHibernate/NHibernateAssetData.cs b/OpenSim/Data/NHibernate/NHibernateAssetData.cs index 9d8cec5..aaba15c 100644 --- a/OpenSim/Data/NHibernate/NHibernateAssetData.cs +++ b/OpenSim/Data/NHibernate/NHibernateAssetData.cs @@ -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); } - private void Save(AssetBase asset) + override public void StoreAsset(AssetBase asset) { AssetBase temp = (AssetBase)manager.Get(typeof(AssetBase), asset.FullID); if (temp == null) { + m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID); manager.Insert(asset); } - } - - override public void CreateAsset(AssetBase 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); + else + { + m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID); + manager.Update(asset); + } } // private void LogAssetLoad(AssetBase asset) @@ -107,7 +101,7 @@ namespace OpenSim.Data.NHibernate override public bool ExistsAsset(UUID uuid) { m_log.InfoFormat("[NHIBERNATE] ExistsAsset: {0}", uuid); - return (FetchAsset(uuid) != null); + return (GetAsset(uuid) != null); } /// diff --git a/OpenSim/Data/SQLite/SQLiteAssetData.cs b/OpenSim/Data/SQLite/SQLiteAssetData.cs index 72af7a0..3831467 100644 --- a/OpenSim/Data/SQLite/SQLiteAssetData.cs +++ b/OpenSim/Data/SQLite/SQLiteAssetData.cs @@ -90,7 +90,7 @@ namespace OpenSim.Data.SQLite /// /// UUID of ... ? /// Asset base - override protected AssetBase FetchStoredAsset(UUID uuid) + override public AssetBase GetAsset(UUID uuid) { lock (this) { @@ -119,18 +119,16 @@ namespace OpenSim.Data.SQLite /// Create an asset /// /// Asset Base - override public void CreateAsset(AssetBase asset) + override public void StoreAsset(AssetBase asset) { //m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString()); if (ExistsAsset(asset.FullID)) { - //m_log.Info("[ASSET DB]: Asset exists already, ignoring."); - } - else - { + LogAssetLoad(asset); + lock (this) { - using (SqliteCommand cmd = new SqliteCommand(InsertAssetSQL, m_conn)) + 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)); @@ -144,29 +142,22 @@ namespace OpenSim.Data.SQLite } } } - } - - /// - /// Update an asset - /// - /// - override public void UpdateAsset(AssetBase asset) - { - LogAssetLoad(asset); - - lock (this) + else { - using (SqliteCommand cmd = new SqliteCommand(UpdateAssetSQL, m_conn)) + lock (this) { - 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(); + using (SqliteCommand cmd = new SqliteCommand(InsertAssetSQL, 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(); + } } } } diff --git a/OpenSim/Data/Tests/BasicAssetTest.cs b/OpenSim/Data/Tests/BasicAssetTest.cs index 09131c1..1969d76 100644 --- a/OpenSim/Data/Tests/BasicAssetTest.cs +++ b/OpenSim/Data/Tests/BasicAssetTest.cs @@ -84,34 +84,34 @@ namespace OpenSim.Data.Tests scrambler.Scramble(a2); scrambler.Scramble(a3); - db.CreateAsset(a1); - db.CreateAsset(a2); - db.CreateAsset(a3); + db.StoreAsset(a1); + db.StoreAsset(a2); + db.StoreAsset(a3); - AssetBase a1a = db.FetchAsset(uuid1); + AssetBase a1a = db.GetAsset(uuid1); Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); - AssetBase a2a = db.FetchAsset(uuid2); + AssetBase a2a = db.GetAsset(uuid2); Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); - AssetBase a3a = db.FetchAsset(uuid3); + AssetBase a3a = db.GetAsset(uuid3); Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); scrambler.Scramble(a1a); scrambler.Scramble(a2a); scrambler.Scramble(a3a); - db.UpdateAsset(a1a); - db.UpdateAsset(a2a); - db.UpdateAsset(a3a); + db.StoreAsset(a1a); + db.StoreAsset(a2a); + db.StoreAsset(a3a); - AssetBase a1b = db.FetchAsset(uuid1); + AssetBase a1b = db.GetAsset(uuid1); Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a)); - AssetBase a2b = db.FetchAsset(uuid2); + AssetBase a2b = db.GetAsset(uuid2); Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a)); - AssetBase a3b = db.FetchAsset(uuid3); + AssetBase a3b = db.GetAsset(uuid3); Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a)); Assert.That(db.ExistsAsset(uuid1), Is.True); -- cgit v1.1