use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getColumn.
private Column getColumn(Element element, boolean isMandatory, Element current) {
// Element subelement = element != null ? element.element( "column" ) : null;
if (element != null) {
AnnotationDescriptor column = new AnnotationDescriptor(Column.class);
copyStringAttribute(column, element, "name", false);
copyBooleanAttribute(column, element, "unique");
copyBooleanAttribute(column, element, "nullable");
copyBooleanAttribute(column, element, "insertable");
copyBooleanAttribute(column, element, "updatable");
copyStringAttribute(column, element, "column-definition", false);
copyStringAttribute(column, element, "table", false);
copyIntegerAttribute(column, element, "length");
copyIntegerAttribute(column, element, "precision");
copyIntegerAttribute(column, element, "scale");
return (Column) AnnotationFactory.create(column);
} else {
if (isMandatory) {
throw new AnnotationException(current.getPath() + ".column is mandatory. " + SCHEMA_VALIDATION);
}
return null;
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getMapKeyTemporal.
/**
* Adds a @MapKeyTemporal annotation to the specified annotationList if the specified element
* contains a map-key-temporal sub-element. This should only be the case for element-collection,
* many-to-many, or one-to-many associations.
*/
private void getMapKeyTemporal(List<Annotation> annotationList, Element element) {
Element subelement = element != null ? element.element("map-key-temporal") : null;
if (subelement != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(MapKeyTemporal.class);
TemporalType value = TemporalType.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 getVersion.
private void getVersion(List<Annotation> annotationList, XMLContext.Default defaults) {
for (Element element : elementsForProperty) {
if ("version".equals(element.getName())) {
Annotation annotation = buildColumns(element);
addIfNotNull(annotationList, annotation);
getTemporal(annotationList, element);
AnnotationDescriptor basic = new AnnotationDescriptor(Version.class);
annotationList.add(AnnotationFactory.create(basic));
getAccessType(annotationList, element);
}
}
if (elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations()) {
// we have nothing, so Java annotations might occurs
Annotation annotation = getPhysicalAnnotation(Version.class);
if (annotation != null) {
annotationList.add(annotation);
annotation = getPhysicalAnnotation(Column.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Columns.class);
addIfNotNull(annotationList, annotation);
annotation = getPhysicalAnnotation(Temporal.class);
addIfNotNull(annotationList, annotation);
}
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method overridesDefaultsInJoinTable.
private JoinTable overridesDefaultsInJoinTable(Annotation annotation, XMLContext.Default defaults) {
// no element but might have some default or some annotation
boolean defaultToJoinTable = !(isPhysicalAnnotationPresent(JoinColumn.class) || isPhysicalAnnotationPresent(JoinColumns.class));
final Class<? extends Annotation> annotationClass = annotation.annotationType();
defaultToJoinTable = defaultToJoinTable && ((annotationClass == ManyToMany.class && StringHelper.isEmpty(((ManyToMany) annotation).mappedBy())) || (annotationClass == OneToMany.class && StringHelper.isEmpty(((OneToMany) annotation).mappedBy())) || (annotationClass == ElementCollection.class));
final Class<JoinTable> annotationType = JoinTable.class;
if (defaultToJoinTable && (StringHelper.isNotEmpty(defaults.getCatalog()) || StringHelper.isNotEmpty(defaults.getSchema()))) {
AnnotationDescriptor ad = new AnnotationDescriptor(annotationType);
if (defaults.canUseJavaAnnotations()) {
JoinTable table = getPhysicalAnnotation(annotationType);
if (table != null) {
ad.setValue("name", table.name());
ad.setValue("schema", table.schema());
ad.setValue("catalog", table.catalog());
ad.setValue("uniqueConstraints", table.uniqueConstraints());
ad.setValue("joinColumns", table.joinColumns());
ad.setValue("inverseJoinColumns", table.inverseJoinColumns());
}
}
if (StringHelper.isEmpty((String) ad.valueOf("schema")) && StringHelper.isNotEmpty(defaults.getSchema())) {
ad.setValue("schema", defaults.getSchema());
}
if (StringHelper.isEmpty((String) ad.valueOf("catalog")) && StringHelper.isNotEmpty(defaults.getCatalog())) {
ad.setValue("catalog", defaults.getCatalog());
}
return AnnotationFactory.create(ad);
} else if (defaults.canUseJavaAnnotations()) {
return getPhysicalAnnotation(annotationType);
} else {
return null;
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method bindNamedAttributeNodes.
private static void bindNamedAttributeNodes(Element subElement, AnnotationDescriptor ann) {
List<Element> namedAttributeNodes = subElement.elements("named-attribute-node");
List<NamedAttributeNode> annNamedAttributeNodes = new ArrayList<>();
for (Element namedAttributeNode : namedAttributeNodes) {
AnnotationDescriptor annNamedAttributeNode = new AnnotationDescriptor(NamedAttributeNode.class);
copyStringAttribute(annNamedAttributeNode, namedAttributeNode, "value", "name", true);
copyStringAttribute(annNamedAttributeNode, namedAttributeNode, "subgraph", false);
copyStringAttribute(annNamedAttributeNode, namedAttributeNode, "key-subgraph", false);
annNamedAttributeNodes.add(AnnotationFactory.create(annNamedAttributeNode));
}
ann.setValue("attributeNodes", annNamedAttributeNodes.toArray(new NamedAttributeNode[annNamedAttributeNodes.size()]));
}
Aggregations