List of usage examples for org.hibernate.criterion DetachedCriteria createAlias
@Deprecated public DetachedCriteria createAlias(String associationPath, String alias, int joinType)
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)); }/* w w w .j a va 2s . 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.DebitCreditNoteCollectionBrowseBean.java
License:LGPL
@Override public DetachedCriteria buildCriteria() { DetachedCriteria crit = DetachedCriteria.forClass(DebitCreditNote.class); if (filterModel.getWorkBunch() != null) { crit.createAlias("this.items", "it", CriteriaSpecification.LEFT_JOIN); crit.add(Restrictions.eq("it.workBunch", filterModel.getWorkBunch())); }/*from w w w. ja va2s . 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())); } crit.add(Restrictions.eq("this.action", FinanceAction.Credit)); crit.addOrder(Order.desc("this.serial")); crit.addOrder(Order.desc("this.date")); return crit; }
From source file:com.ut.tekir.finance.DebitCreditNotePaymentBrowseBean.java
License:LGPL
@Override public DetachedCriteria buildCriteria() { DetachedCriteria crit = DetachedCriteria.forClass(DebitCreditNote.class); if (filterModel.getWorkBunch() != null) { crit.createAlias("this.items", "it", CriteriaSpecification.LEFT_JOIN); crit.add(Restrictions.eq("it.workBunch", filterModel.getWorkBunch())); }/*from w w w . j a v a 2s. 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())); } crit.add(Restrictions.eq("this.action", FinanceAction.Debit)); crit.addOrder(Order.desc("this.date")); crit.addOrder(Order.desc("this.serial")); return crit; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.AbstractLeafNode.java
License:Open Source License
/** * Adds the alias's to the specified {@code criteria} and specifies the join types, used for those * alias. The alias can be later used in {@link #getWhereCriteria(DetachedCriteria)} method to filter * the data./*from w ww . j a va2 s . c o m*/ * * @param criteria to be ammended * @return criteria to be executed within session scope */ DetachedCriteria getFromCriteria(DetachedCriteria criteria) { String previousTypeNameShort = getResultTypeDBNameShortWithSuffix(); for (int i = 0; i < getExtensionSize(); i++) { String currentTypeNameShort = getIntermediaryTypeDBNameShortWithSuffix(i); String path = String.format("%s.%s", previousTypeNameShort, getExtension().getIntermediaryTypeJoinProperty(i)); criteria.createAlias(path, currentTypeNameShort, Criteria.INNER_JOIN); previousTypeNameShort = currentTypeNameShort; } return criteria; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.AttributeLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override//from www. ja va 2 s . co m DetachedCriteria getWhereCriteria(DetachedCriteria criteria) { if (getComparator() == Comparator.NO_ASSIGNMENT) { return createNoAssignmentCriteria(criteria, null); } final String associationPath = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), "attributeValueAssignments"); final String alias = String.format("%sAlias", "attributeValueAssignments"); criteria.createAlias(associationPath, alias, Criteria.INNER_JOIN); final String effectivePropertyName = String.format("%s.%s", alias, "attributeValue"); DetachedCriteria numberAvs = DetachedCriteria.forClass(getAttributeValueClass(), "numberAV"); numberAvs.add(Restrictions.eq("attributeType.id", Integer.valueOf(getAttributeId()))); numberAvs.add(this.getCriterionForComparator()); numberAvs.setProjection(Property.forName("id")); criteria.add(Subqueries.propertyIn(effectivePropertyName, numberAvs)); return criteria; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.ExtensionNode.java
License:Open Source License
/** * Adds the alias's to the specified {@code criteria} and specifies the join types, used for those * alias. The alias can be later used in {@link #getWhereCriteria(DetachedCriteria)} method to filter * the data.//from ww w .ja v a 2s . c o m * * @param criteria to be ammended * @return criteria to be executed within session scope */ private DetachedCriteria getFromCriteria(DetachedCriteria criteria) { String previousTypeNameShort = getResultTypeDBNameShortWithSuffix(); for (int i = 0; i < getExtensionSize(); i++) { String currentTypeNameShort = getIntermediaryTypeDBNameShortWithSuffix(i); String path = String.format("%s.%s", previousTypeNameShort, getExtension().getIntermediaryTypeJoinProperty(i)); criteria.createAlias(path, currentTypeNameShort, Criteria.INNER_JOIN); previousTypeNameShort = currentTypeNameShort; } return criteria; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.NotAssociatedLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override/* w w w .j a va 2 s .c om*/ DetachedCriteria getFromCriteria(DetachedCriteria criteria) { String previousTypeNameShort = getResultTypeDBNameShortWithSuffix(); int lastIndex = getExtensionSize() - 1; if (indexOfLastAssociationType >= 0) { lastIndex = indexOfLastAssociationType; } for (int i = 0; i < lastIndex; i++) { String currentTypeNameShort = getIntermediaryTypeDBNameShortWithSuffix(i); String path = String.format("%s.%s", previousTypeNameShort, getExtension().getIntermediaryTypeJoinProperty(i)); criteria.createAlias(path, currentTypeNameShort, Criteria.INNER_JOIN); previousTypeNameShort = currentTypeNameShort; } return criteria; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.NotAssociatedLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w ww . ja v a 2 s .com DetachedCriteria getWhereCriteria(DetachedCriteria criteria) { int lastIndex = getExtensionSize() - 1; if (indexOfLastAssociationType >= 0) { lastIndex = indexOfLastAssociationType; } if (getExtension().isIntermediaryTypeMultiEnd(lastIndex)) { final String intermediaryTypeNameDBShortWithSuffix = getIntermediaryTypeDBNameShortWithSuffix( lastIndex - 1); final String associationPath = String.format("%s.%s", intermediaryTypeNameDBShortWithSuffix, getExtension().getIntermediaryTypeJoinProperty(lastIndex)); final String alias = String.format("%sAlias", getIntermediaryTypeDBNameShortWithSuffix(lastIndex)); criteria.createAlias(associationPath, alias, Criteria.LEFT_JOIN); final String id = alias + ".id"; criteria.add(Restrictions.isNull(id)); } else { final String intermediaryTypeNameDBShortWithSuffix = getIntermediaryTypeDBNameShortWithSuffix( lastIndex - 1); final String joinProperty = getExtension().getIntermediaryTypeJoinProperty(lastIndex); final String associationPath = String.format("%s.%s", intermediaryTypeNameDBShortWithSuffix, joinProperty); criteria.add(Restrictions.isNull(associationPath)); } return criteria; }
From source file:de.iteratec.iteraplan.businesslogic.reports.query.node.SetPropertyLeafNode.java
License:Open Source License
/** {@inheritDoc} */ @Override//w w w .j a va2s . com DetachedCriteria getWhereCriteria(DetachedCriteria criteria) { final String associationPath = String.format("%s.%s", getResultTypeDBNameShortWithSuffix(), getPropertyName()); final String alias = String.format("%sAlias", getPropertyName()); final String effectivePropertyName = String.format("%s.%s", alias, elementPropertyName); final Criterion criterion = getCriterionForComparator(effectivePropertyName, getComparator(), BBAttribute.FIXED_ATTRIBUTE_SET); criteria.createAlias(associationPath, alias, Criteria.LEFT_JOIN); criteria.add(criterion); return criteria; }
From source file:gov.nih.nci.cananolab.service.protocol.helper.ProtocolServiceHelper.java
License:BSD License
public List<Protocol> findProtocolsBy(String protocolType, String protocolName, String protocolAbbreviation, String fileTitle) throws Exception { List<Protocol> protocols = new ArrayList<Protocol>(); CaNanoLabApplicationService appService = (CaNanoLabApplicationService) ApplicationServiceProvider .getApplicationService();/*ww w . jav a 2s .c o m*/ DetachedCriteria crit = DetachedCriteria.forClass(Protocol.class); crit.createAlias("file", "file", CriteriaSpecification.LEFT_JOIN); crit.setFetchMode("file.keywordCollection", FetchMode.JOIN); if (!StringUtils.isEmpty(protocolType)) { // case insensitive crit.add(Restrictions.ilike("type", protocolType, MatchMode.EXACT)); } if (!StringUtils.isEmpty(protocolName)) { TextMatchMode protocolNameMatchMode = new TextMatchMode(protocolName); crit.add(Restrictions.ilike("name", protocolNameMatchMode.getUpdatedText(), protocolNameMatchMode.getMatchMode())); } if (!StringUtils.isEmpty(protocolAbbreviation)) { TextMatchMode protocolAbbreviationMatchMode = new TextMatchMode(protocolAbbreviation); crit.add(Restrictions.ilike("abbreviation", protocolAbbreviationMatchMode.getUpdatedText(), protocolAbbreviationMatchMode.getMatchMode())); } if (!StringUtils.isEmpty(fileTitle)) { TextMatchMode titleMatchMode = new TextMatchMode(fileTitle); crit.add(Restrictions.ilike("file.title", titleMatchMode.getUpdatedText(), titleMatchMode.getMatchMode())); } crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); List results = appService.query(crit); for (int i = 0; i < results.size(); i++) { Protocol protocol = (Protocol) results.get(i); if (springSecurityAclService.currentUserHasReadPermission(protocol.getId(), SecureClassesEnum.PROTOCOL.getClazz()) || springSecurityAclService.currentUserHasWritePermission(protocol.getId(), SecureClassesEnum.PROTOCOL.getClazz())) { protocols.add(protocol); } else { logger.debug("User doesn't have access ot protocol with id " + protocol.getId()); } } return protocols; }