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.tysanclan.site.projectewok.entities.dao.hibernate.ConversationDAOImpl.java

License:Open Source License

@Override
protected Criteria createCriteria(SearchFilter<Conversation> _filter) {
    ConversationFilter filter = (ConversationFilter) _filter;

    Criteria crit = getSession().createCriteria(Conversation.class);

    if (filter.isSortByLastResponse()) {
        filter.addOrderBy("id", false);
        filter.addOrderBy("lastResponse", false);
    }//from   w  w w.j a  v  a  2s.  c o  m

    if (!filter.getParticipants().isEmpty()) {
        for (User participant : filter.getParticipants()) {
            DetachedCriteria dc = DetachedCriteria.forClass(ConversationParticipation.class);
            dc.add(Restrictions.eq("user", participant));
            dc.setProjection(Projections.property("conversation"));
            crit.add(Subqueries.propertyIn("id", dc));
        }
    }

    return crit;
}

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

License:Open Source License

@Override
public List<Long> getUnnotifiedInactiveUsers() {
    Criteria criteria = getSession().createCriteria(User.class);

    DetachedCriteria dc = DetachedCriteria.forClass(InactivityNotification.class);
    dc.setProjection(Projections.property("user"));

    criteria.add(Subqueries.propertyNotIn("id", dc));

    Disjunction d = Restrictions.disjunction();

    d.add(getTrialMemberInactivityCriterion());
    d.add(getVacationMemberInactivityCriterion());
    d.add(getRetiredMemberInactivityCriterion());
    d.add(getRegularMemberInactivityCriterion());

    criteria.add(d);//from   w w  w.j  a  v a  2s  .  c  o m

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

    List<Long> ids = listOf(criteria);

    return ids;
}

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/*w  ww .  j a va2 s .c  om*/
        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.tysanclan.site.projectewok.entities.dao.hibernate.UserDAOImpl.java

License:Open Source License

/**
 * @see com.tysanclan.site.projectewok.entities.dao.UserDAO#getTrialMembersReadyForVote()
 *///w  w w.  java2s  .co m
@SuppressWarnings("unchecked")
@Override
public List<User> getTrialMembersReadyForVote() {
    Criteria criteria = getSession().createCriteria(User.class);

    Calendar cal = DateUtil.getCalendarInstance();
    cal.add(Calendar.DAY_OF_YEAR, -14);

    criteria.add(Restrictions.eq("rank", Rank.TRIAL));
    criteria.add(Restrictions.le("joinDate", cal.getTime()));

    Criteria reverse = getSession().createCriteria(AcceptanceVote.class);
    reverse.createAlias("trialMember", "user");
    reverse.setProjection(Projections.property("user.id"));

    List<?> activeVotes = reverse.list();

    if (!activeVotes.isEmpty()) {
        criteria.add(Restrictions.not(Restrictions.in("id", activeVotes)));
    }

    return criteria.list();
}

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 ww w  .j av  a2  s . 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 .j  a  v  a  2 s.  c  o  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.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   ww w .ja va 2 s.c  o m*/

    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()));
    }//ww w.j  a  v a2s  . com

    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   w  w w.j av a 2s .  co  m

    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 ww  w  .j  a va  2 s .  co  m

    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;
}