Search in sources :

Example 21 with ConversionManager

use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.

the class DirectCollectionMapping method extractKeyFromTargetRow.

/**
 * INTERNAL:
 * Extract the source primary key value from the reference direct row.
 * Used for batch reading, most following same order and fields as in the mapping.
 */
@Override
protected Object extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) {
    int size = this.referenceKeyFields.size();
    Object[] key = new Object[size];
    ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
    for (int index = 0; index < size; index++) {
        DatabaseField relationField = this.referenceKeyFields.get(index);
        DatabaseField sourceField = this.sourceKeyFields.get(index);
        Object value = row.get(relationField);
        // Must ensure the classification gets a cache hit.
        try {
            value = conversionManager.convertObject(value, sourceField.getType());
        } catch (ConversionException e) {
            throw ConversionException.couldNotBeConverted(this, getDescriptor(), e);
        }
        key[index] = value;
    }
    return new CacheId(key);
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) CacheId(org.eclipse.persistence.internal.identitymaps.CacheId) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager)

Example 22 with ConversionManager

use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.

the class DirectCollectionMapping method extractBatchKeyFromRow.

/**
 * INTERNAL:
 * Extract the primary key value from the source row.
 * Used for batch reading, most following same order and fields as in the mapping.
 */
@Override
protected Object extractBatchKeyFromRow(AbstractRecord row, AbstractSession session) {
    int size = this.sourceKeyFields.size();
    Object[] key = new Object[size];
    ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
    for (int index = 0; index < size; index++) {
        DatabaseField field = this.sourceKeyFields.get(index);
        Object value = row.get(field);
        // Must ensure the classification to get a cache hit.
        try {
            value = conversionManager.convertObject(value, field.getType());
        } catch (ConversionException exception) {
            throw ConversionException.couldNotBeConverted(this, this.descriptor, exception);
        }
        key[index] = value;
    }
    return new CacheId(key);
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) CacheId(org.eclipse.persistence.internal.identitymaps.CacheId) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager)

Example 23 with ConversionManager

use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.

the class OneToManyMapping method extractBatchKeyFromRow.

/**
 * Extract the key field values from the specified row.
 * Used for batch reading. Keep the fields in the same order
 * as in the targetForeignKeysToSourceKeys map.
 */
@Override
protected Object extractBatchKeyFromRow(AbstractRecord row, AbstractSession session) {
    int size = this.sourceKeyFields.size();
    Object[] key = new Object[size];
    ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
    for (int index = 0; index < size; index++) {
        DatabaseField sourceField = this.sourceKeyFields.get(index);
        Object value = row.get(sourceField);
        // Must ensure the classification to get a cache hit.
        try {
            value = conversionManager.convertObject(value, sourceField.getType());
        } catch (ConversionException exception) {
            throw ConversionException.couldNotBeConverted(this, this.descriptor, exception);
        }
        key[index] = value;
    }
    return new CacheId(key);
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) CacheId(org.eclipse.persistence.internal.identitymaps.CacheId) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager)

Example 24 with ConversionManager

use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.

the class OneToManyMapping method extractKeyFromTargetRow.

/**
 * INTERNAL:
 * Extract the source primary key value from the target row.
 * Used for batch reading, most following same order and fields as in the mapping.
 */
@Override
protected Object extractKeyFromTargetRow(AbstractRecord row, AbstractSession session) {
    int size = this.sourceKeyFields.size();
    Object[] key = new Object[size];
    ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
    for (int index = 0; index < size; index++) {
        DatabaseField targetField = this.targetForeignKeyFields.get(index);
        DatabaseField sourceField = this.sourceKeyFields.get(index);
        Object value = row.get(targetField);
        // Must ensure the classification gets a cache hit.
        try {
            value = conversionManager.convertObject(value, sourceField.getType());
        } catch (ConversionException e) {
            throw ConversionException.couldNotBeConverted(this, getDescriptor(), e);
        }
        key[index] = value;
    }
    return new CacheId(key);
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) CacheId(org.eclipse.persistence.internal.identitymaps.CacheId) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager)

Example 25 with ConversionManager

use of org.eclipse.persistence.internal.helper.ConversionManager in project eclipselink by eclipse-ee4j.

the class AnnotationsProcessor method getAnnotations.

/**
 * Returns an array of Annotations for a given TypeMappingInfo. This array
 * will either be populated from the TypeMappingInfo's array of annotations,
 * or based on an xml-element if present. The xml-element will take
 * precedence over the annotation array; if there is an xml-element the
 * Array of Annotations will be ignored.
 */
private java.lang.annotation.Annotation[] getAnnotations(TypeMappingInfo tmInfo) {
    if (tmInfo.getXmlElement() != null) {
        ClassLoader loader = helper.getClassLoader();
        // create a single ConversionManager for that will be shared by the
        // proxy objects
        ConversionManager cMgr = new ConversionManager();
        cMgr.setLoader(loader);
        // unmarshal the node into an XmlElement
        org.eclipse.persistence.jaxb.xmlmodel.XmlElement xElt = CompilerHelper.getXmlElement(tmInfo.getXmlElement(), loader);
        List<Annotation> annotations = new ArrayList<>();
        // where applicable, a given dynamic proxy will contain a Map of
        // method name/return value entries
        Map<String, Object> components = null;
        // handle @XmlElement: set 'type' method
        if (!(xElt.getType().equals("jakarta.xml.bind.annotation.XmlElement.DEFAULT"))) {
            components = new HashMap<>();
            components.put(TYPE_METHOD_NAME, xElt.getType());
            annotations.add(AnnotationProxy.getProxy(components, XmlElement.class, loader, cMgr));
        }
        // handle @XmlList
        if (xElt.isXmlList()) {
            annotations.add(AnnotationProxy.getProxy(components, XmlList.class, loader, cMgr));
        }
        // handle @XmlAttachmentRef
        if (xElt.isXmlAttachmentRef()) {
            annotations.add(AnnotationProxy.getProxy(components, XmlAttachmentRef.class, loader, cMgr));
        }
        // handle @XmlMimeType: set 'value' method
        if (xElt.getXmlMimeType() != null) {
            components = new HashMap<>();
            components.put(VALUE_METHOD_NAME, xElt.getXmlMimeType());
            annotations.add(AnnotationProxy.getProxy(components, XmlMimeType.class, loader, cMgr));
        }
        // handle @XmlJavaTypeAdapter: set 'type' and 'value' methods
        if (xElt.getXmlJavaTypeAdapter() != null) {
            components = new HashMap<>();
            components.put(TYPE_METHOD_NAME, xElt.getXmlJavaTypeAdapter().getType());
            components.put(VALUE_METHOD_NAME, xElt.getXmlJavaTypeAdapter().getValue());
            annotations.add(AnnotationProxy.getProxy(components, XmlJavaTypeAdapter.class, loader, cMgr));
        }
        // return the newly created array of dynamic proxy objects
        return annotations.toArray(new Annotation[annotations.size()]);
    }
    // array of Annotation objects
    return tmInfo.getAnnotations();
}
Also used : XmlMimeType(jakarta.xml.bind.annotation.XmlMimeType) XmlJavaTypeAdapter(jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter) ArrayList(java.util.ArrayList) JavaAnnotation(org.eclipse.persistence.jaxb.javamodel.JavaAnnotation) Annotation(java.lang.annotation.Annotation) XmlList(jakarta.xml.bind.annotation.XmlList) XmlAttachmentRef(jakarta.xml.bind.annotation.XmlAttachmentRef) JaxbClassLoader(org.eclipse.persistence.internal.jaxb.JaxbClassLoader) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager) XmlElement(jakarta.xml.bind.annotation.XmlElement)

Aggregations

ConversionManager (org.eclipse.persistence.internal.helper.ConversionManager)32 Project (org.eclipse.persistence.sessions.Project)12 Platform (org.eclipse.persistence.internal.databaseaccess.Platform)11 XMLContext (org.eclipse.persistence.oxm.XMLContext)11 JAXBException (jakarta.xml.bind.JAXBException)10 StringReader (java.io.StringReader)10 XRDynamicClassLoader (org.eclipse.persistence.internal.xr.XRDynamicClassLoader)10 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)10 JAXBContext (jakarta.xml.bind.JAXBContext)9 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)9 XMLPlatform (org.eclipse.persistence.platform.xml.XMLPlatform)9 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)9 DatasourceLogin (org.eclipse.persistence.sessions.DatasourceLogin)9 Unmarshaller (jakarta.xml.bind.Unmarshaller)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 StreamSource (javax.xml.transform.stream.StreamSource)8 CacheId (org.eclipse.persistence.internal.identitymaps.CacheId)8 MetadataProcessor (org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor)8 DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)8