Search in sources :

Example 11 with ReadAllQuery

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;
    }
}
Also used : ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery)

Example 12 with ReadAllQuery

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();
            }
        }
    };
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Cursor(org.eclipse.persistence.queries.Cursor)

Example 13 with ReadAllQuery

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");
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) EmployeePopulator(org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) UnitOfWorkImpl(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl) Vector(java.util.Vector) BigDecimal(java.math.BigDecimal)

Example 14 with ReadAllQuery

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());
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) PhoneNumber(org.eclipse.persistence.testing.models.employee.domain.PhoneNumber) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Vector(java.util.Vector)

Example 15 with ReadAllQuery

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) {
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) UnitOfWorkImpl(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl) Vector(java.util.Vector)

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