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", new Integer(DatabaseQuery.NoCascading));
cascadePolicyConverter.addConversionValue("all", new Integer(DatabaseQuery.CascadeAllParts));
cascadePolicyConverter.addConversionValue("private", new Integer(DatabaseQuery.CascadePrivateParts));
cascadePolicyMapping.setConverter(cascadePolicyConverter);
cascadePolicyMapping.setNullValue(new Integer(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", new Integer(ObjectLevelReadQuery.CheckCacheByExactPrimaryKey));
cacheUsageConverter.addConversionValue("primary-key", new Integer(ObjectLevelReadQuery.CheckCacheByPrimaryKey));
cacheUsageConverter.addConversionValue("cache-only", new Integer(ObjectLevelReadQuery.CheckCacheOnly));
cacheUsageConverter.addConversionValue("cache-then-database", new Integer(ObjectLevelReadQuery.CheckCacheThenDatabase));
cacheUsageConverter.addConversionValue("conform", new Integer(ObjectLevelReadQuery.ConformResultsInUnitOfWork));
cacheUsageConverter.addConversionValue("none", new Integer(ObjectLevelReadQuery.DoNotCheckCache));
cacheUsageConverter.addConversionValue("use-descriptor-setting", new Integer(ObjectLevelReadQuery.UseDescriptorSetting));
cacheUsageMapping.setConverter(cacheUsageConverter);
cacheUsageMapping.setNullValue(new Integer(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", new Short(ObjectLevelReadQuery.DEFAULT_LOCK_MODE));
lockModeConverter.addConversionValue("lock", new Short(ObjectLevelReadQuery.LOCK));
lockModeConverter.addConversionValue("lock-no-wait", new Short(ObjectLevelReadQuery.LOCK_NOWAIT));
lockModeConverter.addConversionValue("none", new Short(ObjectLevelReadQuery.NO_LOCK));
lockModeMapping.setConverter(lockModeConverter);
lockModeMapping.setNullValue(new Short(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", new Short(ObjectLevelReadQuery.DONT_USE_DISTINCT));
distinctStateConverter.addConversionValue("none", new Short(ObjectLevelReadQuery.UNCOMPUTED_DISTINCT));
distinctStateConverter.addConversionValue("use-distinct", new Short(ObjectLevelReadQuery.USE_DISTINCT));
distinctStateMapping.setConverter(distinctStateConverter);
distinctStateMapping.setNullValue(new Short(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() {
public Object getAttributeValueFromObject(Object object) {
InMemoryQueryIndirectionPolicy policy = ((ObjectLevelReadQuery)object).getInMemoryQueryIndirectionPolicy();
if (policy.shouldThrowIndirectionException()) {
return null;
}
return policy;
}
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");