Пример #1
0
        /// <summary>
        /// Prépare une commande.
        /// </summary>
        /// <param name="commandName">Nom de la commande.</param>
        /// <param name="tableName">Nom de la table.</param>
        /// <param name="criteria">Critères de recherche.</param>
        /// <param name="sortOrder">Ordre de tri.</param>
        /// <param name="maxRows">Nombre maximum d'enregistrements (BrokerManager.NoLimit = pas de limite).</param>
        /// <param name="limit">Nombre de lignes à ramener.</param>
        /// <param name="offset">Offset de sélection des lignes.</param>
        /// <returns>Résultat de la requête.</returns>
        protected override IReadCommand GetCommand(string commandName, string tableName, FilterCriteria criteria, int maxRows, QueryParameter queryParameter)
        {
            string sortOrder = string.Empty;

            foreach (string sort in queryParameter.SortedFields)
            {
                sortOrder += sort + ',';
            }
            sortOrder.Substring(0, sortOrder.Length);
            this.SortOrder = sortOrder;

            if ("SV_SELECT_BEAN".Equals(commandName))
            {
                Assert.AreEqual("BEAN", tableName);
                Assert.IsNull(sortOrder);
                BeanDefinition      definition = BeanDescriptor.GetDefinition(typeof(Bean));
                FilterCriteria      filter     = (FilterCriteria)criteria;
                FilterCriteriaParam pkParam    = null;
                foreach (FilterCriteriaParam criteriaParam in filter.Parameters)
                {
                    if (criteriaParam.ColumnName == definition.PrimaryKey.MemberName)
                    {
                        pkParam = criteriaParam;
                    }
                }
                Assert.IsNotNull(pkParam);
                Assert.IsNotNull(pkParam.Value);

                return(new TestDbCommand(new TestDataReader((int)pkParam.Value)));
            }
            else if ("SV_SELECT_ALL_BEAN".Equals(commandName))
            {
                Assert.AreEqual("BEAN", tableName);
                Assert.AreEqual("BEA_NAME", sortOrder);

                if (maxRows > 10)
                {
                    return(new TestDbCommand(new TestDataReader(maxRows)));
                }
                else
                {
                    return(new TestDbCommand(new TestDataReader(maxRows - 1)));
                }
            }
            else if ("SV_SELECT_ALL_LIKE_BEAN".Equals(commandName))
            {
                return(new TestDbCommand(new TestDataReader(10)));
            }
            else if ("SV_SELECT_LIKE_BEAN".Equals(commandName))
            {
                return(new TestDbCommand(new TestDataReader(1)));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Пример #2
0
        public void TestConstructorOneCriteria()
        {
            FilterCriteria      criteria = new FilterCriteria().Equals(Bean.Cols.BEA_ID, 2);
            FilterCriteriaParam param    = null;

            foreach (FilterCriteriaParam parameter in criteria.Parameters)
            {
                if ("BEA_ID".Equals(parameter.ColumnName))
                {
                    param = parameter;
                }
                else
                {
                    Assert.Fail();
                }
            }
            Assert.IsNotNull(param);
            Assert.AreEqual(2, param.Value);
        }