use of org.eclipse.persistence.internal.jpa.modelgen.objects.PersistenceUnit 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;
}
Aggregations