コード例 #1
0
        private List <Dictionary <string, string> > DoLandQueryAndCombine(IClientAPI remoteClient, ISimpleDB coreDb,
                                                                          string query, Dictionary <string, object> parms,
                                                                          uint queryFlags, int queryStart, int queryEnd,
                                                                          List <UUID> regionsToInclude)
        {
            string[] rdbHosts = this.CheckAndRetrieveRdbHostList(coreDb);
            if (rdbHosts.Length == 0)
            {
                // RDB not configured.  Fall back to core db.
                return(coreDb.QueryWithResults(query, parms));
            }

            List <RDBConnectionQuery> rdbQueries = new List <RDBConnectionQuery>();
            int whichDB = 0;

            foreach (string host in rdbHosts)
            {
                // Initialize the RDB connection and initial results lists

                ConnectionFactory rdbFactory;
                if ((++whichDB == 1) || (_rdbConnectionTemplateDebug.Trim() == String.Empty))
                {
                    rdbFactory = new ConnectionFactory("MySQL", String.Format(_rdbConnectionTemplate, host));
                }
                else  // Special debugging support for multiple RDBs on one machine ("inworldz_rdb2", etc)
                {
                    rdbFactory = new ConnectionFactory("MySQL", String.Format(_rdbConnectionTemplateDebug, host, whichDB));
                }
                RDBConnectionQuery rdb = new RDBConnectionQuery(rdbFactory.GetConnection(), query, queryFlags, parms);
                rdbQueries.Add(rdb);
            }

            List <Dictionary <string, string> > finalList = new List <Dictionary <string, string> >();
            int current = 0;
            Dictionary <string, string> result = null;

            while ((result = ConsumeNext(rdbQueries, queryFlags)) != null)
            {
                UUID regionUUID = new UUID(result["RegionUUID"]);
                // When regionsToInclude.Count==0, it means do not filter by regions.
                if ((regionsToInclude.Count == 0) || regionsToInclude.Contains(regionUUID))
                {
                    // 0-based numbering
                    if ((current >= queryStart) && (current <= queryEnd))
                    {
                        finalList.Add(result);
                    }
                    current++;
                }
            }

            return(finalList);
        }
コード例 #2
0
        private List<Dictionary<string, string>> DoLandQueryAndCombine(IClientAPI remoteClient, ISimpleDB coreDb, 
                                                                    string query, Dictionary<string, object> parms,
                                                                    uint queryFlags, int queryStart, int queryEnd, 
                                                                    List<UUID> regionsToInclude)
        {
            string[] rdbHosts = this.CheckAndRetrieveRdbHostList(coreDb);
            if (rdbHosts.Length == 0)
            {
                // RDB not configured.  Fall back to core db.
                return coreDb.QueryWithResults(query, parms);
            }

            List<RDBConnectionQuery> rdbQueries = new List<RDBConnectionQuery>();
            int whichDB = 0;
            foreach (string host in rdbHosts)
            {
                // Initialize the RDB connection and initial results lists

                ConnectionFactory rdbFactory;
                if ((++whichDB == 1) || String.IsNullOrWhiteSpace(_rdbConnectionTemplateDebug))
                    rdbFactory = new ConnectionFactory("MySQL", String.Format(_rdbConnectionTemplate, host));
                else  // Special debugging support for multiple RDBs on one machine ("inworldz_rdb2", etc)
                    rdbFactory = new ConnectionFactory("MySQL", String.Format(_rdbConnectionTemplateDebug, host, whichDB));
                RDBConnectionQuery rdb = new RDBConnectionQuery(rdbFactory.GetConnection(), query, queryFlags, parms);
                rdbQueries.Add(rdb);
            }

            List<Dictionary<string, string>> finalList = new List<Dictionary<string, string>>();
            int current = 0;
            Dictionary<string, string> result = null;
            while ((result = ConsumeNext(rdbQueries, queryFlags)) != null)
            {
                UUID regionUUID = new UUID(result["RegionUUID"]);
                // When regionsToInclude.Count==0, it means do not filter by regions.
                if ((regionsToInclude.Count == 0) || regionsToInclude.Contains(regionUUID))
                {
                    // 0-based numbering
                    if ((current >= queryStart) && (current <= queryEnd))
                        finalList.Add(result);
                    current++;
                }
            }

            return finalList;
        }
コード例 #3
0
        }   // class RDBQuery

        private Dictionary <string, string> ConsumeNext(List <RDBConnectionQuery> rdbQueries, uint queryFlags)
        {
            Dictionary <string, string> best   = null;
            RDBConnectionQuery          bestDB = null;
            float  bestValue = 0f;
            string bestText  = "";

            foreach (RDBConnectionQuery rdb in rdbQueries)
            {
                // we need to compare the first item in each list to see which one comes next
                Dictionary <string, string> first = rdb.GetNext();
                if (first == null)
                {
                    continue;
                }

                bool ascending = ((queryFlags & (uint)DirFindFlags.SortAsc) != 0);
                bool better    = false;
                if ((queryFlags & (uint)DirFindFlags.NameSort) != 0)
                {
                    if (first.ContainsKey("Name"))
                    {
                        string name = first["Name"];
                        better = (name.CompareTo(bestText) < 0);
                        if (!ascending)
                        {
                            better = !better;
                        }
                        if (better || (best == null))
                        {
                            best     = first;
                            bestDB   = rdb;
                            bestText = name;
                        }
                    }
                }
                else if ((queryFlags & (uint)DirFindFlags.PricesSort) != 0)
                {
                    if (first.ContainsKey("SalePrice"))
                    {
                        float price = (float)Convert.ToInt32(first["SalePrice"]);
                        better = (price < bestValue);
                        if (!ascending)
                        {
                            better = !better;
                        }
                        if (better || (best == null))
                        {
                            best      = first;
                            bestDB    = rdb;
                            bestValue = price;
                        }
                    }
                }
                else if ((queryFlags & (uint)DirFindFlags.PerMeterSort) != 0)
                {
                    if (first.ContainsKey("SalePrice") && first.ContainsKey("Area"))
                    {
                        float price = (float)Convert.ToInt32(first["SalePrice"]);
                        float area  = (float)Convert.ToInt32(first["Area"]);
                        float ppm   = -1.0f;
                        if (area > 0)
                        {
                            ppm = price / area;
                        }
                        better = (ppm < bestValue);
                        if (!ascending)
                        {
                            better = !better;
                        }
                        if (better || (best == null))
                        {
                            best      = first;
                            bestDB    = rdb;
                            bestValue = ppm;
                        }
                    }
                }
                else if ((queryFlags & (uint)DirFindFlags.AreaSort) != 0)
                {
                    if (first.ContainsKey("Area"))
                    {
                        float area = (float)Convert.ToInt32(first["Area"]);
                        better = (area < bestValue);
                        if (!ascending)
                        {
                            better = !better;
                        }
                        if (better || (best == null))
                        {
                            best      = first;
                            bestDB    = rdb;
                            bestValue = area;
                        }
                    }
                }
                else // any order will do
                {
                    // just grab the first one available
                    best   = first;
                    bestDB = rdb;
                    break;
                }
            }

            if (best != null)
            {
                bestDB.Consume();
            }
            return(best);
        }