aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data')
-rw-r--r--OpenSim/Data/AssetDataBase.cs10
-rw-r--r--OpenSim/Data/IAssetData.cs5
-rw-r--r--OpenSim/Data/MSSQL/MSSQLAssetData.cs19
-rw-r--r--OpenSim/Data/MySQL/MySQLAssetData.cs13
-rw-r--r--OpenSim/Data/NHibernate/NHibernateAssetData.cs24
-rw-r--r--OpenSim/Data/SQLite/SQLiteAssetData.cs47
-rw-r--r--OpenSim/Data/Tests/BasicAssetTest.cs24
7 files changed, 60 insertions, 82 deletions
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
36{ 36{
37 public abstract class AssetDataBase : IAssetDataPlugin 37 public abstract class AssetDataBase : IAssetDataPlugin
38 { 38 {
39 public virtual AssetBase FetchAsset(UUID uuid) 39 public abstract AssetBase GetAsset(UUID uuid);
40 {
41 return FetchStoredAsset(uuid);
42 }
43
44 protected abstract AssetBase FetchStoredAsset(UUID uuid);
45 40
46 public abstract void CreateAsset(AssetBase asset); 41 public abstract void StoreAsset(AssetBase asset);
47 public abstract void UpdateAsset(AssetBase asset);
48 public abstract bool ExistsAsset(UUID uuid); 42 public abstract bool ExistsAsset(UUID uuid);
49 43
50 public abstract List<AssetMetadata> FetchAssetMetadataSet(int start, int count); 44 public abstract List<AssetMetadata> 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
33{ 33{
34 public interface IAssetDataPlugin : IPlugin 34 public interface IAssetDataPlugin : IPlugin
35 { 35 {
36 AssetBase FetchAsset(UUID uuid); 36 AssetBase GetAsset(UUID uuid);
37 void CreateAsset(AssetBase asset); 37 void StoreAsset(AssetBase asset);
38 void UpdateAsset(AssetBase asset);
39 bool ExistsAsset(UUID uuid); 38 bool ExistsAsset(UUID uuid);
40 List<AssetMetadata> FetchAssetMetadataSet(int start, int count); 39 List<AssetMetadata> FetchAssetMetadataSet(int start, int count);
41 void Initialise(string connect); 40 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
122 /// </summary> 122 /// </summary>
123 /// <param name="assetID">the asset UUID</param> 123 /// <param name="assetID">the asset UUID</param>
124 /// <returns></returns> 124 /// <returns></returns>
125 override protected AssetBase FetchStoredAsset(UUID assetID) 125 override public AssetBase GetAsset(UUID assetID)
126 { 126 {
127 string sql = "SELECT * FROM assets WHERE id = @id"; 127 string sql = "SELECT * FROM assets WHERE id = @id";
128 using (AutoClosingSqlCommand command = m_database.Query(sql)) 128 using (AutoClosingSqlCommand command = m_database.Query(sql))
@@ -152,7 +152,16 @@ namespace OpenSim.Data.MSSQL
152 /// Create asset in m_database 152 /// Create asset in m_database
153 /// </summary> 153 /// </summary>
154 /// <param name="asset">the asset</param> 154 /// <param name="asset">the asset</param>
155 override public void CreateAsset(AssetBase asset) 155 override public void StoreAsset(AssetBase asset)
156 {
157 if (ExistsAsset(asset.FullID))
158 UpdateAsset(asset);
159 else
160 InsertAsset(asset);
161 }
162
163
164 private void InsertAsset(AssetBase asset)
156 { 165 {
157 if (ExistsAsset(asset.FullID)) 166 if (ExistsAsset(asset.FullID))
158 { 167 {
@@ -208,7 +217,7 @@ namespace OpenSim.Data.MSSQL
208 /// Update asset in m_database 217 /// Update asset in m_database
209 /// </summary> 218 /// </summary>
210 /// <param name="asset">the asset</param> 219 /// <param name="asset">the asset</param>
211 override public void UpdateAsset(AssetBase asset) 220 private void UpdateAsset(AssetBase asset)
212 { 221 {
213 string sql = @"UPDATE assets set id = @id, name = @name, description = @description, assetType = @assetType, 222 string sql = @"UPDATE assets set id = @id, name = @name, description = @description, assetType = @assetType,
214 local = @local, temporary = @temporary, data = @data 223 local = @local, temporary = @temporary, data = @data
@@ -250,7 +259,7 @@ namespace OpenSim.Data.MSSQL
250 } 259 }
251 } 260 }
252 261
253// Commented out since currently unused - this probably should be called in FetchAsset() 262// Commented out since currently unused - this probably should be called in GetAsset()
254// private void UpdateAccessTime(AssetBase asset) 263// private void UpdateAccessTime(AssetBase asset)
255// { 264// {
256// using (AutoClosingSqlCommand cmd = m_database.Query("UPDATE assets SET access_time = @access_time WHERE id=@id")) 265// using (AutoClosingSqlCommand cmd = m_database.Query("UPDATE assets SET access_time = @access_time WHERE id=@id"))
@@ -276,7 +285,7 @@ namespace OpenSim.Data.MSSQL
276 /// <returns>true if exist.</returns> 285 /// <returns>true if exist.</returns>
277 override public bool ExistsAsset(UUID uuid) 286 override public bool ExistsAsset(UUID uuid)
278 { 287 {
279 if (FetchAsset(uuid) != null) 288 if (GetAsset(uuid) != null)
280 { 289 {
281 return true; 290 return true;
282 } 291 }
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
135 /// <param name="assetID">Asset UUID to fetch</param> 135 /// <param name="assetID">Asset UUID to fetch</param>
136 /// <returns>Return the asset</returns> 136 /// <returns>Return the asset</returns>
137 /// <remarks>On failure : throw an exception and attempt to reconnect to database</remarks> 137 /// <remarks>On failure : throw an exception and attempt to reconnect to database</remarks>
138 override protected AssetBase FetchStoredAsset(UUID assetID) 138 override public AssetBase GetAsset(UUID assetID)
139 { 139 {
140 AssetBase asset = null; 140 AssetBase asset = null;
141 lock (_dbConnection) 141 lock (_dbConnection)
@@ -192,7 +192,7 @@ namespace OpenSim.Data.MySQL
192 /// </summary> 192 /// </summary>
193 /// <param name="asset">Asset UUID to create</param> 193 /// <param name="asset">Asset UUID to create</param>
194 /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks> 194 /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks>
195 override public void CreateAsset(AssetBase asset) 195 override public void StoreAsset(AssetBase asset)
196 { 196 {
197 lock (_dbConnection) 197 lock (_dbConnection)
198 { 198 {
@@ -285,15 +285,6 @@ namespace OpenSim.Data.MySQL
285 } 285 }
286 286
287 /// <summary> 287 /// <summary>
288 /// Update a asset in database, see <see cref="CreateAsset"/>
289 /// </summary>
290 /// <param name="asset">Asset UUID to update</param>
291 override public void UpdateAsset(AssetBase asset)
292 {
293 CreateAsset(asset);
294 }
295
296 /// <summary>
297 /// check if the asset UUID exist in database 288 /// check if the asset UUID exist in database
298 /// </summary> 289 /// </summary>
299 /// <param name="uuid">The asset UUID</param> 290 /// <param name="uuid">The asset UUID</param>
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
65 65
66 } 66 }
67 67
68 override protected AssetBase FetchStoredAsset(UUID uuid) 68 override public AssetBase GetAsset(UUID uuid)
69 { 69 {
70 return (AssetBase)manager.Get(typeof(AssetBase), uuid); 70 return (AssetBase)manager.Get(typeof(AssetBase), uuid);
71 } 71 }
72 72
73 private void Save(AssetBase asset) 73 override public void StoreAsset(AssetBase asset)
74 { 74 {
75 AssetBase temp = (AssetBase)manager.Get(typeof(AssetBase), asset.FullID); 75 AssetBase temp = (AssetBase)manager.Get(typeof(AssetBase), asset.FullID);
76 if (temp == null) 76 if (temp == null)
77 { 77 {
78 m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID);
78 manager.Insert(asset); 79 manager.Insert(asset);
79 } 80 }
80 } 81 else
81 82 {
82 override public void CreateAsset(AssetBase asset) 83 m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID);
83 { 84 manager.Update(asset);
84 m_log.InfoFormat("[NHIBERNATE] inserting asset {0}", asset.FullID); 85 }
85 Save(asset);
86 }
87
88 override public void UpdateAsset(AssetBase asset)
89 {
90 m_log.InfoFormat("[NHIBERNATE] updating asset {0}", asset.FullID);
91 manager.Update(asset);
92 } 86 }
93 87
94 // private void LogAssetLoad(AssetBase asset) 88 // private void LogAssetLoad(AssetBase asset)
@@ -107,7 +101,7 @@ namespace OpenSim.Data.NHibernate
107 override public bool ExistsAsset(UUID uuid) 101 override public bool ExistsAsset(UUID uuid)
108 { 102 {
109 m_log.InfoFormat("[NHIBERNATE] ExistsAsset: {0}", uuid); 103 m_log.InfoFormat("[NHIBERNATE] ExistsAsset: {0}", uuid);
110 return (FetchAsset(uuid) != null); 104 return (GetAsset(uuid) != null);
111 } 105 }
112 106
113 /// <summary> 107 /// <summary>
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
90 /// </summary> 90 /// </summary>
91 /// <param name="uuid">UUID of ... ?</param> 91 /// <param name="uuid">UUID of ... ?</param>
92 /// <returns>Asset base</returns> 92 /// <returns>Asset base</returns>
93 override protected AssetBase FetchStoredAsset(UUID uuid) 93 override public AssetBase GetAsset(UUID uuid)
94 { 94 {
95 lock (this) 95 lock (this)
96 { 96 {
@@ -119,18 +119,16 @@ namespace OpenSim.Data.SQLite
119 /// Create an asset 119 /// Create an asset
120 /// </summary> 120 /// </summary>
121 /// <param name="asset">Asset Base</param> 121 /// <param name="asset">Asset Base</param>
122 override public void CreateAsset(AssetBase asset) 122 override public void StoreAsset(AssetBase asset)
123 { 123 {
124 //m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString()); 124 //m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString());
125 if (ExistsAsset(asset.FullID)) 125 if (ExistsAsset(asset.FullID))
126 { 126 {
127 //m_log.Info("[ASSET DB]: Asset exists already, ignoring."); 127 LogAssetLoad(asset);
128 } 128
129 else
130 {
131 lock (this) 129 lock (this)
132 { 130 {
133 using (SqliteCommand cmd = new SqliteCommand(InsertAssetSQL, m_conn)) 131 using (SqliteCommand cmd = new SqliteCommand(UpdateAssetSQL, m_conn))
134 { 132 {
135 cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString())); 133 cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString()));
136 cmd.Parameters.Add(new SqliteParameter(":Name", asset.Name)); 134 cmd.Parameters.Add(new SqliteParameter(":Name", asset.Name));
@@ -144,29 +142,22 @@ namespace OpenSim.Data.SQLite
144 } 142 }
145 } 143 }
146 } 144 }
147 } 145 else
148
149 /// <summary>
150 /// Update an asset
151 /// </summary>
152 /// <param name="asset"></param>
153 override public void UpdateAsset(AssetBase asset)
154 {
155 LogAssetLoad(asset);
156
157 lock (this)
158 { 146 {
159 using (SqliteCommand cmd = new SqliteCommand(UpdateAssetSQL, m_conn)) 147 lock (this)
160 { 148 {
161 cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString())); 149 using (SqliteCommand cmd = new SqliteCommand(InsertAssetSQL, m_conn))
162 cmd.Parameters.Add(new SqliteParameter(":Name", asset.Name)); 150 {
163 cmd.Parameters.Add(new SqliteParameter(":Description", asset.Description)); 151 cmd.Parameters.Add(new SqliteParameter(":UUID", asset.FullID.ToString()));
164 cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type)); 152 cmd.Parameters.Add(new SqliteParameter(":Name", asset.Name));
165 cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local)); 153 cmd.Parameters.Add(new SqliteParameter(":Description", asset.Description));
166 cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary)); 154 cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type));
167 cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); 155 cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local));
168 156 cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary));
169 cmd.ExecuteNonQuery(); 157 cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data));
158
159 cmd.ExecuteNonQuery();
160 }
170 } 161 }
171 } 162 }
172 } 163 }
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
84 scrambler.Scramble(a2); 84 scrambler.Scramble(a2);
85 scrambler.Scramble(a3); 85 scrambler.Scramble(a3);
86 86
87 db.CreateAsset(a1); 87 db.StoreAsset(a1);
88 db.CreateAsset(a2); 88 db.StoreAsset(a2);
89 db.CreateAsset(a3); 89 db.StoreAsset(a3);
90 90
91 AssetBase a1a = db.FetchAsset(uuid1); 91 AssetBase a1a = db.GetAsset(uuid1);
92 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); 92 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
93 93
94 AssetBase a2a = db.FetchAsset(uuid2); 94 AssetBase a2a = db.GetAsset(uuid2);
95 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); 95 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
96 96
97 AssetBase a3a = db.FetchAsset(uuid3); 97 AssetBase a3a = db.GetAsset(uuid3);
98 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); 98 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
99 99
100 scrambler.Scramble(a1a); 100 scrambler.Scramble(a1a);
101 scrambler.Scramble(a2a); 101 scrambler.Scramble(a2a);
102 scrambler.Scramble(a3a); 102 scrambler.Scramble(a3a);
103 103
104 db.UpdateAsset(a1a); 104 db.StoreAsset(a1a);
105 db.UpdateAsset(a2a); 105 db.StoreAsset(a2a);
106 db.UpdateAsset(a3a); 106 db.StoreAsset(a3a);
107 107
108 AssetBase a1b = db.FetchAsset(uuid1); 108 AssetBase a1b = db.GetAsset(uuid1);
109 Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a)); 109 Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a));
110 110
111 AssetBase a2b = db.FetchAsset(uuid2); 111 AssetBase a2b = db.GetAsset(uuid2);
112 Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a)); 112 Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a));
113 113
114 AssetBase a3b = db.FetchAsset(uuid3); 114 AssetBase a3b = db.GetAsset(uuid3);
115 Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a)); 115 Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a));
116 116
117 Assert.That(db.ExistsAsset(uuid1), Is.True); 117 Assert.That(db.ExistsAsset(uuid1), Is.True);