Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ && getAnnotationValue( mirror, "resultClass" ) == null ) {
if ( resultType != null ) {
putMember( "QUERY_" + name,
new TypedMetaAttribute( this, name, "QUERY_", resultType,
"jakarta.persistence.TypedQueryReference" ) );
"jakarta.persistence.TypedQueryReference", hql ) );
}
}
}
Expand Down Expand Up @@ -205,11 +205,11 @@ private NameMetaAttribute auxiliaryMember(AnnotationMirror mirror, String prefix
// and then we will replace this TypedMetaAttribute
return new TypedMetaAttribute( this, name, prefix,
resultClass == null ? JAVA_OBJECT : resultClass.getValue().toString(),
"jakarta.persistence.TypedQueryReference" );
"jakarta.persistence.TypedQueryReference", null );
}
else if ( !isJakartaDataStyle() && "GRAPH_".equals(prefix) ) {
return new TypedMetaAttribute( this, name, prefix, getQualifiedName(),
"jakarta.persistence.EntityGraph" );
"jakarta.persistence.EntityGraph", null );
}
else {
return new NameMetaAttribute( this, name, prefix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,34 @@
*/
package org.hibernate.processor.annotation;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.processor.model.Metamodel;

import static org.hibernate.processor.util.StringUtil.nameToMethodName;

/**
* Represents a named query or named entity graph.
*
* @author Gavin King
*/
class TypedMetaAttribute extends NameMetaAttribute {
private final String prefix;
private final String resultType;
private final String referenceType;
private final @Nullable String query;

public TypedMetaAttribute(
Metamodel annotationMetaEntity,
String name,
String prefix,
String resultType,
String referenceType) {
String referenceType,
@Nullable String query) {
super( annotationMetaEntity, name, prefix );
this.prefix = prefix;
this.resultType = resultType;
this.referenceType = referenceType;
this.query = query;
}

@Override
Expand All @@ -35,14 +41,25 @@ public boolean hasTypedAttribute() {

@Override
public String getAttributeDeclarationString() {
final boolean isQuery = "QUERY_".equals(prefix); //UGLY!
final Metamodel entity = getHostingEntity();
final StringBuilder declaration = new StringBuilder();
declaration
.append("\n/**")
.append("\n * The query named {@value ")
.append("\n * The ")
.append(isQuery ? "query" : "entity graph")
.append(" named {@value ")
.append(prefix)
.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("\n **/\n")
.append("public static volatile ")
Expand All @@ -53,7 +70,7 @@ public String getAttributeDeclarationString() {
.append(' ')
.append('_')
.append(nameToMethodName(getPropertyName()));
if ( "QUERY_".equals(prefix) ) { //UGLY!
if ( isQuery ) {
declaration.append('_');
}
declaration.append(';');
Expand Down
Loading