List of usage examples for org.hibernate.criterion DetachedCriteria setProjection
public DetachedCriteria setProjection(Projection projection)
From source file:com.sccl.attech.modules.sys.service.DictService.java
License:Open Source License
public Page<Dict> find(Page<Dict> page, Dict dict) { // MyBatis //from ww w. j av a 2s . c o m // dict.setPage(page); // page.setList(myBatisDictDao.find(dict)); // return page; // Hibernate DetachedCriteria dc = dictDao.createDetachedCriteria(); dc.setProjection(Projections.distinct(Projections.property("type"))); if (StringUtils.isNotEmpty(dict.getLabel())) { dc.add(Restrictions.like("label", "%" + dict.getLabel() + "%")); } if (StringUtils.isNotEmpty(dict.getType())) { dc.add(Restrictions.eq("type", dict.getType())); } System.out.println(dict.getType()); if (StringUtils.isNotEmpty(dict.getDescription())) { dc.add(Restrictions.like("description", "%" + dict.getDescription() + "%")); } // if(StringUtils.isNotEmpty(dict.getParentId())){ // dc.add(Restrictions.sqlRestriction("parent_id = '"+dict.getParentId()+"'")); // dc.add(Restrictions.like("parentIds", "%"+dict.getParentId()+"%"));//? // } // dc.add(Restrictions.sqlRestriction("parent_ids is not null")); dc.add(Restrictions.sqlRestriction("del_flag=0")); dc.add(Restrictions.eq(Dict.FIELD_DEL_FLAG, Dict.DEL_FLAG_NORMAL)); dc.setResultTransformer(dc.DISTINCT_ROOT_ENTITY); return dictDao.find(page, dc); }
From source file:com.thinkgem.jeesite.common.persistence.BaseDaoImpl.java
License:Open Source License
/** * /* ww w . java 2 s .c o m*/ * * @param detachedCriteria * @return */ public long count(DetachedCriteria detachedCriteria) { long count = ((Number) detachedCriteria.setProjection(Projections.rowCount()) .getExecutableCriteria(getSession()).uniqueResult()).longValue(); detachedCriteria.setProjection(null); return count; }
From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java
License:Apache License
private void checkAndRemoveDuplicates(MaterialInstance materialInstance, List<Modification> newChanges, ArrayList<Modification> list) { if (!new SystemEnvironment().get(SystemEnvironment.CHECK_AND_REMOVE_DUPLICATE_MODIFICATIONS)) { return;//from ww w .j a v a 2s . c om } DetachedCriteria criteria = DetachedCriteria.forClass(Modification.class); criteria.setProjection(Projections.projectionList().add(Projections.property("revision"))); criteria.add(Restrictions.eq("materialInstance.id", materialInstance.getId())); ArrayList<String> revisions = new ArrayList<>(); for (Modification modification : newChanges) { revisions.add(modification.getRevision()); } criteria.add(Restrictions.in("revision", revisions)); List<String> matchingRevisionsFromDb = (List<String>) getHibernateTemplate().findByCriteria(criteria); if (!matchingRevisionsFromDb.isEmpty()) { for (final String revision : matchingRevisionsFromDb) { Modification modification = list.stream().filter(item -> item.getRevision().equals(revision)) .findFirst().orElse(null); list.remove(modification); } } if (!newChanges.isEmpty() && list.isEmpty()) { LOGGER.debug("All modifications already exist in db [{}]", revisions); } if (!matchingRevisionsFromDb.isEmpty()) { LOGGER.info("Saving revisions for material [{}] after removing the following duplicates {}", materialInstance.toOldMaterial(null, null, null).getLongDescription(), matchingRevisionsFromDb); } }
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 ww . ja v a 2 s.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 . jav a 2 s . com*/ criteria.setProjection(Projections.property("id")); List<Long> ids = listOf(criteria); return ids; }
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 www .j ava 2 s. c om*/ 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.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 . ja va2 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 w ww .ja v a 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.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 . ja v a 2 s . c o 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; }
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)); }// w w w .j a v a 2s .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; }