use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildColumns.
private Columns buildColumns(Element element) {
List<Element> subelements = element.elements("column");
List<Column> columns = new ArrayList<>(subelements.size());
for (Element subelement : subelements) {
columns.add(getColumn(subelement, false, element));
}
if (columns.size() > 0) {
AnnotationDescriptor columnsDescr = new AnnotationDescriptor(Columns.class);
columnsDescr.setValue("columns", columns.toArray(new Column[columns.size()]));
return AnnotationFactory.create(columnsDescr);
} else {
return null;
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getElementCollection.
/**
* As per sections 12.2.3.23.9, 12.2.4.8.9 and 12.2.5.3.6 of the JPA 2.0
* specification, the element-collection subelement completely overrides 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.
*/
private void getElementCollection(List<Annotation> annotationList, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
if ("element-collection".equals(element.getName())) {
AnnotationDescriptor ad = new AnnotationDescriptor(ElementCollection.class);
addTargetClass(element, ad, "target-class", defaults);
getFetchType(ad, element);
getOrderBy(annotationList, element);
getOrderColumn(annotationList, element);
getMapKey(annotationList, element);
getMapKeyClass(annotationList, element, defaults);
getMapKeyTemporal(annotationList, element);
getMapKeyEnumerated(annotationList, element);
getMapKeyColumn(annotationList, element);
buildMapKeyJoinColumns(annotationList, element);
Annotation annotation = getColumn(element.element("column"), false, element);
addIfNotNull(annotationList, annotation);
getTemporal(annotationList, element);
getEnumerated(annotationList, element);
getLob(annotationList, element);
// Both map-key-attribute-overrides and attribute-overrides
// translate into AttributeOverride annotations, which need
// need to be wrapped in the same AttributeOverrides annotation.
List<AttributeOverride> attributes = new ArrayList<>();
attributes.addAll(buildAttributeOverrides(element, "map-key-attribute-override"));
attributes.addAll(buildAttributeOverrides(element, "attribute-override"));
annotation = mergeAttributeOverrides(defaults, attributes, false);
addIfNotNull(annotationList, annotation);
annotation = getAssociationOverrides(element, defaults, false);
addIfNotNull(annotationList, annotation);
getCollectionTable(annotationList, element, defaults);
annotationList.add(AnnotationFactory.create(ad));
getAccessType(annotationList, element);
}
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getSecondaryTables.
private SecondaryTables getSecondaryTables(Element tree, XMLContext.Default defaults) {
List<Element> elements = tree == null ? new ArrayList<>() : (List<Element>) tree.elements("secondary-table");
List<SecondaryTable> secondaryTables = new ArrayList<>(3);
for (Element element : elements) {
AnnotationDescriptor annotation = new AnnotationDescriptor(SecondaryTable.class);
copyStringAttribute(annotation, element, "name", false);
copyStringAttribute(annotation, element, "catalog", false);
if (StringHelper.isNotEmpty(defaults.getCatalog()) && StringHelper.isEmpty((String) annotation.valueOf("catalog"))) {
annotation.setValue("catalog", defaults.getCatalog());
}
copyStringAttribute(annotation, element, "schema", false);
if (StringHelper.isNotEmpty(defaults.getSchema()) && StringHelper.isEmpty((String) annotation.valueOf("schema"))) {
annotation.setValue("schema", defaults.getSchema());
}
buildUniqueConstraints(annotation, element);
buildIndex(annotation, element);
annotation.setValue("pkJoinColumns", buildPrimaryKeyJoinColumns(element));
secondaryTables.add(AnnotationFactory.create(annotation));
}
/*
* You can't have both secondary table in XML and Java,
* since there would be no way to "remove" a secondary table
*/
if (secondaryTables.size() == 0 && defaults.canUseJavaAnnotations()) {
SecondaryTable secTableAnn = getPhysicalAnnotation(SecondaryTable.class);
overridesDefaultInSecondaryTable(secTableAnn, defaults, secondaryTables);
SecondaryTables secTablesAnn = getPhysicalAnnotation(SecondaryTables.class);
if (secTablesAnn != null) {
for (SecondaryTable table : secTablesAnn.value()) {
overridesDefaultInSecondaryTable(table, defaults, secondaryTables);
}
}
}
if (secondaryTables.size() > 0) {
AnnotationDescriptor descriptor = new AnnotationDescriptor(SecondaryTables.class);
descriptor.setValue("value", secondaryTables.toArray(new SecondaryTable[secondaryTables.size()]));
return AnnotationFactory.create(descriptor);
} else {
return null;
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getJoinColumns.
private JoinColumn[] getJoinColumns(Element element, boolean isInverse) {
List<Element> subelements = element != null ? element.elements(isInverse ? "inverse-join-column" : "join-column") : null;
List<JoinColumn> joinColumns = new ArrayList<>();
if (subelements != null) {
for (Element subelement : subelements) {
AnnotationDescriptor column = new AnnotationDescriptor(JoinColumn.class);
copyStringAttribute(column, subelement, "name", false);
copyStringAttribute(column, subelement, "referenced-column-name", false);
copyBooleanAttribute(column, subelement, "unique");
copyBooleanAttribute(column, subelement, "nullable");
copyBooleanAttribute(column, subelement, "insertable");
copyBooleanAttribute(column, subelement, "updatable");
copyStringAttribute(column, subelement, "column-definition", false);
copyStringAttribute(column, subelement, "table", false);
joinColumns.add(AnnotationFactory.create(column));
}
}
return joinColumns.toArray(new JoinColumn[joinColumns.size()]);
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildAssociationOverrides.
private List<AssociationOverride> buildAssociationOverrides(Element element, XMLContext.Default defaults) {
List<Element> subelements = element == null ? null : element.elements("association-override");
List<AssociationOverride> overrides = new ArrayList<>();
if (subelements != null && subelements.size() > 0) {
for (Element current : subelements) {
AnnotationDescriptor override = new AnnotationDescriptor(AssociationOverride.class);
copyStringAttribute(override, current, "name", true);
override.setValue("joinColumns", getJoinColumns(current, false));
JoinTable joinTable = buildJoinTable(current, defaults);
if (joinTable != null) {
override.setValue("joinTable", joinTable);
}
overrides.add(AnnotationFactory.create(override));
}
}
return overrides;
}
Aggregations