@Override
  public Type getTypeUsingProjection(Criteria subcriteria, String propertyName)
      throws HibernateException {

    // first look for a reference to a projection alias
    final Projection projection = rootCriteria.getProjection();
    Type[] projectionTypes =
        projection == null ? null : projection.getTypes(propertyName, subcriteria, this);

    if (projectionTypes == null) {
      try {
        // it does not refer to an alias of a projection,
        // look for a property
        return getType(subcriteria, propertyName);
      } catch (HibernateException he) {
        // not found in inner query , try the outer query
        if (outerQueryTranslator != null) {
          return outerQueryTranslator.getType(subcriteria, propertyName);
        } else {
          throw he;
        }
      }
    } else {
      if (projectionTypes.length != 1) {
        // should never happen, i think
        throw new QueryException("not a single-length projection: " + propertyName);
      }
      return projectionTypes[0];
    }
  }
  /** Get the names of the columns constrained by this criterion. */
  @Override
  public String[] getColumnsUsingProjection(Criteria subcriteria, String propertyName)
      throws HibernateException {

    // first look for a reference to a projection alias
    final Projection projection = rootCriteria.getProjection();
    String[] projectionColumns = null;
    if (projection != null) {
      projectionColumns =
          (projection instanceof EnhancedProjection
              ? ((EnhancedProjection) projection)
                  .getColumnAliases(propertyName, 0, rootCriteria, this)
              : projection.getColumnAliases(propertyName, 0));
    }
    if (projectionColumns == null) {
      // it does not refer to an alias of a projection,
      // look for a property
      try {
        return getColumns(propertyName, subcriteria);
      } catch (HibernateException he) {
        // not found in inner query , try the outer query
        if (outerQueryTranslator != null) {
          return outerQueryTranslator.getColumnsUsingProjection(subcriteria, propertyName);
        } else {
          throw he;
        }
      }
    } else {
      // it refers to an alias of a projection
      return projectionColumns;
    }
  }
  public ProjectionExitOperation getProjectionExitOperation(
      Projection projection, SessionFactoryImplementor sessionFactoryImplementor) {
    if (projection instanceof RowCountProjection) {
      return new RowCountExitOperation(projection);
    }
    if (projection instanceof AggregateProjection) {
      return new AggregateExitOperation((AggregateProjection) projection);
    }

    // TODO(maulik) support these projections, hopefully not by creating ShardedProjections
    // Projection rowCount() {
    // AggregateProjection avg(String propertyName) {
    // CountProjection count(String propertyName) {
    // Projection distinct(Projection proj) {
    // ProjectionList projectionList() {
    // CountProjection countDistinct(String propertyName) {
    // Projection sqlProjection(String sql, String[] columnAliases, Type[] types) {
    // Projection sqlGroupProjection(String sql, String groupBy, String[] columnAliases, Type[]
    // types) {
    // PropertyProjection groupProperty(String propertyName) {
    // PropertyProjection property(String propertyName) {
    // IdentifierProjection id() {
    // Projection alias(Projection projection, String alias) {

    throw new UnsupportedOperationException(
        "This projection is unsupported: " + projection.getClass());
  }
Exemplo n.º 4
0
 public String toString() {
   return "CriteriaImpl("
       + entityOrClassName
       + ":"
       + (rootAlias == null ? "" : rootAlias)
       + subcriteriaList.toString()
       + criterionEntries.toString()
       + (projection == null ? "" : projection.toString())
       + ')';
 }