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

Java tutorial

Introduction

Here is the source code for com.webbfontaine.valuewebb.search.DeclarantFinder.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("declarantFinder")
public class DeclarantFinder 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 rimmDec from RimmDec rimmDec where "
                + "lower(rimmDec.tin) like lower(concat(:tin,'%')) and "
                + "lower(rimmDec.adr) like lower(concat(:adr,'%')) and "
                + "lower(rimmDec.country) like lower(concat(:country,'%')) and "
                + "lower(rimmDec.nam) like lower(concat(:nam,'%')) and "
                + "(rimmDec.tradeLevel is null or lower(rimmDec.tradeLevel) like lower(concat(:tradeLevel,'%'))) order by rimmDec.tin, rimmDec.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;
    }
}