Search in sources :

Example 1 with MappingProcessorContext

use of com.haulmont.cuba.core.sys.persistence.mapping.MappingProcessorContext in project cuba by cuba-platform.

the class EclipseLinkSessionEventListener method preLogin.

@Override
public void preLogin(SessionEvent event) {
    Session session = event.getSession();
    boolean useJoinSubclasses = useJoinSubclasses();
    boolean hasMultipleTableConstraintDependency = hasMultipleTableConstraintDependency();
    setPrintInnerJoinOnClause(session);
    if (useJoinSubclasses) {
        setJoinSubclasses(session);
    }
    List<Pair<Class, String>> missingEnhancements = new ArrayList<>();
    Map<String, ClassDescriptor> mappedSuperclassDescriptorMap = session.getProject().getMappedSuperclassDescriptors();
    for (Map.Entry<String, ClassDescriptor> entry : mappedSuperclassDescriptorMap.entrySet()) {
        try {
            Class javaClass = getClass().getClassLoader().loadClass(entry.getKey());
            enhancementCheck(javaClass, missingEnhancements);
        } catch (ClassNotFoundException e) {
            log.warn("MappedSuperclass {} was not found by ClassLoader", entry.getKey());
        }
    }
    Map<Class, ClassDescriptor> descriptorMap = session.getDescriptors();
    for (Map.Entry<Class, ClassDescriptor> entry : descriptorMap.entrySet()) {
        MetaClass metaClass = metadata.getSession().getClassNN(entry.getKey());
        ClassDescriptor desc = entry.getValue();
        enhancementCheck(entry.getKey(), missingEnhancements);
        setCacheable(metaClass, desc, session);
        if (hasMultipleTableConstraintDependency) {
            setMultipleTableConstraintDependency(metaClass, desc);
        }
        if (useJoinSubclasses) {
            setJoinSubclasses(metaClass, desc);
        }
        if (Entity.class.isAssignableFrom(desc.getJavaClass())) {
            // set DescriptorEventManager that doesn't invoke listeners for base classes
            desc.setEventManager(new DescriptorEventManagerWrapper(desc.getDescriptorEventManager()));
            desc.getEventManager().addListener(descriptorEventListener);
        }
        setAdditionalCriteria(desc);
        if (SoftDelete.class.isAssignableFrom(desc.getJavaClass())) {
            desc.setDeletePredicate(entity -> entity instanceof SoftDelete && PersistenceHelper.isLoaded(entity, "deleteTs") && ((SoftDelete) entity).isDeleted());
        }
        Map<String, MappingProcessor> mappingProcessors = AppBeans.getAll(MappingProcessor.class);
        for (DatabaseMapping mapping : desc.getMappings()) {
            MappingProcessorContext mappingProcessorCtx = new MappingProcessorContext(mapping, session);
            for (MappingProcessor mp : mappingProcessors.values()) {
                log.debug("{} mapping processor is started", mp.getClass());
                mp.process(mappingProcessorCtx);
                log.debug("{} mapping processor is finished", mp.getClass());
            }
        }
    }
    logCheckResult(missingEnhancements);
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) SoftDelete(com.haulmont.cuba.core.entity.SoftDelete) MappingProcessorContext(com.haulmont.cuba.core.sys.persistence.mapping.MappingProcessorContext) ArrayList(java.util.ArrayList) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) MetaClass(com.haulmont.chile.core.model.MetaClass) MappingProcessor(com.haulmont.cuba.core.sys.persistence.mapping.MappingProcessor) MetaClass(com.haulmont.chile.core.model.MetaClass) Map(java.util.Map) Session(org.eclipse.persistence.sessions.Session) Pair(com.haulmont.bali.datastruct.Pair)

Aggregations

Pair (com.haulmont.bali.datastruct.Pair)1 MetaClass (com.haulmont.chile.core.model.MetaClass)1 SoftDelete (com.haulmont.cuba.core.entity.SoftDelete)1 MappingProcessor (com.haulmont.cuba.core.sys.persistence.mapping.MappingProcessor)1 MappingProcessorContext (com.haulmont.cuba.core.sys.persistence.mapping.MappingProcessorContext)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 Session (org.eclipse.persistence.sessions.Session)1