package com.bloatit.data;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.bloatit.data.DaoKudosable.PopularityState;

class DaoKudosableListFactory<T extends DaoKudosable> extends DaoUserContentListFactory<T> {

    protected DaoKudosableListFactory(Criteria criteria) {
        super(criteria);
    }

    public DaoKudosableListFactory() {
        super(SessionManager.getSessionFactory().getCurrentSession().createCriteria(DaoKudosable.class));
    }

    public void orderByPopularity(DaoAbstractListFactory.OrderType order) {
        if (order == OrderType.ASC) {
            addOrder(Order.asc("popularity"));
        } else {
            addOrder(Order.desc("popularity"));
        }
    }

    public void popularity(Comparator cmp, int value) {
        add(createNbCriterion(cmp, "popularity", value));
    }

    public void stateEquals(PopularityState state) {
        add(Restrictions.eq("state", state));
    }
    
    public void kudosSize(Comparator cmp, int number){
        add(createNbCriterion(cmp, "kudos", number));
    }

}

@@ -284,16 +284,174 @@
 y%3CT%3E %7B%0A%0A
+    private static final String KUDOS = %22kudos%22;%0A    private static final String STATE = %22state%22;%0A    private static final String POPULARITY = %22popularity%22;%0A%0A
     prot
@@ -830,28 +830,26 @@
 der.asc(
-%22popularity%22
+POPULARITY
 ));%0A    
@@ -893,28 +893,26 @@
 er.desc(
-%22popularity%22
+POPULARITY
 ));%0A    
@@ -1015,28 +1015,26 @@
 on(cmp, 
-%22popularity%22
+POPULARITY
 , value)
@@ -1124,23 +1124,21 @@
 ions.eq(
-%22state%22
+STATE
 , state)
@@ -1146,20 +1146,16 @@
 ;%0A    %7D%0A
-    
 %0A    pub
@@ -1200,16 +1200,17 @@
  number)
+ 
 %7B%0A      
@@ -1238,23 +1238,21 @@
 on(cmp, 
-%22kudos%22
+KUDOS
 , number

introduce constants