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);
}
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);
}
}
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;
}
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);
}
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();
}
}
Aggregations