Search in sources :

Example 96 with XMLDirectMapping

use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping 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 97 with XMLDirectMapping

use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.

the class ObjectPersistenceRuntimeXMLProject method buildTypeMappingDescriptor.

protected ClassDescriptor buildTypeMappingDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(TypeMapping.class);
    descriptor.setDefaultRootElement("type-mapping");
    descriptor.getEventManager().setPostBuildSelector("postBuild");
    XMLDirectMapping valueMapping = new XMLDirectMapping();
    valueMapping.setAttributeName("value");
    valueMapping.setGetMethodName("getValue");
    valueMapping.setSetMethodName("setValue");
    valueMapping.setField(buildTypedField(getPrimaryNamespaceXPath() + "object-value/text()"));
    descriptor.addMapping(valueMapping);
    XMLDirectMapping keyMapping = new XMLDirectMapping();
    keyMapping.setAttributeName("key");
    keyMapping.setGetMethodName("getKey");
    keyMapping.setSetMethodName("setKey");
    keyMapping.setField(buildTypedField(getPrimaryNamespaceXPath() + "data-value/text()"));
    descriptor.addMapping(keyMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Example 98 with XMLDirectMapping

use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.

the class ObjectPersistenceRuntimeXMLProject method buildEventManagerDescriptor.

protected ClassDescriptor buildEventManagerDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(DescriptorEventManager.class);
    descriptor.setDefaultRootElement("event-policy");
    descriptor.getInheritancePolicy().setClassIndicatorField(new XMLField("@xsi:type"));
    descriptor.getInheritancePolicy().addClassIndicator(DescriptorEventManager.class, getPrimaryNamespaceXPath() + "event-policy");
    XMLCompositeDirectCollectionMapping eventListenersMapping = new XMLCompositeDirectCollectionMapping();
    eventListenersMapping.setAttributeName("eventListeners");
    eventListenersMapping.setGetMethodName("getEventListeners");
    eventListenersMapping.setSetMethodName("setEventListeners");
    eventListenersMapping.useCollectionClass(org.eclipse.persistence.internal.helper.NonSynchronizedVector.class);
    eventListenersMapping.setValueConverter(new ClassInstanceConverter());
    eventListenersMapping.setXPath(getSecondaryNamespaceXPath() + "event-listeners/" + getSecondaryNamespaceXPath() + "event-listener/text()");
    descriptor.addMapping(eventListenersMapping);
    XMLDirectMapping postBuildSelectorMapping = new XMLDirectMapping();
    postBuildSelectorMapping.setAttributeName("getPostBuildSelector");
    postBuildSelectorMapping.setGetMethodName("getPostBuildSelector");
    postBuildSelectorMapping.setSetMethodName("setPostBuildSelector");
    postBuildSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "post-build-method/text()");
    descriptor.addMapping(postBuildSelectorMapping);
    XMLDirectMapping preWriteSelectorMapping = new XMLDirectMapping();
    preWriteSelectorMapping.setAttributeName("preWriteSelector");
    preWriteSelectorMapping.setGetMethodName("getPreWriteSelector");
    preWriteSelectorMapping.setSetMethodName("setPreWriteSelector");
    preWriteSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "pre-write-method/text()");
    descriptor.addMapping(preWriteSelectorMapping);
    XMLDirectMapping postWriteSelectorMapping = new XMLDirectMapping();
    postWriteSelectorMapping.setAttributeName("postWriteSelector");
    postWriteSelectorMapping.setGetMethodName("getPostWriteSelector");
    postWriteSelectorMapping.setSetMethodName("setPostWriteSelector");
    postWriteSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "post-write-method/text()");
    descriptor.addMapping(postWriteSelectorMapping);
    XMLDirectMapping preInsertSelectorMapping = new XMLDirectMapping();
    preInsertSelectorMapping.setAttributeName("preInsertSelector");
    preInsertSelectorMapping.setGetMethodName("getPreInsertSelector");
    preInsertSelectorMapping.setSetMethodName("setPreInsertSelector");
    preInsertSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "pre-insert-method/text()");
    descriptor.addMapping(preInsertSelectorMapping);
    XMLDirectMapping postInsertSelectorMapping = new XMLDirectMapping();
    postInsertSelectorMapping.setAttributeName("postInsertSelector");
    postInsertSelectorMapping.setGetMethodName("getPostInsertSelector");
    postInsertSelectorMapping.setSetMethodName("setPostInsertSelector");
    postInsertSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "post-insert-method/text()");
    descriptor.addMapping(postInsertSelectorMapping);
    XMLDirectMapping preUpdateSelectorMapping = new XMLDirectMapping();
    preUpdateSelectorMapping.setAttributeName("preUpdateSelector");
    preUpdateSelectorMapping.setGetMethodName("getPreUpdateSelector");
    preUpdateSelectorMapping.setSetMethodName("setPreUpdateSelector");
    preUpdateSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "pre-update-method/text()");
    descriptor.addMapping(preUpdateSelectorMapping);
    XMLDirectMapping postUpdateSelectorMapping = new XMLDirectMapping();
    postUpdateSelectorMapping.setAttributeName("postUpdateSelector");
    postUpdateSelectorMapping.setGetMethodName("getPostUpdateSelector");
    postUpdateSelectorMapping.setSetMethodName("setPostUpdateSelector");
    postUpdateSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "post-update-method/text()");
    descriptor.addMapping(postUpdateSelectorMapping);
    XMLDirectMapping preDeleteSelectorMapping = new XMLDirectMapping();
    preDeleteSelectorMapping.setAttributeName("preDeleteSelector");
    preDeleteSelectorMapping.setGetMethodName("getPreDeleteSelector");
    preDeleteSelectorMapping.setSetMethodName("setPreDeleteSelector");
    preDeleteSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "pre-delete-method/text()");
    descriptor.addMapping(preDeleteSelectorMapping);
    XMLDirectMapping postDeleteSelectorMapping = new XMLDirectMapping();
    postDeleteSelectorMapping.setAttributeName("postDeleteSelector");
    postDeleteSelectorMapping.setGetMethodName("getPostDeleteSelector");
    postDeleteSelectorMapping.setSetMethodName("setPostDeleteSelector");
    postDeleteSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "post-delete-method/text()");
    descriptor.addMapping(postDeleteSelectorMapping);
    XMLDirectMapping aboutToInsertSelectorMapping = new XMLDirectMapping();
    aboutToInsertSelectorMapping.setAttributeName("aboutToInsertSelector");
    aboutToInsertSelectorMapping.setGetMethodName("getAboutToInsertSelector");
    aboutToInsertSelectorMapping.setSetMethodName("setAboutToInsertSelector");
    aboutToInsertSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "about-to-insert-method/text()");
    descriptor.addMapping(aboutToInsertSelectorMapping);
    XMLDirectMapping aboutToUpdateSelectorMapping = new XMLDirectMapping();
    aboutToUpdateSelectorMapping.setAttributeName("aboutToUpdateSelector");
    aboutToUpdateSelectorMapping.setGetMethodName("getAboutToUpdateSelector");
    aboutToUpdateSelectorMapping.setSetMethodName("setAboutToUpdateSelector");
    aboutToUpdateSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "about-to-update-method/text()");
    descriptor.addMapping(aboutToUpdateSelectorMapping);
    XMLDirectMapping postCloneSelectorMapping = new XMLDirectMapping();
    postCloneSelectorMapping.setAttributeName("postCloneSelector");
    postCloneSelectorMapping.setGetMethodName("getPostCloneSelector");
    postCloneSelectorMapping.setSetMethodName("setPostCloneSelector");
    postCloneSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "post-clone-method/text()");
    descriptor.addMapping(postCloneSelectorMapping);
    XMLDirectMapping postMergeSelectorMapping = new XMLDirectMapping();
    postMergeSelectorMapping.setAttributeName("postMergeSelector");
    postMergeSelectorMapping.setGetMethodName("getPostMergeSelector");
    postMergeSelectorMapping.setSetMethodName("setPostMergeSelector");
    postMergeSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "post-merge-method/text()");
    descriptor.addMapping(postMergeSelectorMapping);
    XMLDirectMapping postRefreshSelectorMapping = new XMLDirectMapping();
    postRefreshSelectorMapping.setAttributeName("getPostRefreshSelector");
    postRefreshSelectorMapping.setGetMethodName("getPostRefreshSelector");
    postRefreshSelectorMapping.setSetMethodName("setPostRefreshSelector");
    postRefreshSelectorMapping.setXPath(getPrimaryNamespaceXPath() + "post-refresh-method/text()");
    descriptor.addMapping(postRefreshSelectorMapping);
    return descriptor;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) ClassInstanceConverter(org.eclipse.persistence.mappings.converters.ClassInstanceConverter)

Example 99 with XMLDirectMapping

use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.

the class ObjectPersistenceRuntimeXMLProject method buildMethodBaseQueryRedirectorDescriptor.

protected ClassDescriptor buildMethodBaseQueryRedirectorDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(MethodBaseQueryRedirector.class);
    descriptor.setDefaultRootElement("method-base-query-redirector");
    XMLDirectMapping methodNameMapping = new XMLDirectMapping();
    methodNameMapping.setAttributeName("methodName");
    methodNameMapping.setGetMethodName("getMethodName");
    methodNameMapping.setSetMethodName("setMethodName");
    methodNameMapping.setXPath(getPrimaryNamespaceXPath() + "method-name/text()");
    descriptor.addMapping(methodNameMapping);
    XMLDirectMapping methodClassMapping = new XMLDirectMapping();
    methodClassMapping.setAttributeName("methodClass");
    methodClassMapping.setGetMethodName("getMethodClass");
    methodClassMapping.setSetMethodName("setMethodClass");
    methodClassMapping.setXPath(getPrimaryNamespaceXPath() + "method-class/text()");
    descriptor.addMapping(methodClassMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Example 100 with XMLDirectMapping

use of org.eclipse.persistence.oxm.mappings.XMLDirectMapping in project eclipselink by eclipse-ee4j.

the class ObjectPersistenceRuntimeXMLProject method buildManyToManyMappingMappingDescriptor.

protected ClassDescriptor buildManyToManyMappingMappingDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(ManyToManyMapping.class);
    descriptor.getInheritancePolicy().setParentClass(CollectionMapping.class);
    XMLDirectMapping relationTableMapping = new XMLDirectMapping();
    relationTableMapping.setAttributeName("relationTableName");
    // CR#2407 Call getRelationTableQualifiedName that includes table qualifier.
    relationTableMapping.setGetMethodName("getRelationTableQualifiedName");
    relationTableMapping.setSetMethodName("setRelationTableName");
    relationTableMapping.setXPath(getSecondaryNamespaceXPath() + "relation-table/text()");
    descriptor.addMapping(relationTableMapping);
    XMLCompositeCollectionMapping sourceToRelationKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
    sourceToRelationKeyFieldAssociationsMapping.setReferenceClass(Association.class);
    // Handle translation of foreign key associations to hashtables.
    sourceToRelationKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            List<DatabaseField> sourceFields = ((ManyToManyMapping) object).getSourceKeyFields();
            List<DatabaseField> relationFields = ((ManyToManyMapping) object).getSourceRelationKeyFields();
            List<Association> associations = new ArrayList<>(sourceFields.size());
            for (int index = 0; index < sourceFields.size(); index++) {
                associations.add(new Association(relationFields.get(index), sourceFields.get(index)));
            }
            return associations;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            ManyToManyMapping mapping = (ManyToManyMapping) object;
            @SuppressWarnings({ "unchecked" }) List<Association> associations = (List<Association>) value;
            mapping.setSourceKeyFields(NonSynchronizedVector.newInstance(associations.size()));
            mapping.setSourceRelationKeyFields(NonSynchronizedVector.newInstance(associations.size()));
            Iterator<Association> iterator = associations.iterator();
            while (iterator.hasNext()) {
                Association association = iterator.next();
                mapping.getSourceKeyFields().add((DatabaseField) association.getValue());
                mapping.getSourceRelationKeyFields().add((DatabaseField) association.getKey());
            }
        }
    });
    sourceToRelationKeyFieldAssociationsMapping.setAttributeName("sourceToRelationKeyFieldAssociationsMapping");
    sourceToRelationKeyFieldAssociationsMapping.setXPath(getSecondaryNamespaceXPath() + "source-relation-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
    descriptor.addMapping(sourceToRelationKeyFieldAssociationsMapping);
    XMLCompositeCollectionMapping targetToRelationKeyFieldAssociationsMapping = new XMLCompositeCollectionMapping();
    targetToRelationKeyFieldAssociationsMapping.setReferenceClass(Association.class);
    // Handle translation of foreign key associations to hashtables.
    targetToRelationKeyFieldAssociationsMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            List<DatabaseField> targetFields = ((ManyToManyMapping) object).getTargetKeyFields();
            List<DatabaseField> relationFields = ((ManyToManyMapping) object).getTargetRelationKeyFields();
            List<Association> associations = new ArrayList<>(targetFields.size());
            for (int index = 0; index < targetFields.size(); index++) {
                associations.add(new Association(relationFields.get(index), targetFields.get(index)));
            }
            return associations;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            ManyToManyMapping mapping = (ManyToManyMapping) object;
            @SuppressWarnings({ "unchecked" }) List<Association> associations = (List<Association>) value;
            mapping.setTargetKeyFields(NonSynchronizedVector.newInstance(associations.size()));
            mapping.setTargetRelationKeyFields(NonSynchronizedVector.newInstance(associations.size()));
            Iterator<Association> iterator = associations.iterator();
            while (iterator.hasNext()) {
                Association association = iterator.next();
                mapping.getTargetKeyFields().add((DatabaseField) association.getValue());
                mapping.getTargetRelationKeyFields().add((DatabaseField) association.getKey());
            }
        }
    });
    targetToRelationKeyFieldAssociationsMapping.setAttributeName("targetToRelationKeyFieldAssociations");
    targetToRelationKeyFieldAssociationsMapping.setXPath(getSecondaryNamespaceXPath() + "target-relation-foreign-key/" + getSecondaryNamespaceXPath() + "field-reference");
    descriptor.addMapping(targetToRelationKeyFieldAssociationsMapping);
    XMLDirectMapping relationshipPartnerAttributeNameMapping = new XMLDirectMapping();
    relationshipPartnerAttributeNameMapping.setAttributeName("relationshipPartnerAttributeName");
    relationshipPartnerAttributeNameMapping.setGetMethodName("getRelationshipPartnerAttributeName");
    relationshipPartnerAttributeNameMapping.setSetMethodName("setRelationshipPartnerAttributeName");
    relationshipPartnerAttributeNameMapping.setXPath(getPrimaryNamespaceXPath() + "bidirectional-target-attribute/text()");
    descriptor.addMapping(relationshipPartnerAttributeNameMapping);
    XMLDirectMapping usesBatchReadingMapping = new XMLDirectMapping();
    usesBatchReadingMapping.setAttributeName("usesBatchReading");
    usesBatchReadingMapping.setGetMethodName("shouldUseBatchReading");
    usesBatchReadingMapping.setSetMethodName("setUsesBatchReading");
    usesBatchReadingMapping.setXPath(getPrimaryNamespaceXPath() + "batch-reading/text()");
    usesBatchReadingMapping.setNullValue(Boolean.FALSE);
    descriptor.addMapping(usesBatchReadingMapping);
    XMLCompositeObjectMapping containerPolicyMapping = new XMLCompositeObjectMapping();
    containerPolicyMapping.setAttributeName("collectionPolicy");
    containerPolicyMapping.setGetMethodName("getContainerPolicy");
    containerPolicyMapping.setSetMethodName("setContainerPolicy");
    containerPolicyMapping.setReferenceClass(ContainerPolicy.class);
    containerPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "container");
    descriptor.addMapping(containerPolicyMapping);
    XMLCompositeObjectMapping indirectionPolicyMapping = new XMLCompositeObjectMapping();
    indirectionPolicyMapping.setReferenceClass(IndirectionPolicy.class);
    // Handle translation of NoIndirectionPolicy -> null.
    indirectionPolicyMapping.setAttributeAccessor(new AttributeAccessor() {

        @Override
        public Object getAttributeValueFromObject(Object object) {
            IndirectionPolicy policy = ((ForeignReferenceMapping) object).getIndirectionPolicy();
            if (policy instanceof NoIndirectionPolicy) {
                return null;
            }
            return policy;
        }

        @Override
        public void setAttributeValueInObject(Object object, Object value) {
            IndirectionPolicy policy = (IndirectionPolicy) value;
            if (value == null) {
                policy = new NoIndirectionPolicy();
            }
            ((ForeignReferenceMapping) object).setIndirectionPolicy(policy);
        }
    });
    indirectionPolicyMapping.setAttributeName("indirectionPolicy");
    indirectionPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "indirection");
    descriptor.addMapping(indirectionPolicyMapping);
    XMLCompositeObjectMapping selectionQueryMapping = new XMLCompositeObjectMapping();
    selectionQueryMapping.setAttributeName("selectionQuery");
    selectionQueryMapping.setGetMethodName("getSelectionQuery");
    selectionQueryMapping.setSetMethodName("setSelectionQuery");
    selectionQueryMapping.setReferenceClass(ReadQuery.class);
    selectionQueryMapping.setXPath(getPrimaryNamespaceXPath() + "selection-query");
    descriptor.addMapping(selectionQueryMapping);
    XMLCompositeObjectMapping insertQueryMapping = new XMLCompositeObjectMapping();
    insertQueryMapping.setAttributeName("insertQuery");
    insertQueryMapping.setGetMethodName("getInsertQuery");
    insertQueryMapping.setSetMethodName("setInsertQuery");
    insertQueryMapping.setReferenceClass(DataModifyQuery.class);
    insertQueryMapping.setXPath(getPrimaryNamespaceXPath() + "insert-query");
    descriptor.addMapping(insertQueryMapping);
    XMLCompositeObjectMapping deleteQueryMapping = new XMLCompositeObjectMapping();
    deleteQueryMapping.setAttributeName("deleteQuery");
    deleteQueryMapping.setGetMethodName("getDeleteQuery");
    deleteQueryMapping.setSetMethodName("setDeleteQuery");
    deleteQueryMapping.setReferenceClass(DataModifyQuery.class);
    deleteQueryMapping.setXPath(getPrimaryNamespaceXPath() + "delete-query");
    descriptor.addMapping(deleteQueryMapping);
    XMLCompositeObjectMapping deleteAllQueryMapping = new XMLCompositeObjectMapping();
    deleteAllQueryMapping.setAttributeName("deleteAllQuery");
    deleteAllQueryMapping.setGetMethodName("getDeleteAllQuery");
    deleteAllQueryMapping.setSetMethodName("setDeleteAllQuery");
    deleteAllQueryMapping.setReferenceClass(DataModifyQuery.class);
    deleteAllQueryMapping.setXPath(getPrimaryNamespaceXPath() + "delete-all-query");
    descriptor.addMapping(deleteAllQueryMapping);
    XMLCompositeObjectMapping historyPolicyMapping = new XMLCompositeObjectMapping();
    historyPolicyMapping.setAttributeName("historyPolicy");
    historyPolicyMapping.setGetMethodName("getHistoryPolicy");
    historyPolicyMapping.setSetMethodName("setHistoryPolicy");
    historyPolicyMapping.setReferenceClass(HistoryPolicy.class);
    historyPolicyMapping.setXPath(getPrimaryNamespaceXPath() + "history-policy");
    descriptor.addMapping(historyPolicyMapping);
    return descriptor;
}
Also used : ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) ProxyIndirectionPolicy(org.eclipse.persistence.internal.indirection.ProxyIndirectionPolicy) IndirectionPolicy(org.eclipse.persistence.internal.indirection.IndirectionPolicy) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) ContainerIndirectionPolicy(org.eclipse.persistence.internal.indirection.ContainerIndirectionPolicy) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) TransparentIndirectionPolicy(org.eclipse.persistence.internal.indirection.TransparentIndirectionPolicy) InMemoryQueryIndirectionPolicy(org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) Association(org.eclipse.persistence.mappings.Association) PropertyAssociation(org.eclipse.persistence.mappings.PropertyAssociation) TypedAssociation(org.eclipse.persistence.mappings.TypedAssociation) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) NoIndirectionPolicy(org.eclipse.persistence.internal.indirection.NoIndirectionPolicy) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Aggregations

XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)802 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)630 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)103 XMLField (org.eclipse.persistence.oxm.XMLField)100 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)78 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)74 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)53 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)41 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)35 QName (javax.xml.namespace.QName)33 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)28 XMLSchemaURLReference (org.eclipse.persistence.oxm.schema.XMLSchemaURLReference)26 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)25 ArrayList (java.util.ArrayList)24 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)22 URL (java.net.URL)21 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)21 List (java.util.List)15 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)14 IsSetNullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy)14