use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getAssociationId.
/**
* Adds an @Id annotation to the specified annotationList if the specified element has the id
* attribute set to true. This should only be the case for many-to-one or one-to-one
* associations.
*/
private void getAssociationId(List<Annotation> annotationList, Element element) {
String attrVal = element.attributeValue("id");
if ("true".equals(attrVal)) {
AnnotationDescriptor ad = new AnnotationDescriptor(Id.class);
annotationList.add(AnnotationFactory.create(ad));
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getAssociation.
/**
* As per section 12.2 of the JPA 2.0 specification, the association
* subelements (many-to-one, one-to-many, one-to-one, many-to-many,
* element-collection) completely override the mapping for the specified
* field or property. Thus, any methods which might in some contexts merge
* with annotations must not do so in this context.
*
* @see #getElementCollection(List, org.hibernate.cfg.annotations.reflection.XMLContext.Default)
*/
private void getAssociation(Class<? extends Annotation> annotationType, List<Annotation> annotationList, XMLContext.Default defaults) {
String xmlName = annotationToXml.get(annotationType);
for (Element element : elementsForProperty) {
if (xmlName.equals(element.getName())) {
AnnotationDescriptor ad = new AnnotationDescriptor(annotationType);
addTargetClass(element, ad, "target-entity", defaults);
getFetchType(ad, element);
getCascades(ad, element, defaults);
getJoinTable(annotationList, element, defaults);
buildJoinColumns(annotationList, element);
Annotation annotation = getPrimaryKeyJoinColumns(element, defaults, false);
addIfNotNull(annotationList, annotation);
copyBooleanAttribute(ad, element, "optional");
copyBooleanAttribute(ad, element, "orphan-removal");
copyStringAttribute(ad, element, "mapped-by", false);
getOrderBy(annotationList, element);
getMapKey(annotationList, element);
getMapKeyClass(annotationList, element, defaults);
getMapKeyColumn(annotationList, element);
getOrderColumn(annotationList, element);
getMapKeyTemporal(annotationList, element);
getMapKeyEnumerated(annotationList, element);
annotation = getMapKeyAttributeOverrides(element, defaults);
addIfNotNull(annotationList, annotation);
buildMapKeyJoinColumns(annotationList, element);
getAssociationId(annotationList, element);
getMapsId(annotationList, element);
annotationList.add(AnnotationFactory.create(ad));
getAccessType(annotationList, element);
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
Annotation annotation = getPhysicalAnnotation(annotationType);
if (annotation != null) {
annotation = overridesDefaultCascadePersist(annotation, defaults);
annotationList.add(annotation);
annotation = overridesDefaultsInJoinTable(annotation, defaults);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(JoinColumn.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(JoinColumns.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(PrimaryKeyJoinColumn.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(PrimaryKeyJoinColumns.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKey.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(OrderBy.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);
annotation = getPhysicalAnnotation(Lob.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Enumerated.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Temporal.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Column.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Columns.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyClass.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyTemporal.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyEnumerated.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyColumn.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyJoinColumn.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyJoinColumns.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(OrderColumn.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Cascade.class);
addIfNotNull(annotationList, annotation);
} else if (isPhysicalAnnotationPresent(ElementCollection.class)) {
// JPA2
annotation = overridesDefaultsInJoinTable(getPhysicalAnnotation(ElementCollection.class), defaults);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKey.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(OrderBy.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);
annotation = getPhysicalAnnotation(Lob.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Enumerated.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Temporal.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Column.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(OrderColumn.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyClass.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyTemporal.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyEnumerated.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyColumn.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyJoinColumn.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(MapKeyJoinColumns.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(CollectionTable.class);
addIfNotNull(annotationList, annotation);
}
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildConstructorResult.
private static ConstructorResult buildConstructorResult(Element constructorResultElement, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
AnnotationDescriptor constructorResultDescriptor = new AnnotationDescriptor(ConstructorResult.class);
final Class entityClass = resolveClassReference(constructorResultElement.attributeValue("target-class"), defaults, classLoaderAccess);
constructorResultDescriptor.setValue("targetClass", entityClass);
List<ColumnResult> columnResultAnnotations = new ArrayList<>();
for (Element columnResultElement : (List<Element>) constructorResultElement.elements("column")) {
columnResultAnnotations.add(buildColumnResult(columnResultElement, defaults, classLoaderAccess));
}
constructorResultDescriptor.setValue("columns", columnResultAnnotations.toArray(new ColumnResult[columnResultAnnotations.size()]));
return AnnotationFactory.create(constructorResultDescriptor);
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getTable.
private Table getTable(Element tree, XMLContext.Default defaults) {
Element subelement = tree == null ? null : tree.element("table");
if (subelement == null) {
// no element but might have some default or some annotation
if (StringHelper.isNotEmpty(defaults.getCatalog()) || StringHelper.isNotEmpty(defaults.getSchema())) {
AnnotationDescriptor annotation = new AnnotationDescriptor(Table.class);
if (defaults.canUseJavaAnnotations()) {
Table table = getPhysicalAnnotation(Table.class);
if (table != null) {
annotation.setValue("name", table.name());
annotation.setValue("schema", table.schema());
annotation.setValue("catalog", table.catalog());
annotation.setValue("uniqueConstraints", table.uniqueConstraints());
annotation.setValue("indexes", table.indexes());
}
}
if (StringHelper.isEmpty((String) annotation.valueOf("schema")) && StringHelper.isNotEmpty(defaults.getSchema())) {
annotation.setValue("schema", defaults.getSchema());
}
if (StringHelper.isEmpty((String) annotation.valueOf("catalog")) && StringHelper.isNotEmpty(defaults.getCatalog())) {
annotation.setValue("catalog", defaults.getCatalog());
}
return AnnotationFactory.create(annotation);
} else if (defaults.canUseJavaAnnotations()) {
return getPhysicalAnnotation(Table.class);
} else {
return null;
}
} else {
// ignore java annotation, an element is defined
AnnotationDescriptor annotation = new AnnotationDescriptor(Table.class);
copyStringAttribute(annotation, subelement, "name", false);
copyStringAttribute(annotation, subelement, "catalog", false);
if (StringHelper.isNotEmpty(defaults.getCatalog()) && StringHelper.isEmpty((String) annotation.valueOf("catalog"))) {
annotation.setValue("catalog", defaults.getCatalog());
}
copyStringAttribute(annotation, subelement, "schema", false);
if (StringHelper.isNotEmpty(defaults.getSchema()) && StringHelper.isEmpty((String) annotation.valueOf("schema"))) {
annotation.setValue("schema", defaults.getSchema());
}
buildUniqueConstraints(annotation, subelement);
buildIndex(annotation, subelement);
return AnnotationFactory.create(annotation);
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildAttributeOverrides.
private List<AttributeOverride> buildAttributeOverrides(List<Element> subelements, String nodeName) {
List<AttributeOverride> overrides = new ArrayList<>();
if (subelements != null && subelements.size() > 0) {
for (Element current : subelements) {
if (!current.getName().equals(nodeName)) {
continue;
}
AnnotationDescriptor override = new AnnotationDescriptor(AttributeOverride.class);
copyStringAttribute(override, current, "name", true);
Element column = current.element("column");
override.setValue("column", getColumn(column, true, current));
overrides.add(AnnotationFactory.create(override));
}
}
return overrides;
}
Aggregations