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

项目:Equella    文件:URLCheckerPolicy.java   
@SuppressWarnings("nls")
public Criteria addRequiresCheckingCriteria(Criteria c)
{
    // DO NOT CHANGE THIS METHOD without also changing the other methods in
    // this policy class, and also the documented policy in the class
    // comments.

    SimpleExpression overOneMonthAgo = lt("lastChecked", new Date(oneMonthAgo()));

    SimpleExpression overOneDayAgo = lt("lastChecked", new Date(oneDayAgo()));
    SimpleExpression lessThanFiveTries = lt("tries", triesUntilDisabled);
    SimpleExpression notSuccessful = eq("success", false);
    LogicalExpression badButStillTrying = and(notSuccessful, and(lessThanFiveTries, overOneDayAgo));

    return c.add(or(overOneMonthAgo, badButStillTrying));
}
项目:ephesoft    文件:BatchInstanceDaoImpl.java   
/**
 * An API to fetch all batch instance by batch name or id.
 * 
 * @param searchString String
 * @param userRoles Set<String>
 * @return List<BatchInstance>
 */
@Override
public List<BatchInstance> getBatchInstancesByBatchNameOrId(String searchString, Set<String> userRoles) {
    DetachedCriteria criteria = criteria();

    List<BatchInstance> batchInstances = new ArrayList<BatchInstance>();

    Set<String> batchClassIdentifiers = batchClassGroupsDao.getBatchClassIdentifierForUserRoles(userRoles);

    String searchStringLocal = searchString.replaceAll(DataAccessConstant.PERCENTAGE, REPLACEMENT_STRING);
    Criterion nameLikeCriteria = Restrictions.like(BATCH_NAME, DataAccessConstant.PERCENTAGE + searchStringLocal
            + DataAccessConstant.PERCENTAGE);
    Criterion idLikeCriteria = Restrictions.like(BATCH_INSTANCE_IDENTIFIER, DataAccessConstant.PERCENTAGE + searchStringLocal
            + DataAccessConstant.PERCENTAGE);

    LogicalExpression searchCriteria = Restrictions.or(nameLikeCriteria, idLikeCriteria);
    criteria.add(searchCriteria);
    if (batchClassIdentifiers != null && batchClassIdentifiers.size() > 0) {
        criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
        criteria.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIdentifiers));
        batchInstances = find(criteria);
    }
    return batchInstances;
}
项目:spring-mvc-base    文件:AccountDao.java   
/**
 * 
 * search account by a keyword which is then
 * compared to name and surname fields
 * 
 * @param text
 * @return list of accounts
 * @throws DataException
 */
public List<Account> textSearch(String text) throws DataException {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();
    Criteria crit = session.createCriteria(Account.class);
    Criterion name = Restrictions.like("name", text);
    Criterion surname = Restrictions.like("surname", text);
    LogicalExpression expression = Restrictions.or(name, surname);

    crit.add(expression);
    List<Account> accountList;
    try {
        accountList = crit.list();
        session.flush();
        session.getTransaction().commit();
    } catch (Exception e) {
        session.getTransaction().rollback();
        throw new HibernateException(e.getMessage());
    }
    return accountList;
}
项目:AIDR    文件:CollectionRepositoryImpl.java   
@Override
public Long getStoppedCollectionsCount(String terms) {
    Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class);
    criteria.setProjection(Projections.projectionList()
            .add(Projections.property("id"), "id"));

    LogicalExpression or = Restrictions.or(
            Restrictions.eq("status", CollectionStatus.STOPPED),
            Restrictions.eq("status", CollectionStatus.NOT_RUNNING)
            );

    LogicalExpression orAll = Restrictions.or(
            or,
            Restrictions.eq("status", CollectionStatus.FATAL_ERROR)
            );

    criteria.add(orAll);
    addCollectionSearchCriteria(terms, criteria);

    ScrollableResults scroll = criteria.scroll();
    int i = scroll.last() ? scroll.getRowNumber() + 1 : 0;
    return Long.valueOf(i);
}
项目:AIDR    文件:CollectionRepositoryImpl.java   
private void addCollectionSearchCriteria(String terms, Criteria criteria) {
    if (StringUtils.hasText(terms)){
        String wildcard ='%'+ URLDecoder.decode(terms.trim())+'%';

        LogicalExpression orNameCode = Restrictions.or(
                Restrictions.ilike("name", wildcard),
                Restrictions.ilike("code", wildcard)
                );

        LogicalExpression orAll = Restrictions.or(
                orNameCode,
                Restrictions.ilike("track", wildcard)
                );

        criteria.add(orAll);
    }
}
项目:replyit-master-3.2-final    文件:PaymentDAS.java   
public BigDecimal findTotalBalanceByUser(Integer userId) {

    //user's payments which are not refunds
    Criteria criteria = getSession().createCriteria(PaymentDTO.class);
    criteria.add(Restrictions.eq("deleted", 0))
        .createAlias("baseUser", "u")
         .add(Restrictions.eq("u.id", userId))
         .add(Restrictions.eq("isRefund", 0))
        .createAlias("paymentResult", "pr");

    Criterion PAYMENT_SUCCESSFUL = Restrictions.eq("pr.id", CommonConstants.PAYMENT_RESULT_SUCCESSFUL);
    Criterion PAYMENT_ENTERED = Restrictions.eq("pr.id", CommonConstants.PAYMENT_RESULT_ENTERED);

    LogicalExpression successOrEntered= Restrictions.or(PAYMENT_ENTERED, PAYMENT_SUCCESSFUL);

    // Criteria or condition
    criteria.add(successOrEntered);

    criteria.setProjection(Projections.sum("balance"));
    criteria.setComment("PaymentDAS.findTotalBalanceByUser");
    BigDecimal paymentBalances = (criteria.uniqueResult() == null ? BigDecimal.ZERO : (BigDecimal) criteria.uniqueResult());

    return paymentBalances;
}
项目:replyit-master-3.2-final    文件:OrderDAS.java   
/**
 * Finds active recurring orders for a given user
 * @param userId
 * @return
 */
public List<OrderDTO> findByUserSubscriptions(Integer userId) {
    // I need to access an association, so I can't use the parent helper class
    Criteria criteria = getSession().createCriteria(OrderDTO.class)
      .add(Restrictions.eq("deleted", 0))
      .createAlias("baseUserByUserId", "u")
        .add(Restrictions.eq("u.id", userId))
        .createAlias("orderPeriod", "p")
        .add(Restrictions.ne("p.id", Constants.ORDER_PERIOD_ONCE))
        .createAlias("orderStatus", "s");

    Criterion ORDER_ACTIVE = Restrictions.eq("s.id", Constants.ORDER_STATUS_ACTIVE);

    Criterion ORDER_FINISHED = Restrictions.eq("s.id", Constants.ORDER_STATUS_FINISHED);
    Criterion UNTIL_FUTURE = Restrictions.gt("activeUntil", new Date());
    LogicalExpression FINISH_IN_FUTURE= Restrictions.and(ORDER_FINISHED, UNTIL_FUTURE);

    LogicalExpression orderActiveOrEndsLater= Restrictions.or(ORDER_ACTIVE, FINISH_IN_FUTURE);

    // Criteria or condition
    criteria.add(orderActiveOrEndsLater);

    return criteria.list();
}
项目:openbravo-brazil    文件:DatabaseValidator.java   
/**
 * Checks if old-style password columns exist which should be updated to use the new references.
 * 
 */
private void checkPasswordColumns(SystemValidationResult result) {
  org.openbravo.model.ad.domain.Reference hashed = OBDal.getInstance().get(
      org.openbravo.model.ad.domain.Reference.class, "C5C21C28B39E4683A91779F16C112E40");
  org.openbravo.model.ad.domain.Reference encrypted = OBDal.getInstance().get(
      org.openbravo.model.ad.domain.Reference.class, "16EC6DF4A59747749FDF256B7FBBB058");

  // if one of the old-booleans is set, but not using new reference-id's -> report as warning
  SimpleExpression enc = Restrictions.eq(Column.PROPERTY_DISPLAYENCRIPTION, Boolean.TRUE);
  LogicalExpression newRefs = Restrictions.or(Restrictions.eq(Column.PROPERTY_REFERENCE, hashed),
      Restrictions.eq(Column.PROPERTY_REFERENCE, encrypted));
  OBCriteria<Column> colQuery = OBDal.getInstance().createCriteria(Column.class);
  colQuery.add(Restrictions.and(enc, Restrictions.not(newRefs)));

  // only validate given module (if given)
  if (validateModule != null) {
    colQuery.add(Restrictions.eq(Column.PROPERTY_MODULE, validateModule));
  }
  if (colQuery.count() > 0) {
    List<Column> columns = colQuery.list();
    for (Column column : columns) {
      result
          .addWarning(
              SystemValidationType.OLDSTYLE_PASSWORD_COLUMNS,
              "The column '"
                  + column.getTable().getName()
                  + "'.'"
                  + column.getName()
                  + "' is using old-style config for password-type columns. It should be changed to use one of the new references '"
                  + hashed.getName() + "' or '" + encrypted.getName() + "'");
    }
  }
}
项目:helicalinsight    文件:ProfileDaoImpl.java   
@Override
public Profile getProfileByNameAndUserId(String profileName, int userId) {
    Criteria criteria = session.getCurrentSession().createCriteria(Profile.class);
    Criterion name = Restrictions.eq("profile_name", profileName);
    Criterion user = Restrictions.eq("user_id", userId);
    LogicalExpression andExp = Restrictions.and(name, user);
    criteria.add(andExp);
    if (criteria.list().isEmpty()) {
        return null;
    }
    return (Profile) criteria.uniqueResult();
}
项目:helicalinsight    文件:ProfileDaoImpl.java   
@Override
public List<Profile> getProfileListByNameAndUserId(String profileName, int userId) {
    Criteria criteria = session.getCurrentSession().createCriteria(Profile.class);
    Criterion name = Restrictions.eq("profile_name", profileName);
    Criterion user = Restrictions.eq("user_id", userId);
    LogicalExpression andExp = Restrictions.and(name, user);
    criteria.add(andExp);
    if (criteria.list().isEmpty()) {
        return null;
    }
    return criteria.list();
}
项目:AIDR    文件:CollectionRepositoryImpl.java   
@Override
public Collection getRunningCollectionStatusByUser(Long userId) {
    Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class);
    //criteria.add(Restrictions.eq("user.id", userId));
    //criteria.add(Restrictions.eq("status", CollectionStatus.RUNNING));

    LogicalExpression or = Restrictions.or(
            Restrictions.eq("status", CollectionStatus.RUNNING),
            Restrictions.eq("status", CollectionStatus.RUNNING_WARNING)             
            );

    LogicalExpression orAll = Restrictions.or(
            or,
            Restrictions.eq("status", CollectionStatus.WARNING)
            );

    /*Is this check needed?
     * 
     * LogicalExpression and = Restrictions.and(
            orAll,
            Restrictions.ne("status", CollectionStatus.TRASHED)             
            );*/
    LogicalExpression andAll = Restrictions.and(
            orAll,
            Restrictions.eq("owner.id", userId)
            );

    criteria.add(andAll);
    //criteria.add(Restrictions.ne("status", CollectionStatus.TRASHED));
    return (Collection) criteria.uniqueResult();
}
项目:AIDR    文件:CollectionRepositoryImpl.java   
@Override
public Long getRunningCollectionsCount(String terms) {
    Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class);
    criteria.setProjection(Projections.projectionList()
            .add(Projections.property("id"), "id"));

    LogicalExpression or = Restrictions.or(
            Restrictions.eq("status", CollectionStatus.RUNNING),
            Restrictions.eq("status", CollectionStatus.RUNNING_WARNING)
            );

    LogicalExpression or2 = Restrictions.or(
            or,
            Restrictions.eq("status", CollectionStatus.INITIALIZING)
            );

    LogicalExpression orAll = Restrictions.or(
            or2,
            Restrictions.eq("status", CollectionStatus.WARNING)
            );

    LogicalExpression andAll = Restrictions.and(
            orAll,
            Restrictions.ne("status", CollectionStatus.TRASHED)
            );

    criteria.add(andAll);
    addCollectionSearchCriteria(terms, criteria);

    ScrollableResults scroll = criteria.scroll();
    int i = scroll.last() ? scroll.getRowNumber() + 1 : 0;
    return Long.valueOf(i);
}
项目:AIDR    文件:CollectionRepositoryImpl.java   
@SuppressWarnings("unchecked")
@Override
public List<Collection> getRunningCollections(Integer start, Integer limit, String terms, String sortColumn, String sortDirection) {
    Criteria criteriaIds = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class);
    criteriaIds.setProjection(Projections.projectionList()
            .add(Projections.property("id"), "id"));

    LogicalExpression or = Restrictions.or(
            Restrictions.eq("status", CollectionStatus.RUNNING),
            Restrictions.eq("status", CollectionStatus.RUNNING_WARNING)
            );

    LogicalExpression or2 = Restrictions.or(
            or,
            Restrictions.eq("status", CollectionStatus.INITIALIZING)
            );

    LogicalExpression orAll = Restrictions.or(
            or2,
            Restrictions.eq("status", CollectionStatus.WARNING)
            );

    LogicalExpression andAll = Restrictions.and(
            orAll,
            Restrictions.ne("status", CollectionStatus.TRASHED)
            );

    criteriaIds.add(andAll);
    addCollectionSearchCriteria(terms, criteriaIds);
    searchCollectionsAddOrder(sortColumn, sortDirection, criteriaIds);

    if (start != null) {
        criteriaIds.setFirstResult(start);
    }
    if (limit != null) {
        criteriaIds.setMaxResults(limit);
    }

    List<Integer> ids = criteriaIds.list();

    if (ids.size() == 0){
        return Collections.emptyList();
    }

    Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class);
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    criteria.add(Restrictions.in("id", ids));
    searchCollectionsAddOrder(sortColumn, sortDirection, criteria);

    return criteria.list();
}
项目:AIDR    文件:CollectionRepositoryImpl.java   
@SuppressWarnings("unchecked")
@Override
public List<Collection> getStoppedCollections(Integer start, Integer limit, String terms, String sortColumn, String sortDirection) {
    Criteria criteriaIds = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class);
    criteriaIds.setProjection(Projections.projectionList()
            .add(Projections.property("id"), "id"));

    LogicalExpression or = Restrictions.or(
            Restrictions.eq("status", CollectionStatus.STOPPED),
            Restrictions.eq("status", CollectionStatus.NOT_RUNNING)
            );

    LogicalExpression orAll = Restrictions.or(
            or,
            Restrictions.eq("status", CollectionStatus.FATAL_ERROR)
            );

    criteriaIds.add(orAll);
    addCollectionSearchCriteria(terms, criteriaIds);
    searchCollectionsAddOrder(sortColumn, sortDirection, criteriaIds);

    if (start != null) {
        criteriaIds.setFirstResult(start);
    }
    if (limit != null) {
        criteriaIds.setMaxResults(limit);
    }

    List<Integer> ids = criteriaIds.list();

    if (ids.size() == 0){
        return Collections.emptyList();
    }

    Criteria criteria = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Collection.class);
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    criteria.add(Restrictions.in("id", ids));
    searchCollectionsAddOrder(sortColumn, sortDirection, criteria);

    return criteria.list();
}
项目:replyit-master-3.2-final    文件:PaymentDAS.java   
/**
   * Revenue = Payments minus Refunds
   * @param userId
   * @return
   */
  public BigDecimal findTotalRevenueByUser(Integer userId) {
      Criteria criteria = getSession().createCriteria(PaymentDTO.class);
      criteria.add(Restrictions.eq("deleted", 0))
              .createAlias("baseUser", "u")
                  .add(Restrictions.eq("u.id", userId))
            .createAlias("paymentResult", "pr");

      Criterion PAYMENT_SUCCESSFUL = Restrictions.eq("pr.id", CommonConstants.PAYMENT_RESULT_SUCCESSFUL);
      Criterion PAYMENT_ENTERED = Restrictions.eq("pr.id", CommonConstants.PAYMENT_RESULT_ENTERED);

      LogicalExpression successOrEntered= Restrictions.or(PAYMENT_ENTERED, PAYMENT_SUCCESSFUL);

      // Criteria or condition
      criteria.add(successOrEntered);

      criteria.add(Restrictions.eq("isRefund", 0));
      criteria.setProjection(Projections.sum("amount"));
      criteria.setComment("PaymentDAS.findTotalRevenueByUser-Gross Receipts");

      BigDecimal grossReceipts= criteria.uniqueResult() == null ? BigDecimal.ZERO : (BigDecimal) criteria.uniqueResult();

      //Calculate Refunds
      Criteria criteria2 = getSession().createCriteria(PaymentDTO.class);
      criteria2.add(Restrictions.eq("deleted", 0))
              .createAlias("baseUser", "u")
                  .add(Restrictions.eq("u.id", userId))
                .createAlias("paymentResult", "pr");

// Criteria or condition
      criteria2.add(successOrEntered);

      criteria2.add(Restrictions.eq("isRefund", 1));
      criteria2.setProjection(Projections.sum("amount"));
      criteria2.setComment("PaymentDAS.findTotalRevenueByUser-Gross Refunds");

      BigDecimal refunds= criteria2.uniqueResult() == null ? BigDecimal.ZERO : (BigDecimal) criteria2.uniqueResult();

      //net revenue = gross - all refunds
      BigDecimal netRevenueFromUser= grossReceipts.subtract(refunds);

LOG.debug("Gross receipts " + grossReceipts + " minus Gross Refunds " + refunds + ": " + netRevenueFromUser);

      return netRevenueFromUser;
  }