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

Java tutorial

Introduction

Here is the source code for com.webbfontaine.valuewebb.search.CompanyFinder.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 java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * Copyrights 2002-2010 Webb Fontaine
 * This software is the proprietary information of Webb Fontaine.
 * Its use is subject to License terms.
 * User: nigiyan
 * Date: Oct 28, 2010
 */

@Name("companyFinder")
public class CompanyFinder implements Serializable {

    private static final long serialVersionUID = 1L;

    @In
    private EntityManager entityManager;

    @In(create = true)
    private CompanyCriteria companyCriteria;

    private List resultList;

    public String select() {
        String sql = "select company from Company company where "
                + "lower(company.tin) like lower(concat(:tin,'%')) and "
                + "lower(company.adr) like lower(concat(:adr,'%')) and "
                + "lower(company.country) like lower(concat(:country,'%')) and "
                + "lower(company.nam) like lower(concat(:nam,'%')) and "
                + "(company.tradeLevel is null or lower(company.tradeLevel) like lower(concat(:tradeLevel,'%'))) order by company.tin, company.tradeLevel";

        resultList = Utils.setDirectRead(entityManager.createQuery(sql))
                .setParameter("tin", companyCriteria.getCompanyData().getTin())
                .setParameter("adr", companyCriteria.getCompanyData().getAdr())
                .setParameter("country", companyCriteria.getCompanyData().getCountry())
                .setParameter("nam", companyCriteria.getCompanyData().getNam())
                .setParameter("tradeLevel", companyCriteria.getCompanyData().getTradeLevel())
                .setMaxResults(Constants.MAX_RECORDS_IN_ATTACHED_FINDER).getResultList();
        return null;
    }

    public List getResultList() {
        if (StringUtils.isEmpty(companyCriteria.getActiveFor())) {
            return Collections.EMPTY_LIST;
        }

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

        select();
        return resultList;
    }

    public void setResultList(List resultList) {
    }

    public CompanyCriteria getCompanyCriteria() {
        return companyCriteria;
    }

    public void setCompanyCriteria(CompanyCriteria companyCriteria) {
    }
}