use of org.hibernate.jpamodelgen.model.MetaEntity in project hibernate-orm by hibernate.
the class JPAMetaModelEntityProcessor method modelGenerationNeedsToBeDeferred.
private boolean modelGenerationNeedsToBeDeferred(Collection<MetaEntity> entities, MetaEntity containedEntity) {
ContainsAttributeTypeVisitor visitor = new ContainsAttributeTypeVisitor(containedEntity.getTypeElement(), context);
for (MetaEntity entity : entities) {
if (entity.equals(containedEntity)) {
continue;
}
for (Element subElement : ElementFilter.fieldsIn(entity.getTypeElement().getEnclosedElements())) {
TypeMirror mirror = subElement.asType();
if (!TypeKind.DECLARED.equals(mirror.getKind())) {
continue;
}
boolean contains = mirror.accept(visitor, subElement);
if (contains) {
return true;
}
}
for (Element subElement : ElementFilter.methodsIn(entity.getTypeElement().getEnclosedElements())) {
TypeMirror mirror = subElement.asType();
if (!TypeKind.DECLARED.equals(mirror.getKind())) {
continue;
}
boolean contains = mirror.accept(visitor, subElement);
if (contains) {
return true;
}
}
}
return false;
}
use of org.hibernate.jpamodelgen.model.MetaEntity in project hibernate-orm by hibernate.
the class JPAMetaModelEntityProcessor method handleRootElementAnnotationMirrors.
private void handleRootElementAnnotationMirrors(final Element element) {
List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
for (AnnotationMirror mirror : annotationMirrors) {
if (!ElementKind.CLASS.equals(element.getKind())) {
continue;
}
String fqn = ((TypeElement) element).getQualifiedName().toString();
MetaEntity alreadyExistingMetaEntity = tryGettingExistingEntityFromContext(mirror, fqn);
if (alreadyExistingMetaEntity != null && alreadyExistingMetaEntity.isMetaComplete()) {
String msg = "Skipping processing of annotations for " + fqn + " since xml configuration is metadata complete.";
context.logMessage(Diagnostic.Kind.OTHER, msg);
continue;
}
boolean requiresLazyMemberInitialization = false;
AnnotationMetaEntity metaEntity;
if (TypeUtils.containsAnnotation(element, Constants.EMBEDDABLE) || TypeUtils.containsAnnotation(element, Constants.MAPPED_SUPERCLASS)) {
requiresLazyMemberInitialization = true;
}
metaEntity = new AnnotationMetaEntity((TypeElement) element, context, requiresLazyMemberInitialization);
if (alreadyExistingMetaEntity != null) {
metaEntity.mergeInMembers(alreadyExistingMetaEntity);
}
addMetaEntityToContext(mirror, metaEntity);
}
}
use of org.hibernate.jpamodelgen.model.MetaEntity in project hibernate-orm by hibernate.
the class JPAMetaModelEntityProcessor method createMetaModelClasses.
private void createMetaModelClasses() {
for (MetaEntity entity : context.getMetaEntities()) {
if (context.isAlreadyGenerated(entity.getQualifiedName())) {
continue;
}
context.logMessage(Diagnostic.Kind.OTHER, "Writing meta model for entity " + entity);
ClassWriter.writeFile(entity, context);
context.markGenerated(entity.getQualifiedName());
}
// we cannot process the delayed entities in any order. There might be dependencies between them.
// we need to process the top level entities first
Collection<MetaEntity> toProcessEntities = context.getMetaEmbeddables();
while (!toProcessEntities.isEmpty()) {
Set<MetaEntity> processedEntities = new HashSet<MetaEntity>();
int toProcessCountBeforeLoop = toProcessEntities.size();
for (MetaEntity entity : toProcessEntities) {
// see METAGEN-36
if (context.isAlreadyGenerated(entity.getQualifiedName())) {
processedEntities.add(entity);
continue;
}
if (modelGenerationNeedsToBeDeferred(toProcessEntities, entity)) {
continue;
}
context.logMessage(Diagnostic.Kind.OTHER, "Writing meta model for embeddable/mapped superclass" + entity);
ClassWriter.writeFile(entity, context);
context.markGenerated(entity.getQualifiedName());
processedEntities.add(entity);
}
toProcessEntities.removeAll(processedEntities);
if (toProcessEntities.size() >= toProcessCountBeforeLoop) {
context.logMessage(Diagnostic.Kind.ERROR, "Potential endless loop in generation of entities.");
}
}
}
Aggregations