package com.bloatit.data;

import java.math.BigDecimal;

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

import com.bloatit.data.DaoDemand.DemandState;
import com.bloatit.data.DaoKudosable.PopularityState;

class DaoDemandListFactory extends DaoKudosableListFactory<DaoDemand> {

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

    public DaoDemandListFactory() {
        super(SessionManager.getSessionFactory().getCurrentSession().createCriteria(DaoDemand.class));
    }

    public void orderByNbComments(DaoAbstractListFactory.OrderType order) {
        // TODO
    }

    public void orderByNbContributions(DaoAbstractListFactory.OrderType order) {
        // TODO
    }

    public void orderByNbOffers(DaoAbstractListFactory.OrderType order) {
        // TODO
    }

    public void stateEquals(DemandState state) {
        add(Restrictions.eq("demandState", state));
    }

    public void projectEquals(DaoProject project) {
        add(Restrictions.eq("project", project));
    }

    public void selectedOfferIsNotNull() {
        add(Restrictions.isNotNull("selectedOffer"));
    }

    public void selectedOfferIsNull() {
        add(Restrictions.isNull("selectedOffer"));
    }

    public void hasOffers() {
        add(Restrictions.isNotEmpty("offers"));
    }

    public void hasNoOffer() {
        add(Restrictions.isEmpty("offers"));
    }

    public void hasContributions() {
        add(Restrictions.isNotEmpty("contribution"));
    }

    public void hasNoContribution() {
        add(Restrictions.isEmpty("contribution"));
    }

    public void contribution(Comparator cmp, BigDecimal value) {
        add(createNbCriterion(cmp, "contribution", value));
    }

}

@@ -85,46 +85,8 @@
 ia;%0A
-import org.hibernate.criterion.Order;%0A
 impo
@@ -177,62 +177,8 @@
 ate;
-%0Aimport com.bloatit.data.DaoKudosable.PopularityState;
 %0A%0Acl
@@ -258,528 +258,524 @@
   pr
-otected DaoDemandListFactory(Criteria criteria) %7B%0A        super(criteria);%0A    %7D%0A%0A    public DaoDemandListFactory() %7B%0A        super(SessionManager.getSessionFactory().getCurrentSession().createCriteria(DaoDemand.class));%0A    %7D%0A%0A    public void orderByNbComments(DaoAbstractListFactory.OrderType order) %7B%0A        // TODO%0A    %7D%0A%0A    public void orderByNbContributions(DaoAbstractListFactory.OrderType order) %7B%0A        // TODO%0A    %7D%0A%0A    public void orderByNbOffers(DaoAbstractListFactory.OrderType order) %7B%0A        // TODO
+ivate static final String CONTRIBUTION = %22contribution%22;%0A    private static final String OFFERS = %22offers%22;%0A    private static final String SELECTED_OFFER = %22selectedOffer%22;%0A    private static final String PROJECT = %22project%22;%0A    private static final String DEMAND_STATE = %22demandState%22;%0A%0A    protected DaoDemandListFactory(Criteria criteria) %7B%0A        super(criteria);%0A    %7D%0A%0A    public DaoDemandListFactory() %7B%0A        super(SessionManager.getSessionFactory().getCurrentSession().createCriteria(DaoDemand.class));
 %0A   
@@ -855,29 +855,28 @@
 ions.eq(
-%22demandState%22
+DEMAND_STATE
 , state)
@@ -965,25 +965,23 @@
 ions.eq(
-%22project%22
+PROJECT
 , projec
@@ -1066,39 +1066,38 @@
 s.isNotNull(
-%22selectedOffer%22
+SELECTED_OFFER
 ));%0A    %7D%0A%0A 
@@ -1167,31 +1167,30 @@
 .isNull(
-%22selectedOffer%22
+SELECTED_OFFER
 ));%0A    
@@ -1254,32 +1254,30 @@
 .isNotEmpty(
-%22offers%22
+OFFERS
 ));%0A    %7D%0A%0A 
@@ -1339,24 +1339,22 @@
 isEmpty(
-%22offers%22
+OFFERS
 ));%0A    
@@ -1425,38 +1425,36 @@
 .isNotEmpty(
-%22contribution%22
+CONTRIBUTION
 ));%0A    %7D%0A%0A 
@@ -1523,30 +1523,28 @@
 isEmpty(
-%22contribution%22
+CONTRIBUTION
 ));%0A    
@@ -1646,30 +1646,28 @@
 on(cmp, 
-%22contribution%22
+CONTRIBUTION
 , value)

introduce constants