Search in sources :

Example 1 with SpatialParameters

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();
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) SimpleSpatial(org.eclipse.persistence.testing.models.jpa.structconverter.SimpleSpatial) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) Query(jakarta.persistence.Query) Expression(org.eclipse.persistence.expressions.Expression) JGeometry(oracle.spatial.geometry.JGeometry) SpatialParameters(org.eclipse.persistence.expressions.spatial.SpatialParameters) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 2 with SpatialParameters

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);
}
Also used : SQLReader(org.eclipse.persistence.testing.tests.spatial.jgeometry.SQLReader) Expression(org.eclipse.persistence.expressions.Expression) Spatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.Spatial) WrappedSpatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.WrappedSpatial) ReportQuery(org.eclipse.persistence.queries.ReportQuery) SpatialParameters(org.eclipse.persistence.expressions.spatial.SpatialParameters) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) List(java.util.List) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 3 with SpatialParameters

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);
}
Also used : SQLReader(org.eclipse.persistence.testing.tests.spatial.jgeometry.SQLReader) Expression(org.eclipse.persistence.expressions.Expression) Spatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.Spatial) WrappedSpatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.WrappedSpatial) ReportQuery(org.eclipse.persistence.queries.ReportQuery) SpatialParameters(org.eclipse.persistence.expressions.spatial.SpatialParameters) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) List(java.util.List) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 4 with SpatialParameters

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);
}
Also used : SQLReader(org.eclipse.persistence.testing.tests.spatial.jgeometry.SQLReader) Expression(org.eclipse.persistence.expressions.Expression) Spatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.Spatial) WrappedSpatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.WrappedSpatial) ReportQuery(org.eclipse.persistence.queries.ReportQuery) SpatialParameters(org.eclipse.persistence.expressions.spatial.SpatialParameters) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) List(java.util.List) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 5 with SpatialParameters

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);
}
Also used : SQLReader(org.eclipse.persistence.testing.tests.spatial.jgeometry.SQLReader) Expression(org.eclipse.persistence.expressions.Expression) Spatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.Spatial) WrappedSpatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.WrappedSpatial) ReportQuery(org.eclipse.persistence.queries.ReportQuery) SpatialParameters(org.eclipse.persistence.expressions.spatial.SpatialParameters) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) List(java.util.List) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Aggregations

Expression (org.eclipse.persistence.expressions.Expression)81 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)81 SpatialParameters (org.eclipse.persistence.expressions.spatial.SpatialParameters)81 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)81 List (java.util.List)78 Spatial (org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.Spatial)76 SimpleSpatial (org.eclipse.persistence.testing.models.spatial.jgeometry.SimpleSpatial)41 WrappedSpatial (org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.WrappedSpatial)39 SQLReader (org.eclipse.persistence.testing.tests.spatial.jgeometry.SQLReader)38 JGeometry (oracle.spatial.geometry.JGeometry)27 ReportQuery (org.eclipse.persistence.queries.ReportQuery)26 TestSetup (junit.extensions.TestSetup)2 TestSuite (junit.framework.TestSuite)2 TestProblemException (org.eclipse.persistence.testing.framework.TestProblemException)2 EntityManager (jakarta.persistence.EntityManager)1 Query (jakarta.persistence.Query)1 SimpleSpatial (org.eclipse.persistence.testing.models.jpa.structconverter.SimpleSpatial)1