@Test
	public void testAllDataTypesAggregate() throws Exception
	{
		PersistenceManager pm = new PersistenceManager(driver,database,login,password);
		for(int x = 1;x<=100;x++)
		{
			AllPrimitives ap = new AllPrimitives();
			if(x%2==0)
			{
				ap.setBoolobject(Boolean.TRUE);
				ap.setBoolvalue(true);
			}
			else
			{
				ap.setBoolobject(Boolean.FALSE);
				ap.setBoolvalue(false);
			}
			ap.setByteobject((byte)x);
			ap.setBytevalue((byte)x);
			ap.setCharobject((char)x);
			ap.setCharvalue((char)x);
			ap.setDoubleobject((double)x);
			ap.setDoublevalue((double)x);
			ap.setFloatobject((float)x);
			ap.setFloatvalue((float)x);
			ap.setIntobject(x);
			ap.setIntvalue(x);
			ap.setLongobject((long)x);
			ap.setLongvalue(x);
			ap.setShortobject((short)x);
			ap.setShortvalue((short)x);
			
			pm.saveObject(ap);
		}
		
		//calculate all sums
		AggregateFunction [] functions = new AggregateFunction[]{
				new Sum("getByteobject"),
				new Sum("getBytevalue"),
				new Sum("getCharobject"),
				new Sum("getCharvalue"),
				new Sum("getDoubleobject"),
				new Sum("getDoublevalue"),
				new Sum("getFloatobject"),
				new Sum("getFloatvalue"),
				new Sum("getIntobject"),
				new Sum("getIntvalue"),
				new Sum("getLongobject"),
				new Sum("getLongvalue"),
				new Sum("getShortobject"),
				new Sum("getShortvalue")
		};
		Number[] sums = pm.calculateAggregate(AllPrimitives.class, functions, new All());
		for(int x = 0;x<sums.length;x++)
		{
			assertEquals(5050,sums[x].longValue());
		}
		
		//calculate all maximums
		functions = new AggregateFunction[]{
				new Maximum("getByteobject"),
				new Maximum("getBytevalue"),
				new Maximum("getCharobject"),
				new Maximum("getCharvalue"),
				new Maximum("getDoubleobject"),
				new Maximum("getDoublevalue"),
				new Maximum("getFloatobject"),
				new Maximum("getFloatvalue"),
				new Maximum("getIntobject"),
				new Maximum("getIntvalue"),
				new Maximum("getLongobject"),
				new Maximum("getLongvalue"),
				new Maximum("getShortobject"),
				new Maximum("getShortvalue")
		};
		Number[] maxs = pm.calculateAggregate(AllPrimitives.class, functions, new All());
		for(int x = 0;x<maxs.length;x++)
		{
			assertEquals(100,maxs[x].longValue());
		}
		//calculate all minimums
		functions = new AggregateFunction[]{
				new Minimum("getByteobject"),
				new Minimum("getBytevalue"),
				new Minimum("getCharobject"),
				new Minimum("getCharvalue"),
				new Minimum("getDoubleobject"),
				new Minimum("getDoublevalue"),
				new Minimum("getFloatobject"),
				new Minimum("getFloatvalue"),
				new Minimum("getIntobject"),
				new Minimum("getIntvalue"),
				new Minimum("getLongobject"),
				new Minimum("getLongvalue"),
				new Minimum("getShortobject"),
				new Minimum("getShortvalue")
		};
		Number[] mins = pm.calculateAggregate(AllPrimitives.class, functions, new All());
		for(int x = 0;x<mins.length;x++)
		{
			assertEquals(1,mins[x].longValue());
		}
		//calculate all averages
		functions = new AggregateFunction[]{
				new Average("getByteobject"),
				new Average("getBytevalue"),
				new Average("getCharobject"),
				new Average("getCharvalue"),
				new Average("getDoubleobject"),
				new Average("getDoublevalue"),
				new Average("getFloatobject"),
				new Average("getFloatvalue"),
				new Average("getIntobject"),
				new Average("getIntvalue"),
				new Average("getLongobject"),
				new Average("getLongvalue"),
				new Average("getShortobject"),
				new Average("getShortvalue")
		};
		Number[] avgs = pm.calculateAggregate(AllPrimitives.class, functions, new All());
		for(int x = 0;x<avgs.length;x++)
		{
			assertEquals(50.5,avgs[x].doubleValue(),0.0001);
		}
		
		//try using the ConnectionWrapper method
		ConnectionWrapper cw = pm.getConnectionWrapper();
		double avg = (double) pm.calculateAggregate(cw, AllPrimitives.class, new Average("getDoubleobject"), new All());
		assertEquals(50.5,avg,0.0001);
		
		//delete all AllPrimitives
		pm.dropTable(cw,AllPrimitives.class);

		//test all integer types return a zero long value
		functions = new AggregateFunction[]{
				new Sum("getByteobject"),
				new Sum("getBytevalue"),
				new Sum("getCharobject"),
				new Sum("getCharvalue"),
				new Sum("getIntobject"),
				new Sum("getIntvalue"),
				new Sum("getLongobject"),
				new Sum("getLongvalue"),
				new Sum("getShortobject"),
				new Sum("getShortvalue")
		};
		Number[] num = pm.calculateAggregate(cw,AllPrimitives.class, functions, new All());
		assertEquals(functions.length,num.length);
		for(int x =0;x<num.length;x++)
		{
			assertTrue(num[x] instanceof Long);
			assertEquals(0l,num[x].longValue());
		}
		
		//test all float types return a zero double value
		functions = new AggregateFunction[]{
				new Sum("getDoubleobject"),
				new Sum("getDoublevalue"),
				new Sum("getFloatobject"),
				new Sum("getFloatvalue")
		};
		num = pm.calculateAggregate(cw,AllPrimitives.class, functions, new All());
		assertEquals(functions.length,num.length);
		for(int x =0;x<num.length;x++)
		{
			assertTrue(num[x] instanceof Double);
			assertEquals(0l,num[x].doubleValue(),0.0001);
		}
		cw.commitAndDiscard();
		
		pm.close();
	}