@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; } }
/** * Determines the column name corresponding to the specified property path. * * @param propertyName The property path * @param criteria The criteria * @param criteriaQuery The criteria query * @return The column name * @throws HibernateException If the property could not be resolved, or more than one column is * mapped by the property path. */ public static String findColumn( String propertyName, Criteria criteria, CriteriaQuery criteriaQuery) { final String[] columns = criteriaQuery.findColumns(propertyName, criteria); if (columns.length != 1) { throw new HibernateException( "Spatial Expression may only be used with single-column properties"); } return columns[0]; }
/** * Get the names of the columns mapped by a property path; if the property path is not found in * subcriteria, try the "outer" query. Projection aliases are ignored. */ public String[] findColumns(String propertyName, Criteria subcriteria) throws HibernateException { try { return getColumns(propertyName, subcriteria); } catch (HibernateException he) { // not found in inner query, try the outer query if (outerQueryTranslator != null) { return outerQueryTranslator.findColumns(propertyName, subcriteria); } else { throw he; } } }
/** * Determines the {@code SpatialDialect} for the specified {@code CriteriaQuery}, and checks if * the specified function is supported. * * @param criteriaQuery The {@code CriteriaQuery} for which the dialect is sought * @param function The function for which to check support * @return The {@code SpatialDialect} associated with the specified {@code CriteriaQuery} * @throws HibernateException If the dialect for the specified {@code CriteriaQuery} is not a * {@code SpatialDialect}. or the specified {@code SpatialFunction} is not supported by the * dialect. */ public static SpatialDialect getSpatialDialect( CriteriaQuery criteriaQuery, SpatialFunction function) { final Dialect dialect = criteriaQuery.getFactory().getDialect(); if (!(dialect instanceof SpatialDialect)) { throw new HibernateException("A spatial expression requires a spatial dialect."); } final SpatialDialect spatialDialect = (SpatialDialect) dialect; if (!spatialDialect.supports(function)) { throw new HibernateException(function + " function not supported by this dialect"); } return spatialDialect; }