Search in sources :

Example 1 with ReadObjectQuery

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

the class IsolatedEmployeeProject method buildIsolatedParentDescriptor.

public RelationalDescriptor buildIsolatedParentDescriptor() {
    RelationalDescriptor descriptor = new RelationalDescriptor();
    descriptor.setJavaClass(IsolatedParent.class);
    descriptor.addTableName("ISOLATED_PARENT");
    descriptor.addPrimaryKeyFieldName("ISOLATED_PARENT.ID");
    // ClassDescriptor Properties.
    descriptor.useFullIdentityMap();
    descriptor.setIdentityMapSize(100);
    descriptor.useRemoteFullIdentityMap();
    descriptor.setRemoteIdentityMapSize(100);
    descriptor.setSequenceNumberFieldName("ISOLATED_PARENT.ID");
    descriptor.setSequenceNumberName("PARENT_SEQ");
    // IMPORTANT!
    descriptor.alwaysConformResultsInUnitOfWork();
    descriptor.setCacheIsolation(CacheIsolationType.ISOLATED);
    descriptor.setAlias("IsolatedParent");
    descriptor.setCacheSynchronizationType(ClassDescriptor.DO_NOT_SEND_CHANGES);
    descriptor.setAmendmentClass(IsolatedParent.class);
    descriptor.setAmendmentMethodName("afterLoad");
    // Query Manager.
    descriptor.getQueryManager().checkCacheForDoesExist();
    // Named Queries.
    // Named Query -- findParentBySerial
    ReadObjectQuery namedQuery0 = new ReadObjectQuery(IsolatedParent.class);
    namedQuery0.setName("findParentBySerial");
    namedQuery0.setShouldBindAllParameters(true);
    ExpressionBuilder expBuilder0 = namedQuery0.getExpressionBuilder();
    namedQuery0.setSelectionCriteria(expBuilder0.get("serial").equal(expBuilder0.getParameter("serial_p")));
    namedQuery0.addArgument("serial_p", java.lang.String.class);
    descriptor.getQueryManager().addQuery("findParentBySerial", namedQuery0);
    // Event Manager.
    // Mappings.
    DirectToFieldMapping idMapping = new DirectToFieldMapping();
    idMapping.setAttributeName("id");
    idMapping.setFieldName("ISOLATED_PARENT.ID");
    descriptor.addMapping(idMapping);
    DirectToFieldMapping serialMapping = new DirectToFieldMapping();
    serialMapping.setAttributeName("serial");
    serialMapping.setFieldName("ISOLATED_PARENT.SERIAL");
    descriptor.addMapping(serialMapping);
    OneToManyMapping childrenMapping = new OneToManyMapping();
    childrenMapping.setAttributeName("children");
    childrenMapping.setReferenceClass(IsolatedChild.class);
    childrenMapping.useTransparentCollection();
    childrenMapping.useCollectionClass(org.eclipse.persistence.indirection.IndirectList.class);
    childrenMapping.addTargetForeignKeyFieldName("ISOLATED_CHILD.PARENT_ID", "ISOLATED_PARENT.ID");
    childrenMapping.privateOwnedRelationship();
    descriptor.addMapping(childrenMapping);
    return descriptor;
}
Also used : DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) RelationalDescriptor(org.eclipse.persistence.descriptors.RelationalDescriptor) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) OneToManyMapping(org.eclipse.persistence.mappings.OneToManyMapping) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder)

Example 2 with ReadObjectQuery

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

the class Runner1 method run.

@Override
public void run() {
    UnitOfWorkImpl uow = (UnitOfWorkImpl) this.session.acquireUnitOfWork();
    ReadObjectQuery roq = new ReadObjectQuery(Employee.class);
    roq.setSelectionCriteria(roq.getExpressionBuilder().get("id").equal(empPK));
    Employee emp = (Employee) uow.executeQuery(roq);
    roq = new ReadObjectQuery(SmallProject.class);
    roq.setSelectionCriteria(roq.getExpressionBuilder().get("id").equal(projPK));
    SmallProject project = (SmallProject) uow.executeQuery(roq);
    emp.getProjects().add(project);
    try {
        Thread.sleep(4000);
    } catch (InterruptedException e) {
    }
    uow.issueSQLbeforeCompletion(true);
    synchronized (this.waitOn) {
        try {
            this.waitOn.notify();
            this.waitOn.wait();
        } catch (InterruptedException e) {
        }
    }
    CacheKey cacheKey = uow.getParent().getIdentityMapAccessorInstance().getCacheKeyForObject(emp);
    synchronized (cacheKey) {
        cacheKey.notify();
    }
    try {
        Thread.sleep(4000);
    } catch (InterruptedException e) {
    }
    uow.mergeClonesAfterCompletion();
}
Also used : SmallProject(org.eclipse.persistence.testing.models.employee.domain.SmallProject) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) UnitOfWorkImpl(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl) CacheKey(org.eclipse.persistence.internal.identitymaps.CacheKey)

Example 3 with ReadObjectQuery

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

the class InvalidateObjectWithMissingReferenceTest method setup.

@Override
public void setup() {
    oldCacheSyncConfigValues = new Hashtable();
    Enumeration keys = cacheSyncConfigValues.keys();
    while (keys.hasMoreElements()) {
        Class<?> keyClass = (Class) keys.nextElement();
        ClassDescriptor descriptor = getSession().getDescriptor(keyClass);
        if (descriptor != null) {
            int cacheSyncType = descriptor.getCacheSynchronizationType();
            Object newCacheSyncType = cacheSyncConfigValues.get(keyClass);
            if (newCacheSyncType != null) {
                oldCacheSyncConfigValues.put(keyClass, cacheSyncType);
                descriptor.setCacheSynchronizationType((Integer) newCacheSyncType);
            }
        }
    }
    getSession().getIdentityMapAccessor().initializeAllIdentityMaps();
    this.originalObject = (Employee) getSession().readObject(Employee.class);
    this.originalAddress = this.originalObject.getAddress();
    this.query = new ReadObjectQuery();
    this.query.setSelectionObject(this.originalObject);
    this.server = (DistributedServer) DistributedServersModel.getDistributedServers().get(0);
    getEmployeeFromDistributedSession(this.query);
}
Also used : Enumeration(java.util.Enumeration) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) Hashtable(java.util.Hashtable)

Example 4 with ReadObjectQuery

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

the class QueryShouldMaintainCacheTest method verify.

@Override
public void verify() {
    ClassDescriptor descriptor = project.getDescriptors().get(org.eclipse.persistence.testing.models.employee.domain.Employee.class);
    // Here we test the maintainCache setting.  This should override any other settings.
    ReadObjectQuery query = (ReadObjectQuery) descriptor.getQueryManager().getQuery("TrueQuery");
    if (/*getSession()*/
    !query.shouldMaintainCache() || !query.shouldMaintainCache()) {
        throw new TestErrorException("Project read from XML should be set to maintainCache, but is not.");
    }
    // Here we test the donMaintainceCacheSetting.  This should override other settings.
    query = (ReadObjectQuery) descriptor.getQueryManager().getQuery("FalseQuery");
    if (/*getSession()*/
    query.shouldMaintainCache() || query.shouldMaintainCache()) {
        throw new TestErrorException("Project read from XML should be set not to maintainCache, but it does.");
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 5 with ReadObjectQuery

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

the class QueryShouldMaintainCacheTest method setup.

@Override
public void setup() {
    project = new EmployeeProject();
    ClassDescriptor descriptor = project.getDescriptors().get(org.eclipse.persistence.testing.models.employee.domain.Employee.class);
    descriptor.disableCacheHits();
    // ReadObjectQuery query = new ReadObjectQuery(Employee.class);
    // descriptor.getQueryManager().addQuery("UndefinedQuery", query);
    ReadObjectQuery query = new ReadObjectQuery(Employee.class);
    query.maintainCache();
    descriptor.getQueryManager().addQuery("TrueQuery", query);
    query = new ReadObjectQuery(Employee.class);
    query.dontMaintainCache();
    descriptor.getQueryManager().addQuery("FalseQuery", query);
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) EmployeeProject(org.eclipse.persistence.testing.models.employee.relational.EmployeeProject)

Aggregations

ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)199 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)80 Expression (org.eclipse.persistence.expressions.Expression)66 Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)38 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)35 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)28 EntityManager (jakarta.persistence.EntityManager)18 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)16 PersistenceException (jakarta.persistence.PersistenceException)9 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)9 DynamicEntity (org.eclipse.persistence.dynamic.DynamicEntity)9 Test (org.junit.Test)9 QueryException (org.eclipse.persistence.exceptions.QueryException)8 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)7 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)7 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)7 EJBQueryImpl (org.eclipse.persistence.internal.jpa.EJBQueryImpl)6 MapContainerPolicy (org.eclipse.persistence.internal.queries.MapContainerPolicy)6 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)6 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)6