Search in sources :

Example 1 with AbstractCompositeDirectCollectionMapping

use of org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping in project eclipselink by eclipse-ee4j.

the class DirectCollectionAccessor method processDirectCollectionMapping.

/**
 * INTERNAL:
 */
protected void processDirectCollectionMapping() {
    // Initialize our mapping.
    DatabaseMapping mapping = getOwningDescriptor().getClassDescriptor().newDirectCollectionMapping();
    // Process common direct collection metadata. This must be done
    // before any field processing since field processing requires that
    // the collection table be processed before hand.
    process(mapping);
    processContainerPolicyAndIndirection((ContainerMapping) mapping);
    if (mapping instanceof DirectCollectionMapping) {
        DirectCollectionMapping directCollectionMapping = (DirectCollectionMapping) mapping;
        // Process the container and indirection policies.
        // Process the value column (we must process this field before the
        // call to processConverter, since it may set a field classification)
        directCollectionMapping.setDirectField(getDatabaseField(getReferenceDatabaseTable(), MetadataLogger.VALUE_COLUMN));
        // mapping to ensure we do the right conversions.
        if (hasAttributeType() || getAccessibleObject().isGenericCollectionType()) {
            directCollectionMapping.setDirectFieldClassificationName(getJavaClassName(getReferenceClass()));
        }
    } else if (mapping.isAbstractCompositeDirectCollectionMapping()) {
        ((AbstractCompositeDirectCollectionMapping) mapping).setField(getDatabaseField(getDescriptor().getPrimaryTable(), MetadataLogger.COLUMN));
    }
    // Process a converter for this mapping. We will look for a convert
    // value. If none is found then we'll look for a JPA converter, that
    // is, Enumerated, Lob and Temporal. With everything falling into
    // a serialized mapping if no converter whatsoever is found.
    processMappingValueConverter(mapping, getValueConverter(), getConverts(), getReferenceClass(), getReferenceClassWithGenerics());
}
Also used : DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) DirectCollectionMapping(org.eclipse.persistence.mappings.DirectCollectionMapping) AbstractCompositeDirectCollectionMapping(org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping)

Example 2 with AbstractCompositeDirectCollectionMapping

use of org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping in project eclipselink by eclipse-ee4j.

the class XMLChoiceCollectionMapping method initialize.

@Override
public void initialize(AbstractSession session) throws DescriptorException {
    super.initialize(session);
    if (this.converter != null) {
        this.converter.initialize(this, session);
    }
    ArrayList<XMLMapping> mappingsList = new ArrayList<>();
    mappingsList.addAll(getChoiceElementMappings().values());
    for (XMLMapping next : getChoiceElementMappingsByClass().values()) {
        if (!(mappingsList.contains(next))) {
            mappingsList.add(next);
        }
    }
    if (isAny) {
        // anyMapping = new XMLAnyCollectionMapping();
        mappingsList.add(anyMapping);
    }
    Iterator<XMLMapping> mappings = mappingsList.iterator();
    while (mappings.hasNext()) {
        DatabaseMapping nextMapping = (DatabaseMapping) mappings.next();
        Converter converter = null;
        if (fieldsToConverters != null) {
            converter = fieldsToConverters.get(nextMapping.getField());
        }
        if (nextMapping.isAbstractCompositeDirectCollectionMapping()) {
            XMLConversionManager xmlConversionManager = (XMLConversionManager) session.getDatasourcePlatform().getConversionManager();
            QName schemaType = xmlConversionManager.schemaType(((AbstractCompositeDirectCollectionMapping) nextMapping).getAttributeElementClass());
            if (schemaType != null) {
                ((XMLField) nextMapping.getField()).setSchemaType(schemaType);
            }
            if (converter != null) {
                ((AbstractCompositeDirectCollectionMapping) nextMapping).setValueConverter(converter);
            }
            ((AbstractCompositeDirectCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
        } else if (nextMapping.isAbstractCompositeCollectionMapping()) {
            if (converter != null) {
                ((AbstractCompositeCollectionMapping) nextMapping).setConverter(converter);
            }
            ((AbstractCompositeCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
        } else if (nextMapping instanceof XMLBinaryDataCollectionMapping) {
            ((XMLBinaryDataCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
            if (converter != null) {
                ((XMLBinaryDataCollectionMapping) nextMapping).setValueConverter(converter);
            }
        } else if (nextMapping instanceof XMLAnyCollectionMapping) {
            ((XMLAnyCollectionMapping) nextMapping).setContainerPolicy(getContainerPolicy());
            if (converter != null && converter instanceof XMLConverter) {
                ((XMLAnyCollectionMapping) nextMapping).setConverter((XMLConverter) converter);
            }
        } else {
            ((XMLCollectionReferenceMapping) nextMapping).setContainerPolicy(getContainerPolicy());
            ((XMLCollectionReferenceMapping) nextMapping).setReuseContainer(true);
        }
        nextMapping.initialize(session);
    }
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) XMLConverter(org.eclipse.persistence.oxm.mappings.converters.XMLConverter) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) AbstractCompositeDirectCollectionMapping(org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping) Converter(org.eclipse.persistence.mappings.converters.Converter) XMLConverter(org.eclipse.persistence.oxm.mappings.converters.XMLConverter) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Aggregations

DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)2 AbstractCompositeDirectCollectionMapping (org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping)2 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)1 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)1 Converter (org.eclipse.persistence.mappings.converters.Converter)1 XMLField (org.eclipse.persistence.oxm.XMLField)1 XMLConverter (org.eclipse.persistence.oxm.mappings.converters.XMLConverter)1