com.webbfontaine.valuewebb.search.ShippingLinesFinder.java Source code

Java tutorial

Introduction

Here is the source code for com.webbfontaine.valuewebb.search.ShippingLinesFinder.java

Source

package com.webbfontaine.valuewebb.search;

import com.webbfontaine.valuewebb.model.constants.Constants;
import com.webbfontaine.valuewebb.model.util.Utils;
import org.apache.commons.lang3.StringUtils;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Copyrights 2002-2009 Webb Fontaine
 * Developer: Grisha Arzumanyan
 * Date: 04/05/2011
 * Time: 15:15
 * This software is the proprietary information of Webb Fontaine.
 * Its use is subject to License terms.
 */

@Name("shippingLinesFinder")
public class ShippingLinesFinder implements Serializable, Constants {

    private static final long serialVersionUID = 1L;

    @In
    EntityManager entityManager;

    @In(create = true)
    RimmCriteria rimmCriteria;

    List resultList;
    static List emptyResultList = new ArrayList();

    public String select() {
        String sql = "select rimmShipLine from RimmShipLine rimmShipLine where "
                + "lower(rimmShipLine.cod) like lower(concat(:codParam, '%')) and ";
        if (FR.equals(Utils.getLanguage())) {
            sql += "lower(rimmShipLine.dscFr) like lower(concat(:dscParam, '%')) ";
        } else {
            sql += "lower(rimmShipLine.dsc) like lower(concat(:dscParam, '%')) ";
        }

        Query query = Utils.setDirectRead(entityManager.createQuery(sql))
                .setParameter("codParam", rimmCriteria.getCod()).setParameter("dscParam", rimmCriteria.getDsc());

        resultList = query.setMaxResults(Constants.MAX_RECORDS_IN_ATTACHED_FINDER).getResultList();
        return null;
    }

    public List getResultList() {
        if (StringUtils.isEmpty(rimmCriteria.getActiveFor())) {
            return emptyResultList;
        }

        if (resultList != null) {
            return resultList;
        }
        select();
        return resultList;
    }

    public void setResultList(List resultList) {
    }

    public RimmCriteria getRimmCriteria() {
        return rimmCriteria;
    }

    public void setRimmCriteria(RimmCriteria rimmCriteria) {
    }
}