use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method mergeAttributeOverrides.
/**
* @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 association mapping) merging with
* annotations is never allowed.
*/
private AttributeOverrides mergeAttributeOverrides(XMLContext.Default defaults, List<AttributeOverride> attributes, boolean mergeWithAnnotations) {
if (mergeWithAnnotations && defaults.canUseJavaAnnotations()) {
AttributeOverride annotation = getPhysicalAnnotation(AttributeOverride.class);
addAttributeOverrideIfNeeded(annotation, attributes);
AttributeOverrides annotations = getPhysicalAnnotation(AttributeOverrides.class);
if (annotations != null) {
for (AttributeOverride current : annotations.value()) {
addAttributeOverrideIfNeeded(current, attributes);
}
}
}
if (attributes.size() > 0) {
AnnotationDescriptor ad = new AnnotationDescriptor(AttributeOverrides.class);
ad.setValue("value", attributes.toArray(new AttributeOverride[attributes.size()]));
return AnnotationFactory.create(ad);
} else {
return null;
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getDiscriminatorColumn.
private DiscriminatorColumn getDiscriminatorColumn(Element tree, XMLContext.Default defaults) {
Element element = tree != null ? tree.element("discriminator-column") : null;
if (element != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(DiscriminatorColumn.class);
copyStringAttribute(ad, element, "name", false);
copyStringAttribute(ad, element, "column-definition", false);
String value = element.attributeValue("discriminator-type");
DiscriminatorType type = DiscriminatorType.STRING;
if (value != null) {
if ("STRING".equals(value)) {
type = DiscriminatorType.STRING;
} else if ("CHAR".equals(value)) {
type = DiscriminatorType.CHAR;
} else if ("INTEGER".equals(value)) {
type = DiscriminatorType.INTEGER;
} else {
throw new AnnotationException("Unknown DiscrimiatorType in XML: " + value + " (" + SCHEMA_VALIDATION + ")");
}
}
ad.setValue("discriminatorType", type);
copyIntegerAttribute(ad, element, "length");
return AnnotationFactory.create(ad);
} else if (defaults.canUseJavaAnnotations()) {
return getPhysicalAnnotation(DiscriminatorColumn.class);
} else {
return null;
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildSequenceGeneratorAnnotation.
public static SequenceGenerator buildSequenceGeneratorAnnotation(Element element) {
if (element != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(SequenceGenerator.class);
copyStringAttribute(ad, element, "name", false);
copyStringAttribute(ad, element, "sequence-name", false);
copyIntegerAttribute(ad, element, "initial-value");
copyIntegerAttribute(ad, element, "allocation-size");
return AnnotationFactory.create(ad);
} else {
return null;
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getEnumerated.
private void getEnumerated(List<Annotation> annotationList, Element element) {
Element subElement = element != null ? element.element("enumerated") : null;
if (subElement != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(Enumerated.class);
String enumerated = subElement.getTextTrim();
if ("ORDINAL".equalsIgnoreCase(enumerated)) {
ad.setValue("value", EnumType.ORDINAL);
} else if ("STRING".equalsIgnoreCase(enumerated)) {
ad.setValue("value", EnumType.STRING);
} else if (StringHelper.isNotEmpty(enumerated)) {
throw new AnnotationException("Unknown EnumType: " + enumerated + ". " + SCHEMA_VALIDATION);
}
annotationList.add(AnnotationFactory.create(ad));
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method getAccessType.
private void getAccessType(List<Annotation> annotationList, Element element) {
if (element == null) {
return;
}
String access = element.attributeValue("access");
if (access != null) {
AnnotationDescriptor ad = new AnnotationDescriptor(Access.class);
AccessType type;
try {
type = AccessType.valueOf(access);
} catch (IllegalArgumentException e) {
throw new AnnotationException(access + " is not a valid access type. Check you xml confguration.");
}
if ((AccessType.PROPERTY.equals(type) && this.element instanceof Method) || (AccessType.FIELD.equals(type) && this.element instanceof Field)) {
return;
}
ad.setValue("value", type);
annotationList.add(AnnotationFactory.create(ad));
}
}
Aggregations