use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getMapKeyEnumerated.
/**
* Adds a @MapKeyEnumerated annotation to the specified annotationList if the specified element
* contains a map-key-enumerated sub-element. This should only be the case for
* element-collection, many-to-many, or one-to-many associations.
*/
private void getMapKeyEnumerated(List<Annotation> annotationList, Element element) {
Element subelement = element != null ? element.element("map-key-enumerated") : null;
if (subelement != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(MapKeyEnumerated.class);
EnumType value = EnumType.valueOf(subelement.getTextTrim());
ad.setValue("value", value);
annotationList.add(AnnotationFactory.create(ad));
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getId.
private void getId(List<Annotation> annotationList, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
if ("id".equals(element.getName())) {
boolean processId = isProcessingId(defaults);
if (processId) {
Annotation annotation = buildColumns(element);
addIfNotNull(annotationList, annotation);
annotation = buildGeneratedValue(element);
addIfNotNull(annotationList, annotation);
getTemporal(annotationList, element);
// FIXME: fix the priority of xml over java for generator names
annotation = getTableGenerator(element, defaults);
addIfNotNull(annotationList, annotation);
annotation = getSequenceGenerator(element, defaults);
addIfNotNull(annotationList, annotation);
AnnotationDescriptor id = new AnnotationDescriptor(Id.class);
annotationList.add(AnnotationFactory.create(id));
getAccessType(annotationList, element);
}
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
Annotation annotation = getPhysicalAnnotation(Id.class);
if (annotation != null) {
annotationList.add(annotation);
annotation = getPhysicalAnnotation(Column.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Columns.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(GeneratedValue.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Temporal.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(TableGenerator.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(SequenceGenerator.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AttributeOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AttributeOverrides.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AssociationOverride.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(AssociationOverrides.class);
addIfNotNull(annotationList, annotation);
}
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getMapsId.
/**
* Adds a @MapsId annotation to the specified annotationList if the specified element has the
* maps-id attribute set. This should only be the case for many-to-one or one-to-one
* associations.
*/
private void getMapsId(List<Annotation> annotationList, Element element) {
String attrVal = element.attributeValue("maps-id");
if (attrVal != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(MapsId.class);
ad.setValue("value", attrVal);
annotationList.add(AnnotationFactory.create(ad));
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getEntity.
private Entity getEntity(Element tree, XMLContext.Default defaults) {
if (tree == null) {
return defaults.canUseJavaAnnotations() ? getPhysicalAnnotation(Entity.class) : null;
} else {
if ("entity".equals(tree.getName())) {
AnnotationDescriptor entity = new AnnotationDescriptor(Entity.class);
copyStringAttribute(entity, tree, "name", false);
if (defaults.canUseJavaAnnotations() && StringHelper.isEmpty((String) entity.valueOf("name"))) {
Entity javaAnn = getPhysicalAnnotation(Entity.class);
if (javaAnn != null) {
entity.setValue("name", javaAnn.name());
}
}
return AnnotationFactory.create(entity);
} else {
// this is not an entity
return null;
}
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getAssociationOverrides.
/**
* @param mergeWithAnnotations Whether to use Java annotations for this
* element, if present and not disabled by the XMLContext defaults.
* In some contexts (such as an element-collection mapping) merging
* with annotations is never allowed.
*/
private AssociationOverrides getAssociationOverrides(Element tree, XMLContext.Default defaults, boolean mergeWithAnnotations) {
List<AssociationOverride> attributes = buildAssociationOverrides(tree, defaults);
if (mergeWithAnnotations && defaults.canUseJavaAnnotations()) {
AssociationOverride annotation = getPhysicalAnnotation(AssociationOverride.class);
addAssociationOverrideIfNeeded(annotation, attributes);
AssociationOverrides annotations = getPhysicalAnnotation(AssociationOverrides.class);
if (annotations != null) {
for (AssociationOverride current : annotations.value()) {
addAssociationOverrideIfNeeded(current, attributes);
}
}
}
if (attributes.size() > 0) {
AnnotationDescriptor ad = new AnnotationDescriptor(AssociationOverrides.class);
ad.setValue("value", attributes.toArray(new AssociationOverride[attributes.size()]));
return AnnotationFactory.create(ad);
} else {
return null;
}
}
Aggregations