Search in sources :

Example 1 with DescriptorCustomizer

use of org.eclipse.persistence.config.DescriptorCustomizer in project eclipselink by eclipse-ee4j.

the class EntityManagerSetupImpl method processDescriptorsFromCachedProject.

/**
 * INTERNAL:
 * This method is used to resolve Descriptor Customizers that might have been stored in the project
 * for JPA project caching.
 */
private void processDescriptorsFromCachedProject(ClassLoader realClassLoader) throws ClassNotFoundException, PrivilegedActionException, IllegalAccessException, InstantiationException {
    for (ClassDescriptor descriptor : session.getProject().getDescriptors().values()) {
        // process customizers:
        if (descriptor.getDescriptorCustomizerClassName() != null) {
            Class<?> listenerClass = findClass(descriptor.getDescriptorCustomizerClassName(), realClassLoader);
            DescriptorCustomizer customizer = (DescriptorCustomizer) buildObjectForClass(listenerClass, DescriptorCustomizer.class);
            try {
                customizer.customize(descriptor);
            } catch (Exception e) {
                session.getSessionLog().logThrowable(SessionLog.FINER, SessionLog.METADATA, e);
            }
        }
    }
}
Also used : DescriptorCustomizer(org.eclipse.persistence.config.DescriptorCustomizer) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) ValidationException(org.eclipse.persistence.exceptions.ValidationException) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) OptimisticLockException(jakarta.persistence.OptimisticLockException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) RemoteException(java.rmi.RemoteException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) EntityManagerSetupException(org.eclipse.persistence.exceptions.EntityManagerSetupException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConversionException(org.eclipse.persistence.exceptions.ConversionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PersistenceException(jakarta.persistence.PersistenceException) MalformedURLException(java.net.MalformedURLException) PersistenceUnitLoadingException(org.eclipse.persistence.exceptions.PersistenceUnitLoadingException)

Example 2 with DescriptorCustomizer

use of org.eclipse.persistence.config.DescriptorCustomizer in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method generateProject.

public CoreProject generateProject(List<JavaClass> typeInfoClasses, Map<String, TypeInfo> typeInfo, Map<String, QName> userDefinedSchemaTypes, Map<String, PackageInfo> packageToPackageInfoMappings, Map<QName, ElementDeclaration> globalElements, List<ElementDeclaration> localElements, Map<TypeMappingInfo, Class<?>> typeMappingInfoToGeneratedClass, Map<TypeMappingInfo, Class<?>> typeMappingInfoToAdapterClasses, boolean isDefaultNamespaceAllowed) throws Exception {
    this.typeInfo = typeInfo;
    this.userDefinedSchemaTypes = userDefinedSchemaTypes;
    this.packageToPackageInfoMappings = packageToPackageInfoMappings;
    this.isDefaultNamespaceAllowed = isDefaultNamespaceAllowed;
    this.globalElements = globalElements;
    this.localElements = localElements;
    this.typeMappingInfoToGeneratedClasses = typeMappingInfoToGeneratedClass;
    this.typeMappingInfoToAdapterClasses = typeMappingInfoToAdapterClasses;
    project = new Project();
    processDefaultNamespacePreferences(packageToPackageInfoMappings.values());
    // Generate descriptors
    for (JavaClass next : typeInfoClasses) {
        if (!next.isEnum()) {
            generateDescriptor(next, project);
        }
    }
    // Setup inheritance
    for (JavaClass next : typeInfoClasses) {
        if (!next.isEnum()) {
            setupInheritance(next);
        }
    }
    // Now create mappings
    generateMappings();
    // Setup AttributeGroups
    for (JavaClass next : typeInfoClasses) {
        setupAttributeGroups(next);
    }
    // apply customizers if necessary
    Set<Entry<String, TypeInfo>> entrySet = this.typeInfo.entrySet();
    for (Entry<String, TypeInfo> entry : entrySet) {
        TypeInfo tInfo = entry.getValue();
        if (tInfo.getXmlCustomizer() != null) {
            String customizerClassName = tInfo.getXmlCustomizer();
            try {
                Class<? extends DescriptorCustomizer> customizerClass = PrivilegedAccessHelper.getClassForName(customizerClassName, true, helper.getClassLoader());
                DescriptorCustomizer descriptorCustomizer = PrivilegedAccessHelper.newInstanceFromClass(customizerClass);
                descriptorCustomizer.customize((XMLDescriptor) tInfo.getDescriptor());
            } catch (ClassCastException cce) {
                throw JAXBException.invalidCustomizerClass(cce, customizerClassName);
            } catch (ReflectiveOperationException roe) {
                throw JAXBException.couldNotCreateCustomizerInstance(roe, customizerClassName);
            }
        }
    }
    processGlobalElements(project);
    return project;
}
Also used : Project(org.eclipse.persistence.sessions.Project) CoreProject(org.eclipse.persistence.core.sessions.CoreProject) Entry(java.util.Map.Entry) DescriptorCustomizer(org.eclipse.persistence.config.DescriptorCustomizer) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass)

Example 3 with DescriptorCustomizer

use of org.eclipse.persistence.config.DescriptorCustomizer in project eclipselink by eclipse-ee4j.

the class EntityManagerSetupImpl method processDescriptorCustomizers.

protected void processDescriptorCustomizers(Map m, ClassLoader loader) {
    Map customizerMap = PropertiesHandler.getPrefixValuesLogDebug(PersistenceUnitProperties.DESCRIPTOR_CUSTOMIZER_, m, session);
    if (customizerMap.isEmpty()) {
        return;
    }
    Iterator it = customizerMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        String name = (String) entry.getKey();
        String customizerClassName = (String) entry.getValue();
        ClassDescriptor descriptor = session.getDescriptorForAlias(name);
        if (descriptor == null) {
            try {
                Class<?> javaClass = findClass(name, loader);
                descriptor = session.getDescriptor(javaClass);
            } catch (Exception ex) {
                throw EntityManagerSetupException.failedWhileProcessingProperty(PersistenceUnitProperties.DESCRIPTOR_CUSTOMIZER_ + name, customizerClassName, ex);
            }
        }
        if (descriptor != null) {
            try {
                Class<? extends DescriptorCustomizer> customizerClass = findClassForProperty(customizerClassName, PersistenceUnitProperties.DESCRIPTOR_CUSTOMIZER_ + name, loader);
                DescriptorCustomizer customizer = customizerClass.getConstructor().newInstance();
                customizer.customize(descriptor);
            } catch (Exception ex) {
                throw EntityManagerSetupException.failedWhileProcessingProperty(PersistenceUnitProperties.DESCRIPTOR_CUSTOMIZER_ + name, customizerClassName, ex);
            }
        } else {
            // TODO throw a better error, missing descriptor for property.
            throw EntityManagerSetupException.failedWhileProcessingProperty(PersistenceUnitProperties.DESCRIPTOR_CUSTOMIZER_ + name, customizerClassName, null);
        }
    }
}
Also used : DescriptorCustomizer(org.eclipse.persistence.config.DescriptorCustomizer) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) Iterator(java.util.Iterator) EntityManagerFactoryProvider.getConfigPropertyAsString(org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap) IdentityMap(org.eclipse.persistence.internal.identitymaps.IdentityMap) HashMap(java.util.HashMap) ValidationException(org.eclipse.persistence.exceptions.ValidationException) EclipseLinkException(org.eclipse.persistence.exceptions.EclipseLinkException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) OptimisticLockException(jakarta.persistence.OptimisticLockException) DatabaseException(org.eclipse.persistence.exceptions.DatabaseException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException) RemoteException(java.rmi.RemoteException) IntegrityException(org.eclipse.persistence.exceptions.IntegrityException) EntityManagerSetupException(org.eclipse.persistence.exceptions.EntityManagerSetupException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConversionException(org.eclipse.persistence.exceptions.ConversionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PersistenceException(jakarta.persistence.PersistenceException) MalformedURLException(java.net.MalformedURLException) PersistenceUnitLoadingException(org.eclipse.persistence.exceptions.PersistenceUnitLoadingException)

Aggregations

DescriptorCustomizer (org.eclipse.persistence.config.DescriptorCustomizer)3 OptimisticLockException (jakarta.persistence.OptimisticLockException)2 PersistenceException (jakarta.persistence.PersistenceException)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 RemoteException (java.rmi.RemoteException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 ConversionException (org.eclipse.persistence.exceptions.ConversionException)2 DatabaseException (org.eclipse.persistence.exceptions.DatabaseException)2 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)2 EclipseLinkException (org.eclipse.persistence.exceptions.EclipseLinkException)2 EntityManagerSetupException (org.eclipse.persistence.exceptions.EntityManagerSetupException)2 IntegrityException (org.eclipse.persistence.exceptions.IntegrityException)2 PersistenceUnitLoadingException (org.eclipse.persistence.exceptions.PersistenceUnitLoadingException)2 ValidationException (org.eclipse.persistence.exceptions.ValidationException)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1