コード例 #1
0
  private static void populateHibernateDetachedCriteria(
      AbstractHibernateQuery hibernateQuery,
      org.hibernate.criterion.DetachedCriteria detachedCriteria,
      QueryableCriteria<?> queryableCriteria) {
    List<Query.Criterion> criteriaList = queryableCriteria.getCriteria();
    for (Query.Criterion criterion : criteriaList) {
      Criterion hibernateCriterion =
          HibernateQuery.HIBERNATE_CRITERION_ADAPTER.toHibernateCriterion(
              hibernateQuery, criterion, null);
      if (hibernateCriterion != null) {
        detachedCriteria.add(hibernateCriterion);
      }
    }

    List<Query.Projection> projections = queryableCriteria.getProjections();
    ProjectionList projectionList = Projections.projectionList();
    for (Query.Projection projection : projections) {
      Projection hibernateProjection =
          new HibernateProjectionAdapter(projection).toHibernateProjection();
      if (hibernateProjection != null) {
        projectionList.add(hibernateProjection);
      }
    }
    detachedCriteria.setProjection(projectionList);
  }
コード例 #2
0
  public static org.hibernate.criterion.DetachedCriteria getHibernateDetachedCriteria(
      AbstractHibernateQuery hibernateQuery, QueryableCriteria<?> queryableCriteria) {

    String alias = queryableCriteria.getAlias();
    PersistentEntity persistentEntity = queryableCriteria.getPersistentEntity();
    Class targetClass = persistentEntity.getJavaClass();
    org.hibernate.criterion.DetachedCriteria detachedCriteria;

    if (alias != null) {
      detachedCriteria = org.hibernate.criterion.DetachedCriteria.forClass(targetClass, alias);
    } else {
      detachedCriteria = org.hibernate.criterion.DetachedCriteria.forClass(targetClass);
    }
    populateHibernateDetachedCriteria(
        new HibernateQuery(detachedCriteria, persistentEntity),
        detachedCriteria,
        queryableCriteria);
    return detachedCriteria;
  }