Skip to content

Commit

Permalink
HHH-18705 Moved resultType to TypeUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
cigaly committed Nov 15, 2024
1 parent 8f11b24 commit 9e2ffa6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
import static org.hibernate.processor.util.TypeUtils.containsAnnotation;
import static org.hibernate.processor.util.TypeUtils.getAnnotationMirror;
import static org.hibernate.processor.util.TypeUtils.getAnnotationValue;
import static org.hibernate.processor.util.TypeUtils.resultType;

public abstract class AnnotationMeta implements Metamodel, ResultTypeSupplier {
public abstract class AnnotationMeta implements Metamodel {

void addAuxiliaryMembers() {
addAuxiliaryMembersForAnnotation( NAMED_QUERY, "QUERY_" );
Expand Down Expand Up @@ -122,7 +123,7 @@ private void handleNamedQuery(AnnotationMirror mirror, boolean checkHql) {
);
}
if ( getAnnotationValue( mirror, "resultClass" ) == null ) {
final String resultType = resultType( selectStatement );
final String resultType = resultType( selectStatement, context );
if ( resultType != null ) {
putMember( "QUERY_" + name,
new TypedMetaAttribute( this, name, "QUERY_", resultType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package org.hibernate.processor.annotation;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.processor.Context;
import org.hibernate.processor.model.MetaAttribute;
import org.hibernate.processor.model.Metamodel;
import org.hibernate.processor.util.Constants;
Expand All @@ -16,11 +15,12 @@
import java.util.TreeSet;

import static org.hibernate.processor.util.StringUtil.nameToFieldName;
import static org.hibernate.processor.util.TypeUtils.resultType;

/**
* @author Gavin King
*/
class NamedQueryMethod implements MetaAttribute, ResultTypeSupplier {
class NamedQueryMethod implements MetaAttribute {
private final AnnotationMeta annotationMeta;
private final SqmSelectStatement<?> select;
private final String name;
Expand All @@ -46,11 +46,6 @@ public NamedQueryMethod(
this.addNonnullAnnotation = addNonnullAnnotation;
}

@Override
public Context getContext() {
return annotationMeta.getContext();
}

@Override
public boolean hasTypedAttribute() {
return true;
Expand Down Expand Up @@ -126,7 +121,7 @@ private void returnType(StringBuilder declaration) {
declaration
.append(annotationMeta.importType(Constants.LIST))
.append('<')
.append(annotationMeta.importType(resultType( select )))
.append( annotationMeta.importType( resultType( select, annotationMeta.getContext() ) ) )
.append("> ")
.append(name);
if ( reactive ) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
import javax.tools.Diagnostic;

import jakarta.persistence.AccessType;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
import org.hibernate.query.sqm.tree.select.SqmSelectableNode;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -682,6 +686,27 @@ static class EmbeddedAttributeVisitor extends SimpleTypeVisitor8<@Nullable TypeE
}
}

public static String resultType(SqmSelectStatement<?> selectStatement, Context context) {
final String javaTypeName = selectStatement.getSelection().getJavaTypeName();
if ( javaTypeName != null ) {
return javaTypeName;
}
else {
final List<SqmSelectableNode<?>> items =
selectStatement.getQuerySpec().getSelectClause().getSelectionItems();
final SqmExpressible<?> expressible;
if ( items.size() == 1 && (expressible = items.getFirst().getExpressible()) != null ) {
final String typeName = expressible.getTypeName();
final TypeElement entityType = context.entityType( typeName );
return entityType == null ? typeName : entityType.getQualifiedName().toString();
}
else {
return "Object[]";
}
}
}


public static boolean isPrimitive(String paramType) {
return PRIMITIVE_TYPES.contains( paramType );
}
Expand Down

0 comments on commit 9e2ffa6

Please sign in to comment.