Search in sources :

Example 16 with ReadAllQuery

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

the class MemoryQueryReturnConfirmedTest method test.

@Override
public void test() {
    ReadAllQuery queryAllCopy = (ReadAllQuery) queryAll.clone();
    // read from cache only
    queryAllCopy.checkCacheOnly();
    queryAllCopy.setSelectionCriteria(new ExpressionBuilder().get("address").get("city").equal("Montreal"));
    inMemoryResult = (Vector) getSession().executeQuery(queryAllCopy);
}
Also used : ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 17 with ReadAllQuery

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

the class MemoryQueryTriggerIndirectionTest method test.

@Override
public void test() {
    ReadAllQuery queryAllCopy = (ReadAllQuery) queryAll.clone();
    // read from cache only
    queryAllCopy.checkCacheOnly();
    queryAllCopy.setSelectionCriteria(new ExpressionBuilder().get("address").get("city").notEqual("Montreal"));
    inMemoryResult = (Vector) getSession().executeQuery(queryAllCopy);
}
Also used : ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 18 with ReadAllQuery

use of org.eclipse.persistence.queries.ReadAllQuery 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 19 with ReadAllQuery

use of org.eclipse.persistence.queries.ReadAllQuery 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 20 with ReadAllQuery

use of org.eclipse.persistence.queries.ReadAllQuery 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)

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