mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-16 16:15:06 +00:00
HHH-17772 cleanup after sorting rework
This commit is contained in:
parent
7f4f760ac8
commit
5d2527383e
@ -22,7 +22,7 @@ public abstract class AbstractFinderMethod extends AbstractQueryMethod {
|
|||||||
final String entity;
|
final String entity;
|
||||||
final List<String> fetchProfiles;
|
final List<String> fetchProfiles;
|
||||||
|
|
||||||
public AbstractFinderMethod(
|
AbstractFinderMethod(
|
||||||
AnnotationMetaEntity annotationMetaEntity,
|
AnnotationMetaEntity annotationMetaEntity,
|
||||||
String methodName,
|
String methodName,
|
||||||
String entity,
|
String entity,
|
||||||
@ -32,13 +32,15 @@ public AbstractFinderMethod(
|
|||||||
List<String> fetchProfiles,
|
List<String> fetchProfiles,
|
||||||
List<String> paramNames,
|
List<String> paramNames,
|
||||||
List<String> paramTypes,
|
List<String> paramTypes,
|
||||||
|
List<OrderBy> orderBys,
|
||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean convertToDataExceptions) {
|
boolean convertToDataExceptions) {
|
||||||
super( annotationMetaEntity,
|
super( annotationMetaEntity,
|
||||||
methodName,
|
methodName,
|
||||||
paramNames, paramTypes, entity,
|
paramNames, paramTypes, entity,
|
||||||
sessionType, sessionName,
|
sessionType, sessionName,
|
||||||
belongsToDao, addNonnullAnnotation,
|
belongsToDao, orderBys,
|
||||||
|
addNonnullAnnotation,
|
||||||
convertToDataExceptions );
|
convertToDataExceptions );
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this.fetchProfiles = fetchProfiles;
|
this.fetchProfiles = fetchProfiles;
|
||||||
@ -204,9 +206,4 @@ void modifiers(StringBuilder declaration) {
|
|||||||
declaration
|
declaration
|
||||||
.append(belongsToDao ? "@Override\npublic " : "public static ");
|
.append(belongsToDao ? "@Override\npublic " : "public static ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
String getSortableEntityClass() {
|
|
||||||
return entity;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -10,30 +10,12 @@
|
|||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.jpamodelgen.model.MetaAttribute;
|
import org.hibernate.jpamodelgen.model.MetaAttribute;
|
||||||
import org.hibernate.jpamodelgen.model.Metamodel;
|
import org.hibernate.jpamodelgen.model.Metamodel;
|
||||||
import org.hibernate.jpamodelgen.util.Constants;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.util.Collections.emptyList;
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.HIB_KEYED_PAGE;
|
import static org.hibernate.jpamodelgen.util.Constants.*;
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.HIB_KEYED_RESULT_LIST;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.HIB_ORDER;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.HIB_PAGE;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.HIB_SELECTION_QUERY;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.JD_KEYED_PAGE;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.JD_KEYED_SLICE;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.JD_LIMIT;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.JD_ORDER;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.JD_PAGE;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.JD_PAGE_REQUEST;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.JD_SLICE;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.JD_SORT;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.LIST;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.OPTIONAL;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.SESSION_TYPES;
|
|
||||||
import static org.hibernate.jpamodelgen.util.Constants.STREAM;
|
|
||||||
import static org.hibernate.jpamodelgen.util.TypeUtils.isPrimitive;
|
import static org.hibernate.jpamodelgen.util.TypeUtils.isPrimitive;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,10 +30,11 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
|
|||||||
final String sessionType;
|
final String sessionType;
|
||||||
final String sessionName;
|
final String sessionName;
|
||||||
final boolean belongsToDao;
|
final boolean belongsToDao;
|
||||||
|
final List<OrderBy> orderBys;
|
||||||
final boolean addNonnullAnnotation;
|
final boolean addNonnullAnnotation;
|
||||||
final boolean dataRepository;
|
final boolean dataRepository;
|
||||||
|
|
||||||
public AbstractQueryMethod(
|
AbstractQueryMethod(
|
||||||
AnnotationMetaEntity annotationMetaEntity,
|
AnnotationMetaEntity annotationMetaEntity,
|
||||||
String methodName,
|
String methodName,
|
||||||
List<String> paramNames, List<String> paramTypes,
|
List<String> paramNames, List<String> paramTypes,
|
||||||
@ -59,6 +42,7 @@ public AbstractQueryMethod(
|
|||||||
String sessionType,
|
String sessionType,
|
||||||
String sessionName,
|
String sessionName,
|
||||||
boolean belongsToDao,
|
boolean belongsToDao,
|
||||||
|
List<OrderBy> orderBys,
|
||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean dataRepository) {
|
boolean dataRepository) {
|
||||||
this.annotationMetaEntity = annotationMetaEntity;
|
this.annotationMetaEntity = annotationMetaEntity;
|
||||||
@ -69,6 +53,7 @@ public AbstractQueryMethod(
|
|||||||
this.sessionType = sessionType;
|
this.sessionType = sessionType;
|
||||||
this.sessionName = sessionName;
|
this.sessionName = sessionName;
|
||||||
this.belongsToDao = belongsToDao;
|
this.belongsToDao = belongsToDao;
|
||||||
|
this.orderBys = orderBys;
|
||||||
this.addNonnullAnnotation = addNonnullAnnotation;
|
this.addNonnullAnnotation = addNonnullAnnotation;
|
||||||
this.dataRepository = dataRepository;
|
this.dataRepository = dataRepository;
|
||||||
}
|
}
|
||||||
@ -112,6 +97,16 @@ String strip(String type) {
|
|||||||
return type.endsWith("...") ? stripped + "..." : stripped;
|
return type.endsWith("...") ? stripped + "..." : stripped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void preamble(StringBuilder declaration, StringBuilder returnType, List<String> paramTypes) {
|
||||||
|
declaration
|
||||||
|
.append(returnType)
|
||||||
|
.append(" ")
|
||||||
|
.append(methodName);
|
||||||
|
parameters( paramTypes, declaration );
|
||||||
|
declaration
|
||||||
|
.append(" {\n");
|
||||||
|
}
|
||||||
|
|
||||||
void parameters(List<String> paramTypes, StringBuilder declaration) {
|
void parameters(List<String> paramTypes, StringBuilder declaration) {
|
||||||
declaration
|
declaration
|
||||||
.append("(");
|
.append("(");
|
||||||
@ -180,15 +175,15 @@ void see(StringBuilder declaration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isUsingEntityManager() {
|
boolean isUsingEntityManager() {
|
||||||
return Constants.ENTITY_MANAGER.equals(sessionType);
|
return ENTITY_MANAGER.equals(sessionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isUsingStatelessSession() {
|
boolean isUsingStatelessSession() {
|
||||||
return Constants.HIB_STATELESS_SESSION.equals(sessionType);
|
return HIB_STATELESS_SESSION.equals(sessionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isReactive() {
|
boolean isReactive() {
|
||||||
return Constants.MUTINY_SESSION.equals(sessionType);
|
return MUTINY_SESSION.equals(sessionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPage(StringBuilder declaration, String paramName, String paramType) {
|
void setPage(StringBuilder declaration, String paramName, String paramType) {
|
||||||
@ -290,17 +285,11 @@ static void closingBrace(StringBuilder declaration) {
|
|||||||
declaration.append("\n}");
|
declaration.append("\n}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable String getSortableEntityClass() {
|
|
||||||
return returnTypeName;
|
|
||||||
}
|
|
||||||
|
|
||||||
void unwrapQuery(StringBuilder declaration, boolean unwrapped) {
|
void unwrapQuery(StringBuilder declaration, boolean unwrapped) {
|
||||||
if ( !unwrapped && isUsingEntityManager() ) {
|
if ( !unwrapped && isUsingEntityManager() ) {
|
||||||
declaration
|
declaration
|
||||||
.append("\t\t\t.unwrap(");
|
.append("\t\t\t.unwrap(")
|
||||||
final String selectionQuery = annotationMetaEntity.importType(HIB_SELECTION_QUERY);
|
.append(annotationMetaEntity.importType(HIB_SELECTION_QUERY))
|
||||||
declaration
|
|
||||||
.append(selectionQuery)
|
|
||||||
.append(".class)\n");
|
.append(".class)\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -346,8 +335,7 @@ void makeKeyedPage(StringBuilder declaration, List<String> paramTypes) {
|
|||||||
annotationMetaEntity.staticImport("org.hibernate.query.Order", "by");
|
annotationMetaEntity.staticImport("org.hibernate.query.Order", "by");
|
||||||
annotationMetaEntity.staticImport("org.hibernate.query.Page", "page");
|
annotationMetaEntity.staticImport("org.hibernate.query.Page", "page");
|
||||||
annotationMetaEntity.staticImport(Collectors.class.getName(), "toList");
|
annotationMetaEntity.staticImport(Collectors.class.getName(), "toList");
|
||||||
final String entityClass = getSortableEntityClass();
|
if ( returnTypeName == null ) {
|
||||||
if ( entityClass == null ) {
|
|
||||||
throw new AssertionFailure("entity class cannot be null");
|
throw new AssertionFailure("entity class cannot be null");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -355,7 +343,7 @@ void makeKeyedPage(StringBuilder declaration, List<String> paramTypes) {
|
|||||||
.append(MAKE_KEYED_PAGE
|
.append(MAKE_KEYED_PAGE
|
||||||
.replace("pageRequest",
|
.replace("pageRequest",
|
||||||
parameterName(JD_PAGE_REQUEST, paramTypes, paramNames))
|
parameterName(JD_PAGE_REQUEST, paramTypes, paramNames))
|
||||||
.replace("Entity", annotationMetaEntity.importType(entityClass)));
|
.replace("Entity", annotationMetaEntity.importType(returnTypeName)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,10 +382,6 @@ void createQuery(StringBuilder declaration) {}
|
|||||||
|
|
||||||
void setParameters(StringBuilder declaration, List<String> paramTypes) {}
|
void setParameters(StringBuilder declaration, List<String> paramTypes) {}
|
||||||
|
|
||||||
List<OrderBy> getOrderBys() {
|
|
||||||
return emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
void tryReturn(StringBuilder declaration, List<String> paramTypes, @Nullable String containerType) {
|
void tryReturn(StringBuilder declaration, List<String> paramTypes, @Nullable String containerType) {
|
||||||
if ( isJakartaKeyedSlice(containerType) ) {
|
if ( isJakartaKeyedSlice(containerType) ) {
|
||||||
makeKeyedPage( declaration, paramTypes );
|
makeKeyedPage( declaration, paramTypes );
|
||||||
@ -422,14 +406,13 @@ void tryReturn(StringBuilder declaration, List<String> paramTypes, @Nullable Str
|
|||||||
.append('\t');
|
.append('\t');
|
||||||
if ( isJakartaKeyedSlice(containerType)
|
if ( isJakartaKeyedSlice(containerType)
|
||||||
|| isJakartaSlice(containerType) ) {
|
|| isJakartaSlice(containerType) ) {
|
||||||
final String entityClass = getSortableEntityClass();
|
if ( returnTypeName != null && isUsingEntityManager() ) {
|
||||||
if ( entityClass != null && isUsingEntityManager() ) {
|
|
||||||
// this is necessary to avoid losing the type
|
// this is necessary to avoid losing the type
|
||||||
// after unwrapping the Query object
|
// after unwrapping the Query object
|
||||||
declaration
|
declaration
|
||||||
.append(annotationMetaEntity.importType(HIB_KEYED_RESULT_LIST))
|
.append(annotationMetaEntity.importType(HIB_KEYED_RESULT_LIST))
|
||||||
.append('<')
|
.append('<')
|
||||||
.append(annotationMetaEntity.importType(entityClass))
|
.append(annotationMetaEntity.importType(returnTypeName))
|
||||||
.append('>');
|
.append('>');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -454,28 +437,27 @@ private void totalResults(StringBuilder declaration, List<String> paramTypes) {
|
|||||||
setParameters( declaration, paramTypes );
|
setParameters( declaration, paramTypes );
|
||||||
unwrapQuery( declaration, !isUsingEntityManager() );
|
unwrapQuery( declaration, !isUsingEntityManager() );
|
||||||
declaration
|
declaration
|
||||||
.append("\t\t\t\t\t\t.getResultCount();\n");
|
.append("\t\t\t.getResultCount();\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void collectOrdering(StringBuilder declaration, List<String> paramTypes) {
|
void collectOrdering(StringBuilder declaration, List<String> paramTypes) {
|
||||||
final String entityClass = getSortableEntityClass();
|
|
||||||
if ( hasOrdering(paramTypes) ) {
|
if ( hasOrdering(paramTypes) ) {
|
||||||
if ( entityClass != null ) {
|
if ( returnTypeName != null ) {
|
||||||
declaration
|
declaration
|
||||||
.append("\tvar _orders = new ")
|
.append("\tvar _orders = new ")
|
||||||
.append(annotationMetaEntity.importType("java.util.ArrayList"))
|
.append(annotationMetaEntity.importType("java.util.ArrayList"))
|
||||||
.append("<")
|
.append("<")
|
||||||
.append(annotationMetaEntity.importType(HIB_ORDER))
|
.append(annotationMetaEntity.importType(HIB_ORDER))
|
||||||
.append("<? super ")
|
.append("<? super ")
|
||||||
.append(annotationMetaEntity.importType(entityClass))
|
.append(annotationMetaEntity.importType(returnTypeName))
|
||||||
.append(">>();\n");
|
.append(">>();\n");
|
||||||
// static orders declared using @OrderBy must come first
|
// static orders declared using @OrderBy must come first
|
||||||
for ( OrderBy orderBy : getOrderBys() ) {
|
for ( OrderBy orderBy : orderBys ) {
|
||||||
declaration
|
declaration
|
||||||
.append("\t_orders.add(")
|
.append("\t_orders.add(")
|
||||||
.append(annotationMetaEntity.staticImport(HIB_ORDER, "by"))
|
.append(annotationMetaEntity.staticImport(HIB_ORDER, "by"))
|
||||||
.append('(')
|
.append('(')
|
||||||
.append(annotationMetaEntity.importType(entityClass))
|
.append(annotationMetaEntity.importType(returnTypeName))
|
||||||
.append(".class, \"")
|
.append(".class, \"")
|
||||||
.append(orderBy.fieldName)
|
.append(orderBy.fieldName)
|
||||||
.append("\", ")
|
.append("\", ")
|
||||||
@ -517,7 +499,7 @@ else if ( type.startsWith(JD_ORDER)
|
|||||||
.append("\t\t_orders.add(")
|
.append("\t\t_orders.add(")
|
||||||
.append(annotationMetaEntity.staticImport(HIB_ORDER, "by"))
|
.append(annotationMetaEntity.staticImport(HIB_ORDER, "by"))
|
||||||
.append('(')
|
.append('(')
|
||||||
.append(annotationMetaEntity.importType(entityClass))
|
.append(annotationMetaEntity.importType(returnTypeName))
|
||||||
.append(".class, _sort.property(),")
|
.append(".class, _sort.property(),")
|
||||||
.append("\n\t\t\t\t\t\t")
|
.append("\n\t\t\t\t\t\t")
|
||||||
.append("_sort.isAscending() ? ASCENDING : DESCENDING,")
|
.append("_sort.isAscending() ? ASCENDING : DESCENDING,")
|
||||||
@ -534,7 +516,7 @@ else if ( type.startsWith(JD_SORT) && type.endsWith("...") ) {
|
|||||||
.append("\t\t_orders.add(")
|
.append("\t\t_orders.add(")
|
||||||
.append(annotationMetaEntity.staticImport(HIB_ORDER, "by"))
|
.append(annotationMetaEntity.staticImport(HIB_ORDER, "by"))
|
||||||
.append('(')
|
.append('(')
|
||||||
.append(annotationMetaEntity.importType(entityClass))
|
.append(annotationMetaEntity.importType(returnTypeName))
|
||||||
.append(".class, _sort.property(),")
|
.append(".class, _sort.property(),")
|
||||||
.append("\n\t\t\t\t\t\t")
|
.append("\n\t\t\t\t\t\t")
|
||||||
.append("_sort.isAscending() ? ASCENDING : DESCENDING,")
|
.append("_sort.isAscending() ? ASCENDING : DESCENDING,")
|
||||||
@ -547,7 +529,7 @@ else if ( type.startsWith(JD_SORT) ) {
|
|||||||
.append("\t_orders.add(")
|
.append("\t_orders.add(")
|
||||||
.append(annotationMetaEntity.staticImport(HIB_ORDER, "by"))
|
.append(annotationMetaEntity.staticImport(HIB_ORDER, "by"))
|
||||||
.append('(')
|
.append('(')
|
||||||
.append(annotationMetaEntity.importType(entityClass))
|
.append(annotationMetaEntity.importType(returnTypeName))
|
||||||
.append(".class, ")
|
.append(".class, ")
|
||||||
.append(name)
|
.append(name)
|
||||||
.append(".property(),")
|
.append(".property(),")
|
||||||
@ -565,7 +547,7 @@ else if ( type.startsWith(JD_SORT) ) {
|
|||||||
|
|
||||||
private boolean hasOrdering(List<String> paramTypes) {
|
private boolean hasOrdering(List<String> paramTypes) {
|
||||||
return paramTypes.stream().anyMatch(AbstractQueryMethod::isOrderParam)
|
return paramTypes.stream().anyMatch(AbstractQueryMethod::isOrderParam)
|
||||||
|| !getOrderBys().isEmpty();
|
|| !orderBys.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean unwrapIfNecessary(StringBuilder declaration, @Nullable String containerType, boolean unwrapped) {
|
boolean unwrapIfNecessary(StringBuilder declaration, @Nullable String containerType, boolean unwrapped) {
|
||||||
@ -628,8 +610,7 @@ protected void executeSelect(
|
|||||||
break;
|
break;
|
||||||
case JD_KEYED_SLICE:
|
case JD_KEYED_SLICE:
|
||||||
case JD_KEYED_PAGE:
|
case JD_KEYED_PAGE:
|
||||||
final String entityClass = getSortableEntityClass();
|
if ( returnTypeName == null ) {
|
||||||
if ( entityClass == null ) {
|
|
||||||
throw new AssertionFailure("entity class cannot be null");
|
throw new AssertionFailure("entity class cannot be null");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -640,7 +621,7 @@ protected void executeSelect(
|
|||||||
String fragment = MAKE_KEYED_SLICE
|
String fragment = MAKE_KEYED_SLICE
|
||||||
.replace("pageRequest",
|
.replace("pageRequest",
|
||||||
parameterName(JD_PAGE_REQUEST, paramTypes, paramNames))
|
parameterName(JD_PAGE_REQUEST, paramTypes, paramNames))
|
||||||
.replace("Entity", annotationMetaEntity.importType(entityClass))
|
.replace("Entity", annotationMetaEntity.importType(returnTypeName))
|
||||||
.replace("KeysetAwareSliceRecord", implType(containerType));
|
.replace("KeysetAwareSliceRecord", implType(containerType));
|
||||||
if ( JD_KEYED_SLICE.equals(containerType) ) {
|
if ( JD_KEYED_SLICE.equals(containerType) ) {
|
||||||
fragment = fragment.replace("_totalResults, ", "");
|
fragment = fragment.replace("_totalResults, ", "");
|
||||||
|
@ -22,7 +22,6 @@ public class CriteriaFinderMethod extends AbstractFinderMethod {
|
|||||||
|
|
||||||
private final @Nullable String containerType;
|
private final @Nullable String containerType;
|
||||||
private final List<Boolean> paramNullability;
|
private final List<Boolean> paramNullability;
|
||||||
private final List<OrderBy> orderBys;
|
|
||||||
|
|
||||||
CriteriaFinderMethod(
|
CriteriaFinderMethod(
|
||||||
AnnotationMetaEntity annotationMetaEntity,
|
AnnotationMetaEntity annotationMetaEntity,
|
||||||
@ -38,11 +37,9 @@ public class CriteriaFinderMethod extends AbstractFinderMethod {
|
|||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean dataRepository) {
|
boolean dataRepository) {
|
||||||
super( annotationMetaEntity, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
super( annotationMetaEntity, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
||||||
paramNames, paramTypes, addNonnullAnnotation,
|
paramNames, paramTypes, orderBys, addNonnullAnnotation, dataRepository );
|
||||||
dataRepository );
|
|
||||||
this.containerType = containerType;
|
this.containerType = containerType;
|
||||||
this.paramNullability = paramNullability;
|
this.paramNullability = paramNullability;
|
||||||
this.orderBys = orderBys;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -55,18 +52,13 @@ boolean singleResult() {
|
|||||||
return containerType == null;
|
return containerType == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
List<OrderBy> getOrderBys() {
|
|
||||||
return orderBys;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAttributeDeclarationString() {
|
public String getAttributeDeclarationString() {
|
||||||
final List<String> paramTypes = parameterTypes();
|
final List<String> paramTypes = parameterTypes();
|
||||||
final StringBuilder declaration = new StringBuilder();
|
final StringBuilder declaration = new StringBuilder();
|
||||||
comment( declaration );
|
comment( declaration );
|
||||||
modifiers( declaration );
|
modifiers( declaration );
|
||||||
preamble( declaration, paramTypes );
|
preamble( declaration, returnType(), paramTypes );
|
||||||
nullChecks( paramTypes, declaration );
|
nullChecks( paramTypes, declaration );
|
||||||
createCriteriaQuery( declaration );
|
createCriteriaQuery( declaration );
|
||||||
where( declaration, paramTypes );
|
where( declaration, paramTypes );
|
||||||
@ -77,16 +69,6 @@ public String getAttributeDeclarationString() {
|
|||||||
return declaration.toString();
|
return declaration.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void preamble(StringBuilder declaration, List<String> paramTypes) {
|
|
||||||
declaration
|
|
||||||
.append(returnType())
|
|
||||||
.append(" ")
|
|
||||||
.append(methodName);
|
|
||||||
parameters(paramTypes, declaration);
|
|
||||||
declaration
|
|
||||||
.append(" {\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void executeQuery(StringBuilder declaration, List<String> paramTypes) {
|
private void executeQuery(StringBuilder declaration, List<String> paramTypes) {
|
||||||
declaration
|
declaration
|
||||||
.append('\n');
|
.append('\n');
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
import static org.hibernate.jpamodelgen.util.TypeUtils.isPrimitive;
|
import static org.hibernate.jpamodelgen.util.TypeUtils.isPrimitive;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +30,7 @@ public IdFinderMethod(
|
|||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean dataRepository) {
|
boolean dataRepository) {
|
||||||
super( annotationMetaEntity, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
super( annotationMetaEntity, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
||||||
paramNames, paramTypes, addNonnullAnnotation, dataRepository );
|
paramNames, paramTypes, emptyList(), addNonnullAnnotation, dataRepository );
|
||||||
int idParameter = idParameter(paramNames, paramTypes);
|
int idParameter = idParameter(paramNames, paramTypes);
|
||||||
this.paramName = paramNames.get(idParameter);
|
this.paramName = paramNames.get(idParameter);
|
||||||
this.paramType = paramTypes.get(idParameter);
|
this.paramType = paramTypes.get(idParameter);
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
*/
|
*/
|
||||||
@ -27,7 +29,7 @@ public NaturalIdFinderMethod(
|
|||||||
boolean addNonnullAnnotation,
|
boolean addNonnullAnnotation,
|
||||||
boolean dataRepository) {
|
boolean dataRepository) {
|
||||||
super( annotationMetaEntity, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
super( annotationMetaEntity, methodName, entity, belongsToDao, sessionType, sessionName, fetchProfiles,
|
||||||
paramNames, paramTypes, addNonnullAnnotation, dataRepository );
|
paramNames, paramTypes, emptyList(), addNonnullAnnotation, dataRepository );
|
||||||
this.paramNullability = paramNullability;
|
this.paramNullability = paramNullability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ public class QueryMethod extends AbstractQueryMethod {
|
|||||||
private final @Nullable String containerType;
|
private final @Nullable String containerType;
|
||||||
private final boolean isUpdate;
|
private final boolean isUpdate;
|
||||||
private final boolean isNative;
|
private final boolean isNative;
|
||||||
private final List<OrderBy> orderBys;
|
|
||||||
|
|
||||||
QueryMethod(
|
QueryMethod(
|
||||||
AnnotationMetaEntity annotationMetaEntity,
|
AnnotationMetaEntity annotationMetaEntity,
|
||||||
@ -48,13 +47,13 @@ public class QueryMethod extends AbstractQueryMethod {
|
|||||||
methodName,
|
methodName,
|
||||||
paramNames, paramTypes, returnTypeName,
|
paramNames, paramTypes, returnTypeName,
|
||||||
sessionType, sessionName,
|
sessionType, sessionName,
|
||||||
belongsToDao, addNonnullAnnotation,
|
belongsToDao, orderBys,
|
||||||
|
addNonnullAnnotation,
|
||||||
dataRepository );
|
dataRepository );
|
||||||
this.queryString = queryString;
|
this.queryString = queryString;
|
||||||
this.containerType = containerType;
|
this.containerType = containerType;
|
||||||
this.isUpdate = isUpdate;
|
this.isUpdate = isUpdate;
|
||||||
this.isNative = isNative;
|
this.isNative = isNative;
|
||||||
this.orderBys = orderBys;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -77,11 +76,6 @@ boolean singleResult() {
|
|||||||
return containerType == null;
|
return containerType == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
List<OrderBy> getOrderBys() {
|
|
||||||
return orderBys;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAttributeDeclarationString() {
|
public String getAttributeDeclarationString() {
|
||||||
final List<String> paramTypes = parameterTypes();
|
final List<String> paramTypes = parameterTypes();
|
||||||
@ -137,16 +131,6 @@ && isUsingEntityManager() ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void preamble(StringBuilder declaration, StringBuilder returnType, List<String> paramTypes) {
|
|
||||||
declaration
|
|
||||||
.append(returnType)
|
|
||||||
.append(" ")
|
|
||||||
.append(methodName);
|
|
||||||
parameters( paramTypes, declaration );
|
|
||||||
declaration
|
|
||||||
.append(" {\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void execute(StringBuilder declaration, boolean unwrapped) {
|
private void execute(StringBuilder declaration, boolean unwrapped) {
|
||||||
if ( isUpdate ) {
|
if ( isUpdate ) {
|
||||||
declaration
|
declaration
|
||||||
|
Loading…
x
Reference in New Issue
Block a user