Search in sources :

Example 1 with ConverterAccessor

use of org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ConverterAccessor in project eclipselink by eclipse-ee4j.

the class MixedConverterMetadata method buildConverterAccessor.

/**
 * INTERNAL:
 * Build a converter accessor from this metadata.
 */
public ConverterAccessor buildConverterAccessor() {
    ConverterAccessor converterAccessor = new ConverterAccessor();
    converterAccessor.setAutoApply(getAutoApply());
    converterAccessor.setClassName(getClassName());
    return converterAccessor;
}
Also used : ConverterAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ConverterAccessor)

Example 2 with ConverterAccessor

use of org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ConverterAccessor in project eclipselink by eclipse-ee4j.

the class MetadataProcessor method initPersistenceUnitClasses.

/**
 * INTERNAL:
 * This method is responsible for discovering all the entity classes for
 * this PU and adding corresponding MetadataDescriptor in the
 * MetadataProject.
 *
 * This method will also gather all the weavable classes for this PU.
 * Currently, entity and embeddable classes are weavable.
 *
 * NOTE: The order of processing should not be changed as the steps are
 * dependent on one another.
 */
protected void initPersistenceUnitClasses() {
    // 1 - Iterate through the classes that are defined in the <mapping>
    // files and add them to the map. This will merge the accessors where
    // necessary.
    HashMap<String, EntityAccessor> entities = new HashMap<String, EntityAccessor>();
    HashMap<String, EmbeddableAccessor> embeddables = new HashMap<String, EmbeddableAccessor>();
    for (XMLEntityMappings entityMappings : m_project.getEntityMappings()) {
        entityMappings.initPersistenceUnitClasses(entities, embeddables);
    }
    // and apply any persistence unit defaults.
    for (EntityAccessor entity : entities.values()) {
        // This will apply global persistence unit defaults.
        m_project.addEntityAccessor(entity);
        // This will override any global settings.
        entity.getEntityMappings().processEntityMappingsDefaults(entity);
    }
    // project and apply any persistence unit defaults.
    for (EmbeddableAccessor embeddable : embeddables.values()) {
        // This will apply global persistence unit defaults.
        m_project.addEmbeddableAccessor(embeddable);
        // This will override any global settings.
        embeddable.getEntityMappings().processEntityMappingsDefaults(embeddable);
    }
    // in the persistence unit, as by definition only elements declared in ORM XML are to be permitted.
    if (m_project.getPersistenceUnitMetadata() != null && m_project.getPersistenceUnitMetadata().isXMLMappingMetadataComplete()) {
        return;
    }
    // 4 - Iterate through the classes that are referenced from the
    // persistence.xml file.
    PersistenceUnitInfo persistenceUnitInfo = m_project.getPersistenceUnitInfo();
    List<String> classNames = new ArrayList<String>();
    // Add all the <class> specifications.
    classNames.addAll(persistenceUnitInfo.getManagedClassNames());
    // Add all the classes from the <jar> specifications.
    for (URL url : persistenceUnitInfo.getJarFileUrls()) {
        classNames.addAll(PersistenceUnitProcessor.getClassNamesFromURL(url, m_loader, null));
    }
    // Add all the classes off the classpath at the persistence unit root url.
    Set<String> unlistedClasses = Collections.emptySet();
    if (!persistenceUnitInfo.excludeUnlistedClasses()) {
        unlistedClasses = PersistenceUnitProcessor.getClassNamesFromURL(persistenceUnitInfo.getPersistenceUnitRootUrl(), m_loader, m_predeployProperties);
    }
    // 5 - Go through all the class names we found and add those classes
    // that have not yet been added. Be sure to check that the accessor
    // does not already exist since adding an accessor will merge its
    // contents with an existing accessor and we only want that to happen
    // in the XML case. Also, don't add an entity accessor if an embeddable
    // accessor to the same class exists (and vice versa). XML accessors
    // are loaded first, so preserve what we find there.
    Iterator<String> iterator = classNames.iterator();
    boolean unlisted = false;
    while (iterator.hasNext() || !unlisted) {
        if (!iterator.hasNext() && !unlisted) {
            iterator = unlistedClasses.iterator();
            unlisted = true;
        }
        if (iterator.hasNext()) {
            String className = iterator.next();
            MetadataClass candidateClass = m_factory.getMetadataClass(className, unlisted);
            // NPE or a CNF, a warning or exception is thrown in loadClass()
            if (candidateClass != null) {
                if (PersistenceUnitProcessor.isEntity(candidateClass) && !m_project.hasEntity(candidateClass) && !m_project.hasEmbeddable(candidateClass)) {
                    m_project.addEntityAccessor(new EntityAccessor(PersistenceUnitProcessor.getEntityAnnotation(candidateClass), candidateClass, m_project));
                } else if (PersistenceUnitProcessor.isEmbeddable(candidateClass) && !m_project.hasEmbeddable(candidateClass) && !m_project.hasEntity(candidateClass)) {
                    m_project.addEmbeddableAccessor(new EmbeddableAccessor(PersistenceUnitProcessor.getEmbeddableAnnotation(candidateClass), candidateClass, m_project));
                } else if (PersistenceUnitProcessor.isStaticMetamodelClass(candidateClass)) {
                    m_project.addStaticMetamodelClass(PersistenceUnitProcessor.getStaticMetamodelAnnotation(candidateClass), candidateClass);
                } else if (PersistenceUnitProcessor.isConverter(candidateClass) && !m_project.hasConverterAccessor(candidateClass)) {
                    m_project.addConverterAccessor(new ConverterAccessor(PersistenceUnitProcessor.getConverterAnnotation(candidateClass), candidateClass, m_project));
                } else if (PersistenceUnitProcessor.isMappedSuperclass(candidateClass) && !m_project.hasMappedSuperclass(candidateClass)) {
                    // ensure mapped superclasses will be added to the metamodel even if they do not have entity subclasses
                    // add the mapped superclass to keep track of it in case it is not processed later (has no subclasses).
                    m_project.addMappedSuperclass(new MappedSuperclassAccessor(PersistenceUnitProcessor.getMappedSuperclassAnnotation(candidateClass), candidateClass, m_project));
                }
            }
        }
    }
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor) MappedSuperclassAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor) HashMap(java.util.HashMap) ConverterAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ConverterAccessor) XMLEntityMappings(org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings) ArrayList(java.util.ArrayList) EmbeddableAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EmbeddableAccessor) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) URL(java.net.URL) MetadataClass(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass)

Example 3 with ConverterAccessor

use of org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ConverterAccessor in project eclipselink by eclipse-ee4j.

the class XMLEntityMappings method initPersistenceUnitClasses.

/**
 * INTERNAL:
 * Assumes the correct class loader has been set before calling this
 * method.
 */
public void initPersistenceUnitClasses(HashMap<String, EntityAccessor> allEntities, HashMap<String, EmbeddableAccessor> allEmbeddables) {
    // the mixed converter metadata list.
    for (MixedConverterMetadata mixedConverter : m_mixedConverters) {
        if (mixedConverter.isConverterMetadata()) {
            m_converters.add(mixedConverter.buildConverterMetadata());
        } else {
            m_converterAccessors.add(mixedConverter.buildConverterAccessor());
        }
    }
    // Process the entities
    for (EntityAccessor entity : getEntities()) {
        // Initialize the class with the package from entity mappings.
        MetadataClass entityClass = getMetadataClass(getPackageQualifiedClassName(entity.getClassName()), false);
        // Initialize the entity with its metadata descriptor and project.
        // This initialization must be done before a potential merge below.
        entity.initXMLClassAccessor(entityClass, new MetadataDescriptor(entityClass, entity), m_project, this);
        if (allEntities.containsKey(entityClass.getName())) {
            // Merge this entity with the existing one.
            allEntities.get(entityClass.getName()).merge(entity);
        } else {
            // Add this entity to the map.
            allEntities.put(entityClass.getName(), entity);
        }
    }
    // Process the embeddables.
    for (EmbeddableAccessor embeddable : getEmbeddables()) {
        // Initialize the class with the package from entity mappings.
        MetadataClass embeddableClass = getMetadataClass(getPackageQualifiedClassName(embeddable.getClassName()), false);
        // Initialize the embeddable with its metadata descriptor and project.
        // This initialization must be done before a potential merge below.
        embeddable.initXMLClassAccessor(embeddableClass, new MetadataDescriptor(embeddableClass, embeddable), m_project, this);
        if (allEmbeddables.containsKey(embeddableClass.getName())) {
            // Merge this embeddable with the existing one.
            allEmbeddables.get(embeddableClass.getName()).merge(embeddable);
        } else {
            // Add this embeddable to the map.
            allEmbeddables.put(embeddableClass.getName(), embeddable);
        }
    }
    // Process the mapped superclasses
    for (MappedSuperclassAccessor mappedSuperclass : getMappedSuperclasses()) {
        // Initialize the class with the package from entity mappings.
        MetadataClass mappedSuperclassClass = getMetadataClass(getPackageQualifiedClassName(mappedSuperclass.getClassName()), false);
        // Initialize the mapped superclass with a metadata descriptor and project.
        // This initialization must be done before a potential merge below.
        mappedSuperclass.initXMLClassAccessor(mappedSuperclassClass, new MetadataDescriptor(mappedSuperclassClass, mappedSuperclass), m_project, this);
        if (m_project.hasMappedSuperclass(mappedSuperclassClass)) {
            // Merge this mapped superclass with the existing one.
            m_project.getMappedSuperclassAccessor(mappedSuperclassClass).merge(mappedSuperclass);
        } else {
            // Add this mapped superclass to the project.
            m_project.addMappedSuperclass(mappedSuperclass);
        }
    }
    // Process the JPA converter classes.
    for (ConverterAccessor converterAccessor : m_converterAccessors) {
        // Initialize the class with the package from entity mappings.
        MetadataClass converterClass = getMetadataClass(getPackageQualifiedClassName(converterAccessor.getClassName()), false);
        // Initialize the converter class.
        // This initialization must be done before a potential merge below.
        converterAccessor.initXMLObject(converterClass, this);
        if (m_project.hasConverterAccessor(converterClass)) {
            // Merge this converter with the existing one (will check for discrepancies between them)
            m_project.getConverterAccessor(converterClass).merge(converterAccessor);
        } else {
            // Add this converter to the project.
            m_project.addConverterAccessor(converterAccessor);
        }
    }
}
Also used : EntityAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor) MappedSuperclassAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor) MixedConverterMetadata(org.eclipse.persistence.internal.jpa.metadata.converters.MixedConverterMetadata) MetadataClass(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass) ConverterAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ConverterAccessor) MetadataDescriptor(org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor) EmbeddableAccessor(org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EmbeddableAccessor)

Aggregations

ConverterAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ConverterAccessor)3 EmbeddableAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EmbeddableAccessor)2 EntityAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor)2 MappedSuperclassAccessor (org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor)2 MetadataClass (org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataClass)2 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 MetadataDescriptor (org.eclipse.persistence.internal.jpa.metadata.MetadataDescriptor)1 MixedConverterMetadata (org.eclipse.persistence.internal.jpa.metadata.converters.MixedConverterMetadata)1 XMLEntityMappings (org.eclipse.persistence.internal.jpa.metadata.xml.XMLEntityMappings)1