public IList Apply(IList result)
        {
            if (firstResult.HasValue)
            {
                result = new FirstResultExitOperation(firstResult.Value).Apply(result);
            }
            if (maxResults.HasValue)
            {
                result = new MaxResultsExitOperation(maxResults.Value).Apply(result);
            }

            return result;
        }
        public void TestApplyWhenFirstResultIsTooBig()
        {
            FirstResultExitOperation exitOp = new FirstResultExitOperation(9);

            List<Object> list = new List<object> {1, 2, null, 3, 4, 5};

            IList objects = exitOp.Apply(list);
            Assert.IsEmpty(objects);

            // edge case
            exitOp = new FirstResultExitOperation(list.Count);
            objects = exitOp.Apply(list);
            Assert.IsEmpty(objects);
        }
        public void TestApplyWhenNoResults()
        {
            FirstResultExitOperation exitOp = new FirstResultExitOperation(9);

            List<Object> list = new List<object>();

            IList objects = exitOp.Apply(list);
            Assert.IsEmpty(objects);

            Object nullObj = null;
            list = new List<object> {nullObj, nullObj, nullObj};

            objects = exitOp.Apply(list);
            Assert.IsEmpty(objects);
        }
        public void TestApply()
        {
            FirstResultExitOperation exitOp = new FirstResultExitOperation(1);

            var list = new List<object> {1, 2, null, 3, 4, 5};

            IList objects = exitOp.Apply(list);
            Assert.AreEqual(4, objects.Count);

            AssertNoNullElements(objects);
            Assert.AreEqual(new List<object> {2, 3, 4, 5}, objects);
            exitOp = new FirstResultExitOperation(2);

            list = new List<object> {1, 2, null, 3, 4, 5};

            objects = exitOp.Apply(list);
            Assert.AreEqual(3, objects.Count);
            AssertNoNullElements(objects);
            Assert.AreEqual(new List<object> {3, 4, 5}, objects);
        }
        public IList Apply(IList result)
        {
            /**
             * Herein lies the glory
             *
             * hibernate has done as much as it can, we're going to have to deal with
             * the rest in memory.
             *
             * The heirarchy of operations is this so far:
             * Distinct
             * Order
             * FirstResult
             * MaxResult
             * RowCount
             * Average
             * Min/Max/Sum
             */

            // ordering of the following operations *really* matters!
            if (distinct != null)
            {
                result = new DistinctExitOperation(distinct).Apply(result);
            }
            foreach (Order order in orders)
            {
                result = new OrderExitOperation(order).Apply(result);
            }
            if (firstResult != null)
            {
                result = new FirstResultExitOperation((int) firstResult).Apply(result);
            }
            if (maxResults != null)
            {
                result = new MaxResultsExitOperation((int) maxResults).Apply(result);
            }
            ProjectionExitOperationFactory factory = ProjectionExitOperationFactory.GetFactory();

            if (rowCountProjection != null)
            {
                result = factory.GetProjectionExitOperation(rowCountProjection, sessionFactoryImplementor).Apply(result);
            }
            if (avgProjection != null)
            {
                result = new AvgResultsExitOperation().Apply(result);
            }
            // min, max, sum
            if (aggregateProjection != null)
            {
                result = factory.GetProjectionExitOperation(aggregateProjection, sessionFactoryImplementor).Apply(result);
            }

            return result;
        }