use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method overridesDefaultInSecondaryTable.
private void overridesDefaultInSecondaryTable(SecondaryTable secTableAnn, XMLContext.Default defaults, List<SecondaryTable> secondaryTables) {
if (secTableAnn != null) {
// handle default values
if (StringHelper.isNotEmpty(defaults.getCatalog()) || StringHelper.isNotEmpty(defaults.getSchema())) {
AnnotationDescriptor annotation = new AnnotationDescriptor(SecondaryTable.class);
annotation.setValue("name", secTableAnn.name());
annotation.setValue("schema", secTableAnn.schema());
annotation.setValue("catalog", secTableAnn.catalog());
annotation.setValue("uniqueConstraints", secTableAnn.uniqueConstraints());
annotation.setValue("pkJoinColumns", secTableAnn.pkJoinColumns());
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());
}
secondaryTables.add(AnnotationFactory.create(annotation));
} else {
secondaryTables.add(secTableAnn);
}
}
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildNamedEntityGraph.
public static List<NamedEntityGraph> buildNamedEntityGraph(Element element, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
if (element == null) {
return new ArrayList<>();
}
List<NamedEntityGraph> namedEntityGraphList = new ArrayList<>();
List<Element> namedEntityGraphElements = element.elements("named-entity-graph");
for (Element subElement : namedEntityGraphElements) {
AnnotationDescriptor ann = new AnnotationDescriptor(NamedEntityGraph.class);
copyStringAttribute(ann, subElement, "name", false);
copyBooleanAttribute(ann, subElement, "include-all-attributes");
bindNamedAttributeNodes(subElement, ann);
List<Element> subgraphNodes = subElement.elements("subgraph");
List<Element> subclassSubgraphNodes = subElement.elements("subclass-subgraph");
if (!subclassSubgraphNodes.isEmpty()) {
subgraphNodes.addAll(subclassSubgraphNodes);
}
bindNamedSubgraph(defaults, ann, subgraphNodes, classLoaderAccess);
namedEntityGraphList.add(AnnotationFactory.create(ann));
}
// TODO
return namedEntityGraphList;
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method overridesDefaultCascadePersist.
private Annotation overridesDefaultCascadePersist(Annotation annotation, XMLContext.Default defaults) {
if (Boolean.TRUE.equals(defaults.getCascadePersist())) {
final Class<? extends Annotation> annotationType = annotation.annotationType();
if (annotationType == ManyToOne.class) {
ManyToOne manyToOne = (ManyToOne) annotation;
List<CascadeType> cascades = new ArrayList<>(Arrays.asList(manyToOne.cascade()));
if (!cascades.contains(CascadeType.ALL) && !cascades.contains(CascadeType.PERSIST)) {
cascades.add(CascadeType.PERSIST);
} else {
return annotation;
}
AnnotationDescriptor ad = new AnnotationDescriptor(annotationType);
ad.setValue("cascade", cascades.toArray(new CascadeType[] {}));
ad.setValue("targetEntity", manyToOne.targetEntity());
ad.setValue("fetch", manyToOne.fetch());
ad.setValue("optional", manyToOne.optional());
return AnnotationFactory.create(ad);
} else if (annotationType == OneToOne.class) {
OneToOne oneToOne = (OneToOne) annotation;
List<CascadeType> cascades = new ArrayList<>(Arrays.asList(oneToOne.cascade()));
if (!cascades.contains(CascadeType.ALL) && !cascades.contains(CascadeType.PERSIST)) {
cascades.add(CascadeType.PERSIST);
} else {
return annotation;
}
AnnotationDescriptor ad = new AnnotationDescriptor(annotationType);
ad.setValue("cascade", cascades.toArray(new CascadeType[] {}));
ad.setValue("targetEntity", oneToOne.targetEntity());
ad.setValue("fetch", oneToOne.fetch());
ad.setValue("optional", oneToOne.optional());
ad.setValue("mappedBy", oneToOne.mappedBy());
ad.setValue("orphanRemoval", oneToOne.orphanRemoval());
return AnnotationFactory.create(ad);
}
}
return annotation;
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method bindNamedSubgraph.
private static void bindNamedSubgraph(XMLContext.Default defaults, AnnotationDescriptor ann, List<Element> subgraphNodes, ClassLoaderAccess classLoaderAccess) {
List<NamedSubgraph> annSubgraphNodes = new ArrayList<>();
for (Element subgraphNode : subgraphNodes) {
AnnotationDescriptor annSubgraphNode = new AnnotationDescriptor(NamedSubgraph.class);
copyStringAttribute(annSubgraphNode, subgraphNode, "name", true);
String clazzName = subgraphNode.attributeValue("class");
Class clazz;
try {
clazz = classLoaderAccess.classForName(XMLContext.buildSafeClassName(clazzName, defaults));
} catch (ClassLoadingException e) {
throw new AnnotationException("Unable to find entity-class: " + clazzName, e);
}
annSubgraphNode.setValue("type", clazz);
bindNamedAttributeNodes(subgraphNode, annSubgraphNode);
annSubgraphNodes.add(AnnotationFactory.create(annSubgraphNode));
}
ann.setValue("subgraphs", annSubgraphNodes.toArray(new NamedSubgraph[annSubgraphNodes.size()]));
}
use of org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor in project hibernate-orm by hibernate.
the class JPAOverriddenAnnotationReader method buildColumnResult.
private static ColumnResult buildColumnResult(Element columnResultElement, XMLContext.Default defaults, ClassLoaderAccess classLoaderAccess) {
// AnnotationDescriptor columnResultDescriptor = new AnnotationDescriptor( ColumnResult.class );
// copyStringAttribute( columnResultDescriptor, columnResultElement, "name", true );
// return AnnotationFactory.create( columnResultDescriptor );
AnnotationDescriptor columnResultDescriptor = new AnnotationDescriptor(ColumnResult.class);
copyStringAttribute(columnResultDescriptor, columnResultElement, "name", true);
final String columnTypeName = columnResultElement.attributeValue("class");
if (StringHelper.isNotEmpty(columnTypeName)) {
columnResultDescriptor.setValue("type", resolveClassReference(columnTypeName, defaults, classLoaderAccess));
}
return AnnotationFactory.create(columnResultDescriptor);
}
Aggregations