package main.java.meterstanden.domain;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.persistence.Query;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;

import main.java.meterstanden.hibernate.HibernateUtil;
import main.java.meterstanden.util.MonthList;

/**
 * Servlet implementation class ShowMeterverbruik
 */
@WebServlet("/ShowMeterverbruik")
public class ShowMeterverbruik extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowMeterverbruik() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		List<MonthList> ml_overviewList = new ArrayList<MonthList>();
		
		Session session = HibernateUtil.getSessionFactory().openSession();	
		
		Query query = session.createQuery("from Metersoorten");
		List<?> metersoorten = query.getResultList();
		
		StringBuilder hql = new StringBuilder();
		hql.append("select distinct mv.maand, mv.jaar");
		hql.append(" from Maandverbruik mv");
		hql.append(" order by mv.jaar asc, mv.maand asc");
		Query qMaandverbruiken = session.createQuery(hql.toString());
		List<?> maandverbruikenList = qMaandverbruiken.getResultList();
		Iterator<?> maandverbruikenIt = maandverbruikenList.iterator();
		
		session.close();
		
		while (maandverbruikenIt.hasNext()){
			Object[] mj = (Object[]) maandverbruikenIt.next();
			MonthList ml_overview = MonthList.fillMonth((int)mj[1], (int)mj[0]);
			ml_overviewList.add(ml_overview);
		}
		
		request.setAttribute("theMeterverbruik", ml_overviewList);
		request.setAttribute("theMetersoorten", metersoorten);

		RequestDispatcher rd = getServletContext().getRequestDispatcher("/WEB-INF/ShowMeterverbruik.jsp");
		rd.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
@@ -1555,17 +1555,18 @@
 mv.jaar 
-a
+de
 sc, mv.m
@@ -1570,17 +1570,18 @@
 v.maand 
-a
+de
 sc%22);%0A%09%09
@@ -1642,16 +1642,54 @@
 ing());%0A
+%09%09qMaandverbruiken.setMaxResults(20);%0A
 %09%09List%3C?

Set max number of results of maandverbruik