Exemplo n.º 1
0
        public void TestBadInput()
        {
            AvgResultsExitOperation op = new AvgResultsExitOperation();
            Object[] objArr = { null };

            try
            {
                op.Apply(new List<object>{objArr});
                Assert.Fail("expected rte");
            }
            catch (IllegalStateException rte)
            {
                // good
            }

            try
            {
                op.Apply(new List<object> {new object()});
                Assert.Fail("expected rte");
            }
            catch (IllegalStateException rte)
            {
                // good
            }
        }
Exemplo n.º 2
0
        public void TestEmptyList()
        {
            AvgResultsExitOperation op = new AvgResultsExitOperation();

            IList result = op.Apply(new List<object>());
            Assert.AreEqual(1, result.Count);
            Assert.IsNull(result[0]);
        }
Exemplo n.º 3
0
        public void TestMultipleResults()
        {
            AvgResultsExitOperation op = new AvgResultsExitOperation();

            Object[] objArr1 = { null, 3 };
            Object[] objArr2 = { 2.5, 2 };

            IList result = op.Apply(new List<object> { objArr1, objArr2});
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(2.5, result[0]);

            objArr1[0] = 2.0;

            result = op.Apply(new List<object> {objArr1, objArr2});
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(2.2, result[0]);
        }
Exemplo n.º 4
0
        public void TestSingleResult()
        {
            AvgResultsExitOperation op = new AvgResultsExitOperation();

            Object[] objArr = { null, 3 };

            IList result = op.Apply(new List<object> {objArr});
            Assert.AreEqual(1, result.Count);
            Assert.IsNull(result[0]);

            objArr[0] = 9.0;

            result = op.Apply(new List<object>{objArr});
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(9.0, result[0]);
        }
        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;
        }