List of usage examples for org.hibernate.criterion DetachedCriteria setResultTransformer
public DetachedCriteria setResultTransformer(ResultTransformer resultTransformer)
From source file:com.sapienter.jbilling.server.metafields.db.MetaFieldDAS.java
License:Open Source License
public MetaField getFieldByNameTypeAndGroup(Integer entityId, EntityType[] entityType, String name, Integer groupId) {//from w w w . j a v a 2 s .c o m DetachedCriteria query = DetachedCriteria.forClass(MetaField.class); query.add(Restrictions.eq("entityId", entityId)); query.add(Restrictions.in("entityType", entityType)); query.add(Restrictions.eq("name", name)); query.createAlias("metaFieldGroups", "groups", CriteriaSpecification.LEFT_JOIN); query.add(Restrictions.eq("groups.id", groupId)); query.add(Restrictions.eq("groups.entityType", EntityType.ACCOUNT_TYPE)); query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<MetaField> fields = (List<MetaField>) getHibernateTemplate().findByCriteria(query); return !fields.isEmpty() ? fields.get(0) : null; }
From source file:com.sapienter.jbilling.server.metafields.db.MetaFieldDAS.java
License:Open Source License
public MetaField getFieldByNameAndGroup(Integer entityId, String name, Integer groupId) { DetachedCriteria query = DetachedCriteria.forClass(MetaField.class); query.add(Restrictions.eq("entityId", entityId)); query.add(Restrictions.eq("name", name)); query.createAlias("metaFieldGroups", "groups", CriteriaSpecification.LEFT_JOIN); query.add(Restrictions.eq("groups.id", groupId)); query.add(Restrictions.eq("groups.entityType", EntityType.ACCOUNT_TYPE)); query.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List<MetaField> fields = (List<MetaField>) getHibernateTemplate().findByCriteria(query); return !fields.isEmpty() ? fields.get(0) : null; }
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 w w w . ja v a 2 s. c om*/ // 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.thoughtworks.go.server.persistence.MaterialRepository.java
License:Apache License
private DetachedCriteria buildPMRDetachedQuery(List<Long> pipelineIds) { DetachedCriteria criteria = DetachedCriteria.forClass(PipelineMaterialRevision.class); criteria.add(Restrictions.in("pipelineId", pipelineIds)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return criteria; }
From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java
License:Apache License
private DetachedCriteria buildModificationDetachedQuery(List<Criterion> criteria) { DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Modification.class); Disjunction disjunction = Restrictions.disjunction(); detachedCriteria.add(disjunction);//from w w w . ja v a 2s. c om for (Criterion criterion : criteria) { disjunction.add(criterion); } detachedCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return detachedCriteria; }
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 2s. 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.finance.InvoiceMatchHomeBean.java
License:LGPL
@Override public DetachedCriteria buildCriteria() { DetachedCriteria crit = DetachedCriteria.forClass(Invoice.class); crit.setProjection(Projections.projectionList().add(Projections.property("this.serial"), "serial") .add(Projections.property("this.contact"), "contact") .add(Projections.property("this.reference"), "reference") .add(Projections.property("this.action"), "action") .add(Projections.property("this.invoiceTotal.currency"), "invoiceCurrency") .add(Projections.property("this.invoiceTotal.value"), "invoiceValue") .add(Projections.property("this.date"), "date") .add(Projections.property("this.id"), "matchedDocumentId")); crit.add(Restrictions.ne("this.matchingFinished", Boolean.TRUE)); crit.setResultTransformer(Transformers.aliasToBean(InvoiceMatchFilterModel.class)); if (filterModel.getSerial() != null && filterModel.getSerial().length() > 0) { crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START)); }//from w w w. j a v a 2 s . c o m if (filterModel.getReference() != null && filterModel.getReference().length() > 0) { crit.add(Restrictions.ilike("this.reference", filterModel.getReference(), MatchMode.START)); } if (filterModel.getCode() != null && filterModel.getCode().length() > 0) { crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START)); } if (getContact() != null) { crit.add(Restrictions.eq("this.contact", getContact())); } 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 (tradeAction != null) { crit.add(Restrictions.eq("this.action", tradeAction)); } crit.addOrder(Order.desc("this.serial")); return crit; }
From source file:com.ut.tekir.finance.PromissoryChangeStatusBean.java
License:LGPL
@Override public DetachedCriteria buildCriteria() { DetachedCriteria crit = DetachedCriteria.forClass(PromissoryNote.class); crit.createAlias("this.history", "history"); crit.createAlias("contact", "contact"); crit.setProjection(Projections.projectionList().add(Projections.groupProperty("this.id"), "id") .add(Projections.groupProperty("this.maturityDate"), "maturityDate") .add(Projections.groupProperty("this.referenceNo"), "referenceNo") .add(Projections.groupProperty("this.promissorynoteOwner"), "promissorynoteOwner") .add(Projections.groupProperty("contact.id"), "contactId") .add(Projections.groupProperty("contact.name"), "contactName") .add(Projections.groupProperty("this.lastStatus"), "lastStatus") .add(Projections.groupProperty("this.previousStatus"), "previousStatus") .add(Projections.groupProperty("this.info"), "info") .add(Projections.groupProperty("money.currency"), "moneyCurrency") .add(Projections.groupProperty("money.value"), "moneyValue") .add(Projections.groupProperty("this.serialNo"), "serialNo")); crit.setResultTransformer(Transformers.aliasToBean(PromissorySumModel.class)); if (isNotEmpty(filterModel.getReferenceNo())) { crit.add(Restrictions.eq("this.referenceNo", filterModel.getReferenceNo())); }/*from ww w. j a va 2s. c o m*/ if (filterModel.getContact() != null) { crit.add(Restrictions.eq("this.contact", filterModel.getContact())); } if (isNotEmpty(filterModel.getPromissorynoteOwner())) { crit.add(Restrictions.ilike("this.promissorynoteOwner", filterModel.getPromissorynoteOwner() + "%")); } if (filterModel.getBeginDate() != null) { crit.add(Restrictions.ge("history.date", filterModel.getBeginDate())); } if (filterModel.getEndDate() != null) { crit.add(Restrictions.le("history.date", filterModel.getEndDate())); } if (filterModel.getLastStatus() != null) { crit.add(Restrictions.eq("this.lastStatus", filterModel.getLastStatus())); } if (getIsClientPromissory() != null) { crit.add(Restrictions.eq("this.clientPromissoryNote", getIsClientPromissory())); } return crit; }
From source file:com.ut.tekir.general.OrganizationBrowseBean.java
License:LGPL
@Override public DetachedCriteria buildCriteria() { DetachedCriteria crit = DetachedCriteria.forClass(Organization.class); crit.setProjection(Projections.projectionList().add(Projections.property("id"), "id") .add(Projections.property("code"), "code").add(Projections.property("name"), "name") .add(Projections.property("info"), "info")); crit.setResultTransformer(Transformers.aliasToBean(Organization.class)); if (filterModel.getCode() != null && filterModel.getCode().length() > 0) { crit.add(Restrictions.ilike("code", filterModel.getCode(), MatchMode.START)); }// w w w.j a v a 2 s. c om if (filterModel.getName() != null && filterModel.getName().length() > 0) { crit.add(Restrictions.ilike("name", filterModel.getName(), MatchMode.START)); } if (filterModel.getLevel() != null) { crit.add(Restrictions.eq("level", filterModel.getLevel())); } return crit; }
From source file:com.ut.tekir.invoice.yeni.PurchaseInvoiceBrowseBean.java
License:LGPL
@Override public DetachedCriteria buildCriteria() { DetachedCriteria crit = DetachedCriteria.forClass(TekirInvoice.class); crit.createAlias("this.contact", "contact"); crit.createAlias("this.warehouse", "warehouse"); crit.setProjection(Projections.projectionList().add(Projections.property("contact"), "contact") .add(Projections.property("warehouse"), "warehouse").add(Projections.property("serial"), "serial") .add(Projections.property("reference"), "reference").add(Projections.property("code"), "code") .add(Projections.property("date"), "date").add(Projections.property("contact.code"), "contactCode") .add(Projections.property("contact.fullname"), "contactName") .add(Projections.property("tradeAction"), "tradeAction") .add(Projections.property("documentType"), "documentType").add(Projections.property("id"), "id") .add(Projections.property("info"), "info") .add(Projections.property("totalBeforeTax.localAmount"), "totalBeforeTaxLocalAmount") .add(Projections.property("totalBeforeTax.value"), "totalBeforeTaxValue") .add(Projections.property("totalBeforeTax.currency"), "totalBeforeTaxCurrency") .add(Projections.property("totalTax.localAmount"), "totalTaxLocalAmount") .add(Projections.property("totalTax.value"), "totalTaxValue") .add(Projections.property("totalTax.currency"), "totalTaxCurrency") .add(Projections.property("grandTotal.localAmount"), "grandTotalLocalAmount") .add(Projections.property("grandTotal.value"), "grandTotalValue") .add(Projections.property("grandTotal.currency"), "grandTotalCurrency") .add(Projections.property("workBunch"), "workBunch")); crit.setResultTransformer(Transformers.aliasToBean(InvoiceFilterModel.class)); if (isNotEmpty(filterModel.getSerial())) { crit.add(Restrictions.ilike("this.serial", filterModel.getSerial(), MatchMode.START)); }/* w w w . ja v a 2 s .c o 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 (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 (isNotEmpty(filterModel.getInfo())) { crit.add(Restrictions.ilike("this.info", filterModel.getInfo(), MatchMode.ANYWHERE)); } if (filterModel.getWorkBunch() != null) { crit.add(Restrictions.eq("this.workBunch", filterModel.getWorkBunch())); } if (filterModel.getReturned() != null) { if (filterModel.getReturned()) { crit.add(Restrictions.eq("this.tradeAction", TradeAction.SaleReturn)); } else { crit.add(Restrictions.eq("this.tradeAction", TradeAction.Purchase)); } } else { crit.add(Restrictions.or(Restrictions.eq("this.tradeAction", TradeAction.SaleReturn), Restrictions.eq("this.tradeAction", TradeAction.Purchase))); } crit.add(Restrictions.or(Restrictions.eq("this.documentType", DocumentType.PurchaseInvoice), Restrictions.eq("this.documentType", DocumentType.PurchaseShipmentInvoice))); crit.addOrder(Order.desc("this.date")); crit.addOrder(Order.desc("this.serial")); return crit; }