Beispiel #1
0
        // Run the given query
        public static void RunQuery(string query, bool isRegionQuery)
        {
            try
            {
                ISelectResults results = null;

                if (isRegionQuery)
                {
                    results = m_region.Query(query);
                }
                else
                {
                    QueryService qs  = m_cache.GetQueryService("examplePool");
                    Query        qry = qs.NewQuery(query);
                    results = qry.Execute();
                }
                if (results is ResultSet)
                {
                    uint index = 1;
                    foreach (IGFSerializable result in results)
                    {
                        Console.WriteLine("\tResult {0}: {1}", index, result);
                        index++;
                    }
                }
                else
                {
                    StructSet ss = (StructSet)results;
                    Console.Write("Columns:");
                    uint   index = 0;
                    string colName;
                    while ((colName = ss.GetFieldName(index)) != null)
                    {
                        Console.Write('\t' + colName);
                        index++;
                    }
                    Console.WriteLine();
                    index = 1;
                    foreach (Struct si in results)
                    {
                        Console.Write("\tResult {0}: ");
                        while (si.HasNext())
                        {
                            Console.Write(si.Next() + " || ");
                        }
                        Console.WriteLine();
                        index++;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception while running the query [{0}]: {1}",
                                  query, ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="orderField"></param>
        /// <param name="isDescending"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageNo"></param>
        /// <param name="forceRefresh"></param>
        /// <param name="createCache"></param>
        /// <returns></returns>
        public StructSet <T> GetStructSet(
            string condition,
            string orderField,
            bool isDescending,
            int pageSize,
            int pageNo,
            bool forceRefresh = false,
            bool createCache  = false)
        {
            var data     = new StructSet <T>();
            var cacheKey = string.Format(Config.CacheKey, (condition + "." + pageSize + "." + pageNo).Md5()) + typeof(T);

            var obj = Cache.Get <StructSet <T> >(cacheKey);

            if (obj == null || forceRefresh)
            {
                var trans = new Transaction();
                try
                {
                    trans.Begin();
                    var dbHelper = new MssqlHelper <T>();
                    data = dbHelper.GetStructSet(condition, null, orderField, isDescending, pageSize, pageNo, trans.DbConnection, trans.DbTrans);
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.RollBack();
                    Logger.Error(ex);
                }
                finally
                {
                    trans.Dispose();
                }

                if (data != null && createCache)
                {
                    Cache.Insert(cacheKey, data);
                }
            }
            else
            {
                data = obj;
            }
            return(data);
        }
Beispiel #3
0
        public void StepThreeSS()
        {
            bool ErrorOccurred = false;

            QueryHelper <object, object> qh = QueryHelper <object, object> .GetHelper(CacheHelper.DCache);

            var qs = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_").GetQueryService();

            int qryIdx = 0;

            foreach (QueryStrings qrystr in QueryStatics.StructSetQueries)
            {
                if (qrystr.Category == QueryCategory.Unsupported)
                {
                    Util.Log("Skipping query index {0} because it is unsupported.", qryIdx);
                    qryIdx++;
                    continue;
                }

                if (m_isPdx == true)
                {
                    if (qryIdx == 12 || qryIdx == 4 || qryIdx == 7 || qryIdx == 22 || qryIdx == 30 || qryIdx == 34)
                    {
                        Util.Log("Skipping query index {0} for pdx because it has function.", qryIdx);
                        qryIdx++;
                        continue;
                    }
                }

                Util.Log("Evaluating query index {0}. {1}", qryIdx, qrystr.Query);

                Query <object> query = qs.NewQuery <object>(qrystr.Query);

                ISelectResults <object> results = query.Execute();

                int expectedRowCount = qh.IsExpectedRowsConstantSS(qryIdx) ?
                                       QueryStatics.StructSetRowCounts[qryIdx] : QueryStatics.StructSetRowCounts[qryIdx] * qh.PortfolioNumSets;

                if (!qh.VerifySS(results, expectedRowCount, QueryStatics.StructSetFieldCounts[qryIdx]))
                {
                    ErrorOccurred = true;
                    Util.Log("Query verify failed for query index {0}.", qryIdx);
                    qryIdx++;
                    continue;
                }

                StructSet <object> ss = results as StructSet <object>;
                if (ss == null)
                {
                    Util.Log("Zero records found for query index {0}, continuing.", qryIdx);
                    qryIdx++;
                    continue;
                }

                uint  rows   = 0;
                Int32 fields = 0;
                foreach (Struct si in ss)
                {
                    rows++;
                    fields = (Int32)si.Count;
                }

                Util.Log("Query index {0} has {1} rows and {2} fields.", qryIdx, rows, fields);

                qryIdx++;
            }

            Assert.IsFalse(ErrorOccurred, "One or more query validation errors occurred.");
        }
Beispiel #4
0
            public override object Clone()
            {
                StructSet newObj = new StructSet(this);

                foreach (_ElementType v in this.ArrayList)
                    newObj.ArrayList.Add(v);

                return newObj;
            }
Beispiel #5
0
			private StructSet(StructSet c) : base(c) { }
Beispiel #6
0
        public void StepThreePQSS()
        {
            bool ErrorOccurred = false;

            QueryHelper <object, object> qh = QueryHelper <object, object> .GetHelper(CacheHelper.DCache);

            var qs = CacheHelper.DCache.GetPoolManager().Find("__TESTPOOL1_").GetQueryService();

            int qryIdx = 0;

            foreach (QueryStrings qrystr in QueryStatics.StructSetParamQueries)
            {
                if (qrystr.Category == QueryCategory.Unsupported)
                {
                    Util.Log("Skipping query index {0} because it is unsupported.", qryIdx);
                    qryIdx++;
                    continue;
                }

                Util.Log("Evaluating query index {0}. {1}", qryIdx, qrystr.Query);

                if (m_isPdx == true)
                {
                    if (qryIdx == 16)
                    {
                        Util.Log("Skipping query index {0} for pdx because it has function.", qryIdx);
                        qryIdx++;
                        continue;
                    }
                }

                Query <object> query = qs.NewQuery <object>(qrystr.Query);

                //Populate the param list, paramList for parameterized query
                object[] paramList = new object[QueryStatics.NoOfQueryParamSS[qryIdx]];

                Int32 numVal = 0;
                for (Int32 ind = 0; ind < QueryStatics.NoOfQueryParamSS[qryIdx]; ind++)
                {
                    //Util.Log("NIL::PQRS:: QueryStatics.QueryParamSetSS[{0},{1}] = {2}", qryIdx, ind, QueryStatics.QueryParamSetSS[qryIdx, ind]);

                    try
                    {
                        numVal         = Convert.ToInt32(QueryStatics.QueryParamSetSS[qryIdx][ind]);
                        paramList[ind] = numVal;
                        //Util.Log("NIL::PQRS:: Interger Args:: paramList[0] = {1}", ind, paramList[ind]);
                    }
                    catch (FormatException)
                    {
                        //Console.WriteLine("Param string is not a sequence of digits.");
                        paramList[ind] = (System.String)QueryStatics.QueryParamSetSS[qryIdx][ind];
                        //Util.Log("NIL::PQRS:: Interger Args:: paramList[0] = {1}", ind, paramList[ind].ToString());
                    }
                }

                ISelectResults <object> results = query.Execute(paramList);

                int expectedRowCount = qh.IsExpectedRowsConstantPQSS(qryIdx) ?
                                       QueryStatics.StructSetPQRowCounts[qryIdx] : QueryStatics.StructSetPQRowCounts[qryIdx] * qh.PortfolioNumSets;

                if (!qh.VerifySS(results, expectedRowCount, QueryStatics.StructSetPQFieldCounts[qryIdx]))
                {
                    ErrorOccurred = true;
                    Util.Log("Query verify failed for query index {0}.", qryIdx);
                    qryIdx++;
                    continue;
                }

                StructSet <object> ss = results as StructSet <object>;
                if (ss == null)
                {
                    Util.Log("Zero records found for query index {0}, continuing.", qryIdx);
                    qryIdx++;
                    continue;
                }

                uint  rows   = 0;
                Int32 fields = 0;
                foreach (Struct si in ss)
                {
                    rows++;
                    fields = (Int32)si.Count;
                }

                Util.Log("Query index {0} has {1} rows and {2} fields.", qryIdx, rows, fields);

                qryIdx++;
            }

            Assert.IsFalse(ErrorOccurred, "One or more query validation errors occurred.");
        }