Search in sources :

Example 26 with ReadAllQuery

use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.

the class Query_SpatialOp_ExpReport_Tests method testSDOWithinDistanceArbitraryLine.

/**
 * SDO_WITHIN_DISTANCE using an arbitrary line string {(10,10), (20, 20), (30, 30), (45,45)}
 */
public void testSDOWithinDistanceArbitraryLine() throws Exception {
    String sql = "select GID, GEOMETRY FROM WRAPPED_SPATIAL WS where " + "mdsys.sdo_within_distance(ws.geometry.geom, " + "mdsys.sdo_geometry(2,null,null, " + "mdsys.sdo_elem_info_array(1,2,1), " + "mdsys.sdo_ordinate_array(10,10, 20,20, 30,30, 45,45)), " + "'DISTANCE=10') = 'TRUE' ORDER BY GID";
    SQLReader reader = new SQLReader(session, sql);
    double[] points = new double[] { 10, 10, 20, 20, 30, 30, 45, 45 };
    populateTestGeometry(JGeometry.createLinearLineString(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.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);
    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 27 with ReadAllQuery

use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.

the class Query_SpatialExpOp_ExpGeom_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);
    JGeometry circle = JGeometry.createCircle(10, 0, 0, 10, 0, -10, 0);
    ReadAllQuery raq = new ReadAllQuery(WrappedSpatial.class);
    ExpressionBuilder eb = raq.getExpressionBuilder();
    String params = "";
    Expression selectionCriteria = SpatialExpressionFactory.withinDistance(eb.get("geometry").getField("geom"), circle, new SpatialParameters(params));
    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) JGeometry(oracle.spatial.geometry.JGeometry) 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 ReadAllQuery

use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.

the class Query_SpatialExpOp_ExpGeom_Tests method testSDOWithinDistanceCircle.

/**
 * SDO_WITHIN_DISTANCE using a with a circle of radius 10 around (0,0)
 */
public void testSDOWithinDistanceCircle() 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, 10, 0)), " + "'DISTANCE=10') = 'TRUE' ORDER BY GID";
    SQLReader reader = new SQLReader(session, sql);
    JGeometry circle = JGeometry.createCircle(-10, 0, 0, 10, 10, 0, 0);
    ReadAllQuery raq = new ReadAllQuery(WrappedSpatial.class);
    ExpressionBuilder eb = raq.getExpressionBuilder();
    String params = "DISTANCE=10";
    Expression selectionCriteria = SpatialExpressionFactory.withinDistance(eb.get("geometry").getField("geom"), circle, new SpatialParameters(params));
    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) JGeometry(oracle.spatial.geometry.JGeometry) 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 ReadAllQuery

use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.

the class Query_SpatialOp_ExpExp_Tests method testSDORelateCircle.

/**
 * SDO_RELATE using a with a circle of radius 10 around (0,0)
 */
public void testSDORelateCircle() throws Exception {
    String sql = "select GID, GEOMETRY FROM WRAPPED_SPATIAL WS where mdsys.sdo_relate(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, 10, 0)), " + "'MASK=ANYINTERACT QUERYTYPE=WINDOW') = 'TRUE' ORDER BY GID";
    SQLReader reader = new SQLReader(session, sql);
    populateTestGeometry(JGeometry.createCircle(-10, 0, 0, 10, 10, 0, 0));
    ReadAllQuery raq = new ReadAllQuery(WrappedSpatial.class);
    ExpressionBuilder eb = raq.getExpressionBuilder();
    // Expression geom1 = SpatialOperator.getExpression("geometry.geom", eb);
    ExpressionBuilder eb2 = new ExpressionBuilder(WrappedSpatial.class);
    /*      Expression geom2 = SpatialOperator.getExpression("geometry.geom", eb2);

        SpatialOperator relate =
            SpatialOperator.relate().setMask(Mask.ANYINTERACT).setQueryType(QueryType.WINDOW);

        raq.setSelectionCriteria(relate.buildExpression(geom1,
                                                        geom2).and(eb.get("id").notEqual(6666).and(eb2.get("id").equal(6666))));
*/
    SpatialParameters parameters = new SpatialParameters();
    parameters.setMask(Mask.ANYINTERACT).setQueryType(QueryType.WINDOW);
    Expression selectionCriteria = SpatialExpressionFactory.relate(eb.get("geometry").getField("geom"), eb2.get("geometry").getField("geom"), parameters);
    selectionCriteria = selectionCriteria.and(eb.get("id").notEqual(6666).and(eb2.get("id").equal(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) SpatialParameters(org.eclipse.persistence.expressions.spatial.SpatialParameters) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) List(java.util.List) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 30 with ReadAllQuery

use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.

the class Query_SpatialOp_ExpExp_Tests method testSDOFilterCircle.

/**
 * SDO_FILTER using a with a circle of radius 10 around (0,0)
 */
public void testSDOFilterCircle() 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,4), " + "mdsys.sdo_ordinate_array(-10,0, 0, 10, 10, 0)), " + "'QUERYTYPE=WINDOW') = 'TRUE' ORDER BY GID";
    SQLReader reader = new SQLReader(session, sql);
    populateTestGeometry(JGeometry.createCircle(-10, 0, 0, 10, 10, 0, 0));
    ReadAllQuery raq = new ReadAllQuery(WrappedSpatial.class);
    ExpressionBuilder eb = raq.getExpressionBuilder();
    // Expression geom1 = SpatialOperator.getExpression("geometry.geom", eb);
    ExpressionBuilder eb2 = new ExpressionBuilder(WrappedSpatial.class);
    /*    Expression geom2 = SpatialOperator.getExpression("geometry.geom", eb2);

        SpatialOperator filter =
            SpatialOperator.filter().setQueryType(QueryType.WINDOW);

        raq.setSelectionCriteria(filter.buildExpression(geom1,
                                                        geom2).and(eb.get("id").notEqual(6666).and(eb2.get("id").equal(6666))));
 */
    SpatialParameters parameters = new SpatialParameters();
    parameters.setQueryType(QueryType.WINDOW);
    Expression selectionCriteria = SpatialExpressionFactory.filter(eb.get("geometry").getField("geom"), eb2.get("geometry").getField("geom"), parameters);
    selectionCriteria = selectionCriteria.and(eb.get("id").notEqual(6666).and(eb2.get("id").equal(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) SpatialParameters(org.eclipse.persistence.expressions.spatial.SpatialParameters) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) List(java.util.List) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Aggregations

ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)440 Expression (org.eclipse.persistence.expressions.Expression)278 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)265 List (java.util.List)202 EntityManager (jakarta.persistence.EntityManager)135 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)119 Vector (java.util.Vector)112 ArrayList (java.util.ArrayList)88 Spatial (org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.Spatial)82 SpatialParameters (org.eclipse.persistence.expressions.spatial.SpatialParameters)81 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)62 ReportQuery (org.eclipse.persistence.queries.ReportQuery)57 SimpleSpatial (org.eclipse.persistence.testing.models.spatial.jgeometry.SimpleSpatial)47 WrappedSpatial (org.eclipse.persistence.testing.models.spatial.jgeometry.wrapped.WrappedSpatial)44 SQLReader (org.eclipse.persistence.testing.tests.spatial.jgeometry.SQLReader)41 JGeometry (oracle.spatial.geometry.JGeometry)30 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)29 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)28 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)27 Query (jakarta.persistence.Query)25