/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import hibernate.Userstatistic;
import hibernate.util.HibernateUtil;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author Ani
 */
public class Statistic {
    private List<Userstatistic> mostGameWinned;
    private List<Userstatistic> mostGameLost;
    private List<Userstatistic> mostGamePlayed;
    private List<Userstatistic> mostGameRestarted;

    public Statistic() {
        createStatistic();
    }

    private void createStatistic(){
        Session session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();

        Query query = session.createQuery("FROM Userstatistic us " +
                    "ORDER BY us.winned DESC");
        query.setMaxResults(10);
        mostGameWinned = query.list();

        query = session.createQuery("FROM Userstatistic us " +
                    "ORDER BY us.lost DESC");
        query.setMaxResults(10);
        mostGameLost = query.list();

        query = session.createQuery("FROM Userstatistic us " +
                    "ORDER BY us.allGame DESC");
        query.setMaxResults(10);
        mostGamePlayed = query.list();

        query = session.createQuery("FROM Userstatistic us " +
                    "ORDER BY us.gamerestarted DESC");
        query.setMaxResults(10);
        mostGameRestarted = query.list();

        session.getTransaction().commit();
        session.close();
    }

    public List<Userstatistic> getMostGameLost() {
        return mostGameLost;
    }

    public List<Userstatistic> getMostGamePlayed() {
        return mostGamePlayed;
    }

    public List<Userstatistic> getMostGameRestarted() {
        return mostGameRestarted;
    }

    public List<Userstatistic> getMostGameWinned() {
        return mostGameWinned;
    }

}
