Search in sources :

Example 26 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 SIMPLE_SPATIAL where mdsys.sdo_within_distance(" + "geometry, 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(SimpleSpatial.class);
    ExpressionBuilder eb = raq.getExpressionBuilder();
    Expression geom1 = eb.get("geometry");
    ExpressionBuilder eb2 = new ExpressionBuilder();
    ReportQuery rq = new ReportQuery(SimpleSpatial.class, eb2);
    rq.addAttribute("geometry");
    rq.setSelectionCriteria(eb2.get("id").equal(6666));
    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) session.executeQuery(raq);
    String compareResult = reader.compare(results);
    assertNull(compareResult, compareResult);
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) SimpleSpatial(org.eclipse.persistence.testing.models.spatial.jgeometry.SimpleSpatial) Spatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.Spatial) 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 27 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 SIMPLE_SPATIAL where mdsys.sdo_filter(" + "geometry, 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(SimpleSpatial.class);
    ExpressionBuilder eb = raq.getExpressionBuilder();
    Expression geom1 = eb.get("geometry");
    ExpressionBuilder eb2 = new ExpressionBuilder();
    ReportQuery rq = new ReportQuery(SimpleSpatial.class, eb2);
    rq.addAttribute("geometry");
    rq.setSelectionCriteria(eb2.get("id").equal(6666));
    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) session.executeQuery(raq);
    String compareResult = reader.compare(results);
    assertNull(compareResult, compareResult);
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) SimpleSpatial(org.eclipse.persistence.testing.models.spatial.jgeometry.SimpleSpatial) Spatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.Spatial) 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 28 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 SIMPLE_SPATIAL where " + "mdsys.sdo_within_distance(geometry, 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(SimpleSpatial.class);
    ExpressionBuilder eb = raq.getExpressionBuilder();
    Expression geom1 = eb.get("geometry");
    ExpressionBuilder eb2 = new ExpressionBuilder();
    ReportQuery rq = new ReportQuery(SimpleSpatial.class, eb2);
    rq.addAttribute("geometry");
    rq.setSelectionCriteria(eb2.get("id").equal(6666));
    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) session.executeQuery(raq);
    String compareResult = reader.compare(results);
    assertNull(compareResult, compareResult);
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) SimpleSpatial(org.eclipse.persistence.testing.models.spatial.jgeometry.SimpleSpatial) Spatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.Spatial) 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 29 with SpatialParameters

use of org.eclipse.persistence.expressions.spatial.SpatialParameters in project eclipselink by eclipse-ee4j.

the class NamedQueryTests method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.setName("NamedQueryTests");
    suite.addTest(new NamedQueryTests("testNamedSessionQueryNoBinding"));
    suite.addTest(new NamedQueryTests("testNamedSessionQueryBindAllParameters"));
    suite.addTest(new NamedQueryTests("testNamedSessionQueryBindQueryParameters"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryNoBinding"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryBindAllParameter"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryBindQueryParameter"));
    return new TestSetup(suite) {

        protected void setUp() {
            try {
                SimpleSpatialTestCase.repopulate(getSession(), true);
                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("geometry"), eb.getParameter("GEOMETRY"), parameters);
                raq.setSelectionCriteria(selectionCriteria);
                raq.addAscendingOrdering("id");
                raq.addArgument("GEOMETRY", JGeometry.class);
                getSession().addQuery(SESSION_QUERY_NAME, raq);
                raq = new ReadAllQuery(SimpleSpatial.class);
                eb = raq.getExpressionBuilder();
                parameters = new SpatialParameters();
                parameters.setDistance(10d);
                selectionCriteria = SpatialExpressionFactory.withinDistance(eb.get("geometry"), eb.getParameter("GEOMETRY"), parameters);
                raq.setSelectionCriteria(selectionCriteria);
                raq.addAscendingOrdering("id");
                raq.addArgument("GEOMETRY", JGeometry.class);
                getSession().getClassDescriptor(SimpleSpatial.class).getDescriptorQueryManager().addQuery(DESCRIPTOR_QUERY_NAME, raq);
            } catch (Exception e) {
                throw new TestProblemException("Could not setup JGeometry test model", e);
            }
        }

        protected void tearDown() {
            try {
                getSession().removeQuery(SESSION_QUERY_NAME);
                getSession().getClassDescriptor(SimpleSpatial.class).getDescriptorQueryManager().removeQuery(DESCRIPTOR_QUERY_NAME);
            } catch (Exception e) {
                throw new TestProblemException("Could not tearDown NamedQueryTests for SimpleSpatialTestCase.", e);
            }
        }
    };
}
Also used : TestSetup(junit.extensions.TestSetup) SimpleSpatial(org.eclipse.persistence.testing.models.spatial.jgeometry.SimpleSpatial) TestSuite(junit.framework.TestSuite) Expression(org.eclipse.persistence.expressions.Expression) SpatialParameters(org.eclipse.persistence.expressions.spatial.SpatialParameters) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException)

Example 30 with SpatialParameters

use of org.eclipse.persistence.expressions.spatial.SpatialParameters in project eclipselink by eclipse-ee4j.

the class NamedQueryTests method suite.

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.setName("NamedQueryTests");
    suite.addTest(new NamedQueryTests("testNamedSessionQueryNoBinding"));
    suite.addTest(new NamedQueryTests("testNamedSessionQueryBindAllParameters"));
    suite.addTest(new NamedQueryTests("testNamedSessionQueryBindQueryParameters"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryNoBinding"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryBindAllParameter"));
    suite.addTest(new NamedQueryTests("testDescriptorNamedQueryBindQueryParameter"));
    return new TestSetup(suite) {

        protected void setUp() {
            try {
                WrappedSpatialTestCase.repopulate(getSession(), true);
                ReadAllQuery raq = new ReadAllQuery(WrappedSpatial.class);
                ExpressionBuilder eb = raq.getExpressionBuilder();
                SpatialParameters parameters = new SpatialParameters();
                parameters.setMask(Mask.ANYINTERACT).setQueryType(QueryType.WINDOW);
                Expression selectionCriteria = SpatialExpressionFactory.relate(eb.get("geometry").getField("geom"), eb.getParameter("GEOMETRY"), parameters);
                raq.setSelectionCriteria(selectionCriteria);
                raq.addAscendingOrdering("id");
                raq.addArgument("GEOMETRY", JGeometry.class);
                getSession().addQuery(SESSION_QUERY_NAME, raq);
                raq = new ReadAllQuery(WrappedSpatial.class);
                eb = raq.getExpressionBuilder();
                parameters = new SpatialParameters();
                parameters.setDistance(10d);
                selectionCriteria = SpatialExpressionFactory.withinDistance(eb.get("geometry").getField("geom"), eb.getParameter("GEOMETRY"), parameters);
                raq.setSelectionCriteria(selectionCriteria);
                raq.addAscendingOrdering("id");
                raq.addArgument("GEOMETRY", MyGeometry.class);
                getSession().getClassDescriptor(WrappedSpatial.class).getDescriptorQueryManager().addQuery(DESCRIPTOR_QUERY_NAME, raq);
            } catch (Exception e) {
                throw new TestProblemException("Could not setup JGeometry test model. Note: This model requires you to run the following CREATE OR REPLACE TYPE MY_GEOMETRY AS OBJECT (id NUMBER, geom MDSYS.SDO_GEOMETRY): ", e);
            }
        }

        protected void tearDown() {
            try {
                getSession().removeQuery(SESSION_QUERY_NAME);
                getSession().getClassDescriptor(WrappedSpatial.class).getDescriptorQueryManager().removeQuery(DESCRIPTOR_QUERY_NAME);
            } catch (Exception e) {
                throw new TestProblemException("Could not tearDown NamedQueryTests for SimpleSpatialTestCase.", e);
            }
        }
    };
}
Also used : TestSetup(junit.extensions.TestSetup) WrappedSpatial(org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.WrappedSpatial) TestSuite(junit.framework.TestSuite) Expression(org.eclipse.persistence.expressions.Expression) SpatialParameters(org.eclipse.persistence.expressions.spatial.SpatialParameters) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) TestProblemException(org.eclipse.persistence.testing.framework.TestProblemException)

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