Example usage for org.hibernate.criterion Projections projectionList

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

Introduction

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

Prototype

public static ProjectionList projectionList() 

Source Link

Document

Create a new projection list.

Usage

From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.MembershipStatusChangeDAOImpl.java

License:Open Source License

@Override
public SortedMap<Date, Long> getMutationsByDate(Date start, Date end) {
    Criteria criteria = getSession().createCriteria(MembershipStatusChange.class);

    if (start != null)
        criteria.add(Restrictions.ge("changeTime", start));

    if (end != null)
        criteria.add(Restrictions.le("changeTime", end));

    criteria.setProjection(Projections.projectionList().add(Projections.property("changeTime"))
            .add(Projections.sum("memberSizeMutation")));

    List<Object[]> results = listOf(criteria);

    SortedMap<Date, Long> map = new TreeMap<Date, Long>(new Comparator<Date>() {
        @Override//from  w  w  w. j a va 2  s  .c  o  m
        public int compare(Date d1, Date d2) {
            return -d1.compareTo(d2);
        }
    });

    for (Object[] res : results) {
        Date date = (Date) res[0];
        Long sum = (Long) res[1];

        map.put(date, sum);
    }

    return map;
}

From source file:com.usetheindexluke.FewerColumnsHibernate.java

License:Creative Commons License

public static void main(String[] args) {
    Session session = new Configuration().configure().buildSessionFactory().openSession();
    try {/*from w  w  w.  java 2s  .co  m*/
        Criteria q = session.createCriteria(Sales.class, "sales");
        q.add(Restrictions.gt("saleDate", getSixMonthAgo()));
        q.createAlias("employee", "employee");
        q.setProjection(Projections.projectionList().add(Projections.property("sales.saleDate"), "saleDate")
                .add(Projections.property("sales.eurValue"), "eurValue")
                .add(Projections.property("employee.lastName"), "lastName")
                .add(Projections.property("employee.firstName"), "firstName"));
        q.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

        List<Map> result = q.list();

        for (Map s : result) {
            String txt = " Employee: " + s.get("lastName") + " date: " + s.get("saleDate") + " EUR value: "
                    + s.get("eurValue");
            // System.out.println(txt);
        }
    } finally {
        session.close();
    }
}

From source file:com.ut.tekir.contact.ContactBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {
    DetachedCriteria crit = DetachedCriteria.forClass(Contact.class);

    crit.setProjection(Projections.distinct(Projections.projectionList().add(Projections.property("id"), "id")
            .add(Projections.property("code"), "code").add(Projections.property("name"), "name")
            .add(Projections.property("fullname"), "fullname").add(Projections.property("ssn"), "ssn")
            .add(Projections.property("company"), "company").add(Projections.property("taxNumber"), "taxNumber")
            .add(Projections.property("taxOffice"), "taxOffice").add(Projections.property("title"), "title")
            .add(Projections.property("representative"), "representative")
            .add(Projections.property("info"), "info").add(Projections.property("exCode1"), "exCode1")
            .add(Projections.property("exCode2"), "exCode2").add(Projections.property("allType"), "allType")
            .add(Projections.property("customerType"), "customerType")
            .add(Projections.property("providerType"), "providerType")
            .add(Projections.property("agentType"), "agentType")
            .add(Projections.property("personnelType"), "personnelType")
            .add(Projections.property("branchType"), "branchType")
            .add(Projections.property("contactType"), "contactType")
            .add(Projections.property("bankType"), "bankType")
            .add(Projections.property("relatedType"), "relatedType")
            .add(Projections.property("foundationType"), "foundationType")));

    crit.setResultTransformer(Transformers.aliasToBean(ContactModel.class));

    if (filterModel.getCode() != null && filterModel.getCode().length() > 0) {
        crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START));
    }/*from  w  w w .ja v  a2s. co  m*/

    if (filterModel.getFullname() != null && filterModel.getFullname().length() > 0) {
        crit.add(Restrictions.ilike("this.fullname", filterModel.getFullname(), MatchMode.ANYWHERE));
    }

    if (filterModel.getCompany() != null && filterModel.getCompany().length() > 0) {
        crit.add(Restrictions.ilike("this.company", filterModel.getCompany(), MatchMode.START));
    }

    if (filterModel.getSsn() != null && filterModel.getSsn().length() > 0) {
        crit.add(Restrictions.ilike("this.ssn", filterModel.getSsn(), MatchMode.START));
    }

    if (filterModel.getTaxNumber() != null && filterModel.getTaxNumber().length() > 0) {
        crit.add(Restrictions.ilike("this.taxNumber", filterModel.getTaxNumber(), MatchMode.START));
    }

    if (filterModel.getRepresentative() != null && filterModel.getRepresentative().length() > 0) {
        crit.add(Restrictions.ilike("this.representative", filterModel.getRepresentative(), MatchMode.START));
    }

    if (filterModel.getExCode1() != null && filterModel.getExCode1().length() > 0) {
        crit.add(Restrictions.ilike("this.exCode1", filterModel.getExCode1(), MatchMode.START));
    }

    if (filterModel.getExCode2() != null && filterModel.getExCode2().length() > 0) {
        crit.add(Restrictions.ilike("this.exCode2", filterModel.getExCode2(), MatchMode.START));
    }

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

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

    if (filterModel.getCompanyType() != null && !filterModel.getCompanyType().equals("All")) {
        if (filterModel.getCompanyType().equals("Person")) {
            crit.add(Restrictions.eq("this.person", Boolean.TRUE));
        } else
            crit.add(Restrictions.eq("this.person", Boolean.FALSE));
    }

    if (filterModel.getType() != null && filterModel.getType() != ContactType.All) {
        crit.add(Restrictions.eq("this." + filterModel.getType().toString().toLowerCase() + "Type",
                Boolean.TRUE));
    }

    if (filterModel.getCountry() != null) {
        crit.createAlias("this.addressList", "addressList", CriteriaSpecification.INNER_JOIN);
        crit.add(Restrictions.eq("addressList.address.country", filterModel.getCountry()));

        if (filterModel.getCity1() != null) {
            crit.add(Restrictions.eq("addressList.city", filterModel.getCity1()));
        }
    }

    //FIXME: bu kontrol nasl olmal?
    if (hasRegionRestriction()) {
        if (activeUser.getContact() != null && activeUser.getContact().getOrganization() != null
                && activeUser.getContact().getOrganization() != null) {

            crit.add(Restrictions.or(
                    Restrictions.eq("this.organization.id", activeUser.getContact().getOrganization().getId()),
                    Restrictions.eq("this.isPublic", Boolean.TRUE)));
        }
    }
    crit.addOrder(Order.desc("this.code"));

    return crit;
}

From source file:com.ut.tekir.contact.ContactStatusBean.java

License:LGPL

/**
 * nce devir hesaplayalm.../*w  w w.  j a  va  2s  .c om*/
 * 
 */
@SuppressWarnings("unchecked")
protected void calculateOffset() {

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

    Calendar cal = Calendar.getInstance();
    cal.set(getYear(), 0, 1);
    Date beginDate = cal.getTime();

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

    crit.add(Restrictions.eq("contact", contact)).add(Restrictions.lt("date", beginDate))
            .add(Restrictions.eq("active", true)); //Tarih kontrol yaplacak

    crit.setProjection(Projections.projectionList()
            .add(Projections.groupProperty("amount.currency"), "amountCurrency")
            .add(Projections.groupProperty("action"), "action").add(Projections.sum("amount.value"), "amount")
            .add(Projections.sum("localAmount.value"), "localAmount"));

    List ls = crit.list();

    for (Iterator it = ls.iterator(); it.hasNext();) {
        Object obj[] = (Object[]) it.next();
        dataTable.addRow("OPEN", (String) obj[0], (FinanceAction) obj[1], (Double) obj[2], (Double) obj[3]);
    }
}

From source file:com.ut.tekir.contact.ContactStatusBean.java

License:LGPL

@SuppressWarnings("unchecked")
private void calculateMonth(Integer month) {

    String rowKey = "MONTH" + (month < 10 ? "0" + month : month);

    Calendar cal = Calendar.getInstance();
    cal.set(getYear(), month, 1);/*w ww .j  a v a  2 s .c  o  m*/

    Date beginDate = cal.getTime();

    if (month == 12) {
        cal.set(getYear() + 1, 1, 1);
    } else {
        cal.set(getYear(), month + 1, 1);
    }

    Date endDate = cal.getTime();

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

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

    crit.add(Restrictions.eq("contact", contact)).add(Restrictions.ge("date", beginDate))
            .add(Restrictions.lt("date", endDate)).add(Restrictions.eq("active", true)); //Tarih kontrol yaplacak

    crit.setProjection(Projections.projectionList()
            .add(Projections.groupProperty("amount.currency"), "amountCurrency")
            .add(Projections.groupProperty("action"), "action").add(Projections.sum("amount.value"), "amount")
            .add(Projections.sum("localAmount.value"), "localAmount"));

    List ls = crit.list();

    for (Iterator it = ls.iterator(); it.hasNext();) {
        Object obj[] = (Object[]) it.next();
        dataTable.addRow(rowKey, (String) obj[0], (FinanceAction) obj[1], (Double) obj[2], (Double) obj[3]);
    }
}

From source file:com.ut.tekir.contact.ContactSuggestionBean.java

License:LGPL

public void selectCustomerList() {

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

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

    if (getCode() != null && getCode().length() > 0) {
        crit.add(Restrictions.ilike("this.code", getCode(), MatchMode.START));
    }/*from   www .  j av a2  s .  com*/

    if (getCompany() != null && !getCompany().isEmpty()) {
        crit.add(Restrictions.ilike("this.company", getCompany(), MatchMode.START));
    }

    if (getSsn() != null && !getSsn().isEmpty()) {
        crit.add(Restrictions.ilike("this.ssn", getSsn(), MatchMode.START));
    }

    if (getTaxNumber() != null & !getTaxNumber().isEmpty()) {
        crit.add(Restrictions.ilike("this.taxNumber", getTaxNumber(), MatchMode.START));
    }

    if (getFullname() != null && getFullname().length() > 0) {
        crit.add(Restrictions.ilike("this.fullname", getFullname(), MatchMode.ANYWHERE));
    }
    if (getType() != null && getType() != ContactType.All) {
        crit.add(Restrictions.eq("this." + getType().toString().toLowerCase() + "Type", Boolean.TRUE));
    }
    if (getCategory() != null) {
        crit.add(Restrictions.eq("this.category", getCategory()));
    }
    if (getExCode1() != null & !getExCode1().isEmpty()) {
        crit.add(Restrictions.ilike("this.exCode1", getExCode1(), MatchMode.START));
    }
    if (getExCode2() != null & !getExCode2().isEmpty()) {
        crit.add(Restrictions.ilike("this.exCode2", getExCode2(), MatchMode.START));
    }

    crit.setProjection(Projections.projectionList().add(Projections.property("code"), "code")
            .add(Projections.property("fullname"), "fullname")
            .add(Projections.property("customerType"), "customerType")
            .add(Projections.property("personnelType"), "personnelType")
            .add(Projections.property("agentType"), "agentType")
            .add(Projections.property("branchType"), "branchType")
            .add(Projections.property("providerType"), "providerType")
            .add(Projections.property("contactType"), "contactType")
            .add(Projections.property("allType"), "allType").add(Projections.property("id"), "id")
            .add(Projections.property("category"), "category")
            .add(Projections.property("taxNumber"), "taxNumber").add(Projections.property("ssn"), "ssn")
            .add(Projections.property("company"), "company").add(Projections.property("exCode2"), "exCode2")
            .add(Projections.property("exCode1"), "exCode1"));

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

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

}

From source file:com.ut.tekir.finance.BankToContactTransferBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

    DetachedCriteria crit = DetachedCriteria.forClass(BankToContactTransfer.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("bankAccount"), "bankAccount")
            .add(Projections.property("bankBranch"), "bankBranch").add(Projections.property("bank"), "bank")
            .add(Projections.property("contact.name"), "contactName")
            .add(Projections.property("contact.company"), "company")
            .add(Projections.property("contact.person"), "person")
            .add(Projections.property("contact.code"), "contactCode").add(Projections.property("date"), "date")
            .add(Projections.property("info"), "info")
            .add(Projections.property("this.amount.value"), "amountValue")
            .add(Projections.property("this.amount.currency"), "amountCurrency")
            .add(Projections.property("this.cost.value"), "costValue")
            .add(Projections.property("this.cost.currency"), "costCurrency"))
            .setResultTransformer(Transformers.aliasToBean(BankToContactTransferFilterModel.class));

    if (filterModel.getWorkBunch() != null) {
        crit.add(Restrictions.eq("this.workBunch", filterModel.getWorkBunch()));
    }/*from  w  w w . j  a v a  2  s . c o  m*/

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

    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 (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.getBank() != null) {
        crit.add(Restrictions.eq("this.bank", filterModel.getBank()));
    }

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

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

    if (filterModel.getTransferType() != BankTransferType.Unknown) {
        crit.add(Restrictions.eq("this.transferType", filterModel.getTransferType()));
    }

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

    crit.add(Restrictions.eq("action", FinanceAction.Debit));
    crit.addOrder(Order.desc("this.date"));
    crit.addOrder(Order.desc("this.serial"));

    return crit;
}

From source file:com.ut.tekir.finance.ChequeCollectionAtBankPayrollBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

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

    crit.createAlias("this.bank", "bank");
    crit.createAlias("this.bankBranch", "bankBranch");
    crit.createAlias("this.bankAccount", "bankAccount");

    crit.setProjection(Projections.projectionList().add(Projections.property("this.id"), "id")
            .add(Projections.property("this.serial"), "serial")
            .add(Projections.property("this.reference"), "reference")
            .add(Projections.property("this.code"), "code").add(Projections.property("this.date"), "date")
            .add(Projections.property("this.info"), "info").add(Projections.property("bank.name"), "bankName")
            .add(Projections.property("bankBranch.name"), "bankBranchName")
            .add(Projections.property("bankAccount.name"), "bankAccountName"))
            .setResultTransformer(Transformers.aliasToBean(ChequeCollectionAtBankPayrollFilterModel.class));

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START));
    }//from ww  w . ja  v  a2s . 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.getBank() != null) {
        crit.add(Restrictions.eq("this.bank", filterModel.getBank()));
    }
    if (filterModel.getBankBranch() != null) {
        crit.add(Restrictions.eq("this.bankBranch", filterModel.getBankBranch()));
    }
    if (filterModel.getBankAccount() != null) {
        crit.add(Restrictions.eq("this.bankAccount", filterModel.getBankAccount()));
    }

    crit.addOrder(Order.desc("this.date"));
    crit.addOrder(Order.desc("this.serial"));

    return crit;
}

From source file:com.ut.tekir.finance.ChequeFromContactPayrollBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {
    DetachedCriteria crit = DetachedCriteria.forClass(ChequeFromContactPayroll.class);

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

    crit.setProjection(Projections.projectionList().add(Projections.property("this.id"), "id")
            .add(Projections.property("this.serial"), "serial")
            .add(Projections.property("this.reference"), "reference")
            .add(Projections.property("this.code"), "code").add(Projections.property("this.date"), "date")
            .add(Projections.property("this.info"), "info")
            .add(Projections.property("contact.code"), "contactCode")
            .add(Projections.property("contact.person"), "person")
            .add(Projections.property("contact.company"), "company")
            .add(Projections.property("contact.fullname"), "contactName")
            .add(Projections.property("account.code"), "accountCode")
            .add(Projections.property("account.name"), "accountName"))
            .setResultTransformer(Transformers.aliasToBean(ChequeFromContactPayrollFilterModel.class));

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.like("this.serial", filterModel.getSerial() + "%"));
    }//from   www  .  ja  v a2s. c om

    if (isNotEmpty(filterModel.getReference())) {
        crit.add(Restrictions.like("this.reference", filterModel.getReference() + "%"));
    }

    if (isNotEmpty(filterModel.getCode())) {
        crit.add(Restrictions.like("this.code", filterModel.getCode() + "%"));
    }

    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.getBeginDate() != null) {
        crit.add(Restrictions.ge("this.date", filterModel.getBeginDate()));
    }

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

    crit.addOrder(Order.desc("this.date"));
    crit.addOrder(Order.desc("this.serial"));

    return crit;
}

From source file:com.ut.tekir.finance.ChequeToAccountCollectionPayrollBrowseBean.java

License:LGPL

@Override
public DetachedCriteria buildCriteria() {

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

    crit.createAlias("this.account", "account");

    crit.setProjection(Projections.projectionList().add(Projections.property("this.id"), "id")
            .add(Projections.property("this.serial"), "serial")
            .add(Projections.property("this.reference"), "reference")
            .add(Projections.property("this.code"), "code").add(Projections.property("this.date"), "date")
            .add(Projections.property("this.info"), "info")
            .add(Projections.property("account.name"), "accountName"))
            .setResultTransformer(Transformers.aliasToBean(ChequeToAccountCollectionPayrollFilterModel.class));

    if (isNotEmpty(filterModel.getSerial())) {
        crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START));
    }//from  w ww  .j  a  va  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.getAccount() != null) {
        crit.add(Restrictions.eq("this.account", filterModel.getAccount()));
    }

    crit.addOrder(Order.desc("this.date"));

    return crit;
}