コード例 #1
0
  private DetachedCriteria subquery(SubqueryExpression sqex) {

    String entityName = sqex.getTargetPropertyName();
    String alias = Texts.tos(sqex.getAlias(), null);

    DetachedCriteria dtc;
    if (alias != null) {
      dtc = DetachedCriteria.forEntityName(entityName, alias);
    } else {
      dtc = DetachedCriteria.forEntityName(entityName);
    }
    if (log.isTraceEnabled()) {
      log.trace(
          String.format(
              "Creating detached criteria for entity %s of type %s as %s",
              entityName, sqex.getType(), sqex.getValue()));
    }

    if (sqex.getValue() instanceof Restrictions) {
      Restrictions restr = (Restrictions) sqex.getValue();
      dtc.setProjection(Projections.id());
      dtc.add(parseRestriction(restr));
    } else if (sqex.getValue() instanceof Where) {
      dtc.setProjection(Projections.id());
      DetachedWhereParser whp = new DetachedWhereParser();
      whp.parse((Where) sqex.getValue(), dtc);
    } else {
      throw new IllegalStateException(
          String.format(
              "Subquery must be instance of restrictions or Where, but is %s",
              sqex.getValue().getClass().getName()));
    }

    return dtc;
  }
コード例 #2
0
 public DetachedCriteriaHibernateImpl(String entityName, String alias) {
   delegate = org.hibernate.criterion.DetachedCriteria.forEntityName(entityName, alias);
 }