Java 类org.hibernate.criterion.Disjunction 实例源码

项目:ephesoft    文件:BatchInstanceGroupsDaoImpl.java   
/**
 * API for getting the batch instance identifiers having the user roles.
 * @param userRoles Set<String>
 * @return Set<String>
 */
@Override
public Set<String> getBatchInstanceIdentifierForUserRoles(final Set<String> userRoles) {
    boolean isValid = true;
    if (userRoles == null || userRoles.size() == 0) {
        isValid = false;
    }
    Set<String> batchInstanceIdentifiers = null;

    if (isValid) {
        batchInstanceIdentifiers = new HashSet<String>();
        final DetachedCriteria criteria = criteria();
        final Disjunction disjunction = Restrictions.disjunction();
        disjunction.add(Restrictions.in(GROUP_NAME, userRoles));
        criteria.add(disjunction);
        final List<BatchInstanceGroups> batchInstanceGroups = find(criteria);
        for (final BatchInstanceGroups batchInstanceGroup : batchInstanceGroups) {
            batchInstanceIdentifiers.add(batchInstanceGroup.getBatchInstanceIdentifier());
        }
    }
    return batchInstanceIdentifiers;
}
项目:vraptor-boilerplate    文件:UserBS.java   
/**
 * Buscar usuários de acordo com um nome.
 * 
 * @param terms Nome buscado.
 * @return PaginatedList Lista de usuários que contém o nome buscado
 *         em alguma parte do nome.
 */
public PaginatedList<User> listUsersBySearch(String terms) {
    PaginatedList<User> results = new PaginatedList<User>();
    Criteria criteria = this.dao.newCriteria(User.class);
    criteria.add(Restrictions.eq("deleted", false));

    Criteria count = this.dao.newCriteria(User.class).add(Restrictions.eq("deleted", false))
            .setProjection(Projections.countDistinct("id"));

    if (terms != null && !terms.isEmpty()) {
        Disjunction or = Restrictions.disjunction();
        or.add(Restrictions.like("name", "%" + terms + "%").ignoreCase());
        criteria.add(or);
        count.add(or);
    }

    results.setList(this.dao.findByCriteria(criteria, User.class));
    results.setTotal((Long) count.uniqueResult());
    return results;

}
项目:jspresso-ce    文件:QueryEntitiesAction.java   
/**
 * Create a in list criterion potentially using disjunction to overcome the
 * size limitation of certain DBs in restriction (e.g. Oracle is 1000).
 *
 * @param entityIds
 *     the list of entity ids.
 * @param chunkSize
 *     the size of disjunctions parts.
 * @return the criterion.
 */
public static Criterion createEntityIdsInCriterion(Collection<Serializable> entityIds, int chunkSize) {
  if (entityIds.size() < chunkSize) {
    return Restrictions.in(IEntity.ID, entityIds);
  }
  int i = 0;
  Disjunction splittedInlist = Restrictions.disjunction();
  Set<Serializable> currentEntityIds = new LinkedHashSet<>();
  boolean complete = false;
  for (Iterator<Serializable> ite = entityIds.iterator(); ite.hasNext(); i++) {
    currentEntityIds.add(ite.next());
    if (i % chunkSize == (chunkSize - 1)) {
      splittedInlist.add(Restrictions.in(IEntity.ID, currentEntityIds));
      currentEntityIds = new LinkedHashSet<>();
      complete = true;
    } else {
      complete = false;
    }
  }
  if (!complete) {
    splittedInlist.add(Restrictions.in(IEntity.ID, currentEntityIds));
  }
  return splittedInlist;
}
项目:webcurator    文件:InTrayDAOImpl.java   
public Pagination getTasks(final User user, final List<RolePrivilege> privs, final int pageNum, final int pageSize) {
    return (Pagination) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session aSession) throws HibernateException, SQLException {
            Criteria query = aSession.createCriteria(Task.class);

            Disjunction dis = Restrictions.disjunction();

            for(RolePrivilege userPriv: privs) {
              dis.add(Restrictions.eq("privilege", userPriv.getPrivilege()));
            }
            dis.add(Restrictions.eq("assigneeOid",user.getOid()));

            query.add(dis);
            query.createCriteria("agency").add(Restrictions.eq("oid", user.getAgency().getOid()));
            query.addOrder(Order.desc("sentDate"));

            Criteria cntQuery = aSession.createCriteria(Task.class);
            cntQuery.add(dis);
            cntQuery.createCriteria("agency").add(Restrictions.eq("oid", user.getAgency().getOid()));
            cntQuery.setProjection(Projections.rowCount());

            return new Pagination(cntQuery, query, pageNum, pageSize);
        }
    });
}
项目:webcurator    文件:InTrayDAOImpl.java   
public int countTasks(final User user, final List<RolePrivilege> privs) {
    return (Integer) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {

    Criteria query = session.createCriteria(Task.class);
    query.setProjection(Projections.rowCount());
             Disjunction dis = Restrictions.disjunction();

             for(RolePrivilege userPriv: privs) {
               dis.add(Restrictions.eq("privilege", userPriv.getPrivilege()));
             }
             dis.add(Restrictions.eq("assigneeOid",user.getOid()));

             query.add(dis);
             query.createCriteria("agency").add(Restrictions.eq("oid", user.getAgency().getOid()));

             Integer count = (Integer) query.uniqueResult();

             return count;
}
    });
 }
项目:webcurator    文件:TargetInstanceDAOImpl.java   
public int countTargetInstances(final String aUsername, final ArrayList<String> aStates) {
    return (Integer) getHibernateTemplate().execute(
        new HibernateCallback() {
            public Object doInHibernate(Session session) {                  
                Criteria query = session.createCriteria(TargetInstance.class);
                query.setProjection(Projections.rowCount());

                if (aStates != null && !aStates.isEmpty()) {
                    Disjunction stateDisjunction = Restrictions.disjunction();
                    for(String s: aStates) {
                        stateDisjunction.add(Restrictions.eq("state", s));
                    }
                    query.add(stateDisjunction);
                }

                query.createCriteria("owner").add(Restrictions.eq("username", aUsername));


                Integer count = (Integer) query.uniqueResult();

                return count;
            }
        }
    );  
}
项目:MiniTwitter    文件:TweetDAOImpl.java   
@SuppressWarnings("unchecked")
public List<Tweet> getTweetByOwnerId(String ownerId){

    DetachedCriteria dcr = DetachedCriteria.forClass(User.class, "follower");
    dcr.createAlias("follower.following", "following");
    dcr.add(Restrictions.eq("follower.id", ownerId));
    dcr.setProjection(Projections.property("following.id"));

    Criteria cr = getSession().createCriteria(Tweet.class, "tweets");

    Disjunction res = Restrictions.disjunction();
    res.add(Restrictions.eq("ownerId", ownerId));
    res.add(Subqueries.propertyIn("tweets.ownerId", dcr));

    cr.add(res);        
    return cr.list();
}
项目:MiniTwitter    文件:TweetDAOImpl.java   
@SuppressWarnings("unchecked")
public List<Tweet> getTweetByOwnerId(String ownerId, int page){

    DetachedCriteria dcr = DetachedCriteria.forClass(User.class, "follower");
    dcr.createAlias("follower.following", "following");
    dcr.add(Restrictions.eq("follower.id", ownerId));
    dcr.setProjection(Projections.property("following.id"));

    Criteria cr = getSession().createCriteria(Tweet.class, "tweets");

    Disjunction res = Restrictions.disjunction();
    res.add(Restrictions.eq("ownerId", ownerId));
    res.add(Subqueries.propertyIn("tweets.ownerId", dcr));


    cr.add(res);
    cr.setFirstResult((page-1)*10);
    cr.setMaxResults(10);
    return cr.list();
}
项目:opennmszh    文件:DefaultNodeListService.java   
private void addCriteriaForMaclike(OnmsCriteria criteria, String macLike) {
    String macLikeStripped = macLike.replaceAll("[:-]", "");

    criteria.createAlias("node.snmpInterfaces", "snmpInterface", CriteriaSpecification.LEFT_JOIN);
    criteria.createAlias("node.arpInterfaces", "arpInterface", CriteriaSpecification.LEFT_JOIN);
    Disjunction physAddrDisjunction = Restrictions.disjunction();
    physAddrDisjunction.add(Restrictions.ilike("snmpInterface.physAddr", macLikeStripped, MatchMode.ANYWHERE));
    physAddrDisjunction.add(Restrictions.ilike("arpInterface.physAddr", macLikeStripped, MatchMode.ANYWHERE));
    criteria.add(physAddrDisjunction);

    // This is an alternative to the above code if we need to use the out-of-the-box DetachedCriteria which doesn't let us specify the join type 
    /*
    String propertyName = "nodeId";
    String value = "%" + macLikeStripped + "%";

    Disjunction physAddrDisjuction = Restrictions.disjunction();
    physAddrDisjuction.add(Restrictions.sqlRestriction("{alias}." + propertyName + " IN (SELECT nodeid FROM snmpinterface WHERE snmpphysaddr LIKE ? )", value, new StringType()));
    physAddrDisjuction.add(Restrictions.sqlRestriction("{alias}." + propertyName + " IN (SELECT nodeid FROM atinterface WHERE atphysaddr LIKE ? )", value, new StringType()));
    criteria.add(physAddrDisjuction);
    */
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private Junction getDatumJunction(AdvancedSampleSearchBean searchBean) {
    // if AND and more than one type of datum, don't use junction
    if (searchBean.getCharacterizationLogicalOperator().equals("and")
            && searchBean.getDatumTypeCount() > 1) {
        return null;
    }
    Disjunction datumDisjunction = Restrictions.disjunction();
    Conjunction datumConjunction = Restrictions.conjunction();
    for (CharacterizationQueryBean charQuery : searchBean
            .getCharacterizationQueries()) {
        Criterion datumCrit = getDatumCriterion(charQuery);
        if (datumCrit != null) {
            datumDisjunction.add(datumCrit);
            if (searchBean.getDatumTypeCount() == 1) {
                datumConjunction.add(datumCrit);
            }
        }
    }
    // default to or if only one query
    Junction junction = (searchBean.getCharacterizationLogicalOperator()
            .equals("or") || searchBean.getCharacterizationQueries().size() == 1) ? datumDisjunction
            : datumConjunction;
    return junction;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private Disjunction getPointOfContactDisjunctionPerQuery(
        SampleQueryBean query, String pocAlias, String otherPOCAlias) {
    String pocCritStrs[] = null;
    if (StringUtils.isEmpty(otherPOCAlias)) {
        pocCritStrs = new String[] { pocAlias + "lastName",
                pocAlias + "firstName", "organization.name" };
    } else {
        pocCritStrs = new String[] { pocAlias + "lastName",
                pocAlias + "firstName", "organization.name",
                otherPOCAlias + "lastName", otherPOCAlias + "firstName",
                "otherOrg.name" };
    }
    TextMatchMode nameMatchMode = null;
    if (query.getOperand().equals("equals")) {
        nameMatchMode = new TextMatchMode(query.getName());
    } else if (query.getOperand().equals(Constants.STRING_OPERAND_CONTAINS)) {
        nameMatchMode = new TextMatchMode("*" + query.getName() + "*");
    }
    Disjunction pocDisjunction = Restrictions.disjunction();
    for (String critStr : pocCritStrs) {
        Criterion pocCrit = Restrictions.ilike(critStr, nameMatchMode
                .getUpdatedText(), nameMatchMode.getMatchMode());
        pocDisjunction.add(pocCrit);
    }
    return pocDisjunction;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
/**
 * Get the sample name junction used in sample queries
 * 
 * @param searchBean
 * @param crit
 * @return
 * @throws Exception
 */
private Junction getSampleNameJunction(AdvancedSampleSearchBean searchBean)
        throws Exception {
    Disjunction sampleDisjunction = Restrictions.disjunction();
    Conjunction sampleConjunction = Restrictions.conjunction();
    for (SampleQueryBean query : searchBean.getSampleQueries()) {
        if (query.getNameType().equals("sample name")) {
            Criterion sampleNameCrit = getSampleNameCriterion(query);
            if (sampleNameCrit != null) {
                sampleDisjunction.add(sampleNameCrit);
                sampleConjunction.add(sampleNameCrit);
            }
        }
    }
    Junction junction = (searchBean.getSampleLogicalOperator().equals("or") || searchBean
            .getSampleQueries().size() == 1) ? sampleDisjunction
            : sampleConjunction;
    return junction;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private DetachedCriteria getPointOfContactSubquery(SampleQueryBean query,
        String pocAlias1, String pocAlias2, String projectionProperty) {
    DetachedCriteria subCrit = DetachedCriteria.forClass(
            PointOfContact.class, "subCrit");
    subCrit.createAlias("subCrit.organization", "organization",
            CriteriaSpecification.LEFT_JOIN);
    subCrit.setProjection(Projections.distinct(Property.forName("id")));
    Disjunction pocDisjunction = getPointOfContactDisjunctionPerQuery(
            query, "", "");
    subCrit.add(pocDisjunction);
    if (pocAlias1.equals(pocAlias2)) {
        subCrit.add(Restrictions.eqProperty(
                "subCrit." + projectionProperty, pocAlias1 + "id"));
    } else {
        subCrit.add(Restrictions.or(Restrictions.eqProperty("subCrit."
                + projectionProperty, pocAlias1 + "id"), Restrictions
                .eqProperty("subCrit." + projectionProperty, pocAlias2
                        + "id")));
    }
    return subCrit;
}
项目:termitaria    文件:DaoRoleImpl.java   
/**
 * Return the roles with the given names in the organisation if present
 * 
 * @author Adelina
 * 
 * @param organisationId
 * @param count
 * @param name 
 * @return List<Role> 
 */
public List<Role> getRolesByNamesAndOrg(Integer organisationId, int count, String... name) {

    logger.debug("getRoleByNameAndOrg DAO IMPL - START - ");    
    for(int i = 0; i < count; i++) {
        logger.debug("name = ".concat(name[i]));
    }
    logger.debug("organisationId = ".concat(String.valueOf(organisationId)));

    DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.roleForListingEntity);

    Disjunction disjunction = Restrictions.disjunction();
    for(int i = 0; i < count; i++) {            
        disjunction.add(Restrictions.eq("name", name[i]));
    }
    dc.add(disjunction);
    dc.add(Restrictions.eq("organisation.organisationId", organisationId));
    List<Role> roles = getHibernateTemplate().findByCriteria(dc);

    return roles;               
}
项目:national-biomedical-image-archive    文件:GeneralSeriesDAOImpl.java   
private static void setSeriesSecurityGroups(DetachedCriteria criteria, List<String> securityGroups)
{
    Conjunction con = new Conjunction();

    if (securityGroups != null && securityGroups.size() != 0)
    {
        Disjunction disjunction = Restrictions.disjunction();
        disjunction.add(Restrictions.isNull("securityGroup"));
        disjunction.add(Restrictions.in("securityGroup", securityGroups));
        con.add(disjunction);
        criteria.add(con);
    }
    else
    {
        criteria.add(Restrictions.isNull("securityGroup"));
    }
}
项目:OpenNMS    文件:DefaultNodeListService.java   
private void addCriteriaForMaclike(OnmsCriteria criteria, String macLike) {
    String macLikeStripped = macLike.replaceAll("[:-]", "");

    criteria.createAlias("node.snmpInterfaces", "snmpInterface", CriteriaSpecification.LEFT_JOIN);
    criteria.createAlias("node.arpInterfaces", "arpInterface", CriteriaSpecification.LEFT_JOIN);
    Disjunction physAddrDisjunction = Restrictions.disjunction();
    physAddrDisjunction.add(Restrictions.ilike("snmpInterface.physAddr", macLikeStripped, MatchMode.ANYWHERE));
    physAddrDisjunction.add(Restrictions.ilike("arpInterface.physAddr", macLikeStripped, MatchMode.ANYWHERE));
    criteria.add(physAddrDisjunction);

    // This is an alternative to the above code if we need to use the out-of-the-box DetachedCriteria which doesn't let us specify the join type 
    /*
    String propertyName = "nodeId";
    String value = "%" + macLikeStripped + "%";

    Disjunction physAddrDisjuction = Restrictions.disjunction();
    physAddrDisjuction.add(Restrictions.sqlRestriction("{alias}." + propertyName + " IN (SELECT nodeid FROM snmpinterface WHERE snmpphysaddr LIKE ? )", value, new StringType()));
    physAddrDisjuction.add(Restrictions.sqlRestriction("{alias}." + propertyName + " IN (SELECT nodeid FROM atinterface WHERE atphysaddr LIKE ? )", value, new StringType()));
    criteria.add(physAddrDisjuction);
    */
}
项目:music-for-all-application    文件:UserServiceImpl.java   
@Override
public List<User> getUsersById(Collection<Integer> usersId) {
    if (usersId.isEmpty()) {
        return new ArrayList<>();
    }
    final Disjunction disjunction = Restrictions.disjunction();
    for (final Integer id : usersId) {
        disjunction.add(Property.forName(Constants.ID).eq(id));
    }
    final DetachedCriteria detachedCriteria = DetachedCriteria.forClass(User.class)
            .add(disjunction);
    return dao.getAllBy(detachedCriteria);
}
项目:ephesoft    文件:BatchInstanceGroupsDaoImpl.java   
/**
 * API for getting roles for the specified batch instance.
 * @param batchInstanceId String
 * @return Set<String>
 */
@Override
public Set<String> getRolesForBatchInstance(String batchInstanceId) {
    Set<String> grps = new HashSet<String>();
    final DetachedCriteria criteria = criteria();
    final Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(Restrictions.eq(BATCH_INSTANCE_ID, batchInstanceId));
    criteria.add(disjunction);
    final List<BatchInstanceGroups> batchClassGroups = find(criteria);
    for (final BatchInstanceGroups batchInstanceGroup : batchClassGroups) {
        grps.add(batchInstanceGroup.getGroupName());
    }
    return grps;
}
项目:ephesoft    文件:BatchInstanceGroupsDaoImpl.java   
/**
 * API for getting the batch instance identifiers except provided user roles.
 * 
 * @param userRoles Set<String>
 * @return Set<String>
 */
@Override
public Set<String> getBatchInstanceIdentifiersExceptUserRoles(final Set<String> userRoles) {
    Set<String> batchInstanceIdentifiers = new HashSet<String>();
    final DetachedCriteria criteria = criteria();
    final Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(Restrictions.not(Restrictions.in(GROUP_NAME, userRoles)));
    criteria.add(disjunction);
    final List<BatchInstanceGroups> batchInstanceGroups = find(criteria);
    for (final BatchInstanceGroups batchInstanceGroup : batchInstanceGroups) {
        batchInstanceIdentifiers.add(batchInstanceGroup.getBatchInstanceIdentifier());
    }
    return batchInstanceIdentifiers;
}
项目:ephesoft    文件:BatchClassGroupsDaoImpl.java   
/**
 * API for getting the batch class identifiers having the user roles.
 * @param userRoles Set<String>
 * @param includeDeleted boolean
 * @return Set<String>
 */
@Override
public Set<String> getBatchClassIdentifierForUserRoles(Set<String> userRoles, boolean includeDeleted) {
    boolean isValid = true;
    if (userRoles == null || userRoles.size() == 0) {
        isValid = false;
    }
    Set<String> batchClassIdentifiers = null;

    // New version of fetching.
    if (isValid) {
        batchClassIdentifiers = new LinkedHashSet<String>();
        DetachedCriteria criteria = criteria();
        Disjunction disjunction = Restrictions.disjunction();
        for (String userRole : userRoles) {
            disjunction.add(Restrictions.eq(GROUP_NAME, userRole));
        }
        criteria.add(disjunction);
        criteria.addOrder(Order.asc(BATCH_CLASS));
        List<BatchClassGroups> batchClassGroups = find(criteria);
        for (BatchClassGroups batchClassGroup : batchClassGroups) {
            if(includeDeleted) {
                batchClassIdentifiers.add(batchClassGroup.getBatchClass().getIdentifier()); 
            } else {
                if(!batchClassGroup.getBatchClass().isDeleted()) {
                    batchClassIdentifiers.add(batchClassGroup.getBatchClass().getIdentifier());
                }
            }
        }
    }
    return batchClassIdentifiers;
}
项目:onecmdb    文件:OneCMDBExpression.java   
protected DetachedCriteria getAttributeSearch(DetachedCriteria ciCrit) {
    if (getTextMatch() != null) {
        DetachedCriteria attribute = DetachedCriteria.forClass(BasicAttribute.class);
        //ciCrit.setProjection();
        Disjunction orAttribute = Restrictions.disjunction();
        boolean orAttributeAdded = false;

        if (isTextMatchAlias()) {
            orAttribute.add(Expression.ilike("alias", getTextMatch(), MatchMode.ANYWHERE));
            orAttributeAdded = true;

        }

        if (isTextMatchDescription()) {
            orAttribute.add(Expression.ilike("description", getTextMatch(), MatchMode.ANYWHERE));
            orAttributeAdded = true;

        }

        if (isTextMatchValue()) {
            orAttribute.add(Expression.ilike("valueAsString", getTextMatch(), MatchMode.ANYWHERE));
            orAttributeAdded = true;
        }
        if (orAttributeAdded) {
            DetachedCriteria ciIdCriteria = ciCrit.setProjection(Projections.property("longId"));
            DetachedCriteria attributeCriteira = DetachedCriteria.forClass(BasicAttribute.class);
            attributeCriteira.add(Property.forName("ownerId").in(ciIdCriteria));
            attributeCriteira.add(orAttribute);

            return(attributeCriteira);
        }
    }
    return(null);
}
项目:onecmdb    文件:OneCMDBExpression.java   
protected DetachedCriteria addCISearch(DetachedCriteria ciCrit) {
    if (getTextMatch() != null) {
        Disjunction orCi = Restrictions.disjunction();

        boolean orCiAdded = false;
        if (isTextMatchAlias()) {
            orCi.add(Expression.ilike("alias", getTextMatch(), MatchMode.ANYWHERE));
            orCiAdded = true;
        }

        if (isTextMatchDescription()) {
            orCi.add(Expression.ilike("description", getTextMatch(), MatchMode.ANYWHERE));
            orCiAdded = true;
        }
        if (orCiAdded) {
            DetachedCriteria attributeCriteria = getAttributeSearch(ciCrit);
            DetachedCriteria attrOwnerIdCriteria = attributeCriteria.setProjection(Projections.property("ownerId"));
            orCi.add(Property.forName("longId").in(attrOwnerIdCriteria));


            DetachedCriteria selectSearchCi = DetachedCriteria.forClass(ConfigurationItem.class);
            selectSearchCi.add(orCi);
            return(selectSearchCi);
        }
    }
    return(ciCrit);
}
项目:AnSoMia    文件:HibernateSupport.java   
/**
 * Gets the string like disjunction.
 *
 * @param to_read the to_read
 * @param property the property
 * @return the string like disjunction
 */
public static Criterion getStringLikeDisjunction(List<String> to_read, String property) {

    Disjunction disj = Restrictions.disjunction();
    for(int i = 0; i < to_read.size(); i++) {
        disj.add(Restrictions.like(property, "%" + to_read.get(i) + "%"));
    }

    return disj;
}
项目:AgileAlligators    文件:HibernateGenericStore.java   
private final Criteria getSharingCriteria( String access )
{
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria( getClazz(), "c" ).setCacheable( cacheable );

    User user = currentUserService.getCurrentUser();

    if ( !sharingEnabled( user ) || user == null )
    {
        return criteria;
    }

    Assert.notNull( user, "User argument can't be null." );

    Disjunction disjunction = Restrictions.disjunction();

    disjunction.add( Restrictions.like( "c.publicAccess", access ) );
    disjunction.add( Restrictions.isNull( "c.publicAccess" ) );
    disjunction.add( Restrictions.isNull( "c.user.id" ) );
    disjunction.add( Restrictions.eq( "c.user.id", user.getId() ) );

    DetachedCriteria detachedCriteria = DetachedCriteria.forClass( getClazz(), "dc" );
    detachedCriteria.createCriteria( "dc.userGroupAccesses", "uga" );
    detachedCriteria.createCriteria( "uga.userGroup", "ug" );
    detachedCriteria.createCriteria( "ug.members", "ugm" );

    detachedCriteria.add( Restrictions.eqProperty( "dc.id", "c.id" ) );
    detachedCriteria.add( Restrictions.eq( "ugm.id", user.getId() ) );
    detachedCriteria.add( Restrictions.like( "uga.access", access ) );

    detachedCriteria.setProjection( Property.forName( "uga.id" ) );

    disjunction.add( Subqueries.exists( detachedCriteria ) );

    criteria.add( disjunction );

    return criteria;
}
项目:bumper-persistence    文件:AbstractGenericDAO.java   
/**
 *
 * @param field
 * @param objects
 * @return
 */
protected AbstractGenericDAO<T> andNotEqual(String field, List<Object> objects) {

    Disjunction disj = Restrictions.disjunction();

    for (Object o : objects) {
        disj.add(Restrictions.ne(field, o));
    }

    this.criteria.add(disj);
    return this;
}
项目:bumper-persistence    文件:AbstractGenericDAO.java   
/**
 *
 * @param field
 * @param patterns
 * @return
 */
protected AbstractGenericDAO<T> andLike(String field, List<String> patterns) {

    Disjunction disj = Restrictions.disjunction();

    for (String o : patterns) {
        disj.add(Restrictions.like(field, o));
    }
    this.criteria.add(disj);
    return this;
}
项目:bumper-persistence    文件:AbstractGenericDAO.java   
/**
 *
 * @param field
 * @param objects
 * @return
 */
protected AbstractGenericDAO<T> or(String field, List<Object> objects) {
    Disjunction disj = Restrictions.disjunction();

    for (Object o : objects) {
        disj.add(Restrictions.eq(field, o));
    }

    this.criteria.add(disj);
    return this;
}
项目:bumper-persistence    文件:AbstractGenericDAO.java   
/**
 *
 * @param field
 * @param objects
 * @return
 */
protected AbstractGenericDAO<T> orNotEqual(String field, List<Object> objects) {
    Disjunction disj = Restrictions.disjunction();

    for (Object o : objects) {
        disj.add(Restrictions.ne(field, o));
    }
    this.criteria.add(disj);
    return this;
}
项目:webcurator    文件:TargetInstanceDAOImpl.java   
public int countActiveTIsForTarget(final Long targetOid) {
    return (Integer) getHibernateTemplate().execute(
        new HibernateCallback() {
            public Object doInHibernate(Session session) {                  
                Criteria query = session.createCriteria(TargetInstance.class);
                query.setProjection(Projections.rowCount());

                Disjunction stateDisjunction = Restrictions.disjunction();

                stateDisjunction.add(Restrictions.eq("state", TargetInstance.STATE_SCHEDULED));
                stateDisjunction.add(Restrictions.eq("state", TargetInstance.STATE_QUEUED));
                stateDisjunction.add(Restrictions.eq("state", TargetInstance.STATE_RUNNING));
                stateDisjunction.add(Restrictions.eq("state", TargetInstance.STATE_PAUSED));
                stateDisjunction.add(Restrictions.eq("state", TargetInstance.STATE_STOPPING));

                query.add(stateDisjunction);

                //query.createAlias("target", "t");
                query.createCriteria("target").add(Restrictions.eq("oid", targetOid));

                Integer count = (Integer) query.uniqueResult();

                return count;
            }
        }
    );  
}
项目:community-edition-old    文件:JBPMEngine.java   
/**
 * @param variables Criteria
 * @return Disjunction
 */
private Disjunction createProcessIdCriteria(Criteria variables)
{
    // retrieve list of processes matching specified variables
    List<?> processList = variables.list();
    Object[] processIds = getProcessIds( processList);

    // ALF-5841 fix
    int batch = 0;
    List<Object> buf = new ArrayList<Object>(1000);

    Disjunction ids = Restrictions.disjunction();
    for (Object id : processIds)
    {
        if (batch < 1000)
        {
            batch++;
            buf.add(id);
        }
        else
        {
            ids.add(Restrictions.in("id", buf));
            batch = 0;
            buf.clear();
        }
    }

    if (!buf.isEmpty())
    {
        ids.add(Restrictions.in("id", buf));
    }
    return ids;
}
项目:shogun2    文件:GenericHibernateDaoTest.java   
/**
 * Tests whether findByCriteria() returns correct results when fed with a
 * rather complex {@link Criterion}.
 */
@Test
public void findByCriteria_canHandleComplexCriteria() {

    Application app1;
    Application app2;
    Application app3;

    try {
        app1 = getRandomSavedMockApp(); // should be returned
        Thread.sleep(1);
        app2 = getRandomSavedMockApp(); // should not be returned
        Thread.sleep(1);
        app3 = getRandomSavedMockApp(); // should be returned
    } catch (InterruptedException e) {
        fail("Caught exception while attempting to wait");
        return;
    }

    Criterion c1 = Restrictions.eq("name", app1.getName());
    Criterion c3 = Restrictions.eq("modified", app3.getModified());

    Disjunction or = Restrictions.disjunction();

    or.add(c1).add(c3);

    List<Application> got = appDao.findByCriteria(or);

    assertTrue("findByCriteria() returned expected number of apps",
            got.size() == 2);
    assertTrue("findByCriteria() returned expected applications (app1)",
            got.contains(app1));
    assertFalse("findByCriteria() returned expected applications (app2)",
            got.contains(app2));
    assertTrue("findByCriteria() returned expected applications (app3)",
            got.contains(app3));
}
项目:OneCMDBwithMaven    文件:OneCMDBExpression.java   
protected DetachedCriteria getAttributeSearch(DetachedCriteria ciCrit) {
    if (getTextMatch() != null) {
        DetachedCriteria attribute = DetachedCriteria.forClass(BasicAttribute.class);
        //ciCrit.setProjection();
        Disjunction orAttribute = Restrictions.disjunction();
        boolean orAttributeAdded = false;

        if (isTextMatchAlias()) {
            orAttribute.add(Expression.ilike("alias", getTextMatch(), MatchMode.ANYWHERE));
            orAttributeAdded = true;

        }

        if (isTextMatchDescription()) {
            orAttribute.add(Expression.ilike("description", getTextMatch(), MatchMode.ANYWHERE));
            orAttributeAdded = true;

        }

        if (isTextMatchValue()) {
            orAttribute.add(Expression.ilike("valueAsString", getTextMatch(), MatchMode.ANYWHERE));
            orAttributeAdded = true;
        }
        if (orAttributeAdded) {
            DetachedCriteria ciIdCriteria = ciCrit.setProjection(Projections.property("longId"));
            DetachedCriteria attributeCriteira = DetachedCriteria.forClass(BasicAttribute.class);
            attributeCriteira.add(Property.forName("ownerId").in(ciIdCriteria));
            attributeCriteira.add(orAttribute);

            return(attributeCriteira);
        }
    }
    return(null);
}
项目:OneCMDBwithMaven    文件:OneCMDBExpression.java   
protected DetachedCriteria addCISearch(DetachedCriteria ciCrit) {
    if (getTextMatch() != null) {
        Disjunction orCi = Restrictions.disjunction();

        boolean orCiAdded = false;
        if (isTextMatchAlias()) {
            orCi.add(Expression.ilike("alias", getTextMatch(), MatchMode.ANYWHERE));
            orCiAdded = true;
        }

        if (isTextMatchDescription()) {
            orCi.add(Expression.ilike("description", getTextMatch(), MatchMode.ANYWHERE));
            orCiAdded = true;
        }
        if (orCiAdded) {
            DetachedCriteria attributeCriteria = getAttributeSearch(ciCrit);
            DetachedCriteria attrOwnerIdCriteria = attributeCriteria.setProjection(Projections.property("ownerId"));
            orCi.add(Property.forName("longId").in(attrOwnerIdCriteria));


            DetachedCriteria selectSearchCi = DetachedCriteria.forClass(ConfigurationItem.class);
            selectSearchCi.add(orCi);
            return(selectSearchCi);
        }
    }
    return(ciCrit);
}
项目:opennmszh    文件:OrFilter.java   
/** {@inheritDoc} */
@Override
public Criterion getCriterion() {
    Disjunction disjunction = Restrictions.disjunction();

    for(Filter filter : getFilters()) {
        disjunction.add(filter.getCriterion());
    }

    return disjunction;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private Disjunction getCharacterizationDisjunction(
        AdvancedSampleSearchBean searchBean, DetachedCriteria crit,
        String charAlias) {
    Disjunction charDisjunction = Restrictions.disjunction();
    for (CharacterizationQueryBean charQuery : searchBean
            .getCharacterizationQueries()) {
        Criterion charCrit = getCharacterizationCriterion(charQuery,
                charAlias);
        if (charCrit != null) {
            charDisjunction.add(charCrit);
        }
    }
    return charDisjunction;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
/**
 * Get the junction used in function queries
 * 
 * @param searchBean
 * @param crit
 * @return
 * @throws Exception
 */
private Junction getFunctionJunction(AdvancedSampleSearchBean searchBean,
        DetachedCriteria crit) throws Exception {
    // if AND and more than one query per type, don't use junction
    if (searchBean.getCompositionLogicalOperator().equals("and")
            && searchBean.getFuncCount() > 1) {
        return null;
    }
    Disjunction compDisjunction = Restrictions.disjunction();
    Conjunction compConjunction = Restrictions.conjunction();
    for (CompositionQueryBean compQuery : searchBean
            .getCompositionQueries()) {
        // function
        if (compQuery.getCompositionType().equals("function")) {
            Criterion funcCrit = this.getFunctionCriterion(compQuery, "",
                    "");
            if (funcCrit != null) {
                compDisjunction.add(funcCrit);
                // only add to conjunction if there is only one query for
                // the type
                if (searchBean.getFuncCount() == 1) {
                    compConjunction.add(funcCrit);
                }
            }
        }
    }
    // default to or if only one query
    Junction junction = (searchBean.getCompositionLogicalOperator().equals(
            "or") || searchBean.getCompositionQueries().size() == 1) ? compDisjunction
            : compConjunction;
    return junction;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
/**
 * Get the junction used in nanomaterial entity queries
 * 
 * @param searchBean
 * @param crit
 * @return
 * @throws Exception
 */
private Junction getNanomaterialEntityJunction(
        AdvancedSampleSearchBean searchBean, DetachedCriteria crit)
        throws Exception {
    // if AND and more than one query per type, don't use junction
    if (searchBean.getCompositionLogicalOperator().equals("and")
            && searchBean.getNanoEntityCount() > 1) {
        return null;
    }
    Disjunction compDisjunction = Restrictions.disjunction();
    Conjunction compConjunction = Restrictions.conjunction();
    for (CompositionQueryBean compQuery : searchBean
            .getCompositionQueries()) {
        // nanomaterial entity
        if (compQuery.getCompositionType().equals("nanomaterial entity")) {
            Criterion nanoEntityCrit = getNanomaterialEntityCriterion(
                    compQuery, "");
            if (nanoEntityCrit != null) {
                compDisjunction.add(nanoEntityCrit);
                // only add to conjunction if there is only one query for
                // the type
                if (searchBean.getNanoEntityCount() == 1) {
                    compConjunction.add(nanoEntityCrit);
                }
            }
        }
    }
    // default to or if only one query
    Junction junction = (searchBean.getCompositionLogicalOperator().equals(
            "or") || searchBean.getCompositionQueries().size() == 1) ? compDisjunction
            : compConjunction;
    return junction;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
/**
 * Get the junction used in functionalizing entity queries
 * 
 * @param searchBean
 * @param crit
 * @return
 * @throws Exception
 */
private Junction getFunctionalizingEntityJunction(
        AdvancedSampleSearchBean searchBean, DetachedCriteria crit)
        throws Exception {
    // if AND and more than one query per type, don't use junction
    if (searchBean.getCompositionLogicalOperator().equals("and")
            && searchBean.getFuncEntityCount() > 1) {
        return null;
    }
    Disjunction compDisjunction = Restrictions.disjunction();
    Conjunction compConjunction = Restrictions.conjunction();
    for (CompositionQueryBean compQuery : searchBean
            .getCompositionQueries()) {
        // functionalizing entity
        if (compQuery.getCompositionType().equals("functionalizing entity")) {
            Criterion funcEntityCrit = getFunctionalizingEntityCriterion(
                    compQuery, "");
            if (funcEntityCrit != null) {
                compDisjunction.add(funcEntityCrit);
                // only add to conjunction if there is only one query for
                // the type
                if (searchBean.getFuncEntityCount() == 1) {
                    compConjunction.add(funcEntityCrit);
                }
            }
        }
    }
    // default to or if only one query
    Junction junction = (searchBean.getCompositionLogicalOperator().equals(
            "or") || searchBean.getCompositionQueries().size() == 1) ? compDisjunction
            : compConjunction;
    return junction;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
/**
 * Set the disjunction used in point of contact queries
 * 
 * @param query
 * @return
 */
private Disjunction getPointOfContactDisjunction(
        AdvancedSampleSearchBean searchBean, String pocAlias,
        String otherPOCAlias) {
    Disjunction disjunction = Restrictions.disjunction();
    for (SampleQueryBean query : searchBean.getSampleQueries()) {
        if (query.getNameType().equals("point of contact name")) {
            Disjunction pocDisjunction = getPointOfContactDisjunctionPerQuery(
                    query, pocAlias, otherPOCAlias);
            if (pocDisjunction != null)
                disjunction.add(pocDisjunction);
        }
    }
    return disjunction;
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
/**
 * Get the sample disjunction used in sample queries
 * 
 * @param searchBean
 * @param crit
 * @return
 * @throws Exception
 */
private Junction getSampleJunction(AdvancedSampleSearchBean searchBean)
        throws Exception {
    // if there are more than one POC query in AND, don't use junction.
    if (searchBean.getSampleLogicalOperator().equals("and")
            && searchBean.getPocCount() > 1) {
        return null;
    }
    Disjunction sampleDisjunction = Restrictions.disjunction();
    Conjunction sampleConjunction = Restrictions.conjunction();
    for (SampleQueryBean query : searchBean.getSampleQueries()) {
        if (query.getNameType().equals("sample name")) {
            Criterion sampleNameCrit = getSampleNameCriterion(query);
            if (sampleNameCrit != null) {
                sampleDisjunction.add(sampleNameCrit);
                sampleConjunction.add(sampleNameCrit);
            }
        }
        if (query.getNameType().equals("point of contact name")) {
            Disjunction pocDisjunction = getPointOfContactDisjunction(
                    searchBean, "poc.", "otherPOC.");
            if (pocDisjunction != null) {
                sampleDisjunction.add(pocDisjunction);
                if (searchBean.getPocCount() == 1) {
                    sampleConjunction.add(pocDisjunction);
                }
            }
        }
    }
    Junction junction = (searchBean.getSampleLogicalOperator().equals("or") || searchBean
            .getSampleQueries().size() == 1) ? sampleDisjunction
            : sampleConjunction;
    return junction;
}