aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-11-09 00:59:18 +0000
committerJustin Clark-Casey (justincc)2012-11-09 01:13:19 +0000
commit75c880a6f3631a527b532773a8a493309a96028e (patch)
treed07023ef4a277420b66f3b144df3be1287c26d92
parentODECharacter overrides TargetVelocity. No change to existing behavior (diff)
downloadopensim-SC_OLD-75c880a6f3631a527b532773a8a493309a96028e.zip
opensim-SC_OLD-75c880a6f3631a527b532773a8a493309a96028e.tar.gz
opensim-SC_OLD-75c880a6f3631a527b532773a8a493309a96028e.tar.bz2
opensim-SC_OLD-75c880a6f3631a527b532773a8a493309a96028e.tar.xz
Update parent inventory folder version numbers when folders are moved/created/deleted to match version numbers cached by viewers.
This is done in the way that one would expect (e.g. moving a folder increments version number on both source and destination parent folders). This should hopefully improve viewer reuse of its cached inventory information. Currently MySQL only but will be implement for SQLite/MSSQL if there are no issues.
-rw-r--r--OpenSim/Data/IXInventoryData.cs15
-rw-r--r--OpenSim/Data/MSSQL/MSSQLXInventoryData.cs128
-rw-r--r--OpenSim/Data/MySQL/MySQLXInventoryData.cs94
-rw-r--r--OpenSim/Data/SQLite/SQLiteXInventoryData.cs30
-rw-r--r--OpenSim/Services/InventoryService/XInventoryService.cs11
-rw-r--r--OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs1
6 files changed, 222 insertions, 57 deletions
diff --git a/OpenSim/Data/IXInventoryData.cs b/OpenSim/Data/IXInventoryData.cs
index e64a828..0df71f5 100644
--- a/OpenSim/Data/IXInventoryData.cs
+++ b/OpenSim/Data/IXInventoryData.cs
@@ -116,7 +116,22 @@ namespace OpenSim.Data
116 /// <returns>true if the delete was successful, false if it was not</returns> 116 /// <returns>true if the delete was successful, false if it was not</returns>
117 bool DeleteItems(string[] fields, string[] vals); 117 bool DeleteItems(string[] fields, string[] vals);
118 118
119 /// <summary>
120 /// Move an item to a new folder.
121 /// </summary>
122 /// <returns>/returns>
123 /// <param name='id'>UUID of the item</param>
124 /// <param name='newParent'>UUID of the new folder.</param>
119 bool MoveItem(string id, string newParent); 125 bool MoveItem(string id, string newParent);
126
127 /// <summary>
128 /// Move a folder to a new folder.
129 /// </summary>
130 /// <returns>/returns>
131 /// <param name='id'>UUID of the item</param>
132 /// <param name='newParent'>UUID of the new folder.</param>
133 bool MoveFolder(string id, string newParent);
134
120 XInventoryItem[] GetActiveGestures(UUID principalID); 135 XInventoryItem[] GetActiveGestures(UUID principalID);
121 int GetAssetPermissions(UUID principalID, UUID assetID); 136 int GetAssetPermissions(UUID principalID, UUID assetID);
122 } 137 }
diff --git a/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs
index b19a0da..7ab0ebb 100644
--- a/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs
@@ -43,12 +43,12 @@ namespace OpenSim.Data.MSSQL
43// private static readonly ILog m_log = LogManager.GetLogger( 43// private static readonly ILog m_log = LogManager.GetLogger(
44// MethodBase.GetCurrentMethod().DeclaringType); 44// MethodBase.GetCurrentMethod().DeclaringType);
45 45
46 private MSSQLGenericTableHandler<XInventoryFolder> m_Folders; 46 private MSSQLFolderHandler m_Folders;
47 private MSSQLItemHandler m_Items; 47 private MSSQLItemHandler m_Items;
48 48
49 public MSSQLXInventoryData(string conn, string realm) 49 public MSSQLXInventoryData(string conn, string realm)
50 { 50 {
51 m_Folders = new MSSQLGenericTableHandler<XInventoryFolder>( 51 m_Folders = new MSSQLFolderHandler(
52 conn, "inventoryfolders", "InventoryStore"); 52 conn, "inventoryfolders", "InventoryStore");
53 m_Items = new MSSQLItemHandler( 53 m_Items = new MSSQLItemHandler(
54 conn, "inventoryitems", String.Empty); 54 conn, "inventoryitems", String.Empty);
@@ -85,6 +85,7 @@ namespace OpenSim.Data.MSSQL
85 { 85 {
86 return m_Folders.Delete(field, val); 86 return m_Folders.Delete(field, val);
87 } 87 }
88
88 public bool DeleteFolders(string[] fields, string[] vals) 89 public bool DeleteFolders(string[] fields, string[] vals)
89 { 90 {
90 return m_Folders.Delete(fields, vals); 91 return m_Folders.Delete(fields, vals);
@@ -94,15 +95,22 @@ namespace OpenSim.Data.MSSQL
94 { 95 {
95 return m_Items.Delete(field, val); 96 return m_Items.Delete(field, val);
96 } 97 }
98
97 public bool DeleteItems(string[] fields, string[] vals) 99 public bool DeleteItems(string[] fields, string[] vals)
98 { 100 {
99 return m_Items.Delete(fields, vals); 101 return m_Items.Delete(fields, vals);
100 } 102 }
103
101 public bool MoveItem(string id, string newParent) 104 public bool MoveItem(string id, string newParent)
102 { 105 {
103 return m_Items.MoveItem(id, newParent); 106 return m_Items.MoveItem(id, newParent);
104 } 107 }
105 108
109 public bool MoveFolder(string id, string newParent)
110 {
111 return m_Folders.MoveFolder(id, newParent);
112 }
113
106 public XInventoryItem[] GetActiveGestures(UUID principalID) 114 public XInventoryItem[] GetActiveGestures(UUID principalID)
107 { 115 {
108 return m_Items.GetActiveGestures(principalID); 116 return m_Items.GetActiveGestures(principalID);
@@ -124,79 +132,115 @@ namespace OpenSim.Data.MSSQL
124 public bool MoveItem(string id, string newParent) 132 public bool MoveItem(string id, string newParent)
125 { 133 {
126 using (SqlConnection conn = new SqlConnection(m_ConnectionString)) 134 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
127 using (SqlCommand cmd = new SqlCommand())
128 { 135 {
136 using (SqlCommand cmd = new SqlCommand())
137 {
129 138
130 cmd.CommandText = String.Format("update {0} set parentFolderID = @ParentFolderID where inventoryID = @InventoryID", m_Realm); 139 cmd.CommandText = String.Format("update {0} set parentFolderID = @ParentFolderID where inventoryID = @InventoryID", m_Realm);
131 cmd.Parameters.Add(m_database.CreateParameter("@ParentFolderID", newParent)); 140 cmd.Parameters.Add(m_database.CreateParameter("@ParentFolderID", newParent));
132 cmd.Parameters.Add(m_database.CreateParameter("@InventoryID", id)); 141 cmd.Parameters.Add(m_database.CreateParameter("@InventoryID", id));
133 cmd.Connection = conn; 142 cmd.Connection = conn;
134 conn.Open(); 143 conn.Open();
135 return cmd.ExecuteNonQuery() == 0 ? false : true; 144 return cmd.ExecuteNonQuery() == 0 ? false : true;
145 }
136 } 146 }
137 } 147 }
138 148
139 public XInventoryItem[] GetActiveGestures(UUID principalID) 149 public XInventoryItem[] GetActiveGestures(UUID principalID)
140 { 150 {
141 using (SqlConnection conn = new SqlConnection(m_ConnectionString)) 151 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
142 using (SqlCommand cmd = new SqlCommand())
143 { 152 {
144 cmd.CommandText = String.Format("select * from inventoryitems where avatarId = @uuid and assetType = @type and flags = 1", m_Realm); 153 using (SqlCommand cmd = new SqlCommand())
154 {
155 cmd.CommandText = String.Format("select * from inventoryitems where avatarId = @uuid and assetType = @type and flags = 1", m_Realm);
145 156
146 cmd.Parameters.Add(m_database.CreateParameter("@uuid", principalID.ToString())); 157 cmd.Parameters.Add(m_database.CreateParameter("@uuid", principalID.ToString()));
147 cmd.Parameters.Add(m_database.CreateParameter("@type", (int)AssetType.Gesture)); 158 cmd.Parameters.Add(m_database.CreateParameter("@type", (int)AssetType.Gesture));
148 cmd.Connection = conn; 159 cmd.Connection = conn;
149 conn.Open(); 160 conn.Open();
150 return DoQuery(cmd); 161 return DoQuery(cmd);
162 }
151 } 163 }
152 } 164 }
153 165
154 public int GetAssetPermissions(UUID principalID, UUID assetID) 166 public int GetAssetPermissions(UUID principalID, UUID assetID)
155 { 167 {
156 using (SqlConnection conn = new SqlConnection(m_ConnectionString)) 168 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
157 using (SqlCommand cmd = new SqlCommand())
158 { 169 {
159 cmd.CommandText = String.Format("select bit_or(inventoryCurrentPermissions) as inventoryCurrentPermissions from inventoryitems where avatarID = @PrincipalID and assetID = @AssetID group by assetID", m_Realm); 170 using (SqlCommand cmd = new SqlCommand())
160 cmd.Parameters.Add(m_database.CreateParameter("@PrincipalID", principalID.ToString()));
161 cmd.Parameters.Add(m_database.CreateParameter("@AssetID", assetID.ToString()));
162 cmd.Connection = conn;
163 conn.Open();
164 using (SqlDataReader reader = cmd.ExecuteReader())
165 { 171 {
172 cmd.CommandText = String.Format("select bit_or(inventoryCurrentPermissions) as inventoryCurrentPermissions from inventoryitems where avatarID = @PrincipalID and assetID = @AssetID group by assetID", m_Realm);
173 cmd.Parameters.Add(m_database.CreateParameter("@PrincipalID", principalID.ToString()));
174 cmd.Parameters.Add(m_database.CreateParameter("@AssetID", assetID.ToString()));
175 cmd.Connection = conn;
176 conn.Open();
177 using (SqlDataReader reader = cmd.ExecuteReader())
178 {
166 179
167 int perms = 0; 180 int perms = 0;
168 181
169 if (reader.Read()) 182 if (reader.Read())
170 { 183 {
171 perms = Convert.ToInt32(reader["inventoryCurrentPermissions"]); 184 perms = Convert.ToInt32(reader["inventoryCurrentPermissions"]);
185 }
186
187 return perms;
172 } 188 }
173 189
174 return perms;
175 } 190 }
176
177 } 191 }
178 } 192 }
193
179 public override bool Store(XInventoryItem item) 194 public override bool Store(XInventoryItem item)
180 { 195 {
181 if (!base.Store(item)) 196 if (!base.Store(item))
182 return false; 197 return false;
198
183 string sql = "update inventoryfolders set version=version+1 where folderID = @folderID"; 199 string sql = "update inventoryfolders set version=version+1 where folderID = @folderID";
184 using (SqlConnection conn = new SqlConnection(m_ConnectionString)) 200 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
185 using (SqlCommand cmd = new SqlCommand(sql, conn))
186 { 201 {
187 conn.Open(); 202 using (SqlCommand cmd = new SqlCommand(sql, conn))
203 {
204 conn.Open();
205
206 cmd.Parameters.AddWithValue("@folderID", item.parentFolderID.ToString());
207 try
208 {
209 cmd.ExecuteNonQuery();
210 }
211 catch (Exception)
212 {
213 return false;
214 }
215 }
216
217 return true;
218 }
219 }
220 }
221
222 public class MSSQLFolderHandler : MSSQLGenericTableHandler<XInventoryFolder>
223 {
224 public MSSQLFolderHandler(string c, string t, string m) :
225 base(c, t, m)
226 {
227 }
228
229 public bool MoveFolder(string id, string newParentFolderID)
230 {
231 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
232 {
233 using (SqlCommand cmd = new SqlCommand())
234 {
188 235
189 cmd.Parameters.AddWithValue("@folderID", item.parentFolderID.ToString()); 236 cmd.CommandText = String.Format("update {0} set parentFolderID = @ParentFolderID where folderID = @folderID", m_Realm);
190 try 237 cmd.Parameters.Add(m_database.CreateParameter("@ParentFolderID", newParentFolderID));
191 { 238 cmd.Parameters.Add(m_database.CreateParameter("@folderID", id));
192 cmd.ExecuteNonQuery(); 239 cmd.Connection = conn;
193 } 240 conn.Open();
194 catch (Exception) 241 return cmd.ExecuteNonQuery() == 0 ? false : true;
195 { 242 }
196 return false;
197 }
198 } 243 }
199 return true;
200 } 244 }
201 } 245 }
202} 246} \ No newline at end of file
diff --git a/OpenSim/Data/MySQL/MySQLXInventoryData.cs b/OpenSim/Data/MySQL/MySQLXInventoryData.cs
index cccc500..7a3b5b4 100644
--- a/OpenSim/Data/MySQL/MySQLXInventoryData.cs
+++ b/OpenSim/Data/MySQL/MySQLXInventoryData.cs
@@ -42,12 +42,12 @@ namespace OpenSim.Data.MySQL
42 /// </summary> 42 /// </summary>
43 public class MySQLXInventoryData : IXInventoryData 43 public class MySQLXInventoryData : IXInventoryData
44 { 44 {
45 private MySQLGenericTableHandler<XInventoryFolder> m_Folders; 45 private MySqlFolderHandler m_Folders;
46 private MySqlItemHandler m_Items; 46 private MySqlItemHandler m_Items;
47 47
48 public MySQLXInventoryData(string conn, string realm) 48 public MySQLXInventoryData(string conn, string realm)
49 { 49 {
50 m_Folders = new MySQLGenericTableHandler<XInventoryFolder>( 50 m_Folders = new MySqlFolderHandler(
51 conn, "inventoryfolders", "InventoryStore"); 51 conn, "inventoryfolders", "InventoryStore");
52 m_Items = new MySqlItemHandler( 52 m_Items = new MySqlItemHandler(
53 conn, "inventoryitems", String.Empty); 53 conn, "inventoryitems", String.Empty);
@@ -106,6 +106,11 @@ namespace OpenSim.Data.MySQL
106 return m_Items.MoveItem(id, newParent); 106 return m_Items.MoveItem(id, newParent);
107 } 107 }
108 108
109 public bool MoveFolder(string id, string newParent)
110 {
111 return m_Folders.MoveFolder(id, newParent);
112 }
113
109 public XInventoryItem[] GetActiveGestures(UUID principalID) 114 public XInventoryItem[] GetActiveGestures(UUID principalID)
110 { 115 {
111 return m_Items.GetActiveGestures(principalID); 116 return m_Items.GetActiveGestures(principalID);
@@ -275,4 +280,89 @@ namespace OpenSim.Data.MySQL
275 return true; 280 return true;
276 } 281 }
277 } 282 }
283
284 public class MySqlFolderHandler : MySQLGenericTableHandler<XInventoryFolder>
285 {
286// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
287
288 public MySqlFolderHandler(string c, string t, string m) :
289 base(c, t, m)
290 {
291 }
292
293 public bool MoveFolder(string id, string newParentFolderID)
294 {
295 XInventoryFolder[] folders = Get(new string[] { "folderID" }, new string[] { id });
296
297 if (folders.Length == 0)
298 return false;
299
300 UUID oldParentFolderUUID = folders[0].parentFolderID;
301
302 using (MySqlCommand cmd = new MySqlCommand())
303 {
304 cmd.CommandText
305 = String.Format(
306 "update {0} set parentFolderID = ?ParentFolderID where folderID = ?folderID", m_Realm);
307 cmd.Parameters.AddWithValue("?ParentFolderID", newParentFolderID);
308 cmd.Parameters.AddWithValue("?folderID", id);
309
310 if (ExecuteNonQuery(cmd) == 0)
311 return false;
312 }
313
314 IncrementFolderVersion(oldParentFolderUUID);
315 IncrementFolderVersion(newParentFolderID);
316
317 return true;
318 }
319
320 public override bool Store(XInventoryFolder folder)
321 {
322 if (!base.Store(folder))
323 return false;
324
325 IncrementFolderVersion(folder.parentFolderID);
326
327 return true;
328 }
329
330 private bool IncrementFolderVersion(UUID folderID)
331 {
332 return IncrementFolderVersion(folderID.ToString());
333 }
334
335 private bool IncrementFolderVersion(string folderID)
336 {
337// m_log.DebugFormat("[MYSQL FOLDER HANDLER]: Incrementing version on folder {0}", folderID);
338// Util.PrintCallStack();
339
340 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
341 {
342 dbcon.Open();
343
344 using (MySqlCommand cmd = new MySqlCommand())
345 {
346 cmd.Connection = dbcon;
347
348 cmd.CommandText = String.Format("update inventoryfolders set version=version+1 where folderID = ?folderID");
349 cmd.Parameters.AddWithValue("?folderID", folderID);
350
351 try
352 {
353 cmd.ExecuteNonQuery();
354 }
355 catch (Exception)
356 {
357 return false;
358 }
359 cmd.Dispose();
360 }
361
362 dbcon.Close();
363 }
364
365 return true;
366 }
367 }
278} \ No newline at end of file 368} \ No newline at end of file
diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
index 1f36986..75f8c87 100644
--- a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
+++ b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
@@ -47,7 +47,7 @@ namespace OpenSim.Data.SQLite
47 { 47 {
48// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 48// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49 49
50 private SQLiteGenericTableHandler<XInventoryFolder> m_Folders; 50 private SqliteFolderHandler m_Folders;
51 private SqliteItemHandler m_Items; 51 private SqliteItemHandler m_Items;
52 52
53 public SQLiteXInventoryData(string conn, string realm) 53 public SQLiteXInventoryData(string conn, string realm)
@@ -55,7 +55,7 @@ namespace OpenSim.Data.SQLite
55 if (Util.IsWindows()) 55 if (Util.IsWindows())
56 Util.LoadArchSpecificWindowsDll("sqlite3.dll"); 56 Util.LoadArchSpecificWindowsDll("sqlite3.dll");
57 57
58 m_Folders = new SQLiteGenericTableHandler<XInventoryFolder>( 58 m_Folders = new SqliteFolderHandler(
59 conn, "inventoryfolders", "XInventoryStore"); 59 conn, "inventoryfolders", "XInventoryStore");
60 m_Items = new SqliteItemHandler( 60 m_Items = new SqliteItemHandler(
61 conn, "inventoryitems", String.Empty); 61 conn, "inventoryitems", String.Empty);
@@ -114,6 +114,11 @@ namespace OpenSim.Data.SQLite
114 return m_Items.MoveItem(id, newParent); 114 return m_Items.MoveItem(id, newParent);
115 } 115 }
116 116
117 public bool MoveFolder(string id, string newParent)
118 {
119 return m_Folders.MoveFolder(id, newParent);
120 }
121
117 public XInventoryItem[] GetActiveGestures(UUID principalID) 122 public XInventoryItem[] GetActiveGestures(UUID principalID)
118 { 123 {
119 return m_Items.GetActiveGestures(principalID); 124 return m_Items.GetActiveGestures(principalID);
@@ -177,4 +182,23 @@ namespace OpenSim.Data.SQLite
177 return perms; 182 return perms;
178 } 183 }
179 } 184 }
180} 185
186 public class SqliteFolderHandler : SQLiteGenericTableHandler<XInventoryFolder>
187 {
188 public SqliteFolderHandler(string c, string t, string m) :
189 base(c, t, m)
190 {
191 }
192
193 public bool MoveFolder(string id, string newParentFolderID)
194 {
195 SqliteCommand cmd = new SqliteCommand();
196
197 cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where folderID = :FolderID", m_Realm);
198 cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParentFolderID));
199 cmd.Parameters.Add(new SqliteParameter(":FolderID", id));
200
201 return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true;
202 }
203 }
204} \ No newline at end of file
diff --git a/OpenSim/Services/InventoryService/XInventoryService.cs b/OpenSim/Services/InventoryService/XInventoryService.cs
index 309dab4..9abc5e4 100644
--- a/OpenSim/Services/InventoryService/XInventoryService.cs
+++ b/OpenSim/Services/InventoryService/XInventoryService.cs
@@ -400,16 +400,7 @@ namespace OpenSim.Services.InventoryService
400 400
401 public virtual bool MoveFolder(InventoryFolderBase folder) 401 public virtual bool MoveFolder(InventoryFolderBase folder)
402 { 402 {
403 XInventoryFolder[] x = m_Database.GetFolders( 403 return m_Database.MoveFolder(folder.ID.ToString(), folder.ParentID.ToString());
404 new string[] { "folderID" },
405 new string[] { folder.ID.ToString() });
406
407 if (x.Length == 0)
408 return false;
409
410 x[0].parentFolderID = folder.ParentID;
411
412 return m_Database.StoreFolder(x[0]);
413 } 404 }
414 405
415 // We don't check the principal's ID here 406 // We don't check the principal's ID here
diff --git a/OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs b/OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs
index bca5979..f9bf768 100644
--- a/OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs
+++ b/OpenSim/Tests/Common/Mock/TestXInventoryDataPlugin.cs
@@ -125,6 +125,7 @@ namespace OpenSim.Tests.Common.Mock
125 } 125 }
126 126
127 public bool MoveItem(string id, string newParent) { throw new NotImplementedException(); } 127 public bool MoveItem(string id, string newParent) { throw new NotImplementedException(); }
128 public bool MoveFolder(string id, string newParent) { throw new NotImplementedException(); }
128 public XInventoryItem[] GetActiveGestures(UUID principalID) { throw new NotImplementedException(); } 129 public XInventoryItem[] GetActiveGestures(UUID principalID) { throw new NotImplementedException(); }
129 public int GetAssetPermissions(UUID principalID, UUID assetID) { throw new NotImplementedException(); } 130 public int GetAssetPermissions(UUID principalID, UUID assetID) { throw new NotImplementedException(); }
130 } 131 }