HHH-18649 nice Javadoc for static TypedQueryReferences

This commit is contained in:
Gavin King 2024-09-23 09:09:38 +02:00
parent 975dfa1ed9
commit f929a78948
2 changed files with 24 additions and 7 deletions

View File

@ -127,7 +127,7 @@ public abstract class AnnotationMeta implements Metamodel {
if ( resultType != null ) { if ( resultType != null ) {
putMember( "QUERY_" + name, putMember( "QUERY_" + name,
new TypedMetaAttribute( this, name, "QUERY_", resultType, new TypedMetaAttribute( this, name, "QUERY_", resultType,
"jakarta.persistence.TypedQueryReference" ) ); "jakarta.persistence.TypedQueryReference", hql ) );
} }
} }
} }
@ -205,11 +205,11 @@ public abstract class AnnotationMeta implements Metamodel {
// and then we will replace this TypedMetaAttribute // and then we will replace this TypedMetaAttribute
return new TypedMetaAttribute( this, name, prefix, return new TypedMetaAttribute( this, name, prefix,
resultClass == null ? JAVA_OBJECT : resultClass.getValue().toString(), resultClass == null ? JAVA_OBJECT : resultClass.getValue().toString(),
"jakarta.persistence.TypedQueryReference" ); "jakarta.persistence.TypedQueryReference", null );
} }
else if ( !isJakartaDataStyle() && "GRAPH_".equals(prefix) ) { else if ( !isJakartaDataStyle() && "GRAPH_".equals(prefix) ) {
return new TypedMetaAttribute( this, name, prefix, getQualifiedName(), return new TypedMetaAttribute( this, name, prefix, getQualifiedName(),
"jakarta.persistence.EntityGraph" ); "jakarta.persistence.EntityGraph", null );
} }
else { else {
return new NameMetaAttribute( this, name, prefix); return new NameMetaAttribute( this, name, prefix);

View File

@ -4,28 +4,34 @@
*/ */
package org.hibernate.processor.annotation; package org.hibernate.processor.annotation;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.processor.model.Metamodel; import org.hibernate.processor.model.Metamodel;
import static org.hibernate.processor.util.StringUtil.nameToMethodName; import static org.hibernate.processor.util.StringUtil.nameToMethodName;
/** /**
* Represents a named query or named entity graph.
*
* @author Gavin King * @author Gavin King
*/ */
class TypedMetaAttribute extends NameMetaAttribute { class TypedMetaAttribute extends NameMetaAttribute {
private final String prefix; private final String prefix;
private final String resultType; private final String resultType;
private final String referenceType; private final String referenceType;
private final @Nullable String query;
public TypedMetaAttribute( public TypedMetaAttribute(
Metamodel annotationMetaEntity, Metamodel annotationMetaEntity,
String name, String name,
String prefix, String prefix,
String resultType, String resultType,
String referenceType) { String referenceType,
@Nullable String query) {
super( annotationMetaEntity, name, prefix ); super( annotationMetaEntity, name, prefix );
this.prefix = prefix; this.prefix = prefix;
this.resultType = resultType; this.resultType = resultType;
this.referenceType = referenceType; this.referenceType = referenceType;
this.query = query;
} }
@Override @Override
@ -35,14 +41,25 @@ class TypedMetaAttribute extends NameMetaAttribute {
@Override @Override
public String getAttributeDeclarationString() { public String getAttributeDeclarationString() {
final boolean isQuery = "QUERY_".equals(prefix); //UGLY!
final Metamodel entity = getHostingEntity(); final Metamodel entity = getHostingEntity();
final StringBuilder declaration = new StringBuilder(); final StringBuilder declaration = new StringBuilder();
declaration declaration
.append("\n/**") .append("\n/**")
.append("\n * The query named {@value ") .append("\n * The ")
.append(isQuery ? "query" : "entity graph")
.append(" named {@value ")
.append(prefix) .append(prefix)
.append(fieldName()) .append(fieldName())
.append("}\n *\n * @see ") .append("}\n");
if ( query != null ) {
declaration.append(" * <pre>");
query.lines()
.forEach( line -> declaration.append("\n * ").append( line ) );
declaration.append("\n * </pre>\n");
}
declaration
.append(" *\n * @see ")
.append(entity.getQualifiedName()) .append(entity.getQualifiedName())
.append("\n **/\n") .append("\n **/\n")
.append("public static volatile ") .append("public static volatile ")
@ -53,7 +70,7 @@ class TypedMetaAttribute extends NameMetaAttribute {
.append(' ') .append(' ')
.append('_') .append('_')
.append(nameToMethodName(getPropertyName())); .append(nameToMethodName(getPropertyName()));
if ( "QUERY_".equals(prefix) ) { //UGLY! if ( isQuery ) {
declaration.append('_'); declaration.append('_');
} }
declaration.append(';'); declaration.append(';');