Search in sources :

Example 1 with PersistenceUnitReader

use of org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader in project eclipselink by eclipse-ee4j.

the class CanonicalModelProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver() && !roundEnv.errorRaised()) {
        MetadataMirrorFactory factory = null;
        try {
            if (useStaticFactory) {
                if (staticFactory == null) {
                    // We must remember some state from one round to another.
                    // In some rounds, the user may only change one class
                    // meaning we only have one root element from the round.
                    // If it is a child class to an existing already generated
                    // parent class we need to know about this class, so the
                    // factory will also hang onto static projects for each
                    // persistence unit. Doing this is going to need careful
                    // cleanup thoughts though. Adding classes ok, but what
                    // about removing some?
                    AbstractSession session = new ServerSession(new Project(new DatabaseLogin()));
                    session.setSessionLog(log);
                    final MetadataLogger logger = new MetadataLogger(session);
                    staticFactory = new MetadataMirrorFactory(logger, Thread.currentThread().getContextClassLoader());
                    log(SessionLog.INFO, "Creating static metadata factory ...");
                }
                factory = staticFactory;
            } else {
                if (nonStaticFactory == null) {
                    AbstractSession session = new ServerSession(new Project(new DatabaseLogin()));
                    session.setSessionLog(log);
                    final MetadataLogger logger = new MetadataLogger(session);
                    nonStaticFactory = new MetadataMirrorFactory(logger, Thread.currentThread().getContextClassLoader());
                    log(SessionLog.INFO, "Creating non-static metadata factory ...");
                }
                factory = nonStaticFactory;
            }
            final MetadataLogger logger = factory.getLogger();
            // Step 1 - The factory is passed around so those who want the
            // processing or round env can get it off the factory. This
            // saves us from having to pass around multiple objects.
            factory.setEnvironments(processingEnv, roundEnv);
            // Step 2 - read the persistence xml classes (gives us extra
            // classes and mapping files. From them we get transients and
            // access). Metadata read from XML causes new accessors to be
            // created and override existing ones (causing them to be un-
            // pre-processed. We can never tell what changes in XML so we
            // have to do this.
            final PersistenceUnitReader puReader = new PersistenceUnitReader(logger, processingEnv);
            puReader.initPersistenceUnits(factory);
            // their canonical model classes.
            for (PersistenceUnit persistenceUnit : factory.getPersistenceUnits()) {
                // being compiled.
                for (Element element : roundEnv.getElementsAnnotatedWith(Entity.class)) {
                    persistenceUnit.addEntityAccessor(element);
                }
                // being compiled.
                for (Element element : roundEnv.getElementsAnnotatedWith(Embeddable.class)) {
                    persistenceUnit.addEmbeddableAccessor(element);
                }
                // that are being compiled.
                for (Element element : roundEnv.getElementsAnnotatedWith(MappedSuperclass.class)) {
                    persistenceUnit.addMappedSuperclassAccessor(element);
                }
                // Step 3d - tell the persistence unit to pre-process itself.
                persistenceUnit.preProcessForCanonicalModel();
                // Step 3e - We're set, generate the canonical model classes.
                generateCanonicalModelClasses(factory, persistenceUnit);
            }
        } catch (Exception e) {
            log.logThrowable(SessionLog.SEVERE, SessionLog.PROCESSOR, e);
            throw new RuntimeException(e);
        }
    }
    // Don't claim any annotations
    return false;
}
Also used : MetadataProject(org.eclipse.persistence.internal.jpa.metadata.MetadataProject) Project(org.eclipse.persistence.sessions.Project) DatabaseLogin(org.eclipse.persistence.sessions.DatabaseLogin) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) MetadataLogger(org.eclipse.persistence.internal.jpa.metadata.MetadataLogger) PersistenceUnit(org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnit) TypeElement(javax.lang.model.element.TypeElement) MetadataAnnotatedElement(org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAnnotatedElement) Element(javax.lang.model.element.Element) PersistenceUnitReader(org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader) IOException(java.io.IOException) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Aggregations

IOException (java.io.IOException)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1 MetadataLogger (org.eclipse.persistence.internal.jpa.metadata.MetadataLogger)1 MetadataProject (org.eclipse.persistence.internal.jpa.metadata.MetadataProject)1 MetadataAnnotatedElement (org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAnnotatedElement)1 PersistenceUnit (org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnit)1 PersistenceUnitReader (org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnitReader)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 DatabaseLogin (org.eclipse.persistence.sessions.DatabaseLogin)1 Project (org.eclipse.persistence.sessions.Project)1 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)1