use of org.eclipse.persistence.expressions.spatial.SpatialParameters in project eclipselink by eclipse-ee4j.
the class StructConverterTestSuite method testSimpleReadQuery.
/**
* Tests if SpatialExpressions will work properly without hung up when using ANYINTERACT query type
*/
public void testSimpleReadQuery() {
if (supported) {
JGeometry circle = JGeometry.createCircle(-10, 0, 0, 10, 10, 0, 0);
JGeometry newCircle = JGeometry.createCircle(0, -10, 0, 10, 10, 0, 0);
EntityManager em = createEntityManager(STRUCT_CONVERTER_PU);
try {
beginTransaction(em);
SimpleSpatial simpleSpatial = new SimpleSpatial(2000, circle);
em.persist(simpleSpatial);
commitTransaction(em);
} catch (RuntimeException ex) {
if (isTransactionActive(em)) {
rollbackTransaction(em);
}
throw ex;
}
clearCache(STRUCT_CONVERTER_PU);
ReadAllQuery raq = new ReadAllQuery(SimpleSpatial.class);
ExpressionBuilder eb = raq.getExpressionBuilder();
SpatialParameters parameters = new SpatialParameters();
parameters.setQueryType(SpatialParameters.QueryType.WINDOW).setMask(Mask.ANYINTERACT);
Expression selectionCriteria = SpatialExpressionFactory.relate(eb.get("jGeometry"), newCircle, parameters);
raq.setSelectionCriteria(selectionCriteria);
raq.addAscendingOrdering("id");
getServerSession(STRUCT_CONVERTER_PU).executeQuery(raq);
// now read using jpql - should generate the same sql as the ReadAllQuery above.
clearCache(STRUCT_CONVERTER_PU);
Query query = em.createQuery("SELECT ss FROM SimpleSpatial ss WHERE FUNC('MDSYS.SDO_RELATE', ss.jGeometry, :otherGeometry, :params) = 'TRUE' ORDER BY ss.id ASC");
query.setParameter("otherGeometry", newCircle);
query.setParameter("params", parameters.getParameterString());
query.getResultList();
}
}
use of org.eclipse.persistence.expressions.spatial.SpatialParameters in project eclipselink by eclipse-ee4j.
the class Query_SpatialOp_ExpReport_Tests method testSDOFilterRectangle.
/**
* SDO_Filter using a dynamic rectangular window with lower left
* and upper right coordinates of {(1,1), (20,20)}
*/
public void testSDOFilterRectangle() throws Exception {
String sql = "select GID, GEOMETRY FROM WRAPPED_SPATIAL WS where mdsys.sdo_filter(" + "ws.geometry.geom, mdsys.sdo_geometry(3,null,null, " + "mdsys.sdo_elem_info_array(1,3,3), " + "mdsys.sdo_ordinate_array(1,1, 20, 20)), " + "'QUERYTYPE=WINDOW') = 'TRUE' ORDER BY GID";
SQLReader reader = new SQLReader(session, sql);
double[] points = new double[] { 1, 1, 1, 20, 10, 20, 20, 1, 1, 1 };
populateTestGeometry(JGeometry.createLinearPolygon(points, 2, 0));
ReadAllQuery raq = new ReadAllQuery(WrappedSpatial.class);
ExpressionBuilder eb = raq.getExpressionBuilder();
ExpressionBuilder eb2 = new ExpressionBuilder();
ReportQuery rq = new ReportQuery(WrappedSpatial.class, eb2);
// rq.addAttribute("geometry.geom");
rq.addItem("geom", eb2.get("geometry").getField("geom"));
rq.setSelectionCriteria(eb2.get("id").equal(6666));
Expression geom1 = eb.get("geometry").getField("geom");
SpatialParameters parameters = new SpatialParameters();
parameters.setQueryType(QueryType.WINDOW);
Expression selectionCriteria = SpatialExpressionFactory.filter(geom1, rq, parameters);
selectionCriteria = selectionCriteria.and(eb.get("id").notEqual(6666));
raq.setSelectionCriteria(selectionCriteria);
raq.addAscendingOrdering("id");
List<Spatial> results = (List<Spatial>) session.executeQuery(raq);
String compareResult = reader.compare(results);
assertNull(compareResult, compareResult);
}
use of org.eclipse.persistence.expressions.spatial.SpatialParameters in project eclipselink by eclipse-ee4j.
the class Query_SpatialOp_ExpReport_Tests method testSDOWithinDistanceRectangleUsingMaxResolution.
public void testSDOWithinDistanceRectangleUsingMaxResolution() throws Exception {
String sql = "select GID, GEOMETRY FROM WRAPPED_SPATIAL WS where mdsys.sdo_within_distance(" + "ws.geometry.geom, mdsys.sdo_geometry(3,null,null, mdsys.sdo_elem_info_array(1,3,3), " + "mdsys.sdo_ordinate_array(1,1, 20, 20)), " + "'DISTANCE=10 MAX_RESOLUTION=5') = 'TRUE' ORDER BY GID";
SQLReader reader = new SQLReader(session, sql);
double[] points = new double[] { 1, 1, 1, 20, 10, 20, 20, 1, 1, 1 };
populateTestGeometry(JGeometry.createLinearPolygon(points, 2, 0));
ReadAllQuery raq = new ReadAllQuery(WrappedSpatial.class);
ExpressionBuilder eb = raq.getExpressionBuilder();
ExpressionBuilder eb2 = new ExpressionBuilder();
ReportQuery rq = new ReportQuery(WrappedSpatial.class, eb2);
// rq.addAttribute("geometry.geom");
rq.addItem("geom", eb2.get("geometry").getField("geom"));
rq.setSelectionCriteria(eb2.get("id").equal(6666));
Expression geom1 = eb.get("geometry").getField("geom");
SpatialParameters parameters = new SpatialParameters();
parameters.setDistance(10d).setMaxResolution(5);
Expression selectionCriteria = SpatialExpressionFactory.withinDistance(geom1, rq, parameters);
selectionCriteria = selectionCriteria.and(eb.get("id").notEqual(6666));
raq.setSelectionCriteria(selectionCriteria);
raq.addAscendingOrdering("id");
List<Spatial> results = (List<Spatial>) session.executeQuery(raq);
String compareResult = reader.compare(results);
assertNull(compareResult, compareResult);
}
use of org.eclipse.persistence.expressions.spatial.SpatialParameters in project eclipselink by eclipse-ee4j.
the class Query_SpatialOp_ExpReport_Tests method testSDOWithinDistanceNullParamsNotMatching.
/**
* SDO_WITHIN_DISTANCE with NULL params not matching existing
*/
public void testSDOWithinDistanceNullParamsNotMatching() throws Exception {
String sql = "select GID, GEOMETRY FROM WRAPPED_SPATIAL WS where " + "mdsys.sdo_within_distance(ws.geometry.geom, mdsys.sdo_geometry(3, " + "NULL, null, mdsys.sdo_elem_info_array(1,3,4), " + "mdsys.sdo_ordinate_array(10, 0, 0, 10, 0, -10)), " + "NULL) = 'TRUE' ORDER BY GID";
SQLReader reader = new SQLReader(session, sql);
populateTestGeometry(JGeometry.createCircle(10, 0, 0, 10, 0, -10, 0));
ReadAllQuery raq = new ReadAllQuery(WrappedSpatial.class);
ExpressionBuilder eb = raq.getExpressionBuilder();
ExpressionBuilder eb2 = new ExpressionBuilder();
ReportQuery rq = new ReportQuery(WrappedSpatial.class, eb2);
rq.addItem("geom", eb2.get("geometry").getField("geom"));
rq.setSelectionCriteria(eb2.get("id").equal(6666));
Expression geom1 = eb.get("geometry").getField("geom");
Expression selectionCriteria = SpatialExpressionFactory.withinDistance(geom1, rq, new SpatialParameters(""));
selectionCriteria = selectionCriteria.and(eb.get("id").notEqual(6666));
raq.setSelectionCriteria(selectionCriteria);
raq.addAscendingOrdering("id");
List<Spatial> results = (List<Spatial>) session.executeQuery(raq);
String compareResult = reader.compare(results);
assertNull(compareResult, compareResult);
}
use of org.eclipse.persistence.expressions.spatial.SpatialParameters in project eclipselink by eclipse-ee4j.
the class Query_SpatialOp_ExpReport_Tests method testSDOWithinDistanceNullParamsMatchingCircle1004.
/**
* SDO_WITHIN_DISTANCE with NULL params matching a known circle geometry (1004)
*/
public void testSDOWithinDistanceNullParamsMatchingCircle1004() throws Exception {
String sql = "select GID, GEOMETRY FROM WRAPPED_SPATIAL WS where " + "mdsys.sdo_within_distance(ws.geometry.geom, mdsys.sdo_geometry(3, " + "NULL, null, mdsys.sdo_elem_info_array(1,3,4), " + "mdsys.sdo_ordinate_array(1, 0, 0, 1, 0, -1)), " + "NULL) = 'TRUE' ORDER BY GID";
SQLReader reader = new SQLReader(session, sql);
populateTestGeometry(JGeometry.createCircle(1, 0, 0, 1, 0, -1, 0));
ReadAllQuery raq = new ReadAllQuery(WrappedSpatial.class);
ExpressionBuilder eb = raq.getExpressionBuilder();
ExpressionBuilder eb2 = new ExpressionBuilder();
ReportQuery rq = new ReportQuery(WrappedSpatial.class, eb2);
rq.addItem("geom", eb2.get("geometry").getField("geom"));
rq.setSelectionCriteria(eb2.get("id").equal(6666));
Expression geom1 = eb.get("geometry").getField("geom");
Expression selectionCriteria = SpatialExpressionFactory.withinDistance(geom1, rq, new SpatialParameters(""));
selectionCriteria = selectionCriteria.and(eb.get("id").notEqual(6666));
raq.setSelectionCriteria(selectionCriteria);
raq.addAscendingOrdering("id");
List<Spatial> results = (List<Spatial>) session.executeQuery(raq);
String compareResult = reader.compare(results);
assertNull(compareResult, compareResult);
}
Aggregations