/// <summary> /// Return a list of folders in a users inventory contained within the specified folder. /// This method is only used in tests - in normal operation the user always have one, /// and only one, root folder. /// </summary> /// <param name="parentID">The folder to search</param> /// <returns>A list of inventory folders</returns> public List <InventoryFolderBase> getInventoryFolders(UUID parentID) { try { using (ISimpleDB conn = _connFactory.GetConnection()) { string query = "SELECT * FROM inventoryfolders WHERE parentFolderID = ?uuid"; Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("?uuid", parentID.ToString()); using (IDataReader reader = conn.QueryAndUseReader(query, parms)) { List <InventoryFolderBase> items = new List <InventoryFolderBase>(); while (reader.Read()) { InventoryFolderBase folder = readInventoryFolder(reader); items.Add(folder); } return(items); } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
public InventoryFolderBase findUserFolderForType(UUID userId, int typeId) { string query = "SELECT * FROM inventoryfolders WHERE agentID = ?agentId AND type = ?type;"; Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("?agentId", userId); parms.Add("?type", typeId); try { using (ISimpleDB conn = _connFactory.GetConnection()) { using (IDataReader reader = conn.QueryAndUseReader(query, parms)) { if (reader.Read()) { // A null item (because something went wrong) breaks everything in the folder return(readInventoryFolder(reader)); } else { return(null); } } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
/// <summary> /// Returns a list of items in a specified folder /// </summary> /// <param name="folderID">The folder to search</param> /// <returns>A list containing inventory items</returns> public List <InventoryItemBase> getInventoryInFolder(UUID folderID) { try { using (ISimpleDB conn = _connFactory.GetConnection()) { string query = "SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid"; Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("?uuid", folderID.ToString()); List <InventoryItemBase> items = new List <InventoryItemBase>(); using (IDataReader reader = conn.QueryAndUseReader(query, parms)) { while (reader.Read()) { // A null item (because something went wrong) breaks everything in the folder InventoryItemBase item = readInventoryItem(reader); if (item != null) { items.Add(item); } } } return(items); } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
/// <summary> /// Returns up to maxNum profiles of regions that have a name starting with namePrefix /// </summary> /// <param name="name">The name to match against</param> /// <param name="maxNum">Maximum number of profiles to return</param> /// <returns>A list of sim profiles</returns> override public List <RegionProfileData> GetRegionsByName(string namePrefix, uint maxNum) { try { Dictionary <string, object> parms = new Dictionary <string, object>(); parms["?name"] = namePrefix + "%"; using (ISimpleDB conn = _connFactory.GetConnection()) { using (IDataReader reader = conn.QueryAndUseReader("SELECT * FROM regions WHERE regionName LIKE ?name", parms)) { RegionProfileData row; List <RegionProfileData> rows = new List <RegionProfileData>(); while (rows.Count < maxNum && (row = this.readSimRow(reader)) != null) { rows.Add(row); } return(rows); } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
public List <InventoryItemBase> getAllItems(UUID avatarID) { try { using (ISimpleDB conn = _connFactory.GetConnection()) { string query = "SELECT * FROM inventoryitems WHERE avatarId = ?uuid"; Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("?uuid", avatarID.ToString()); using (IDataReader result = conn.QueryAndUseReader(query, parms)) { List <InventoryItemBase> list = new List <InventoryItemBase>(); while (result.Read()) { InventoryItemBase item = readInventoryItem(result); if (item != null) { list.Add(item); } } return(list); } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
/// <summary> /// Returns the folder info for the given folder, or null if one could not be found. /// </summary> /// <param name="userId"></param> /// <param name="type"></param> /// <returns></returns> public InventoryFolderBase findFolder(UUID owner, UUID folderID) { string query = "SELECT * FROM inventoryfolders WHERE agentID = ?agentId AND folderId = ?folderId;"; Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("?agentId", owner); parms.Add("?folderId", folderID); try { using (ISimpleDB conn = _connFactory.GetConnection()) { using (IDataReader reader = conn.QueryAndUseReader(query, parms)) { if (reader.Read()) { // A null item (because something went wrong) breaks everything in the folder return(readInventoryFolder(reader)); } else { m_log.WarnFormat("[Inventory]: findUserTopLevelFolderFor: No top-level folders."); return(null); } } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
/// <summary> /// Returns a sim profile from it's Region name string /// </summary> /// <returns>The sim profile</returns> override public RegionProfileData GetProfileByString(string regionName) { if (regionName.Length > 2) { try { Dictionary <string, object> parms = new Dictionary <string, object>(); // Add % because this is a like query. parms["?regionName"] = regionName + "%"; using (ISimpleDB conn = _connFactory.GetConnection()) { string query = "SELECT * FROM regions WHERE regionName LIKE ?regionName ORDER BY LENGTH(regionName) ASC LIMIT 1"; using (IDataReader reader = conn.QueryAndUseReader(query, parms)) { RegionProfileData row = this.readSimRow(reader); return(row); } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } } m_log.Error("[GRID DB]: Searched for a Region Name shorter then 3 characters"); return(null); }
/// <summary> /// Returns a specified inventory folder /// </summary> /// <param name="folder">The folder to return</param> /// <returns>A folder class</returns> public InventoryFolderBase getInventoryFolder(UUID folderID) { try { using (ISimpleDB conn = _connFactory.GetConnection()) { string query = "SELECT * FROM inventoryfolders WHERE folderID = ?uuid"; Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("?uuid", folderID.ToString()); using (IDataReader reader = conn.QueryAndUseReader(query, parms)) { if (reader.Read()) { InventoryFolderBase folder = readInventoryFolder(reader); return(folder); } else { return(null); } } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
/// <summary> /// Returns a specified inventory item /// </summary> /// <param name="item">The item to return</param> /// <returns>An inventory item</returns> public InventoryItemBase getInventoryItem(UUID itemID) { try { using (ISimpleDB conn = _connFactory.GetConnection()) { string query = "SELECT * FROM inventoryitems WHERE inventoryID = ?uuid"; Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("?uuid", itemID.ToString()); using (IDataReader reader = conn.QueryAndUseReader(query, parms)) { InventoryItemBase item = null; if (reader.Read()) { item = readInventoryItem(reader); } return(item); } } } catch (Exception e) { m_log.Error(e.ToString()); } return(null); }
/// <summary> /// Returns a list of items in the given folders /// </summary> /// <param name="folders"></param> /// <returns></returns> public List <InventoryItemBase> getItemsInFolders(IEnumerable <InventoryFolderBase> folders) { string inList = String.Empty; foreach (InventoryFolderBase folder in folders) { if (!String.IsNullOrEmpty(inList)) { inList += ","; } inList += "'" + folder.ID.ToString() + "'"; } if (String.IsNullOrEmpty(inList)) { return(new List <InventoryItemBase>()); } string query = "SELECT * FROM inventoryitems WHERE parentFolderID IN (" + inList + ");"; try { using (ISimpleDB conn = _connFactory.GetConnection()) { using (IDataReader reader = conn.QueryAndUseReader(query)) { List <InventoryItemBase> items = new List <InventoryItemBase>(); while (reader.Read()) { // A null item (because something went wrong) breaks everything in the folder InventoryItemBase item = readInventoryItem(reader); if (item != null) { items.Add(item); } } return(items); } } } catch (Exception e) { m_log.Error(e.ToString()); return(new List <InventoryItemBase>()); } }
public InventoryFolderBase findUserFolderForType(UUID owner, int typeId) { InventoryFolderBase rootFolder = getUserRootFolder(owner); if (typeId == 8) // by convention, this means root folder { return(rootFolder); } string query = "SELECT * FROM inventoryfolders WHERE agentID = ?agentId AND type = ?type and parentFolderId = ?parent;"; Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("?agentId", owner); parms.Add("?type", typeId); parms.Add("?parent", rootFolder.ID); try { using (ISimpleDB conn = _connFactory.GetConnection()) { using (IDataReader reader = conn.QueryAndUseReader(query, parms)) { if (reader.Read()) { // A null item (because something went wrong) breaks everything in the folder InventoryFolderBase folder = readInventoryFolder(reader); folder.Level = InventoryFolderBase.FolderLevel.TopLevel; return(folder); } else { // m_log.WarnFormat("[Inventory]: findUserFolderForType folder for type {0} not found.", typeId); return(null); } } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
/// <summary> /// see <see cref="InventoryItemBase.getUserRootFolder"/> /// </summary> /// <param name="user">The user UUID</param> /// <returns></returns> public InventoryFolderBase getUserRootFolder(UUID user) { try { using (ISimpleDB conn = _connFactory.GetConnection()) { string query = "SELECT * FROM inventoryfolders WHERE parentFolderID = ?zero AND agentID = ?uuid"; Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("?uuid", user.ToString()); parms.Add("?zero", UUID.Zero.ToString()); using (IDataReader reader = conn.QueryAndUseReader(query, parms)) { List <InventoryFolderBase> items = new List <InventoryFolderBase>(); while (reader.Read()) { items.Add(readInventoryFolder(reader)); } InventoryFolderBase rootFolder = null; // There should only ever be one root folder for a user. However, if there's more // than one we'll simply use the first one rather than failing. It would be even // nicer to print some message to this effect, but this feels like it's too low a // to put such a message out, and it's too minor right now to spare the time to // suitably refactor. if (items.Count > 0) { rootFolder = items[0]; } rootFolder.Level = InventoryFolderBase.FolderLevel.Root; return(rootFolder); } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
/// <summary> /// Returns a sim profile from it's UUID /// </summary> /// <param name="uuid">The region UUID</param> /// <returns>The sim profile</returns> override public RegionProfileData GetProfileByUUID(UUID uuid) { try { Dictionary <string, object> parms = new Dictionary <string, object>(); parms["?uuid"] = uuid.ToString(); using (ISimpleDB conn = _connFactory.GetConnection()) { using (IDataReader reader = conn.QueryAndUseReader("SELECT * FROM regions WHERE uuid = ?uuid", parms)) { RegionProfileData row = this.readSimRow(reader); return(row); } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
/// <summary> /// Returns all the specified region profiles within coordates -- coordinates are inclusive /// </summary> /// <param name="xmin">Minimum X coordinate</param> /// <param name="ymin">Minimum Y coordinate</param> /// <param name="xmax">Maximum X coordinate</param> /// <param name="ymax">Maximum Y coordinate</param> /// <returns>Array of sim profiles</returns> override public RegionProfileData[] GetProfilesInRange(uint xmin, uint ymin, uint xmax, uint ymax) { try { using (ISimpleDB conn = _connFactory.GetConnection()) { Dictionary <string, object> parms = new Dictionary <string, object>(); parms["?xmin"] = xmin.ToString(); parms["?ymin"] = ymin.ToString(); parms["?xmax"] = xmax.ToString(); parms["?ymax"] = ymax.ToString(); IDataReader reader = conn.QueryAndUseReader( "SELECT * FROM regions WHERE locX >= ?xmin AND locX <= ?xmax AND locY >= ?ymin AND locY <= ?ymax", parms); using (reader) { RegionProfileData row; List <RegionProfileData> rows = new List <RegionProfileData>(); while ((row = this.readSimRow(reader)) != null) { rows.Add(row); } return(rows.ToArray()); } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
/// <summary> /// Adds a location reservation /// </summary> /// <param name="x">x coordinate</param> /// <param name="y">y coordinate</param> /// <returns></returns> override public ReservationData GetReservationAtPoint(uint x, uint y) { try { Dictionary <string, object> param = new Dictionary <string, object>(); param["?x"] = x.ToString(); param["?y"] = y.ToString(); using (ISimpleDB conn = _connFactory.GetConnection()) { string query = "SELECT * FROM reservations WHERE resXMin <= ?x AND resXMax >= ?x AND resYMin <= ?y AND resYMax >= ?y"; using (IDataReader reader = conn.QueryAndUseReader(query, param)) { ReservationData row = this.readReservationRow(reader); return(row); } } } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }
public MigrationStatus GetUserMigrationStatus(UUID userId) { using (ISimpleDB conn = _connFactory.GetConnection()) { const string query = "SELECT status FROM InventoryMigrationStatus WHERE user_id = ?userId"; Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("?userId", userId); using (IDataReader reader = conn.QueryAndUseReader(query, parms)) { if (reader.Read()) { short status = Convert.ToInt16(reader["status"]); MigrationStatus retStatus = (MigrationStatus)status; return(retStatus); } else { return(MigrationStatus.Unmigrated); } } } }
/// <summary> /// See IInventoryDataPlugin /// </summary> /// <param name="parentID"></param> /// <returns></returns> public List <InventoryFolderBase> getFolderHierarchy(UUID parentID) { /* Note: There are subtle changes between this implementation of getFolderHierarchy and the previous one * - We will only need to hit the database twice instead of n times. * - We assume the database is well-formed - no stranded/dangling folders, all folders in heirarchy owned * by the same person, each user only has 1 inventory heirarchy * - The returned list is not ordered, instead of breadth-first ordered * There are basically 2 usage cases for getFolderHeirarchy: * 1) Getting the user's entire inventory heirarchy when they log in * 2) Finding a subfolder heirarchy to delete when emptying the trash. * This implementation will pull all inventory folders from the database, and then prune away any folder that * is not part of the requested sub-heirarchy. The theory is that it is cheaper to make 1 request from the * database than to make n requests. This pays off only if requested heirarchy is large. * By making this choice, we are making the worst case better at the cost of making the best case worse. * This way is generally better because we don't have to rebuild the connection/sql query per subfolder, * even if we end up getting more data from the SQL server than we need. * - Francis */ try { List <InventoryFolderBase> folders = new List <InventoryFolderBase>(); Dictionary <UUID, List <InventoryFolderBase> > hashtable = new Dictionary <UUID, List <InventoryFolderBase> >();; List <InventoryFolderBase> parentFolder = new List <InventoryFolderBase>(); using (ISimpleDB conn = _connFactory.GetConnection()) { bool buildResultsFromHashTable = false; /* Fetch the parent folder from the database to determine the agent ID, and if * we're querying the root of the inventory folder tree */ string query = "SELECT * FROM inventoryfolders WHERE folderID = ?uuid"; Dictionary <string, object> parms = new Dictionary <string, object>(); parms.Add("?uuid", parentID.ToString()); IDataReader reader; using (reader = conn.QueryAndUseReader(query, parms)) { while (reader.Read()) // Should be at most 1 result { parentFolder.Add(readInventoryFolder(reader)); } } if (parentFolder.Count >= 1) // No result means parent folder does not exist { if (parentFolder[0].ParentID == UUID.Zero) // We are querying the root folder { /* Get all of the agent's folders from the database, put them in a list and return it */ parms.Clear(); query = "SELECT * FROM inventoryfolders WHERE agentID = ?uuid"; parms.Add("?uuid", parentFolder[0].Owner.ToString()); using (reader = conn.QueryAndUseReader(query, parms)) { while (reader.Read()) { InventoryFolderBase curFolder = readInventoryFolder(reader); if (curFolder.ID != parentID) // Do not need to add the root node of the tree to the list { folders.Add(curFolder); } } } } // if we are querying the root folder else // else we are querying a subtree of the inventory folder tree { /* Get all of the agent's folders from the database, put them all in a hash table * indexed by their parent ID */ parms.Clear(); query = "SELECT * FROM inventoryfolders WHERE agentID = ?uuid"; parms.Add("?uuid", parentFolder[0].Owner.ToString()); using (reader = conn.QueryAndUseReader(query, parms)) { while (reader.Read()) { InventoryFolderBase curFolder = readInventoryFolder(reader); if (hashtable.ContainsKey(curFolder.ParentID)) // Current folder already has a sibling { hashtable[curFolder.ParentID].Add(curFolder); // append to sibling list } else // else current folder has no known (yet) siblings { List <InventoryFolderBase> siblingList = new List <InventoryFolderBase>(); siblingList.Add(curFolder); // Current folder has no known (yet) siblings hashtable.Add(curFolder.ParentID, siblingList); } } // while more items to read from the database } // Set flag so we know we need to build the results from the hash table after // we unlock the database buildResultsFromHashTable = true; } // else we are querying a subtree of the inventory folder tree } // if folder parentID exists if (buildResultsFromHashTable) { /* We have all of the user's folders stored in a hash table indexed by their parent ID * and we need to return the requested subtree. We will build the requested subtree * by performing a breadth-first-search on the hash table */ if (hashtable.ContainsKey(parentID)) { folders.AddRange(hashtable[parentID]); } for (int i = 0; i < folders.Count; i++) // **Note: folders.Count is *not* static { if (hashtable.ContainsKey(folders[i].ID)) { folders.AddRange(hashtable[folders[i].ID]); } } } } // lock (database) return(folders); } catch (Exception e) { m_log.Error(e.ToString()); return(null); } }