List of usage examples for org.hibernate.criterion DetachedCriteria createAlias
public DetachedCriteria createAlias(String associationPath, String alias)
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.GridCQLToDetachedCriteria.java
License:Open Source License
private Criterion processAssociation(Association assoc, String alias, DetachedCriteria criteria, String parentClass) throws TranslationException { String assocClassName = assoc.getName(); String sourceRoleName = assoc.getRoleName(); String roleName = LexEVSTranslatorsUtil.getRoleName(parentClass, assocClassName, sourceRoleName); Conjunction con = Restrictions.conjunction(); criteria.createAlias(alias + "." + roleName, roleName); //Process Attribute Attribute at = assoc.getAttribute(); if (at != null) { con.add(processAttribute(at, roleName)); }/* ww w.j a v a2s . c o m*/ //Process Group Group group = assoc.getGroup(); if (group != null) { con.add(processGroup(group, roleName, criteria, assocClassName)); } //Process Nested Associations Association nestedAssoc = assoc.getAssociation(); if (nestedAssoc != null) { con.add(processAssociation(nestedAssoc, roleName, criteria, assocClassName)); } return con; }
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.NestedObjectToCriterion.java
License:Open Source License
public Criterion buildCriterionFromNestedObjects(Object object, String parentAlias, DetachedCriteria crit) throws TranslationException { Conjunction conjunction = Restrictions.conjunction(); Class c = object.getClass();// ww w .j a v a 2s. c om while (c != null) { Field[] fields = c.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); Object fieldVal; try { fieldVal = field.get(object); } catch (Exception e) { log.error(e.getMessage()); throw new TranslationException(this.getClass().getName(), e); } //Only process if the field value is not null if (fieldVal != null) { Class fieldValClass = fieldVal.getClass(); String fieldName = field.getName(); if (LexEVSTranslatorsUtil.isCollectionClass(fieldValClass)) { log.debug("Processing a Collection"); //check if the List is empty List list = (List) fieldVal; if (list.size() > 0) { log.debug("Collection associated with : " + fieldName + " is non-empty."); crit.createAlias(parentAlias + "." + fieldName, fieldName); //Iterate through the list Iterator itr = list.iterator(); while (itr.hasNext()) { conjunction.add(buildCriterionFromNestedObjects(itr.next(), fieldName, crit)); } } } else if (!LexEVSTranslatorsUtil.isPrimitiveClass(fieldValClass)) { log.debug("Processing a non-primitive association : " + fieldName + " " + fieldValClass); crit = crit.createAlias(parentAlias + "." + fieldName, fieldName); conjunction.add(buildCriterionFromNestedObjects(fieldVal, fieldName, crit)); } else { log.debug("Processing a primitive : " + fieldName + " value: " + fieldVal); //check for a wildcard if (fieldVal instanceof String) { String value = (String) fieldVal; //if the String value is blank, don't add it as a restriction. //The LexEVS Model sometimes initializes Strings with a "" value. //We don't want to add these as restrictions -- treat them as null values. if (!value.equals("")) { //check if it contains a wildcard if (value.contains("*")) { value = value.replace("*", "%"); conjunction.add(Restrictions.like(parentAlias + "." + fieldName, value)); } else { conjunction.add(Restrictions.eq(parentAlias + "." + fieldName, fieldVal)); } } else { log.debug("Skipping empty String value : " + fieldName + " value: " + fieldVal); } } else { conjunction.add(Restrictions.eq(parentAlias + "." + fieldName, fieldVal)); } } } } c = c.getSuperclass(); } return conjunction; }
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.QBEPathToDetachedCriteria.java
License:Open Source License
public DetachedCriteria translate(String path, List searchObjectList) throws TranslationException { List<String> pathList = new ArrayList<String>(); StringTokenizer tokens = new StringTokenizer(path, ","); while (tokens.hasMoreTokens()) { pathList.add(tokens.nextToken().trim()); }//from w w w. java2 s. c o m String rootClass = pathList.remove(0); DetachedCriteria dCrit = DetachedCriteria.forEntityName(rootClass); dCrit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); //Set the Association Path String alias = dCrit.getAlias(); for (String pathElement : pathList) { String roleName = LexEVSTranslatorsUtil.getRoleName(rootClass, pathElement); dCrit.createAlias(alias + "." + roleName, roleName); rootClass = pathElement; alias = roleName; } //Apply the List of Associated Objects (OR'ed) Disjunction disjunction = Restrictions.disjunction(); for (Object searchObject : searchObjectList) { Criterion crit = translator.buildCriterionFromNestedObjects(searchObject, alias, dCrit); disjunction.add(crit); } dCrit.add(disjunction); return dCrit; }
From source file:org.LexGrid.LexBIG.caCore.dao.orm.translators.SDKCQLToDetachedCriteria.java
License:Open Source License
private Criterion processAssociation(CQLAssociation assoc, String alias, DetachedCriteria criteria, String parentClass) throws TranslationException { String assocClassName = assoc.getName(); String sourceRoleName = assoc.getSourceRoleName(); String roleName = LexEVSTranslatorsUtil.getRoleName(parentClass, assocClassName, sourceRoleName); Conjunction con = Restrictions.conjunction(); criteria.createAlias(alias + "." + roleName, roleName); //Process Attribute CQLAttribute at = assoc.getAttribute(); if (at != null) { con.add(processAttribute(at, roleName)); }//from ww w . j a v a2 s . c o m //Process Group CQLGroup group = assoc.getGroup(); if (group != null) { con.add(processGroup(group, roleName, criteria, assocClassName)); } //Process Nested Associations CQLAssociation nestedAssoc = assoc.getAssociation(); if (nestedAssoc != null) { con.add(processAssociation(nestedAssoc, roleName, criteria, assocClassName)); } return con; }
From source file:org.linagora.linshare.core.repository.hibernate.AccountQuotaRepositoryImpl.java
License:Open Source License
@Override public List<String> findDomainUuidByBatchModificationDate(Date startDate) { DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass()); criteria.add(Restrictions.ge("batchModificationDate", startDate)); criteria.add(Restrictions.le("batchModificationDate", new Date())); criteria.createAlias("domain", "do"); criteria.setProjection(Projections.distinct(Projections.property("do.uuid"))); @SuppressWarnings("unchecked") List<String> listIdentifier = (List<String>) getHibernateTemplate().findByCriteria(criteria); return listIdentifier; }
From source file:org.linagora.linshare.core.repository.hibernate.GenericAccountRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w . j av a2 s .c om*/ public List<U> findByDomain(String domain) { Assert.notNull(domain); DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass()); criteria.createAlias("domain", "domain"); criteria.add(Restrictions.eq("domain.identifier", domain)); criteria.add(Restrictions.eq("destroyed", false)); return getHibernateTemplate().findByCriteria(criteria); }
From source file:org.linagora.linshare.core.repository.hibernate.GenericUserRepositoryImpl.java
License:Open Source License
@Override public U findByMailAndDomain(String domain, String mail) { DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass()); criteria.createAlias("domain", "domain"); criteria.add(Restrictions.eq("domain.identifier", domain)); criteria.add(Restrictions.eq("mail", mail).ignoreCase()); criteria.add(Restrictions.eq("destroyed", false)); List<U> users = findByCriteria(criteria); if (users == null || users.isEmpty()) { return null; } else if (users.size() == 1) { return users.get(0); } else {//from w w w . j a v a 2 s. c o m throw new IllegalStateException("Mail and domain must be unique"); } }
From source file:org.linagora.linshare.core.repository.hibernate.GenericUserRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/* w w w . j a v a 2 s. co m*/ public List<U> findByDomain(String domain) { DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass()); criteria.createAlias("domain", "domain"); criteria.add(Restrictions.eq("domain.identifier", domain)); criteria.add(Restrictions.eq("destroyed", false)); return getHibernateTemplate().findByCriteria(criteria); }
From source file:org.linagora.linshare.core.repository.hibernate.GenericUserRepositoryImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from ww w. java 2s .c o m public List<U> findByCriteria(AccountOccupationCriteriaBean accountCriteria) { DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass()); criteria.add(Restrictions.eq("destroyed", false)); if ((accountCriteria.getActorMails() != null) && (accountCriteria.getActorMails().size() > 0)) { criteria.add(Restrictions.in("mail", accountCriteria.getActorMails())); } if ((accountCriteria.getActorFirstname() != null) && (accountCriteria.getActorFirstname().length() > 0)) { criteria.add(Restrictions.like("firstName", accountCriteria.getActorFirstname(), MatchMode.START) .ignoreCase()); } if ((accountCriteria.getActorLastname() != null) && (accountCriteria.getActorLastname().length() > 0)) { criteria.add(Restrictions.like("lastName", accountCriteria.getActorLastname(), MatchMode.START) .ignoreCase()); } if ((accountCriteria.getActorDomain() != null) && (accountCriteria.getActorDomain().length() > 0)) { criteria.createAlias("domain", "domain"); criteria.add(Restrictions.like("domain.identifier", accountCriteria.getActorDomain()).ignoreCase()); } return getHibernateTemplate().findByCriteria(criteria); }
From source file:org.linagora.linshare.core.repository.hibernate.InternalRepositoryImpl.java
License:Open Source License
private Internal findByDomainAndLdapUid(String domain, String ldapUid) { DetachedCriteria criteria = DetachedCriteria.forClass(getPersistentClass()); criteria.createAlias("domain", "domain"); criteria.add(Restrictions.eq("domain.identifier", domain)); criteria.add(Restrictions.eq("ldapUid", ldapUid).ignoreCase()); criteria.add(Restrictions.eq("destroyed", false)); List<Internal> users = findByCriteria(criteria); if (users == null || users.isEmpty()) { return null; } else if (users.size() == 1) { return users.get(0); } else {//from www. ja va2 s . com throw new IllegalStateException("Ldap uid must be unique"); } }