use of org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class GetAllFromIdentityMapTest method newReadAllQuery.
/**
* Create an instance of {@link ReadAllQuery} and initialize it.
*
* @param c entity class
* @return new instance of initialized {@link ReadAllQuery}
*/
private static ReadAllQuery newReadAllQuery(Class<?> c) {
final ReadAllQuery query = new ReadAllQuery(c);
query.conformResultsInUnitOfWork();
query.setInMemoryQueryIndirectionPolicy(new InMemoryQueryIndirectionPolicy(InMemoryQueryIndirectionPolicy.SHOULD_TRIGGER_INDIRECTION));
return query;
}
use of org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject method buildObjectLevelReadQueryDescriptor.
protected ClassDescriptor buildObjectLevelReadQueryDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(ObjectLevelReadQuery.class);
descriptor.getInheritancePolicy().setParentClass(ReadQuery.class);
XMLDirectMapping referenceClassMapping = new XMLDirectMapping();
referenceClassMapping.setAttributeName("referenceClass");
referenceClassMapping.setGetMethodName("getReferenceClass");
referenceClassMapping.setSetMethodName("setReferenceClass");
referenceClassMapping.setXPath(getPrimaryNamespaceXPath() + "reference-class/text()");
descriptor.addMapping(referenceClassMapping);
XMLDirectMapping refreshIdentityMapping = new XMLDirectMapping();
refreshIdentityMapping.setAttributeName("shouldRefreshIdentityMapResult");
refreshIdentityMapping.setGetMethodName("shouldRefreshIdentityMapResult");
refreshIdentityMapping.setSetMethodName("setShouldRefreshIdentityMapResult");
refreshIdentityMapping.setXPath(getPrimaryNamespaceXPath() + "refresh/text()");
refreshIdentityMapping.setNullValue(Boolean.FALSE);
descriptor.addMapping(refreshIdentityMapping);
XMLDirectMapping refreshRemoteIdentityMapping = new XMLDirectMapping();
refreshRemoteIdentityMapping.setAttributeName("shouldRefreshRemoteIdentityMapResult");
refreshRemoteIdentityMapping.setGetMethodName("shouldRefreshRemoteIdentityMapResult");
refreshRemoteIdentityMapping.setSetMethodName("setShouldRefreshRemoteIdentityMapResult");
refreshRemoteIdentityMapping.setXPath(getPrimaryNamespaceXPath() + "remote-refresh/text()");
refreshRemoteIdentityMapping.setNullValue(Boolean.FALSE);
descriptor.addMapping(refreshRemoteIdentityMapping);
XMLDirectMapping cascadePolicyMapping = new XMLDirectMapping();
cascadePolicyMapping.setAttributeName("cascadePolicy");
cascadePolicyMapping.setGetMethodName("getCascadePolicy");
cascadePolicyMapping.setSetMethodName("setCascadePolicy");
ObjectTypeConverter cascadePolicyConverter = new ObjectTypeConverter();
cascadePolicyConverter.addConversionValue("none", DatabaseQuery.NoCascading);
cascadePolicyConverter.addConversionValue("all", DatabaseQuery.CascadeAllParts);
cascadePolicyConverter.addConversionValue("private", DatabaseQuery.CascadePrivateParts);
cascadePolicyMapping.setConverter(cascadePolicyConverter);
cascadePolicyMapping.setNullValue(DatabaseQuery.NoCascading);
cascadePolicyMapping.setXPath(getPrimaryNamespaceXPath() + "cascade-policy/text()");
descriptor.addMapping(cascadePolicyMapping);
XMLDirectMapping cacheUsageMapping = new XMLDirectMapping();
cacheUsageMapping.setAttributeName("cacheUsage");
cacheUsageMapping.setGetMethodName("getCacheUsage");
cacheUsageMapping.setSetMethodName("setCacheUsage");
cacheUsageMapping.setXPath(getPrimaryNamespaceXPath() + "cache-usage/text()");
ObjectTypeConverter cacheUsageConverter = new ObjectTypeConverter();
cacheUsageConverter.addConversionValue("exact-primary-key", ObjectLevelReadQuery.CheckCacheByExactPrimaryKey);
cacheUsageConverter.addConversionValue("primary-key", ObjectLevelReadQuery.CheckCacheByPrimaryKey);
cacheUsageConverter.addConversionValue("cache-only", ObjectLevelReadQuery.CheckCacheOnly);
cacheUsageConverter.addConversionValue("cache-then-database", ObjectLevelReadQuery.CheckCacheThenDatabase);
cacheUsageConverter.addConversionValue("conform", ObjectLevelReadQuery.ConformResultsInUnitOfWork);
cacheUsageConverter.addConversionValue("none", ObjectLevelReadQuery.DoNotCheckCache);
cacheUsageConverter.addConversionValue("use-descriptor-setting", ObjectLevelReadQuery.UseDescriptorSetting);
cacheUsageMapping.setConverter(cacheUsageConverter);
cacheUsageMapping.setNullValue(ObjectLevelReadQuery.UseDescriptorSetting);
descriptor.addMapping(cacheUsageMapping);
XMLDirectMapping lockModeMapping = new XMLDirectMapping();
lockModeMapping.setAttributeName("lockMode");
lockModeMapping.setGetMethodName("getLockMode");
lockModeMapping.setSetMethodName("setLockMode");
lockModeMapping.setXPath(getPrimaryNamespaceXPath() + "lock-mode/text()");
ObjectTypeConverter lockModeConverter = new ObjectTypeConverter();
lockModeConverter.addConversionValue("default", ObjectLevelReadQuery.DEFAULT_LOCK_MODE);
lockModeConverter.addConversionValue("lock", ObjectLevelReadQuery.LOCK);
lockModeConverter.addConversionValue("lock-no-wait", ObjectLevelReadQuery.LOCK_NOWAIT);
lockModeConverter.addConversionValue("none", ObjectLevelReadQuery.NO_LOCK);
lockModeMapping.setConverter(lockModeConverter);
lockModeMapping.setNullValue(ObjectLevelReadQuery.DEFAULT_LOCK_MODE);
descriptor.addMapping(lockModeMapping);
XMLDirectMapping distinctStateMapping = new XMLDirectMapping();
distinctStateMapping.setAttributeName("distinctState");
distinctStateMapping.setGetMethodName("getDistinctState");
distinctStateMapping.setSetMethodName("setDistinctState");
distinctStateMapping.setXPath(getPrimaryNamespaceXPath() + "distinct-state/text()");
ObjectTypeConverter distinctStateConverter = new ObjectTypeConverter();
distinctStateConverter.addConversionValue("dont-use-distinct", ObjectLevelReadQuery.DONT_USE_DISTINCT);
distinctStateConverter.addConversionValue("none", ObjectLevelReadQuery.UNCOMPUTED_DISTINCT);
distinctStateConverter.addConversionValue("use-distinct", ObjectLevelReadQuery.USE_DISTINCT);
distinctStateMapping.setConverter(distinctStateConverter);
distinctStateMapping.setNullValue(ObjectLevelReadQuery.UNCOMPUTED_DISTINCT);
descriptor.addMapping(distinctStateMapping);
XMLCompositeObjectMapping inMemoryQueryIndirectionPolicyMapping = new XMLCompositeObjectMapping();
inMemoryQueryIndirectionPolicyMapping.setAttributeName("inMemoryQueryIndirectionPolicy");
inMemoryQueryIndirectionPolicyMapping.setReferenceClass(InMemoryQueryIndirectionPolicy.class);
// Handle translation of default to null.
inMemoryQueryIndirectionPolicyMapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
InMemoryQueryIndirectionPolicy policy = ((ObjectLevelReadQuery) object).getInMemoryQueryIndirectionPolicy();
if (policy.shouldThrowIndirectionException()) {
return null;
}
return policy;
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
if (value == null) {
return;
}
InMemoryQueryIndirectionPolicy policy = (InMemoryQueryIndirectionPolicy) value;
((ObjectLevelReadQuery) object).setInMemoryQueryIndirectionPolicy(policy);
}
});
inMemoryQueryIndirectionPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "in-memory-querying");
descriptor.addMapping(inMemoryQueryIndirectionPolicyMapping);
// fetch group setting
XMLDirectMapping useDefaultFetchGroupMapping = new XMLDirectMapping();
useDefaultFetchGroupMapping.setAttributeName("shouldUseDefaultFetchGroup");
useDefaultFetchGroupMapping.setXPath(getPrimaryNamespaceXPath() + "use-default-fetch-group/text()");
useDefaultFetchGroupMapping.setNullValue(Boolean.TRUE);
descriptor.addMapping(useDefaultFetchGroupMapping);
XMLCompositeObjectMapping fetchGroupMapping = new XMLCompositeObjectMapping();
fetchGroupMapping.setAttributeName("fetchGroup");
fetchGroupMapping.setReferenceClass(FetchGroup.class);
fetchGroupMapping.setXPath(getPrimaryNamespaceXPath() + "fetch-group");
descriptor.addMapping(fetchGroupMapping);
XMLDirectMapping fetchGroupNameMapping = new XMLDirectMapping();
fetchGroupNameMapping.setAttributeName("fetchGroupName");
fetchGroupNameMapping.setXPath(getPrimaryNamespaceXPath() + "fetch-group-name/text()");
descriptor.addMapping(fetchGroupNameMapping);
// shouldUseExclusiveConnection setting
XMLDirectMapping useExclusiveConnectionMapping = new XMLDirectMapping();
useExclusiveConnectionMapping.setAttributeName("shouldUseExclusiveConnection");
useExclusiveConnectionMapping.setXPath(getPrimaryNamespaceXPath() + "use-exclusive-connection/text()");
useExclusiveConnectionMapping.setNullValue(Boolean.FALSE);
descriptor.addMapping(useExclusiveConnectionMapping);
XMLCompositeCollectionMapping joinedAttributeMapping = new XMLCompositeCollectionMapping();
joinedAttributeMapping.useCollectionClass(NonSynchronizedVector.class);
joinedAttributeMapping.setAttributeName("joinedAttributeExpressions");
joinedAttributeMapping.setGetMethodName("getJoinedAttributeExpressions");
joinedAttributeMapping.setSetMethodName("setJoinedAttributeExpressions");
joinedAttributeMapping.setReferenceClass(Expression.class);
joinedAttributeMapping.setXPath(getPrimaryNamespaceXPath() + "joined-attribute-expressions/" + getPrimaryNamespaceXPath() + "expression");
descriptor.addMapping(joinedAttributeMapping);
return descriptor;
}
use of org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class EmployeeWorkbenchIntegrationSystem method buildMemoryQueryReturnNotConfirmedQuery.
public void buildMemoryQueryReturnNotConfirmedQuery(DescriptorQueryManager queryManager) {
ReadAllQuery namedQuery = new ReadAllQuery(Employee.class);
namedQuery.setInMemoryQueryIndirectionPolicy(new InMemoryQueryIndirectionPolicy(3));
queryManager.addQuery("memoryQueryReturnNotConfirmedQuery", namedQuery);
}
use of org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class EmployeeWorkbenchIntegrationSystem method buildMemoryQueryReturnConfirmedQuery.
public void buildMemoryQueryReturnConfirmedQuery(DescriptorQueryManager queryManager) {
ReadAllQuery namedQuery = new ReadAllQuery(Employee.class);
namedQuery.setInMemoryQueryIndirectionPolicy(new InMemoryQueryIndirectionPolicy(2));
queryManager.addQuery("memoryQueryReturnConfirmedQuery", namedQuery);
}
use of org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy in project eclipselink by eclipse-ee4j.
the class EmployeeWorkbenchIntegrationSystem method buildMemoryQueryThrowExceptionQuery.
public void buildMemoryQueryThrowExceptionQuery(DescriptorQueryManager queryManager) {
ReadObjectQuery namedQuery = new ReadObjectQuery(Employee.class);
namedQuery.setInMemoryQueryIndirectionPolicy(new InMemoryQueryIndirectionPolicy(0));
queryManager.addQuery("memoryQueryThrowExceptionQuery", namedQuery);
}
Aggregations