Search in sources :

Example 71 with ReadAllQuery

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

the class ExpressionSubSelectTestSuite method addSubSelectEmployeeTest.

private void addSubSelectEmployeeTest() {
    ReadAllQuery query = new ReadAllQuery(Employee.class);
    ExpressionBuilder raqb = new ExpressionBuilder(Employee.class);
    ExpressionBuilder rqb = new ExpressionBuilder();
    ReportQuery rq = new ReportQuery(PhoneNumber.class, rqb);
    Expression exp = rqb.get("id").equal(raqb.get("id"));
    rq.setSelectionCriteria(exp);
    rq.addAttribute("id");
    Expression expression = raqb.get("id").in(rq);
    query.setSelectionCriteria(expression);
    ReadAllExpressionTest test = new ReadAllExpressionTest(Employee.class, 12);
    test.setExpression(expression);
    test.setName("SubSelectEmployeeTest");
    test.setDescription("Test subselects with employees and PhoneNumbers");
    addTest(test);
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) ReportQuery(org.eclipse.persistence.queries.ReportQuery) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 72 with ReadAllQuery

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

the class ReportQueryFunctionTypeTestCase method test.

@Override
public void test() {
    // on all platforms.
    if (getSession().getLogin().getDriverClassName().equals("com.oracle.ias.jdbc.db2.DB2Driver")) {
        throw new TestWarningException("This test is not supported on DB2 DataDirect");
    } else {
        ReportQuery reportQuery = new ReportQuery();
        reportQuery.setReferenceClass(Employee.class);
        ExpressionBuilder builder = reportQuery.getExpressionBuilder();
        reportQuery.addAverage("salary-ave", builder.get("salary"));
        // Oracle specific function.
        if (getSession().getDatasourcePlatform().isOracle()) {
            reportQuery.addVariance("salary-var", builder.get("salary"));
        }
        // Sybase, Symfoware (bug 304909) and TimesTen don't support
        if (!(getSession().getDatasourcePlatform().isSybase() || getSession().getDatasourcePlatform().isTimesTen() || getSession().getDatasourcePlatform().isDerby() || getSession().getDatasourcePlatform().isSymfoware())) {
            reportQuery.addStandardDeviation("salary-std", builder.get("salary"));
        }
        reportQuery.addSum("id-sum", builder.get("id"));
        reportQuery.addMinimum("id-min", builder.get("id"));
        reportQuery.addMaximum("id-max", builder.get("id"));
        if (this.shouldHaveReadAllQueryInDescriptor) {
            ClassDescriptor desc = getSession().getDescriptor(Employee.class);
            if (!desc.getQueryManager().hasReadAllQuery()) {
                desc.getQueryManager().setReadAllQuery(new ReadAllQuery());
                hasSetReadAllQueryIntoDescriptor = true;
            }
        }
        results = (Vector<ReportQueryResult>) getSession().executeQuery(reportQuery);
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ReportQuery(org.eclipse.persistence.queries.ReportQuery) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) TestWarningException(org.eclipse.persistence.testing.framework.TestWarningException) ReportQueryResult(org.eclipse.persistence.queries.ReportQueryResult)

Example 73 with ReadAllQuery

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

the class HierarchicalOneToManyInverseTest method getQuery.

@Override
public ReadAllQuery getQuery() {
    ReadAllQuery query = new ReadAllQuery(Employee.class);
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression startWith = builder.get("firstName").equal("Norman");
    Expression connectBy = builder.get("managedEmployees");
    // Default direction for collections is PARENT_TO_CHILD
    query.setHierarchicalQueryClause(startWith, connectBy, null, CHILD_TO_PARENT);
    return query;
}
Also used : Expression(org.eclipse.persistence.expressions.Expression) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 74 with ReadAllQuery

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

the class BatchReadingStackOverflowTest method setup.

@Override
protected void setup() throws Throwable {
    if ((batchType == BatchFetchType.IN) && !getSession().getPlatform().isOracle()) {
        throwWarning("Nested arrays not supported on this database");
    }
    // set readBatch to true on managedEmployees mapping
    mappingToDisableBatchReadInReset = (ForeignReferenceMapping) getSession().getDescriptor(Employee.class).getMappingForAttributeName("managedEmployees");
    if (mappingToDisableBatchReadInReset.shouldUseBatchReading()) {
        // nothing to do - it already uses batch reading
        mappingToDisableBatchReadInReset = null;
    } else {
        mappingToDisableBatchReadInReset.setUsesBatchReading(true);
        mappingToDisableBatchReadInReset.setBatchFetchType(batchType);
        mappingToDisableBatchReadInReset.getSelectionQuery().setIsPrepared(false);
        ((ReadAllQuery) mappingToDisableBatchReadInReset.getSelectionQuery()).setBatchFetchPolicy(null);
        mappingToDisableBatchReadInReset.getDescriptor().getObjectBuilder().initializeBatchFetchedAttributes();
    }
    // create objects to be used by the test:
    // emp_1 has two managed employees, each of them has one managed employee.
    emp_1 = new Employee();
    emp_1.firstName = firstName;
    emp_1.lastName = "1";
    emp_1.sex = "male";
    emp_1.managedEmployees = new Vector(2);
    Employee emp_1_1 = new Employee();
    emp_1_1.firstName = firstName;
    emp_1_1.lastName = "1_1";
    emp_1_1.sex = "male";
    emp_1_1.managedEmployees = new Vector(1);
    emp_1.managedEmployees.add(emp_1_1);
    emp_1_1.manager = emp_1;
    Employee emp_1_2 = new Employee();
    emp_1_2.firstName = firstName;
    emp_1_2.lastName = "1_2";
    emp_1_2.sex = "male";
    emp_1_2.managedEmployees = new Vector(1);
    emp_1.managedEmployees.add(emp_1_2);
    emp_1_2.manager = emp_1;
    Employee emp_1_1_1 = new Employee();
    emp_1_1_1.firstName = firstName;
    emp_1_1_1.lastName = "1_1_1";
    emp_1_1_1.sex = "male";
    emp_1_1.managedEmployees.add(emp_1_1_1);
    emp_1_1_1.manager = emp_1_1;
    Employee emp_1_2_1 = new Employee();
    emp_1_2_1.firstName = firstName;
    emp_1_2_1.lastName = "1_2_1";
    emp_1_2_1.sex = "male";
    emp_1_2.managedEmployees.add(emp_1_2_1);
    emp_1_2_1.manager = emp_1_2;
    // Begin transaction here and rollback it in reset.
    ((AbstractSession) getSession()).beginTransaction();
    // write the objects into the db, merge them into session's cache.
    UnitOfWork uow = getSession().acquireUnitOfWork();
    uow.registerObject(emp_1);
    uow.commit();
    // now invalidate all the created objects in the session's cache
    getSession().getIdentityMapAccessor().invalidateObject(emp_1);
    getSession().getIdentityMapAccessor().invalidateObject(emp_1_1);
    getSession().getIdentityMapAccessor().invalidateObject(emp_1_2);
    getSession().getIdentityMapAccessor().invalidateObject(emp_1_1_1);
    getSession().getIdentityMapAccessor().invalidateObject(emp_1_2_1);
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.mapping.Employee) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) Vector(java.util.Vector) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 75 with ReadAllQuery

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

the class WriteChanges_NonCachingOLReadQuery_TestCase method test.

@Override
public void test() {
    UnitOfWork uow = getSession().acquireUnitOfWork();
    try {
        Expression expression = (new ExpressionBuilder()).get("firstName").equal("Steve");
        ReadAllQuery query = new ReadAllQuery(Employee.class, expression);
        query.dontMaintainCache();
        uow.executeNonSelectingCall(new SQLCall("UPDATE EMPLOYEE SET F_NAME = 'Steve'"));
        uow.writeChanges();
        // verify that changes are in the database.
        result = (Vector) uow.executeQuery(query);
    } catch (Exception e) {
        exception = e;
    } finally {
        uow.release();
    }
}
Also used : SQLCall(org.eclipse.persistence.queries.SQLCall) UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Expression(org.eclipse.persistence.expressions.Expression) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

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