Search in sources :

Example 6 with ConversionManager

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

the class ProjectHelper method fixOROXAccessors.

/**
 * INTERNAL: Fix the given EclipseLink OR and OX projects so that the
 * descriptors for all generated sub-classes of XRDynamicEntity have the correct
 * AttributeAccessors.
 */
public static void fixOROXAccessors(Project orProject, Project oxProject) {
    for (Iterator<ClassDescriptor> i = orProject.getDescriptors().values().iterator(); i.hasNext(); ) {
        ClassDescriptor desc = i.next();
        if (!XRDynamicEntity.class.isAssignableFrom(desc.getJavaClass())) {
            continue;
        }
        Class<?> clz = desc.getJavaClass();
        ClassDescriptor xdesc = null;
        if (oxProject != null) {
            xdesc = oxProject.getDescriptorForAlias(desc.getAlias());
        }
        XRDynamicPropertiesManager xrDPM = null;
        if (!clz.getName().endsWith(COLLECTION_WRAPPER_SUFFIX)) {
            try {
                XRDynamicEntity newInstance = (XRDynamicEntity) clz.getConstructor().newInstance();
                xrDPM = newInstance.fetchPropertiesManager();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        Set<String> propertiesNameSet = new HashSet<>();
        for (Iterator<DatabaseMapping> j = desc.getMappings().iterator(); j.hasNext(); ) {
            DatabaseMapping dm = j.next();
            String attributeName = dm.getAttributeName();
            DatabaseMapping xdm = null;
            if (xdesc != null) {
                xdm = xdesc.getMappingForAttributeName(attributeName);
            }
            dm.setAttributeAccessor(new XRDynamicEntityAccessor(dm));
            if (xdm != null) {
                if (dm.isForeignReferenceMapping()) {
                    ForeignReferenceMapping frm = (ForeignReferenceMapping) dm;
                    if (frm.usesIndirection() && frm.getIndirectionPolicy().getClass().isAssignableFrom(BasicIndirectionPolicy.class)) {
                        xdm.setAttributeAccessor(new XRDynamicEntityVHAccessor(dm));
                    } else {
                        // no indirection or indirection that is transparent enough (!) to work
                        xdm.setAttributeAccessor(new XRDynamicEntityAccessor(dm));
                    }
                } else {
                    xdm.setAttributeAccessor(new XRDynamicEntityAccessor(dm));
                }
            }
            propertiesNameSet.add(attributeName);
        }
        if (xrDPM != null) {
            xrDPM.setPropertyNames(propertiesNameSet);
        }
    }
    // turn-off dynamic class generation
    ClassLoader cl = null;
    Login login = orProject.getDatasourceLogin();
    if (login != null) {
        Platform platform = login.getDatasourcePlatform();
        if (platform != null) {
            ConversionManager conversionManager = platform.getConversionManager();
            if (conversionManager != null) {
                cl = conversionManager.getLoader();
            }
        }
    }
    if (cl instanceof XRDynamicClassLoader) {
        XRDynamicClassLoader xrdecl = (XRDynamicClassLoader) cl;
        xrdecl.dontGenerateSubclasses();
    }
    if (oxProject != null) {
        cl = null;
        login = oxProject.getDatasourceLogin();
        if (login != null) {
            Platform platform = login.getDatasourcePlatform();
            if (platform != null) {
                ConversionManager conversionManager = platform.getConversionManager();
                if (conversionManager != null) {
                    cl = conversionManager.getLoader();
                }
            }
        }
        if (cl instanceof XRDynamicClassLoader) {
            XRDynamicClassLoader xrdecl = (XRDynamicClassLoader) cl;
            xrdecl.dontGenerateSubclasses();
        }
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Platform(org.eclipse.persistence.internal.databaseaccess.Platform) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) BasicIndirectionPolicy(org.eclipse.persistence.internal.indirection.BasicIndirectionPolicy) Login(org.eclipse.persistence.sessions.Login) ForeignReferenceMapping(org.eclipse.persistence.mappings.ForeignReferenceMapping) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) HashSet(java.util.HashSet)

Example 7 with ConversionManager

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

the class JCEEncryptionTest method convertToEncryptionObject.

/**
 * Convert a String into a Securable object
 * Class name must be fully qualified, eg. org.eclipse.persistence.internal.security.JCEEncryptor
 */
private Securable convertToEncryptionObject(String encryptionClassName) {
    try {
        ConversionManager cm = ConversionManager.getDefaultManager();
        Class<?> securableClass = cm.convertObject(encryptionClassName, Class.class);
        return (Securable) securableClass.getConstructor().newInstance();
    } catch (Throwable e) {
        return null;
    }
}
Also used : Securable(org.eclipse.persistence.internal.security.Securable) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager)

Example 8 with ConversionManager

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

the class ClassLoaderTest method setup.

@Override
public void setup() {
    m_failure = false;
    m_mgr = new ConversionManager();
    m_mgr.setShouldUseClassLoaderFromCurrentThread(false);
    m_mgr.setLoader(null);
    ConversionManager.setDefaultLoader(ConversionManager.class.getClassLoader());
}
Also used : ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager)

Example 9 with ConversionManager

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

the class UnidirectionalOneToManyMapping method extractSourceKeyFromRow.

/**
 * 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.
 */
protected Vector extractSourceKeyFromRow(AbstractRecord row, AbstractSession session) {
    int size = sourceKeyFields.size();
    Vector key = new Vector(size);
    ConversionManager conversionManager = session.getDatasourcePlatform().getConversionManager();
    for (int index = 0; index < size; index++) {
        DatabaseField targetField = targetForeignKeyFields.get(index);
        DatabaseField sourceField = 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.addElement(value);
    }
    return key;
}
Also used : ConversionException(org.eclipse.persistence.exceptions.ConversionException) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) Vector(java.util.Vector)

Example 10 with ConversionManager

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

the class AggregateCollectionMapping 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 gets 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)

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