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

项目:ephesoft    文件:BatchClassDynamicPluginConfigDaoImpl.java   
/**
 * To get all Dynamic Plugin Properties for Batch instance.
 * 
 * @param batchClassIdentifier String
 * @return List<BatchClassDynamicPluginConfig>
 */
@Override
public List<BatchClassDynamicPluginConfig> getAllDynamicPluginPropertiesForBatchInstance(String batchInstanceIdentifier) {
    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS_PLUGIN, BATCH_CLASS_PLUGIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_MODULE, BATCH_CLASS_MODULE);
    criteria.createAlias("batchClassModule.batchClass", BATCH_CLASS);

    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq("identifier", batchInstanceIdentifier));
    subQuery.setProjection(Projections.property("batchClass.id"));

    criteria.add(Subqueries.propertyEq("batchClass.id", subQuery));

    return find(criteria);
}
项目:ephesoft    文件:FieldTypeDaoImpl.java   
/**
 * An API to fetch all Field types by document type name.
 * 
 * @param docTypeName String
 * @param batchInstanceIdentifierIdentifier String
 * @return List<FieldType>
 */
@Override
public List<FieldType> getFdTypeByDocTypeNameForBatchInstance(String docTypeName, String batchInstanceIdentifier) {

    LOG.info("batchInstanceID  : " + batchInstanceIdentifier);
    DetachedCriteria criteria = criteria();
    criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName));
    criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);
    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
    subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
    subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
    criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));
    criteria.addOrder(org.hibernate.criterion.Order.asc(FIELD_ORDER_NUMBER));

    return find(criteria);

}
项目:ephesoft    文件:FieldTypeDaoImpl.java   
/**
 * An API to get field type for a batch for a particular document.
 *  
 * @param fieldTypeName String
 * @param docTypeName String
 * @param batchInstanceIdentifier String
 * @return FieldType
 */
@Override
public FieldType getFieldType(String fieldTypeName, String docTypeName, String batchInstanceIdentifier) {

    LOG.info("batchInstanceID  : " + batchInstanceIdentifier);
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.eq(NAME, fieldTypeName));
    criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName));
    criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);
    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
    subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
    subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
    criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));

    return findSingle(criteria);

}
项目:ephesoft    文件:FieldTypeDaoImpl.java   
/**
 * An API to fetch all Field types by document type name.
 * 
 * @param docTypeName String
 * @param batchInstanceIdentifier String
 * @param isKVExtraction boolean
 * @return List<FieldType>
 */
@Override
public List<FieldType> getFdTypeByDocumentTypeName(String docTypeName, String batchInstanceIdentifier, boolean isKVExtraction) {
    LOG.info("batchInstanceID ID  : " + batchInstanceIdentifier);
    DetachedCriteria criteria = criteria();
    criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName));
    criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);

    if (isKVExtraction) {
        criteria.setFetchMode("kvExtraction", FetchMode.JOIN);
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    }

    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
    subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
    subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
    criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));
    criteria.addOrder(org.hibernate.criterion.Order.asc(FIELD_ORDER_NUMBER));
    return find(criteria);
}
项目:ephesoft    文件:FieldTypeDaoImpl.java   
/**
 * An API to fetch all Field types by document type name.
 * 
 * @param docTypeName String
 * @param batchInstanceIdentifier String
 * @return List<FieldType>
 */
@Override
public List<FieldType> getFdTypeAndRegexValidationByDocTypeName(String docTypeName, String batchInstanceIdentifier) {

    LOG.info("batchInstanceID ID  : " + batchInstanceIdentifier);
    DetachedCriteria criteria = criteria();
    criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(DOC_TYPE_NAME, docTypeName));
    criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);

    criteria.setFetchMode(REGEX_VALIDATION, FetchMode.JOIN);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
    subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
    subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
    criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));
    criteria.addOrder(org.hibernate.criterion.Order.asc(FIELD_ORDER_NUMBER));

    return find(criteria);

}
项目:ephesoft    文件:PageTypeDaoImpl.java   
/**
 * An API to fetch page type by page type name.
 * 
 * @param name String
 * @param batchInstanceIdentifier String
 * @return List<PageType>
 */
@Override
public List<PageType> getPageTypeByName(String name, String batchInstanceIdentifier) {
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.eq(NAME, name));
    if (null != batchInstanceIdentifier) {
        criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
        criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);
        DetachedCriteria subQuery = criteria(BatchInstance.class);
        subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
        subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
        subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));
        criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));
    }
    return find(criteria);
}
项目:ephesoft    文件:BatchClassPluginConfigDaoImpl.java   
/**
 * API to get plugin properties for Batch.
 * 
 * @param batchInstanceIdentifier {@link String}
 * @param pluginName {@link String}
 * @return List<BatchClassPluginConfig> 
 */
@Override
public List<BatchClassPluginConfig> getPluginPropertiesForBatch(String batchInstanceIdentifier, String pluginName) {

    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS_PLUGIN, BATCH_CLASS_PLUGIN, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_MODULE, BATCH_CLASS_MODULE, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_MODULE_BATCH_CLASS, BATCH_CLASS, JoinFragment.INNER_JOIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_PLUGIN, PLUGIN, JoinFragment.INNER_JOIN);
    criteria.add(Restrictions.eq(PLUGIN_PLUGIN_NAME, pluginName));
    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq("identifier", batchInstanceIdentifier));
    subQuery.createAlias(BATCH_CLASS, "batchClass1", JoinFragment.INNER_JOIN);
    subQuery.setProjection(Projections.property("batchClass1.identifier"));
    criteria.add(Subqueries.propertyEq(BATCH_CLASS_IDENTIFIER, subQuery));
    return find(criteria);

}
项目:ephesoft    文件:BatchClassPluginConfigDaoImpl.java   
/**
 * API to get all plugin properties for Batch instance.
 * 
 * @param batchInstanceIdentifier {@link String}
 * @return List<BatchClassPluginConfig> 
 */
@Override
public List<BatchClassPluginConfig> getAllPluginPropertiesForBatchInstance(String batchInstanceIdentifier) {
    DetachedCriteria criteria = criteria();
    criteria.createAlias(BATCH_CLASS_PLUGIN, BATCH_CLASS_PLUGIN);
    criteria.createAlias(BATCH_CLASS_PLUGIN_BATCH_CLASS_MODULE, BATCH_CLASS_MODULE);
    criteria.createAlias("batchClassModule.batchClass", BATCH_CLASS);

    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq("identifier", batchInstanceIdentifier));
    subQuery.setProjection(Projections.property("batchClass.id"));

    criteria.add(Subqueries.propertyEq("batchClass.id", subQuery));

    return find(criteria);
}
项目:ephesoft    文件:BatchClassDaoImpl.java   
/**
 * API to get the list of Batch Classes specifying startindex, no of results and sorting if any.
 * 
 * @param firstResult int
 * @param maxResults int 
 * @param order List<Order>
 * @param userRoles Set<String>
 * @return List of batch class.
 */
@Override
public List<BatchClass> getBatchClassList(final int firstResult, final int maxResults, final List<Order> order,
        final Set<String> userRoles) {
    EphesoftCriteria criteria = criteria();
    List<BatchClass> batchClassList = null;
    if (userRoles == null) {
        batchClassList = new ArrayList<BatchClass>(0);
    } else {
        List<String> roleList = new ArrayList<String>();
        for (String userRole : userRoles) {
            if (null == userRole || userRole.isEmpty()) {
                continue;
            }
            roleList.add(userRole);
        }
        DetachedCriteria detachedCriteria = criteria();
        detachedCriteria.createAlias(ASSIGNED_GROUPS, ASSIGNED_GROUPS);
        detachedCriteria.add(Restrictions.in(ASSIGNED_GROUPS_NAME, roleList));
        detachedCriteria.setProjection(Projections.distinct(Projections.property(BATCH_ID)));
        criteria.add(Subqueries.propertyIn(BATCH_ID, detachedCriteria));
        criteria.add(Restrictions.or(Restrictions.isNull(IS_DELETED), Restrictions.eq(IS_DELETED, false)));
        batchClassList = find(criteria, firstResult, maxResults, order.toArray(new Order[order.size()]));
    }
    return batchClassList;
}
项目:eurocarbdb    文件:SearchGlycanSequence.java   
public Criteria createCriteria()
{      
  DetachedCriteria crit = createSerializableCriteria();
  crit.setProjection(
      Projections.distinct(
          Projections.property("glycanSequenceId")));

  Criteria criteria = getEntityManager().createQuery(GlycanSequence.class);

  criteria.add( Subqueries.propertyIn("glycanSequenceId",crit) );

  if( getIndex() != null ) 
  {
      getIndex().apply(criteria);
  }

  return criteria;
}
项目: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();
}
项目:MiniTwitter    文件:UserDAOImpl.java   
@SuppressWarnings("unchecked")
public List<User> getFollowerByuserId(String userId){

    // criteria query is suitable for dynamically creating queries, easier to use;
    Criteria cr = getSession().createCriteria(User.class, "user");

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

    cr.add(Subqueries.propertyIn("user.id", dcr));
    return cr.list();


    // HQL resembles SQL language, is suitable for complex queries, more flexible;
    /**return getSession().createQuery("select user "
                                    + "from User user "
                                    + "where user.id in "
                                        + "(select follower.id "
                                        + "from User following "
                                        + "inner join following.follower follower "
                                        + "where following.id = :userId)")
                        .setParameter("userId", userId)
                        .list();*/
}
项目:opennmszh    文件:HibernateCriteriaConverter.java   
public DetachedCriteria getCriteria() {
    if (m_criteria == null) {
        throw new IllegalStateException("Unable to determine Class<?> of this criteria!");
    }

    for (final Criterion criterion : m_criterions) {
        m_criteria.add(criterion);
    }

    if (m_distinct) {
        m_criteria.setProjection(Projections.distinct(Projections.id()));

        final DetachedCriteria newCriteria = DetachedCriteria.forClass(m_class);
        newCriteria.add(Subqueries.propertyIn("id", m_criteria));

        m_criteria = newCriteria;
    }

    for (final org.hibernate.criterion.Order order : m_orders) {
        m_criteria.addOrder(order);
    }

    return m_criteria;
}
项目:further-open-core    文件:CriterionBuilderHibernateImpl.java   
/**
 * Corresponds to the sub-select
 * 
 * <pre>
 * sub-criterion + group-by-having count([distinct] id)
 * op count
 * </pre>
 * 
 * .
 * 
 * @see <code>LTestHibernateCount</code>
 */
public void visitCountExpression()
{
    // TODO: move projection code to ProjectionFactoryHibernateImpl for more
    // generic sub-select support (after we add more sub-select types in
    // addition to COUNT)
    final String idPropertyName = classMetadata.getIdentifierPropertyName();
    final CountProjectionParams projectionParams = CountProjectionParams.newInstance(
            this, criterion);
    final DetachedCriteria subQuery = createCountSubQuery().setProjection(
            CustomProjections.groupByHaving(idPropertyName, CustomProjections
                    .countProjection(projectionParams.propertyName,
                            projectionParams.distinct), projectionParams.relation,
                    projectionParams.value));

    // Main criterion: ID in (result of sub-query)
    result = Subqueries.propertyIn(classMetadata.getIdentifierPropertyName(),
            subQuery);
}
项目:termitaria    文件:DaoOrganisationImpl.java   
/**
 * Get the list of Organisation that has not a calendar defined
 * 
 * @author Adelina  
 * @return List<Organisation>
 */
public List<Organisation> getAllOrganisationsForNomWithoutCalendar(){
    logger.debug("getAllOrganisationsForNomWithoutCalendar - START");

    DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.organisationForNomEntity);          
    dc.addOrder(Order.asc("name"));     
    DetachedCriteria subquery = DetachedCriteria.forEntityName(IModelConstant.calendarEntity);      
    subquery.setProjection(Projections.property("organisation.organisationId"));        
    dc.add(Subqueries.propertyNotIn("organisationId", subquery));       

    List organisations = getHibernateTemplate().findByCriteria(dc);

    logger.debug("getAllOrganisationsForNomWithoutCalendar - END - ".concat(String.valueOf(organisations.size())));
    return organisations;

}
项目:OpenNMS    文件:HibernateCriteriaConverter.java   
public DetachedCriteria getCriteria() {
    if (m_criteria == null) {
        throw new IllegalStateException("Unable to determine Class<?> of this criteria!");
    }

    for (final Criterion criterion : m_criterions) {
        m_criteria.add(criterion);
    }

    if (m_distinct) {
        m_criteria.setProjection(Projections.distinct(Projections.id()));

        final DetachedCriteria newCriteria = DetachedCriteria.forClass(m_class);
        newCriteria.add(Subqueries.propertyIn("id", m_criteria));

        m_criteria = newCriteria;
    }

    for (final org.hibernate.criterion.Order order : m_orders) {
        m_criteria.addOrder(order);
    }

    return m_criteria;
}
项目:ctsms    文件:PasswordDaoImpl.java   
@Override
protected Collection<Password> handleFindExpiring(Date today,
        Long departmentId, AuthenticationType authMethod, VariablePeriod reminderPeriod,
        Long reminderPeriodDays, PSFVO psf) throws Exception {
    org.hibernate.Criteria passwordCriteria = createPasswordCriteria("password0");
    SubCriteriaMap criteriaMap = new SubCriteriaMap(Password.class, passwordCriteria);
    if (departmentId != null) {
        criteriaMap.createCriteria("user").add(Restrictions.eq("department.id", departmentId.longValue()));
    }
    if (authMethod != null) {
        criteriaMap.createCriteria("user").add(Restrictions.eq("authMethod", authMethod));
    }
    DetachedCriteria subQuery = DetachedCriteria.forClass(PasswordImpl.class, "password1"); // IMPL!!!!
    subQuery.add(Restrictions.eqProperty("password1.user", "password0.user"));
    subQuery.setProjection(Projections.max("id"));
    passwordCriteria.add(Subqueries.propertyEq("id", subQuery));
    passwordCriteria.add(Restrictions.eq("expires", true)); // performance only...
    if (psf != null) {
        PSFVO sorterFilter = new PSFVO();
        sorterFilter.setFilters(psf.getFilters());
        sorterFilter.setSortField(psf.getSortField());
        sorterFilter.setSortOrder(psf.getSortOrder());
        CriteriaUtil.applyPSFVO(criteriaMap, sorterFilter);
    }
    ArrayList<Password> resultSet = CriteriaUtil.listExpirations(passwordCriteria, today, null, null, null, reminderPeriod, reminderPeriodDays);
    return (Collection<Password>) CriteriaUtil.applyPVO(resultSet, psf, false); // no dupes by default
}
项目:ctsms    文件:ProbandListEntryDaoImpl.java   
@Override
protected Collection<ProbandListEntry> handleGetProbandList(
        Long trialId, org.phoenixctms.ctsms.enumeration.ProbandListStatusLogLevel logLevel, boolean last)
                throws Exception {
    // http://stackoverflow.com/questions/1648426/hibernate-detached-queries-as-a-part-of-the-criteria-query
    // https://forum.hibernate.org/viewtopic.php?p=2317841#2317841
    org.hibernate.Criteria listEntryCriteria = createListEntryCriteria();
    boolean distinctRoot = false;
    if (trialId != null) {
        listEntryCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
    }
    if (logLevel != null) {
        org.hibernate.Criteria statusEntryCriteria;
        if (last) {
            statusEntryCriteria = listEntryCriteria.createCriteria("statusEntries", "probandListStatusEntry0", CriteriaSpecification.INNER_JOIN);
        } else {
            statusEntryCriteria = listEntryCriteria.createCriteria("statusEntries", CriteriaSpecification.INNER_JOIN);
        }
        org.hibernate.Criteria statusTypeCriteria = statusEntryCriteria.createCriteria("status", CriteriaSpecification.INNER_JOIN);
        org.hibernate.Criteria logLevelCriteria = statusTypeCriteria.createCriteria("logLevels", CriteriaSpecification.INNER_JOIN);
        logLevelCriteria.add(Restrictions.eq("logLevel", logLevel));
        if (last) {
            DetachedCriteria subQuery = DetachedCriteria.forClass(ProbandListStatusEntryImpl.class, "probandListStatusEntry1"); // IMPL!!!!
            subQuery.add(Restrictions.eqProperty("probandListStatusEntry1.listEntry", "probandListStatusEntry0.listEntry"));
            subQuery.setProjection(Projections.max("id"));
            statusEntryCriteria.add(Subqueries.propertyEq("id", subQuery));
        } else {
            // listEntryCriteria.setResultTransformer(org.hibernate.Criteria.DISTINCT_ROOT_ENTITY);
            distinctRoot = true;
        }
    }
    listEntryCriteria.addOrder(Order.asc("trial"));
    listEntryCriteria.addOrder(Order.asc("position"));
    if (distinctRoot) {
        return CriteriaUtil.listDistinctRoot(listEntryCriteria, this, "trial.id", "position");
    } else {
        return listEntryCriteria.list();
    }
}
项目:ctsms    文件:ECRFFieldStatusEntryDaoImpl.java   
private static void applyEcrfFieldStatusEntryMaxIdSubCriteria(org.hibernate.Criteria ecrfFieldStatusEntryCriteria, org.hibernate.Criteria ecrfFieldCriteria,
        org.hibernate.Criteria probandListEntryCriteria, ECRFFieldStatusQueue queue, Long probandListEntryId, Long ecrfFieldId) {
    DetachedCriteria subQuery = createEcrfFieldStatusEntryDetachedCriteriaMaxId(ecrfFieldStatusEntryCriteria, ecrfFieldCriteria, probandListEntryCriteria, queue,
            probandListEntryId,
            ecrfFieldId);
    subQuery.add(Restrictions.or(Restrictions.isNull("index"),
            Restrictions.eqProperty("index", ecrfFieldStatusEntryCriteria.getAlias() + ".index")));
    ecrfFieldStatusEntryCriteria.add(Subqueries.propertyIn("id", subQuery));
}
项目:ctsms    文件:ECRFFieldStatusEntryDaoImpl.java   
private static void applyEcrfFieldStatusEntryMaxIdSubCriteria(org.hibernate.Criteria ecrfFieldStatusEntryCriteria, org.hibernate.Criteria ecrfFieldCriteria,
        org.hibernate.Criteria probandListEntryCriteria, ECRFFieldStatusQueue queue, Long probandListEntryId, Long ecrfFieldId, Long index) {
    DetachedCriteria subQuery = createEcrfFieldStatusEntryDetachedCriteriaMaxId(ecrfFieldStatusEntryCriteria, ecrfFieldCriteria, probandListEntryCriteria, queue,
            probandListEntryId,
            ecrfFieldId);
    if (index != null) {
        subQuery.add(Restrictions.eq("index", index.longValue()));
    } else {
        subQuery.add(Restrictions.isNull("index"));
    }
    ecrfFieldStatusEntryCriteria.add(Subqueries.propertyIn("id", subQuery));
}
项目:ctsms    文件:PermissionDaoImpl.java   
@Override
protected Collection<Permission> handleFindByServiceMethodUser(
        String serviceMethod, Long userId, Boolean profilePermissionActive,
        Boolean userPermissionProfileActive) throws Exception {
    org.hibernate.Criteria permissionCritria = createPermissionCriteria();
    if (serviceMethod != null) {
        permissionCritria.add(Restrictions.eq("serviceMethod", serviceMethod));
    }
    if (userId != null || profilePermissionActive != null || userPermissionProfileActive != null) {
        org.hibernate.Criteria profilePermissionCritria = permissionCritria.createCriteria("profilePermissions", CriteriaSpecification.LEFT_JOIN);
        if (profilePermissionActive != null) {
            profilePermissionCritria.add(Restrictions.eq("active", profilePermissionActive.booleanValue()));
        }
        if (userId != null || userPermissionProfileActive != null) {
            DetachedCriteria subQuery = DetachedCriteria.forClass(UserPermissionProfileImpl.class, "userPermissionProfile"); // IMPL!!!!
            subQuery.setProjection(Projections.projectionList().add(Projections.property("profile")));
            if (userId != null) {
                subQuery.add(Restrictions.eq("user.id", userId.longValue()));
            }
            if (userPermissionProfileActive != null) {
                subQuery.add(Restrictions.eq("active", userPermissionProfileActive.booleanValue()));
            }
            profilePermissionCritria.add(Subqueries.propertyIn("profile", subQuery));
        }
    }
    return permissionCritria.list();
}
项目:ctsms    文件:ProbandDaoImpl.java   
@Override
protected Collection<Proband> handleFindByMoneyTransferNoParticipation(Long trialId,
        PaymentMethod method, String costType, Boolean paid, boolean total,
        Boolean person, PSFVO psf)
                throws Exception {
    org.hibernate.Criteria probandCriteria = createProbandCriteria("proband0");
    if (person != null) {
        probandCriteria.add(Restrictions.eq("person", person.booleanValue()));
    }
    SubCriteriaMap criteriaMap = new SubCriteriaMap(Proband.class, probandCriteria);
    Criteria moneyTransferCriteria = criteriaMap.createCriteria("moneyTransfers");
    moneyTransferCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
    if (method != null) {
        moneyTransferCriteria.add(Restrictions.eq("method", method));
    }
    if (paid != null) {
        moneyTransferCriteria.add(Restrictions.eq("paid", paid.booleanValue()));
    }
    CategoryCriterion.apply(moneyTransferCriteria, new CategoryCriterion(costType, "costType", MatchMode.EXACT, EmptyPrefixModes.ALL_ROWS));
    DetachedCriteria subQuery = DetachedCriteria.forClass(ProbandListEntryImpl.class, "probandListEntry"); // IMPL!!!!
    subQuery.setProjection(Projections.rowCount());
    subQuery.add(Restrictions.eqProperty("proband.id", "proband0.id"));
    subQuery.add(Restrictions.eq("trial.id", trialId.longValue()));
    if (!total) {
        subQuery.createCriteria("lastStatus", CriteriaSpecification.INNER_JOIN).createCriteria("status", CriteriaSpecification.INNER_JOIN)
        .add(Restrictions.eq("count", true));
    }
    probandCriteria.add(Subqueries.eq(0l, subQuery));
    return CriteriaUtil.listDistinctRootPSFVO(criteriaMap, psf, this);
    // return probandCriteria.list();
}
项目:ctsms    文件:ECRFFieldValueDaoImpl.java   
private static void applyEcrfFieldValueMaxIdSubCriteria(org.hibernate.Criteria ecrfFieldValueCriteria, org.hibernate.Criteria ecrfFieldCriteria,
        org.hibernate.Criteria probandListEntryCriteria,Long probandListEntryId, Long ecrfFieldId) {
    DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteriaMaxId(ecrfFieldValueCriteria, ecrfFieldCriteria, probandListEntryCriteria, probandListEntryId, ecrfFieldId);
    subQuery.add(Restrictions.or(Restrictions.isNull("index"),
            Restrictions.eqProperty("index", ecrfFieldValueCriteria.getAlias() + ".index")));
    ecrfFieldValueCriteria.add(Subqueries.propertyEq("id", subQuery));
}
项目:ctsms    文件:ECRFFieldValueDaoImpl.java   
private static void applyEcrfFieldValueMaxIdSubCriteria(org.hibernate.Criteria ecrfFieldValueCriteria, org.hibernate.Criteria ecrfFieldCriteria,
        org.hibernate.Criteria probandListEntryCriteria,Long probandListEntryId, Long ecrfFieldId, Long index) {
    DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteriaMaxId(ecrfFieldValueCriteria, ecrfFieldCriteria, probandListEntryCriteria, probandListEntryId, ecrfFieldId);
    if (index != null) {
        subQuery.add(Restrictions.eq("index", index.longValue()));
    } else {
        subQuery.add(Restrictions.isNull("index"));
    }
    ecrfFieldValueCriteria.add(Subqueries.propertyEq("id", subQuery));
}
项目:ctsms    文件:ECRFFieldValueDaoImpl.java   
private org.hibernate.Criteria[] createEcrfFieldCriteria(Long probandListEntryId, Long ecrfId) {
    org.hibernate.Criteria ecrfFieldCriteria = this.getSession().createCriteria(ECRFField.class, ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_ALIAS);
    ecrfFieldCriteria.add(Restrictions.eq("ecrf.id", ecrfId.longValue()));

    org.hibernate.Criteria ecrfFieldValueCriteria = ecrfFieldCriteria.createCriteria("fieldValues", ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_VALUE_ALIAS,
            CriteriaSpecification.LEFT_JOIN,
            Restrictions.eq(ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_VALUE_ALIAS + ".listEntry.id", probandListEntryId.longValue()));
    // criteriaMap.createCriteria("ecrfField", CriteriaSpecification.LEFT_JOIN);
    // ecrfFieldValueCriteria.add(Restrictions.or(Restrictions.eq("listEntry.id", probandListEntryId.longValue()),
    // Restrictions.isNull("listEntry")));
    // correlated - slow:
    DetachedCriteria subQuery = createEcrfFieldValueDetachedCriteriaMaxId(ecrfFieldValueCriteria, ecrfFieldCriteria, null, probandListEntryId, null);
    // DetachedCriteria subQuery = DetachedCriteria.forClass(ECRFFieldValueImpl.class, "ecrfFieldValue1"); // IMPL!!!!
    // subQuery.setProjection(Projections.max("id"));
    // subQuery.add(Restrictions.eq("listEntry.id", probandListEntryId.longValue()));
    // subQuery.add(Restrictions.eqProperty("ecrfField.id", "ecrfField0.id"));
    subQuery.add(Restrictions.or(Restrictions.isNull("index"),
            Restrictions.eqProperty("index", ServiceUtil.ECRF_FIELD_VALUE_DAO_ECRF_FIELD_VALUE_ALIAS + ".index")));
    ecrfFieldValueCriteria.add(Restrictions.or(
            Restrictions.isNull("listEntry"),
            Restrictions.and(
                    Restrictions.eq("listEntry.id", probandListEntryId.longValue()),
                    Subqueries.propertyIn("id", subQuery)
                    )
            ));

    // System.out.println(CriteriaUtil.criteriaToSql(ecrfFieldCriteria));
    return new org.hibernate.Criteria[] { ecrfFieldCriteria, ecrfFieldValueCriteria };
}
项目:ctsms    文件:TrialDaoImpl.java   
@Override
protected Collection<Trial> handleFindBySignup(Long departmentId, boolean ignoreSignupInquiries, PSFVO psf) throws Exception {
    org.hibernate.Criteria trialCriteria = createTrialCriteria("trial0");
    SubCriteriaMap criteriaMap = new SubCriteriaMap(Trial.class, trialCriteria);
    if (departmentId != null) {
        trialCriteria.add(Restrictions.eq("department.id", departmentId.longValue()));
    }
    org.hibernate.Criteria statusCriteria = trialCriteria.createCriteria("status", "trialStatus", CriteriaSpecification.INNER_JOIN);
    statusCriteria.add(Restrictions.eq("lockdown", false));
    DetachedCriteria subQuery = DetachedCriteria.forClass(InquiryImpl.class, "inquiry"); // IMPL!!!!
    subQuery.setProjection(Projections.rowCount());
    subQuery.add(Restrictions.eqProperty("trial.id", "trial0.id"));
    subQuery.add(Restrictions.eq("activeSignup", true));
    trialCriteria.add(
            Restrictions.or(
                    Restrictions.eq("signupProbandList", true),
                    Restrictions.and(
                            ignoreSignupInquiries ? Subqueries.lt(0l, subQuery) : Restrictions.and(
                                    Restrictions.eq("signupInquiries", true),
                                    Subqueries.lt(0l, subQuery)
                                    // Restrictions.sizeGt("inquiries", 0)
                                    ),
                                    Restrictions.eq("trialStatus.inquiryValueInputEnabled", true)
                            )
                    )
            );
    // if (probandList != null) {
    // trialCriteria.add(Restrictions.eq("signupProbandList", probandList.booleanValue()));
    // }
    // if (inquiries != null) {
    // trialCriteria.add(Restrictions.eq("signupInquiries", inquiries.booleanValue()));
    // statusCriteria.add(Restrictions.eq("inquiryValueInputEnabled", true));
    // trialCriteria.add(Restrictions.sizeGt("inquiries", 0));
    // }
    CriteriaUtil.applyPSFVO(criteriaMap, psf);
    return trialCriteria.list();
}
项目:almoxarifado    文件:Saidas.java   
@SuppressWarnings("unchecked")
public List <Saida> saidaTodosEquipamentos(List<Equipamento> equipamentos) {
    Criteria criteria = session.createCriteria(Saida.class, "s");
    Conjunction c = Restrictions.conjunction();
    for (Equipamento e : equipamentos) {
        c.add(Subqueries.exists(
          DetachedCriteria.forClass(SaidaEquipamento.class, "se")
            .setProjection(Projections.id())
            .add(Restrictions.eqProperty("s.id", "se.saida.id"))
            .add(Restrictions.eq("se.equipamento",e))));
      }
      criteria.add(c);
      return criteria.list();
}
项目:dhis2-core    文件:CriteriaQueryEngine.java   
@Override
@SuppressWarnings( "unchecked" )
public int count( Query query )
{
    Schema schema = query.getSchema();
    InternalHibernateGenericStore<?> store = getStore( (Class<? extends IdentifiableObject>) schema.getKlass() );

    if ( store == null )
    {
        return 0;
    }

    if ( query.getUser() == null )
    {
        query.setUser( currentUserService.getCurrentUser() );
    }

    if ( !query.isPlannedQuery() )
    {
        QueryPlan queryPlan = queryPlanner.planQuery( query, true );
        query = queryPlan.getPersistedQuery();
    }

    DetachedCriteria detachedCriteria = buildCriteria( store.getSharingDetachedCriteria( query.getUser() ), query );
    Criteria criteria = store.getCriteria();

    if ( criteria == null )
    {
        return 0;
    }

    return ((Number) criteria.add( Subqueries.propertyIn( "id", detachedCriteria ) )
        .setProjection( Projections.countDistinct( "id" ) )
        .uniqueResult()).intValue();
}
项目:ephesoft    文件:PageTypeDaoImpl.java   
/**
 * An API to fetch all Page types by batchInstanceID.
 * 
 * @param batchInstanceIdentifier String
 * @return List<PageType>
 */
@Override
public List<PageType> getPageTypesByBatchInstanceID(String batchInstanceIdentifier) {
    DetachedCriteria criteria = criteria();
    criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
    criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);
    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq(IDENTIFIER, batchInstanceIdentifier));
    subQuery.createAlias(BATCH_CLASS, BATCH_CLASS2, JoinFragment.INNER_JOIN);
    subQuery.setProjection(Projections.property(BATCH_CLASS2_IDENTIFIER));

    criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));

    return find(criteria);
}
项目:ephesoft    文件:PageTypeDaoImpl.java   
/**
 * An API to fetch all Page types by batchClassID.
 * 
 * @param batchClassID String
 * @return List<PageType>
 */
@Override
public List<PageType> getPageTypesByBatchClassID(String batchClassID) {
    DetachedCriteria criteria = criteria();
    criteria.createAlias(DOC_TYPE, DOC_TYPE, JoinFragment.INNER_JOIN);
    criteria.createAlias(DOC_TYPE_BATCH_CLASS, BATCH_CLASS1, JoinFragment.INNER_JOIN);
    DetachedCriteria subQuery = criteria(BatchClass.class);
    subQuery.add(Restrictions.eq(IDENTIFIER, batchClassID));
    subQuery.setProjection(Projections.property(IDENTIFIER));
    criteria.add(Subqueries.propertyEq(BATCH_CLASS1_IDENTIFIER, subQuery));
    return find(criteria);
}
项目:ephesoft    文件:DocumentTypeDaoImpl.java   
/**
 * An API to fetch all DocumentType by batch instance id.
 * 
 * @param batchInstanceIdentifier String
 * @return List<DocumentType>
 */
@Override
public List<DocumentType> getDocTypeByBatchInstanceIdentifier(String batchInstanceIdentifier) {
    LOG.info("batchInstanceID : " + batchInstanceIdentifier);
    DetachedCriteria criteria = criteria();
    DetachedCriteria subQuery = criteria(BatchInstance.class);
    subQuery.add(Restrictions.eq(DataAccessConstant.IDENTIFIER, batchInstanceIdentifier));
    subQuery.setProjection(Projections.property(DataAccessConstant.BATCH_CLASS_ID));
    criteria.add(Subqueries.propertyIn(DataAccessConstant.BATCH_CLASS_ID, subQuery));
    return find(criteria);
}
项目: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;
}
项目:JForum    文件:TopicRepository.java   
public Post getLastPost(Topic topic) {
    DetachedCriteria lastPost = DetachedCriteria.forClass(Post.class)
        .setProjection(Projections.max("id"))
        .add(Restrictions.eq("topic", topic))
        .add(Restrictions.eq("moderate", false))
        .setComment("topicDAO.getLastPostID");

    return (Post)session.createCriteria(Post.class)
        .add(Subqueries.propertyEq("id", lastPost))
        .setComment("topicDAO.getLastPost")
        .uniqueResult();
}
项目:JForum    文件:TopicRepository.java   
public Post getFirstPost(Topic topic) {
    DetachedCriteria firstPost = DetachedCriteria.forClass(Post.class)
        .setProjection(Projections.min("id"))
        .add(Restrictions.eq("topic", topic))
        .setComment("topicDAO.getFirstPostID");

    return (Post)session.createCriteria(Post.class)
        .add(Subqueries.propertyEq("id", firstPost))
        .setComment("topicDAO.getFirstPost")
        .uniqueResult();
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private void setCharacterizationAndCriteria(
        AdvancedSampleSearchBean searchBean, DetachedCriteria crit,
        String projectionProperty) {
    if (searchBean.getCharacterizationQueries().isEmpty()) {
        return;
    }
    for (CharacterizationQueryBean charQuery : searchBean
            .getCharacterizationQueries()) {
        DetachedCriteria subCrit = getCharacterizationSubquery(charQuery,
                projectionProperty);
        crit.add(Subqueries.exists(subCrit));
    }
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private void setFunctionalizingEntityAndCriteria(
        AdvancedSampleSearchBean searchBean, DetachedCriteria crit,
        String projectionProperty) throws Exception {
    for (CompositionQueryBean query : searchBean.getCompositionQueries()) {
        if (query.getCompositionType().equals("functionalizing entity")) {
            DetachedCriteria subCrit = getFunctionalizingEntitySubquery(
                    query, "funcEntity.", projectionProperty);
            crit.add(Subqueries.exists(subCrit));
        }
    }
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private void setFunctionAndCriteria(AdvancedSampleSearchBean searchBean,
        DetachedCriteria crit, String projectionProperty) throws Exception {
    for (CompositionQueryBean query : searchBean.getCompositionQueries()) {
        if (query.getCompositionType().equals("function")) {
            DetachedCriteria subCrit = getFunctionSubquery(query,
                    "inherentFunction.", "function.", projectionProperty);
            crit.add(Subqueries.exists(subCrit));
        }
    }
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
private void setNanomaterialEntityAndCriteria(
        AdvancedSampleSearchBean searchBean, DetachedCriteria crit,
        String projectionProperty) throws Exception {
    for (CompositionQueryBean query : searchBean.getCompositionQueries()) {
        if (query.getCompositionType().equals("nanomaterial entity")) {
            DetachedCriteria subCrit = getNanomaterialEntitySubquery(query,
                    "nanoEntity.", projectionProperty);
            crit.add(Subqueries.exists(subCrit));
        }
    }
}
项目:cananolab    文件:AdvancedSampleServiceHelper.java   
/**
 * Set the DetachedCriteria for sample queries
 * 
 * @param searchBean
 * @param crit
 * @throws Exception
 */
private void setSampleCriteria(AdvancedSampleSearchBean searchBean,
        DetachedCriteria crit) throws Exception {
    if (searchBean.getSampleQueries().isEmpty()) {
        return;
    }
    // join POC
    if (searchBean.getHasPOC()) {
        crit.createAlias("primaryPointOfContact", "poc");
        crit.createAlias("poc.organization", "organization");
        crit.createAlias("otherPointOfContactCollection", "otherPOC",
                CriteriaSpecification.LEFT_JOIN);
        crit.createAlias("otherPOC.organization", "otherOrg",
                CriteriaSpecification.LEFT_JOIN);
    }
    Junction junction = getSampleJunction(searchBean);
    if (junction != null) {
        crit.add(junction);
    }
    // more than one POC and AND
    else {
        crit.add(getSampleNameJunction(searchBean));
        for (SampleQueryBean query : searchBean.getSampleQueries()) {
            if (query.getNameType().equals("point of contact name")) {
                DetachedCriteria subCrit = getPointOfContactSubquery(query,
                        "poc.", "otherPOC.", "id");
                crit.add(Subqueries.exists(subCrit));
            }
        }
    }
}