Search in sources :

Example 6 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)

Example 7 with XMLDirectMapping

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

the class ObjectPersistenceRuntimeXMLProject method buildAggregateMappingDescriptor.

protected ClassDescriptor buildAggregateMappingDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(AggregateMapping.class);
    descriptor.getInheritancePolicy().setParentClass(DatabaseMapping.class);
    XMLDirectMapping referenceClassMapping = new XMLDirectMapping();
    referenceClassMapping.setAttributeName("referenceClass");
    referenceClassMapping.setGetMethodName("getReferenceClass");
    referenceClassMapping.setSetMethodName("setReferenceClass");
    referenceClassMapping.setXPath(getPrimaryNamespaceXPath() + "reference-class/text()");
    descriptor.addMapping(referenceClassMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Example 8 with XMLDirectMapping

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

the class ObjectPersistenceRuntimeXMLProject method buildTypedAssociationDescriptor.

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

Example 9 with XMLDirectMapping

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

the class ObjectPersistenceRuntimeXMLProject method buildInterfacePolicyDescriptor.

protected ClassDescriptor buildInterfacePolicyDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(InterfacePolicy.class);
    descriptor.setDefaultRootElement("interfaces");
    XMLCompositeDirectCollectionMapping parentInterfacesMapping = new XMLCompositeDirectCollectionMapping();
    parentInterfacesMapping.setAttributeElementClass(Class.class);
    parentInterfacesMapping.setAttributeName("parentInterfaces");
    parentInterfacesMapping.setGetMethodName("getParentInterfaces");
    parentInterfacesMapping.setSetMethodName("setParentInterfaces");
    parentInterfacesMapping.setXPath(getPrimaryNamespaceXPath() + "interface/text()");
    descriptor.addMapping(parentInterfacesMapping);
    XMLDirectMapping implementorDescriptorMapping = new XMLDirectMapping();
    implementorDescriptorMapping.setAttributeName("implementorDescriptor");
    implementorDescriptorMapping.setGetMethodName("getImplementorDescriptor");
    implementorDescriptorMapping.setSetMethodName("setImplementorDescriptor");
    implementorDescriptorMapping.setXPath(getPrimaryNamespaceXPath() + "implementor-descriptor/text()");
    descriptor.addMapping(implementorDescriptorMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)

Example 10 with XMLDirectMapping

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

the class ObjectPersistenceRuntimeXMLProject method buildDailyCacheInvalidationPolicyDescriptor.

protected ClassDescriptor buildDailyCacheInvalidationPolicyDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(DailyCacheInvalidationPolicy.class);
    descriptor.getInheritancePolicy().setParentClass(CacheInvalidationPolicy.class);
    XMLDirectMapping expiryMinuteMapping = new XMLDirectMapping();
    expiryMinuteMapping.setAttributeName("expiryTime");
    expiryMinuteMapping.setGetMethodName("getExpiryTime");
    expiryMinuteMapping.setSetMethodName("setExpiryTime");
    XMLField expiryTimeField = new XMLField(getPrimaryNamespaceXPath() + "expiry-time/text()");
    expiryTimeField.setIsTypedTextField(true);
    expiryMinuteMapping.setField(expiryTimeField);
    descriptor.addMapping(expiryMinuteMapping);
    return descriptor;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

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