Search in sources :

Example 1 with SimpleProjection

use of org.hibernate.criterion.SimpleProjection in project hibernate-orm by hibernate.

the class SpatialProjections method extent.

/**
 * Applies an extent projection to the specified geometry function
 * <p>
 * <p>The extent of a set of {@code Geometry}s is the union of their bounding boxes.</p>
 *
 * @param propertyName The property to use for calculating the extent
 *
 * @return an extent-projection for the specified property.
 */
public static Projection extent(final String propertyName) {
    return new SimpleProjection() {

        public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
            return new Type[] { criteriaQuery.getType(criteria, propertyName) };
        }

        public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException {
            final StringBuilder stbuf = new StringBuilder();
            final SessionFactoryImplementor factory = criteriaQuery.getFactory();
            final String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName);
            final Dialect dialect = factory.getDialect();
            if (dialect instanceof SpatialDialect) {
                final SpatialDialect seDialect = (SpatialDialect) dialect;
                stbuf.append(seDialect.getSpatialAggregateSQL(columns[0], SpatialAggregate.EXTENT));
                stbuf.append(" as y").append(position).append('_');
                return stbuf.toString();
            }
            return null;
        }
    };
}
Also used : Type(org.hibernate.type.Type) SpatialDialect(org.hibernate.spatial.SpatialDialect) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) CriteriaQuery(org.hibernate.criterion.CriteriaQuery) Dialect(org.hibernate.dialect.Dialect) SpatialDialect(org.hibernate.spatial.SpatialDialect) Criteria(org.hibernate.Criteria) SimpleProjection(org.hibernate.criterion.SimpleProjection)

Aggregations

Criteria (org.hibernate.Criteria)1 CriteriaQuery (org.hibernate.criterion.CriteriaQuery)1 SimpleProjection (org.hibernate.criterion.SimpleProjection)1 Dialect (org.hibernate.dialect.Dialect)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 SpatialDialect (org.hibernate.spatial.SpatialDialect)1 Type (org.hibernate.type.Type)1