Search in sources :

Example 1 with InMemoryQueryIndirectionPolicy

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

Example 2 with InMemoryQueryIndirectionPolicy

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;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) InMemoryQueryIndirectionPolicy(org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy)

Example 3 with InMemoryQueryIndirectionPolicy

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

Example 4 with InMemoryQueryIndirectionPolicy

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

Example 5 with InMemoryQueryIndirectionPolicy

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

Aggregations

InMemoryQueryIndirectionPolicy (org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy)6 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)4 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)1 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)1 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)1 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)1 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)1 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)1 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)1