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