aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MSSQL/MSSQLXInventoryData.cs')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLXInventoryData.cs175
1 files changed, 139 insertions, 36 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs
index b19a0da..9164ffe 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);
@@ -114,7 +122,7 @@ namespace OpenSim.Data.MSSQL
114 } 122 }
115 } 123 }
116 124
117 public class MSSQLItemHandler : MSSQLGenericTableHandler<XInventoryItem> 125 public class MSSQLItemHandler : MSSQLInventoryHandler<XInventoryItem>
118 { 126 {
119 public MSSQLItemHandler(string c, string t, string m) : 127 public MSSQLItemHandler(string c, string t, string m) :
120 base(c, t, m) 128 base(c, t, m)
@@ -123,70 +131,163 @@ namespace OpenSim.Data.MSSQL
123 131
124 public bool MoveItem(string id, string newParent) 132 public bool MoveItem(string id, string newParent)
125 { 133 {
134 XInventoryItem[] retrievedItems = Get(new string[] { "inventoryID" }, new string[] { id });
135 if (retrievedItems.Length == 0)
136 return false;
137
138 UUID oldParent = retrievedItems[0].parentFolderID;
139
126 using (SqlConnection conn = new SqlConnection(m_ConnectionString)) 140 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
127 using (SqlCommand cmd = new SqlCommand())
128 { 141 {
142 using (SqlCommand cmd = new SqlCommand())
143 {
144
145 cmd.CommandText = String.Format("update {0} set parentFolderID = @ParentFolderID where inventoryID = @InventoryID", m_Realm);
146 cmd.Parameters.Add(m_database.CreateParameter("@ParentFolderID", newParent));
147 cmd.Parameters.Add(m_database.CreateParameter("@InventoryID", id));
148 cmd.Connection = conn;
149 conn.Open();
129 150
130 cmd.CommandText = String.Format("update {0} set parentFolderID = @ParentFolderID where inventoryID = @InventoryID", m_Realm); 151 if (cmd.ExecuteNonQuery() == 0)
131 cmd.Parameters.Add(m_database.CreateParameter("@ParentFolderID", newParent)); 152 return false;
132 cmd.Parameters.Add(m_database.CreateParameter("@InventoryID", id)); 153 }
133 cmd.Connection = conn;
134 conn.Open();
135 return cmd.ExecuteNonQuery() == 0 ? false : true;
136 } 154 }
155
156 IncrementFolderVersion(oldParent);
157 IncrementFolderVersion(newParent);
158
159 return true;
137 } 160 }
138 161
139 public XInventoryItem[] GetActiveGestures(UUID principalID) 162 public XInventoryItem[] GetActiveGestures(UUID principalID)
140 { 163 {
141 using (SqlConnection conn = new SqlConnection(m_ConnectionString)) 164 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
142 using (SqlCommand cmd = new SqlCommand())
143 { 165 {
144 cmd.CommandText = String.Format("select * from inventoryitems where avatarId = @uuid and assetType = @type and flags = 1", m_Realm); 166 using (SqlCommand cmd = new SqlCommand())
167 {
168 cmd.CommandText = String.Format("select * from inventoryitems where avatarId = @uuid and assetType = @type and flags = 1", m_Realm);
145 169
146 cmd.Parameters.Add(m_database.CreateParameter("@uuid", principalID.ToString())); 170 cmd.Parameters.Add(m_database.CreateParameter("@uuid", principalID.ToString()));
147 cmd.Parameters.Add(m_database.CreateParameter("@type", (int)AssetType.Gesture)); 171 cmd.Parameters.Add(m_database.CreateParameter("@type", (int)AssetType.Gesture));
148 cmd.Connection = conn; 172 cmd.Connection = conn;
149 conn.Open(); 173 conn.Open();
150 return DoQuery(cmd); 174 return DoQuery(cmd);
175 }
151 } 176 }
152 } 177 }
153 178
154 public int GetAssetPermissions(UUID principalID, UUID assetID) 179 public int GetAssetPermissions(UUID principalID, UUID assetID)
155 { 180 {
156 using (SqlConnection conn = new SqlConnection(m_ConnectionString)) 181 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
157 using (SqlCommand cmd = new SqlCommand())
158 { 182 {
159 cmd.CommandText = String.Format("select bit_or(inventoryCurrentPermissions) as inventoryCurrentPermissions from inventoryitems where avatarID = @PrincipalID and assetID = @AssetID group by assetID", m_Realm); 183 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 { 184 {
185 cmd.CommandText = String.Format("select bit_or(inventoryCurrentPermissions) as inventoryCurrentPermissions from inventoryitems where avatarID = @PrincipalID and assetID = @AssetID group by assetID", m_Realm);
186 cmd.Parameters.Add(m_database.CreateParameter("@PrincipalID", principalID.ToString()));
187 cmd.Parameters.Add(m_database.CreateParameter("@AssetID", assetID.ToString()));
188 cmd.Connection = conn;
189 conn.Open();
190 using (SqlDataReader reader = cmd.ExecuteReader())
191 {
166 192
167 int perms = 0; 193 int perms = 0;
168 194
169 if (reader.Read()) 195 if (reader.Read())
170 { 196 {
171 perms = Convert.ToInt32(reader["inventoryCurrentPermissions"]); 197 perms = Convert.ToInt32(reader["inventoryCurrentPermissions"]);
198 }
199
200 return perms;
172 } 201 }
173 202
174 return perms;
175 } 203 }
176
177 } 204 }
178 } 205 }
206
179 public override bool Store(XInventoryItem item) 207 public override bool Store(XInventoryItem item)
180 { 208 {
181 if (!base.Store(item)) 209 if (!base.Store(item))
182 return false; 210 return false;
183 string sql = "update inventoryfolders set version=version+1 where folderID = @folderID"; 211
212 IncrementFolderVersion(item.parentFolderID);
213
214 return true;
215 }
216 }
217
218 public class MSSQLFolderHandler : MSSQLInventoryHandler<XInventoryFolder>
219 {
220 public MSSQLFolderHandler(string c, string t, string m) :
221 base(c, t, m)
222 {
223 }
224
225 public bool MoveFolder(string id, string newParentFolderID)
226 {
227 XInventoryFolder[] folders = Get(new string[] { "folderID" }, new string[] { id });
228
229 if (folders.Length == 0)
230 return false;
231
232 UUID oldParentFolderUUID = folders[0].parentFolderID;
233
234 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
235 {
236 using (SqlCommand cmd = new SqlCommand())
237 {
238
239 cmd.CommandText = String.Format("update {0} set parentFolderID = @ParentFolderID where folderID = @folderID", m_Realm);
240 cmd.Parameters.Add(m_database.CreateParameter("@ParentFolderID", newParentFolderID));
241 cmd.Parameters.Add(m_database.CreateParameter("@folderID", id));
242 cmd.Connection = conn;
243 conn.Open();
244
245 if (cmd.ExecuteNonQuery() == 0)
246 return false;
247 }
248 }
249
250 IncrementFolderVersion(oldParentFolderUUID);
251 IncrementFolderVersion(newParentFolderID);
252
253 return true;
254 }
255
256 public override bool Store(XInventoryFolder folder)
257 {
258 if (!base.Store(folder))
259 return false;
260
261 IncrementFolderVersion(folder.parentFolderID);
262
263 return true;
264 }
265 }
266
267 public class MSSQLInventoryHandler<T> : MSSQLGenericTableHandler<T> where T: class, new()
268 {
269 public MSSQLInventoryHandler(string c, string t, string m) : base(c, t, m) {}
270
271 protected bool IncrementFolderVersion(UUID folderID)
272 {
273 return IncrementFolderVersion(folderID.ToString());
274 }
275
276 protected bool IncrementFolderVersion(string folderID)
277 {
278// m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID);
279// Util.PrintCallStack();
280
281 string sql = "update inventoryfolders set version=version+1 where folderID = ?folderID";
282
184 using (SqlConnection conn = new SqlConnection(m_ConnectionString)) 283 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
185 using (SqlCommand cmd = new SqlCommand(sql, conn))
186 { 284 {
187 conn.Open(); 285 using (SqlCommand cmd = new SqlCommand(sql, conn))
286 {
287 conn.Open();
288
289 cmd.Parameters.AddWithValue("@folderID", folderID);
188 290
189 cmd.Parameters.AddWithValue("@folderID", item.parentFolderID.ToString());
190 try 291 try
191 { 292 {
192 cmd.ExecuteNonQuery(); 293 cmd.ExecuteNonQuery();
@@ -194,9 +295,11 @@ namespace OpenSim.Data.MSSQL
194 catch (Exception) 295 catch (Exception)
195 { 296 {
196 return false; 297 return false;
197 } 298 }
299 }
198 } 300 }
301
199 return true; 302 return true;
200 } 303 }
201 } 304 }
202} 305} \ No newline at end of file