use of org.hibernate.spatial.SpatialDialect in project hibernate-orm by hibernate.
the class ExpressionUtil method getSpatialDialect.
/**
* 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;
}
use of org.hibernate.spatial.SpatialDialect 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;
}
};
}
use of org.hibernate.spatial.SpatialDialect in project hibernate-orm by hibernate.
the class SpatialRelateExpression method toSqlString.
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
final String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, this.propertyName);
final Dialect dialect = factory.getDialect();
if (dialect instanceof SpatialDialect) {
final SpatialDialect seDialect = (SpatialDialect) dialect;
return seDialect.getSpatialRelateSQL(columns[0], spatialRelation);
} else {
throw new IllegalStateException("Dialect must be spatially enabled dialect");
}
}
use of org.hibernate.spatial.SpatialDialect in project hibernate-orm by hibernate.
the class DWithinExpression method getTypedValues.
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
final SpatialDialect spatialDialect = ExpressionUtil.getSpatialDialect(criteriaQuery, SpatialFunction.dwithin);
TypedValue typedDistanceValue = new TypedValue(StandardBasicTypes.DOUBLE, distance);
if (spatialDialect instanceof OracleSpatial10gDialect) {
typedDistanceValue = new TypedValue(StandardBasicTypes.STRING, "distance=" + distance);
}
return new TypedValue[] { criteriaQuery.getTypedValue(criteria, propertyName, geometry), typedDistanceValue };
}
use of org.hibernate.spatial.SpatialDialect in project hibernate-orm by hibernate.
the class DWithinExpression method toSqlString.
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
final String column = ExpressionUtil.findColumn(propertyName, criteria, criteriaQuery);
final SpatialDialect spatialDialect = ExpressionUtil.getSpatialDialect(criteriaQuery, SpatialFunction.dwithin);
return spatialDialect.getDWithinSQL(column);
}
Aggregations