Class BoundingboxJdbcFunction
java.lang.Object
ch.tocco.nice2.persist.core.api.hibernate.query.AbstractJdbcFunction
ch.tocco.nice2.optional.geolocation.impl.jdbc.BoundingboxJdbcFunction
- All Implemented Interfaces:
JdbcFunction
Creates a boolean expression that evaluates to true, if a given point is within the
bounds of a given rectangle.
It expects exactly 6 arguments in order, where
1. `x` is the x coordinate of a certain position 2. `y` is the y coordinate of a certain position 3. `ul.y` is the y coordinate of the upper left corner of the rectangle 4. `ul.x` is the x coordinate of the upper left corner of the rectangle 5. `lr.y` is the y coordinate of the lower right corner of the rectangle 6. `lr.x` is the x coordinate of the lower right corner of the rectangleThe function writes the following expression in SQL:
(x >= ul.x) and (x < = lr.x) and (y >= lr.y) and (y <= ul.y)
Selecting those (x,y) points that are within the bounds of (ul, lr).
Example usage
Use it in queries like the following example (here, lat=y and lng=x, respectively, as used in geographical coordinate system):
Query q = ctx.compileQuery("find Cities where INBOUNDINGBOX(ps_lat, pos_lng, :ul_lat, :ul_lng, :lr_lat, :lr_lng) == true");
Position zurich = new Position(...);
Position[] box = zurich.getBoundingBox(Distance.kilometer("20"));
q.setParameter("ul_lat", box[0].getLatitude());
q.setParameter("ul_lng", box[0].getLongitude());
q.setParameter("lr_lat", box[1].getLatitude());
q.setParameter("lr_lng", box[1].getLongitude());
This will select all cities that are at maximum 20km (are within a square around Zurich with side length=40km)
away from Zurich (assuming that the "Cities" entity has two fields "pos_lat" and "pos_lng" of respective type.)-
Field Summary
Fields inherited from class ch.tocco.nice2.persist.core.api.hibernate.query.AbstractJdbcFunction
returnType
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
getName()
protected void
render
(JdbcFunctionWriter writer, List<? extends org.hibernate.sql.ast.tree.SqlAstNode> arguments) void
validateArguments
(jakarta.persistence.criteria.Expression<?>[] arguments) Methods inherited from class ch.tocco.nice2.persist.core.api.hibernate.query.AbstractJdbcFunction
checkIfFunctionCallOfType, checkIfLiteralOrParameter, checkIfReferenceOfType, createFunction, getReturnType
-
Constructor Details
-
BoundingboxJdbcFunction
-
-
Method Details
-
render
protected void render(JdbcFunctionWriter writer, List<? extends org.hibernate.sql.ast.tree.SqlAstNode> arguments) - Specified by:
render
in classAbstractJdbcFunction
-
getName
-
validateArguments
public void validateArguments(jakarta.persistence.criteria.Expression<?>[] arguments) throws JdbcFunctionException - Throws:
JdbcFunctionException
-
argumentCount
public int argumentCount()- Returns:
- the number of expected arguments.
-