use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.
the class RefreshWithCheckCacheOnlyTest method test.
@Override
protected void test() {
try {
ReadAllQuery query = new ReadAllQuery(Employee.class);
ExpressionBuilder emp = new ExpressionBuilder(Employee.class);
Expression expression = emp.get("firstName").equal("Bob").or(emp.get("firstName").equal("Jill")).or(emp.get("firstName").equal("John"));
query.setSelectionCriteria(expression);
query.checkCacheOnly();
query.refreshIdentityMapResult();
getSession().executeQuery(query);
} catch (EclipseLinkException ex) {
caughtException = ex;
}
}
use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.
the class ConcurrentRefreshOnUpdateTest method runnable.
public Runnable runnable() {
return new Runnable() {
@Override
public void run() {
if (writer) {
UnitOfWork uow = session.acquireUnitOfWork();
Employee empClone = (Employee) uow.registerObject(ConcurrentRefreshOnUpdateTest.lock);
empClone.setFirstName("The New City Name" + System.currentTimeMillis());
synchronized (ConcurrentRefreshOnUpdateTest.lock) {
if (ConcurrentRefreshOnUpdateTest.readerWaiting) {
ConcurrentRefreshOnUpdateTest.lock.notifyAll();
} else {
ConcurrentRefreshOnUpdateTest.writerWaiting = true;
try {
ConcurrentRefreshOnUpdateTest.lock.wait(30000);
} catch (InterruptedException ex) {
// ignore
}
ConcurrentRefreshOnUpdateTest.writerWaiting = false;
}
}
uow.commit();
} else {
ReadAllQuery query = new ReadAllQuery(Employee.class);
query.setShouldRefreshIdentityMapResult(true);
query.useCursoredStream(0, 1);
query.setSelectionCriteria(new ExpressionBuilder().get("id").equal(ConcurrentRefreshOnUpdateTest.lock.getId()));
Cursor cursor = (Cursor) session.executeQuery(query);
// wait for both thread to set up
synchronized (ConcurrentRefreshOnUpdateTest.lock) {
if (ConcurrentRefreshOnUpdateTest.writerWaiting) {
ConcurrentRefreshOnUpdateTest.lock.notifyAll();
} else {
ConcurrentRefreshOnUpdateTest.readerWaiting = true;
try {
ConcurrentRefreshOnUpdateTest.lock.wait(30000);
} catch (InterruptedException ex) {
// ignore
}
ConcurrentRefreshOnUpdateTest.readerWaiting = false;
}
}
Thread.yield();
// writer is commiting, wait for postMerge event
synchronized (ConcurrentRefreshOnUpdateTest.lock) {
if (!ConcurrentRefreshOnUpdateTest.writerWaiting) {
ConcurrentRefreshOnUpdateTest.readerWaiting = true;
try {
ConcurrentRefreshOnUpdateTest.lock.wait(30000);
} catch (InterruptedException ex) {
}
// ignore
ConcurrentRefreshOnUpdateTest.readerWaiting = false;
}
}
if (cursor.hasMoreElements()) {
cursor.nextElement();
}
cursor.close();
}
}
};
}
use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.
the class NestedUnitOfWorkDeleteConformedNestedNewObjectTest method test.
@Override
public void test() {
UnitOfWork uow = getSession().acquireUnitOfWork();
UnitOfWork nestedUow1 = uow.acquireUnitOfWork();
Employee employee = (Employee) new EmployeePopulator().basicEmployeeExample1();
employee.setId(new BigDecimal(15));
nestedUow1.registerObject(employee);
nestedUow1.commit();
nestedUow1 = uow.acquireUnitOfWork();
ReadAllQuery query = new ReadAllQuery();
query.setReferenceClass(Employee.class);
query.setSelectionCriteria(new org.eclipse.persistence.expressions.ExpressionBuilder().get("id").equal(new BigDecimal(15)));
query.conformResultsInUnitOfWork();
Vector results = (Vector) nestedUow1.executeQuery(query);
if (results.size() > 1) {
throw new TestErrorException("The read all query on primary key returned more than one object see bug # 3183379");
}
Employee nestedEmployee = (Employee) results.firstElement();
nestedUow1.deleteObject(nestedEmployee);
nestedUow1.commit();
if (!((UnitOfWorkImpl) uow).getNewObjectsCloneToOriginal().isEmpty()) {
throw new TestErrorException("Failed to unregister the Object in the nested unit of work");
}
}
use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.
the class NestedUnitOfWorkDeleteFromNestedObjectTest method test.
@Override
public void test() {
UnitOfWork uow = getSession().acquireUnitOfWork();
UnitOfWork nestedUow1 = uow.acquireUnitOfWork();
ReadAllQuery query = new ReadAllQuery();
query.setReferenceClass(Employee.class);
ExpressionBuilder expressionBuilder = new ExpressionBuilder();
query.setSelectionCriteria(expressionBuilder.get("firstName").equal("Bob").and(expressionBuilder.get("lastName").equal("Smith")));
query.conformResultsInUnitOfWork();
Vector<Employee> results = (Vector<Employee>) uow.executeQuery(query);
Employee employee = results.firstElement();
Employee employeeNested = (Employee) nestedUow1.registerObject(employee);
assertTrue(employeeNested.getPhoneNumbers().size() > 0);
for (PhoneNumber item : new Vector<PhoneNumber>(employeeNested.getPhoneNumbers())) {
if (item != null) {
nestedUow1.deleteObject(item);
employeeNested.removePhoneNumber(item);
}
}
nestedUow1.deleteObject(employeeNested);
nestedUow1.commitAndResume();
if (employee.getPhoneNumbers().size() != 0) {
throw new TestErrorException("Objects removal from the nested unit of work is not merged into outer/main unit of work. Number of remaining objects is: " + employee.getPhoneNumbers().size());
}
}
use of org.eclipse.persistence.queries.ReadAllQuery in project eclipselink by eclipse-ee4j.
the class NewObjectIdentityTest method test.
@Override
public void test() {
UnitOfWork uow = getSession().acquireUnitOfWork();
origPerson = new Employee();
Employee person = (Employee) uow.registerObject(origPerson);
person.setFirstName("Anthony");
person.setLastName("Anthony");
((UnitOfWorkImpl) uow).issueSQLbeforeCompletion();
Runnable runnable = new Runnable() {
@Override
public void run() {
ReadAllQuery query = new ReadAllQuery(Employee.class);
query.setSelectionCriteria(query.getExpressionBuilder().get("firstName").equal("Anthony").and(query.getExpressionBuilder().get("lastName").equal("Anthony")));
readPerson = (Employee) ((Vector) getSession().executeQuery(query)).firstElement();
}
};
Thread thread = new Thread(runnable);
thread.start();
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
}
((UnitOfWorkImpl) uow).mergeClonesAfterCompletion();
try {
thread.join();
} catch (InterruptedException ex) {
}
}
Aggregations