aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteXInventoryData.cs')
-rw-r--r--OpenSim/Data/SQLite/SQLiteXInventoryData.cs182
1 files changed, 163 insertions, 19 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
index 1f36986..2a0a8f6 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);
@@ -125,44 +130,106 @@ namespace OpenSim.Data.SQLite
125 } 130 }
126 } 131 }
127 132
128 public class SqliteItemHandler : SQLiteGenericTableHandler<XInventoryItem> 133 public class SqliteItemHandler : SqliteInventoryHandler<XInventoryItem>
129 { 134 {
130 public SqliteItemHandler(string c, string t, string m) : 135 public SqliteItemHandler(string c, string t, string m) :
131 base(c, t, m) 136 base(c, t, m)
132 { 137 {
133 } 138 }
134 139
140 public override bool Store(XInventoryItem item)
141 {
142 if (!base.Store(item))
143 return false;
144
145 IncrementFolderVersion(item.parentFolderID);
146
147 return true;
148 }
149
150 public override bool Delete(string field, string val)
151 {
152 XInventoryItem[] retrievedItems = Get(new string[] { field }, new string[] { val });
153 if (retrievedItems.Length == 0)
154 return false;
155
156 if (!base.Delete(field, val))
157 return false;
158
159 // Don't increment folder version here since Delete(string, string) calls Delete(string[], string[])
160// IncrementFolderVersion(retrievedItems[0].parentFolderID);
161
162 return true;
163 }
164
165 public override bool Delete(string[] fields, string[] vals)
166 {
167 XInventoryItem[] retrievedItems = Get(fields, vals);
168 if (retrievedItems.Length == 0)
169 return false;
170
171 if (!base.Delete(fields, vals))
172 return false;
173
174 HashSet<UUID> deletedItemFolderUUIDs = new HashSet<UUID>();
175
176 Array.ForEach<XInventoryItem>(retrievedItems, i => deletedItemFolderUUIDs.Add(i.parentFolderID));
177
178 foreach (UUID deletedItemFolderUUID in deletedItemFolderUUIDs)
179 IncrementFolderVersion(deletedItemFolderUUID);
180
181 return true;
182 }
183
135 public bool MoveItem(string id, string newParent) 184 public bool MoveItem(string id, string newParent)
136 { 185 {
137 SqliteCommand cmd = new SqliteCommand(); 186 XInventoryItem[] retrievedItems = Get(new string[] { "inventoryID" }, new string[] { id });
187 if (retrievedItems.Length == 0)
188 return false;
189
190 UUID oldParent = retrievedItems[0].parentFolderID;
191
192 using (SqliteCommand cmd = new SqliteCommand())
193 {
194 cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where inventoryID = :InventoryID", m_Realm);
195 cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParent));
196 cmd.Parameters.Add(new SqliteParameter(":InventoryID", id));
138 197
139 cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where inventoryID = :InventoryID", m_Realm); 198 if (ExecuteNonQuery(cmd, m_Connection) == 0)
140 cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParent)); 199 return false;
141 cmd.Parameters.Add(new SqliteParameter(":InventoryID", id)); 200 }
201
202 IncrementFolderVersion(oldParent);
203 IncrementFolderVersion(newParent);
142 204
143 return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true; 205 return true;
144 } 206 }
145 207
146 public XInventoryItem[] GetActiveGestures(UUID principalID) 208 public XInventoryItem[] GetActiveGestures(UUID principalID)
147 { 209 {
148 SqliteCommand cmd = new SqliteCommand(); 210 using (SqliteCommand cmd = new SqliteCommand())
149 cmd.CommandText = String.Format("select * from inventoryitems where avatarId = :uuid and assetType = :type and flags = 1", m_Realm); 211 {
212 cmd.CommandText = String.Format("select * from inventoryitems where avatarId = :uuid and assetType = :type and flags = 1", m_Realm);
150 213
151 cmd.Parameters.Add(new SqliteParameter(":uuid", principalID.ToString())); 214 cmd.Parameters.Add(new SqliteParameter(":uuid", principalID.ToString()));
152 cmd.Parameters.Add(new SqliteParameter(":type", (int)AssetType.Gesture)); 215 cmd.Parameters.Add(new SqliteParameter(":type", (int)AssetType.Gesture));
153 216
154 return DoQuery(cmd); 217 return DoQuery(cmd);
218 }
155 } 219 }
156 220
157 public int GetAssetPermissions(UUID principalID, UUID assetID) 221 public int GetAssetPermissions(UUID principalID, UUID assetID)
158 { 222 {
159 SqliteCommand cmd = new SqliteCommand(); 223 IDataReader reader;
160 224
161 cmd.CommandText = String.Format("select inventoryCurrentPermissions from inventoryitems where avatarID = :PrincipalID and assetID = :AssetID", m_Realm); 225 using (SqliteCommand cmd = new SqliteCommand())
162 cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString())); 226 {
163 cmd.Parameters.Add(new SqliteParameter(":AssetID", assetID.ToString())); 227 cmd.CommandText = String.Format("select inventoryCurrentPermissions from inventoryitems where avatarID = :PrincipalID and assetID = :AssetID", m_Realm);
228 cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString()));
229 cmd.Parameters.Add(new SqliteParameter(":AssetID", assetID.ToString()));
164 230
165 IDataReader reader = ExecuteReader(cmd, m_Connection); 231 reader = ExecuteReader(cmd, m_Connection);
232 }
166 233
167 int perms = 0; 234 int perms = 0;
168 235
@@ -177,4 +244,81 @@ namespace OpenSim.Data.SQLite
177 return perms; 244 return perms;
178 } 245 }
179 } 246 }
180} 247
248 public class SqliteFolderHandler : SqliteInventoryHandler<XInventoryFolder>
249 {
250 public SqliteFolderHandler(string c, string t, string m) :
251 base(c, t, m)
252 {
253 }
254
255 public override bool Store(XInventoryFolder folder)
256 {
257 if (!base.Store(folder))
258 return false;
259
260 IncrementFolderVersion(folder.parentFolderID);
261
262 return true;
263 }
264
265 public bool MoveFolder(string id, string newParentFolderID)
266 {
267 XInventoryFolder[] folders = Get(new string[] { "folderID" }, new string[] { id });
268
269 if (folders.Length == 0)
270 return false;
271
272 UUID oldParentFolderUUID = folders[0].parentFolderID;
273
274 using (SqliteCommand cmd = new SqliteCommand())
275 {
276 cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where folderID = :FolderID", m_Realm);
277 cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParentFolderID));
278 cmd.Parameters.Add(new SqliteParameter(":FolderID", id));
279
280 if (ExecuteNonQuery(cmd, m_Connection) == 0)
281 return false;
282 }
283
284 IncrementFolderVersion(oldParentFolderUUID);
285 IncrementFolderVersion(newParentFolderID);
286
287 return true;
288 }
289
290 }
291
292 public class SqliteInventoryHandler<T> : SQLiteGenericTableHandler<T> where T: class, new()
293 {
294 public SqliteInventoryHandler(string c, string t, string m) : base(c, t, m) {}
295
296 protected bool IncrementFolderVersion(UUID folderID)
297 {
298 return IncrementFolderVersion(folderID.ToString());
299 }
300
301 protected bool IncrementFolderVersion(string folderID)
302 {
303// m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID);
304// Util.PrintCallStack();
305
306 using (SqliteCommand cmd = new SqliteCommand())
307 {
308 cmd.CommandText = "update inventoryfolders set version=version+1 where folderID = ?folderID";
309 cmd.Parameters.Add(new SqliteParameter(":folderID", folderID));
310
311 try
312 {
313 cmd.ExecuteNonQuery();
314 }
315 catch (Exception)
316 {
317 return false;
318 }
319 }
320
321 return true;
322 }
323 }
324} \ No newline at end of file