Example usage for org.hibernate.criterion Projections property

List of usage examples for org.hibernate.criterion Projections property

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections property.

Prototype

public static PropertyProjection property(String propertyName) 

Source Link

Document

A property value projection

Usage

From source file:com.ut.tekir.stock.StockSuggestionBean.java

License:LGPL

public void selectProductList() {

    HibernateSessionProxy session = (HibernateSessionProxy) entityManager.getDelegate();

    Criteria crit = session.createCriteria(Product.class);

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.like("this.code", getCode() + "%"));
    }//from  www  .  j ava  2  s  .c  om

    if (getName() != null && getName().length() > 0) {
        crit.add(Restrictions.like("this.name", getName() + "%"));
    }

    if (getBarcode() != null && getBarcode().length() > 0) {
        SimpleExpression barcodeCrit1 = Restrictions.like("this.barcode1", getBarcode() + "%");
        SimpleExpression barcodeCrit2 = Restrictions.like("this.barcode2", getBarcode() + "%");
        SimpleExpression barcodeCrit3 = Restrictions.like("this.barcode3", getBarcode() + "%");

        crit.add(Restrictions.or(Restrictions.or(barcodeCrit1, barcodeCrit2), barcodeCrit3));
    }

    if (getProductType() != ProductType.Unknown) {
        crit.add(Restrictions.eq("this.productType", getProductType()));
    }

    if (getCategory() != null) {
        crit.add(Restrictions.eq("this.category", getCategory()));
    }

    if (getGroup() != null) {
        crit.add(Restrictions.eq("this.group", getGroup()));
    }

    crit.setProjection(Projections.projectionList().add(Projections.property("code"), "code")
            .add(Projections.property("name"), "name").add(Projections.property("productType"), "productType")
            .add(Projections.property("barcode1"), "barcode1").add(Projections.property("category"), "category")
            .add(Projections.property("group"), "group"));

    crit.add(Restrictions.eq("this.active", true));

    crit.setMaxResults(30);
    //        crit.setCacheable(true);
    //TODO: Map niye almyor kine?
    //crit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    productList = crit.list();

}

From source file:com.ut.tekir.stock.StockSuggestionBean.java

License:LGPL

public void selectExpenseAndDiscountList() {

    HibernateSessionProxy session = (HibernateSessionProxy) entityManager.getDelegate();
    Criteria crit = session.createCriteria(Product.class);

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.like("this.code", getCode() + "%"));
    }//w w w.  j  ava  2s.co  m

    if (getName() != null && getName().length() > 0) {
        crit.add(Restrictions.like("this.name", getName() + "%"));
    }

    if (getProductType() != null && getProductType() == ProductType.Unknown) {
        crit.add(Restrictions.or(Restrictions.eq("this.productType", ProductType.Expense),
                Restrictions.eq("this.productType", ProductType.Discount)));
    } else {
        crit.add(Restrictions.eq("this.productType", getProductType()));
    }

    crit.setProjection(Projections.projectionList().add(Projections.property("code"), "code")
            .add(Projections.property("name"), "name").add(Projections.property("productType"), "productType"));

    crit.add(Restrictions.eq("active", true));

    crit.setMaxResults(30);
    crit.setCacheable(true);
    //TODO: Map niye almyor kine?
    //crit.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    expenseAndDiscountList = crit.list();

}

From source file:com.ut.tekir.stock.yeni.PurchaseShipmentBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(TekirShipmentNote.class);

    crit.createAlias("contact", "contact");

    crit.setProjection(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("serial"), "serial").add(Projections.property("reference"), "reference")
            .add(Projections.property("code"), "code").add(Projections.property("date"), "date")
            .add(Projections.property("info"), "info").add(Projections.property("info1"), "info1")
            .add(Projections.property("info2"), "info2").add(Projections.property("warehouse"), "warehouse")
            .add(Projections.property("contact.fullname"), "contactName")
            .add(Projections.property("contact.company"), "company")
            .add(Projections.property("contact.person"), "person")
            .add(Projections.property("contact.code"), "contactCode")
            .add(Projections.property("workBunch"), "workBunch"))
            .setResultTransformer(Transformers.aliasToBean(ShipmentFilterModel.class));

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START));
    }// w  w w.ja va  2  s .  c  om

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.ilike("this.reference", filterModel.getReference(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("this.date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("this.date", filterModel.getEndDate()));
    }

    if (filterModel.getWarehouse() != null) {
        crit.add(Restrictions.eq("this.warehouse", filterModel.getWarehouse()));
    }

    if (isNotEmpty(filterModel.getContactName())) {
        crit.add(Restrictions.ilike("contact.fullname", filterModel.getContactName(), MatchMode.ANYWHERE));
    }

    if (isNotEmpty(filterModel.getContactCode())) {
        crit.add(Restrictions.ilike("contact.code", filterModel.getContactCode(), MatchMode.START));
    }

    if (filterModel.getInvoiced() != null) {
        if (filterModel.getInvoiced().equals(Boolean.TRUE)) {
            crit.add(Restrictions.isNotNull("this.invoice"));
        } else {
            crit.add(Restrictions.isNull("this.invoice"));
        }
    }

    if (filterModel.getWorkBunch() != null) {
        crit.add(Restrictions.eq("this.workBunch", filterModel.getWorkBunch()));
    }

    crit.add(Restrictions.eq("this.tradeAction", TradeAction.Purchase));
    crit.addOrder(Order.desc("this.date"));
    crit.addOrder(Order.desc("this.serial"));

    return crit;
}

From source file:com.ut.tekir.stock.yeni.SaleOrderBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(TekirOrderNote.class);

    crit.createAlias("contact", "contact");

    crit.setProjection(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("serial"), "serial").add(Projections.property("reference"), "reference")
            .add(Projections.property("code"), "code").add(Projections.property("status"), "status")
            .add(Projections.property("date"), "date").add(Projections.property("deliveryDate"), "deliveryDate")
            .add(Projections.property("info"), "info").add(Projections.property("warehouse"), "warehouse")
            .add(Projections.property("contact.fullname"), "contactName")
            .add(Projections.property("contact.code"), "contactCode")
            .add(Projections.property("contact.person"), "person")
            .add(Projections.property("contact.company"), "company")
            .add(Projections.property("workBunch"), "workBunch"))
            .setResultTransformer(Transformers.aliasToBean(OrderFilterModel.class));

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START));
    }/*from w w w. ja v  a 2 s .  com*/

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.ilike("this.reference", filterModel.getReference(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("this.date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("this.date", filterModel.getEndDate()));
    }

    if (filterModel.getDeliveryBeginDate() != null) {
        crit.add(Restrictions.ge("this.deliveryDate", filterModel.getDeliveryBeginDate()));
    }

    if (filterModel.getDeliveryEndDate() != null) {
        crit.add(Restrictions.le("this.deliveryDate", filterModel.getDeliveryEndDate()));
    }

    if (filterModel.getWarehouse() != null) {
        crit.add(Restrictions.eq("this.warehouse", filterModel.getWarehouse()));
    }

    if (isNotEmpty(filterModel.getContactCode())) {
        crit.add(Restrictions.ilike("contact.code", filterModel.getContactCode(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getContactName())) {
        crit.add(Restrictions.ilike("contact.name", filterModel.getContactName(), MatchMode.START));
    }

    if (filterModel.getStatus() != null) {
        crit.add(Restrictions.eq("this.status", filterModel.getStatus()));
    }

    if (filterModel.getWorkBunch() != null) {
        crit.add(Restrictions.eq("this.workBunch", filterModel.getWorkBunch()));
    }

    crit.add(Restrictions.eq("this.tradeAction", TradeAction.Sale));
    crit.addOrder(Order.desc("this.serial"));

    return crit;
}

From source file:com.ut.tekir.stock.yeni.SaleShipmentBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(TekirShipmentNote.class);

    crit.createAlias("contact", "contact");

    crit.setProjection(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("serial"), "serial").add(Projections.property("reference"), "reference")
            .add(Projections.property("code"), "code").add(Projections.property("date"), "date")
            .add(Projections.property("info1"), "info1").add(Projections.property("info2"), "info2")
            .add(Projections.property("warehouse"), "warehouse")
            .add(Projections.property("contact.fullname"), "contactName")
            .add(Projections.property("contact.company"), "company")
            .add(Projections.property("contact.person"), "person")
            .add(Projections.property("contact.code"), "contactCode")
            .add(Projections.property("workBunch"), "workBunch"))
            .setResultTransformer(Transformers.aliasToBean(ShipmentFilterModel.class));

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START));
    }//  www. j a va2 s .  com

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.ilike("this.reference", filterModel.getReference(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START));
    }

    if (filterModel.getBeginDate() != null) {
        crit.add(Restrictions.ge("this.date", filterModel.getBeginDate()));
    }

    if (filterModel.getEndDate() != null) {
        crit.add(Restrictions.le("this.date", filterModel.getEndDate()));
    }

    if (filterModel.getWarehouse() != null) {
        crit.add(Restrictions.eq("this.warehouse", filterModel.getWarehouse()));
    }

    if (isNotEmpty(filterModel.getContactCode())) {
        crit.add(Restrictions.ilike("contact.code", filterModel.getContactCode(), MatchMode.START));
    }

    if (isNotEmpty(filterModel.getContactName())) {
        crit.add(Restrictions.ilike("contact.fullname", filterModel.getContactName(), MatchMode.ANYWHERE));
    }

    if (filterModel.getInvoiced() != null) {
        if (filterModel.getInvoiced().equals(Boolean.TRUE)) {
            crit.add(Restrictions.isNotNull("this.invoice"));
        } else {
            crit.add(Restrictions.isNull("this.invoice"));
        }
    }

    if (filterModel.getWorkBunch() != null) {
        crit.add(Restrictions.eq("this.workBunch", filterModel.getWorkBunch()));
    }

    crit.add(Restrictions.eq("this.tradeAction", TradeAction.Sale));
    crit.addOrder(Order.desc("this.date"));
    crit.addOrder(Order.desc("this.serial"));

    return crit;
}

From source file:com.ut.tekir.tender.TenderBrowseBean.java

License:LGPL

private void addProjections(DetachedCriteria crit) {
    crit.setProjection(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("serial"), "serial").add(Projections.property("reference"), "reference")
            .add(Projections.property("status"), "status")
            .add(Projections.property("referenceSuffix"), "referenceSuffix")
            .add(Projections.property("code"), "code").add(Projections.property("date"), "date")
            .add(Projections.property("info1"), "info1").add(Projections.property("info2"), "info2")
            .add(Projections.property("contact.fullname"), "contactName")
            .add(Projections.property("contact.code"), "contactCode")
            .add(Projections.property("totalAmount.value"), "totalAmountValue")
            .add(Projections.property("totalAmount.currency"), "totalAmountCurrency")
            .add(Projections.property("totalDiscount.value"), "totalDiscountValue")
            .add(Projections.property("totalDiscount.currency"), "totalDiscountCurrency")
            .add(Projections.property("totalExpense.value"), "totalExpenseValue")
            .add(Projections.property("totalExpense.currency"), "totalExpenseCurrency")
            .add(Projections.property("totalFee.value"), "totalFeeValue")
            .add(Projections.property("totalFee.currency"), "totalFeeCurrency")
            .add(Projections.property("totalTax.value"), "totalTaxValue")
            .add(Projections.property("totalTax.currency"), "totalTaxCurrency"))
            .setResultTransformer(Transformers.aliasToBean(TenderFilterModel.class));
}

From source file:com.vmware.bdd.dal.impl.ClusterDAO.java

License:Open Source License

@Override
public String findInfraConfig(String clusterName) {
    Session session = getSessionFactory().getCurrentSession();

    Criteria criteria = session.createCriteria(ClusterEntity.class);
    criteria.add(Restrictions.eq("name", clusterName));

    criteria.setProjection(Projections.property("infraConfig"));

    return (String) criteria.uniqueResult();
}

From source file:control.dao.StaffDAO.java

public List<Object> getStaffList(String key, int type, int page) {
    int firstResult = (page - 1) * 20;
    int totalSize;
    Session session = utils.HibernateUtils.getSessionFactory().getCurrentSession();
    List<Object> resultSet = new ArrayList<>();
    boolean searchByFirstName = true;
    try {// w ww .  j a va 2s  .  c  o m
        session.beginTransaction();
        //            Query qr =session.createQuery("from "
        //                    +Staff.class.getName() 
        //                    + " s left join fetch s.roleCollection");
        //            session.createQuery(")
        Criteria crit = session.createCriteria(Staff.class);
        crit.setFetchMode("roleCollection", FetchMode.SELECT);
        crit.addOrder(Order.asc("id"));
        crit.setProjection(Projections.projectionList().add(Projections.property("id"))
                .add(Projections.property("userName")).add(Projections.property("firstName"))
                .add(Projections.property("lastName")).add(Projections.property("phone"))
                .add(Projections.property("email")).add(Projections.property("status")));

        switch (type) {
        case 0:
            break;

        case 1:
            crit.add(Restrictions.ilike("userName", "%" + key + "%"));
            break;

        case 2:
            while (true) {
                if (searchByFirstName) {
                    crit.add(Restrictions.ilike("firstName", "%" + key + "%"));
                    searchByFirstName = crit.list().isEmpty();
                    if (searchByFirstName) {
                        break;
                    }
                } else {
                    crit.add(Restrictions.ilike("lastName", "%" + key + "%"));
                    break;
                }
            }
            break;

        case 3:
            crit.add(Restrictions.ilike("phone", "%" + key + "%"));
            break;

        case 4:
            crit.add(Restrictions.ilike("email", "%" + key + "%"));
            break;

        case 5:
            crit.add(Restrictions.ilike("adress", "%" + key + "%"));
            break;
        }

        totalSize = crit.list().size();
        crit.setFirstResult(firstResult);
        crit.setMaxResults(20);
        resultSet = crit.list();
        resultSet.add(totalSize);
        return resultSet == null ? new ArrayList<>() : resultSet;
    } catch (Exception e) {
        e.printStackTrace();
        return new ArrayList<>();
    } finally {
        if (session.getTransaction().isActive()) {
            session.getTransaction().commit();
        }
    }
}

From source file:control.dao.StaffDAO.java

public String getUserName(String userName) {
    Session session = utils.HibernateUtils.getSessionFactory().getCurrentSession();
    Object obj = null;/*from w  ww  .  j a  va 2  s  .  com*/
    try {
        session.beginTransaction();
        Criteria crit = session.createCriteria(Staff.class);
        //            ProjectionList prl = Projections.projectionList();
        //            prl.add(Projections.property("userName"));
        crit.setProjection(Projections.property("userName"));
        //            crit.setProjection(prl);
        crit.add(Restrictions.eq("userName", userName));
        obj = crit.uniqueResult();
        return (obj != null) ? obj.toString() : null;
    } catch (Exception e) {
        //log here
        return null;
    } finally {
        if (session.getTransaction().isActive()) {
            session.getTransaction().commit();
        }
    }
}

From source file:corner.orm.tapestry.component.prototype.autocompleter.AbstractSelectModel.java

License:Apache License

/**
 * ?/*from  w  ww  .  j  a  v a  2  s.c o  m*/
 * @param criteria
 */
protected void appendProjection(Criteria criteria) {
    criteria.setProjection(Projections.projectionList().add(Projections.property(INDEX_CODE_FIELD))
            .add(Projections.property(ABC_FIELD)).add(Projections.property(CHN_FIELD)));
}