implement support for requestTotals() in processor
also fix up some newline handling
This commit is contained in:
parent
7773e28b2c
commit
c3bbd193c8
|
@ -209,14 +209,14 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
|
||||||
|
|
||||||
void chainSessionEnd(boolean isUpdate, StringBuilder declaration) {
|
void chainSessionEnd(boolean isUpdate, StringBuilder declaration) {
|
||||||
if ( isReactiveSession() ) {
|
if ( isReactiveSession() ) {
|
||||||
declaration.append("\n\t})");
|
declaration.append("\t})");
|
||||||
// here we're checking for a boxed void and not Uni<Void> because the returnType has already
|
// here we're checking for a boxed void and not Uni<Void> because the returnType has already
|
||||||
// been checked, and is ununi-ed
|
// been checked, and is ununi-ed
|
||||||
if ( isUpdate && returnTypeName != null && returnTypeName.equals(BOXED_VOID) ) {
|
if ( isUpdate && returnTypeName != null && returnTypeName.equals(BOXED_VOID) ) {
|
||||||
declaration.append(".replaceWithVoid();");
|
declaration.append(".replaceWithVoid();\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
declaration.append(";");
|
declaration.append(";\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,7 +317,7 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
|
||||||
abstract boolean singleResult();
|
abstract boolean singleResult();
|
||||||
|
|
||||||
static void closingBrace(StringBuilder declaration) {
|
static void closingBrace(StringBuilder declaration) {
|
||||||
declaration.append("\n}");
|
declaration.append("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
void unwrapQuery(StringBuilder declaration, boolean unwrapped) {
|
void unwrapQuery(StringBuilder declaration, boolean unwrapped) {
|
||||||
|
@ -391,9 +391,9 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
|
||||||
"\t\t\t\t\t\t.sortBy(pageRequest.sorts())\n" +
|
"\t\t\t\t\t\t.sortBy(pageRequest.sorts())\n" +
|
||||||
"\t\t\t\t\t\t.size(pageRequest.size())\n" +
|
"\t\t\t\t\t\t.size(pageRequest.size())\n" +
|
||||||
"\t\t\t\t\t\t.page(pageRequest.page() + 1);\n" +
|
"\t\t\t\t\t\t.page(pageRequest.page() + 1);\n" +
|
||||||
"\t\treturn new CursoredPageRecord<>( _results.getResultList(), _cursors, _totalResults, pageRequest,\n" +
|
"\t\treturn new CursoredPageRecord<>(_results.getResultList(), _cursors, _totalResults, pageRequest,\n" +
|
||||||
"\t\t\t\t_results.isLastPage() ? null : _page.afterKey(_results.getNextPage().getKey().toArray()),\n" +
|
"\t\t\t\t_results.isLastPage() ? null : _page.afterKey(_results.getNextPage().getKey().toArray()),\n" +
|
||||||
"\t\t\t\t_results.isFirstPage() ? null : _page.beforeKey(_results.getPreviousPage().getKey().toArray()) );\n";
|
"\t\t\t\t_results.isFirstPage() ? null : _page.beforeKey(_results.getPreviousPage().getKey().toArray()));";
|
||||||
|
|
||||||
static final String MAKE_KEYED_PAGE
|
static final String MAKE_KEYED_PAGE
|
||||||
= "\tvar _unkeyedPage =\n" +
|
= "\tvar _unkeyedPage =\n" +
|
||||||
|
@ -404,16 +404,16 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
|
||||||
"\t\t\t\t\t.map(_cursor -> {\n" +
|
"\t\t\t\t\t.map(_cursor -> {\n" +
|
||||||
"\t\t\t\t\t\t@SuppressWarnings(\"unchecked\")\n" +
|
"\t\t\t\t\t\t@SuppressWarnings(\"unchecked\")\n" +
|
||||||
"\t\t\t\t\t\tvar _elements = (List<Comparable<?>>) _cursor.elements();\n" +
|
"\t\t\t\t\t\tvar _elements = (List<Comparable<?>>) _cursor.elements();\n" +
|
||||||
"\t\t\t\t\t\treturn switch ( pageRequest.mode() ) {\n" +
|
"\t\t\t\t\t\treturn switch (pageRequest.mode()) {\n" +
|
||||||
"\t\t\t\t\t\t\tcase CURSOR_NEXT -> _unkeyedPage.withKey(_elements, KEY_OF_LAST_ON_PREVIOUS_PAGE);\n" +
|
"\t\t\t\t\t\t\tcase CURSOR_NEXT -> _unkeyedPage.withKey(_elements, KEY_OF_LAST_ON_PREVIOUS_PAGE);\n" +
|
||||||
"\t\t\t\t\t\t\tcase CURSOR_PREVIOUS -> _unkeyedPage.withKey(_elements, KEY_OF_FIRST_ON_NEXT_PAGE);\n" +
|
"\t\t\t\t\t\t\tcase CURSOR_PREVIOUS -> _unkeyedPage.withKey(_elements, KEY_OF_FIRST_ON_NEXT_PAGE);\n" +
|
||||||
"\t\t\t\t\t\t\tdefault -> _unkeyedPage;\n" +
|
"\t\t\t\t\t\t\tdefault -> _unkeyedPage;\n" +
|
||||||
"\t\t\t\t\t\t};\n" +
|
"\t\t\t\t\t\t};\n" +
|
||||||
"\t\t\t\t\t}).orElse(_unkeyedPage);\n";
|
"\t\t\t\t\t}).orElse(_unkeyedPage);";
|
||||||
|
|
||||||
void createQuery(StringBuilder declaration) {}
|
void createQuery(StringBuilder declaration) {}
|
||||||
|
|
||||||
void setParameters(StringBuilder declaration, List<String> paramTypes) {}
|
void setParameters(StringBuilder declaration, List<String> paramTypes, String indent) {}
|
||||||
|
|
||||||
void tryReturn(StringBuilder declaration, List<String> paramTypes, @Nullable String containerType) {
|
void tryReturn(StringBuilder declaration, List<String> paramTypes, @Nullable String containerType) {
|
||||||
if ( isJakartaCursoredPage(containerType) ) {
|
if ( isJakartaCursoredPage(containerType) ) {
|
||||||
|
@ -465,12 +465,14 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
|
||||||
|
|
||||||
private void totalResults(StringBuilder declaration, List<String> paramTypes) {
|
private void totalResults(StringBuilder declaration, List<String> paramTypes) {
|
||||||
declaration
|
declaration
|
||||||
.append("\tlong _totalResults = ");
|
.append("\tlong _totalResults = \n\t\t\t\t")
|
||||||
|
.append(parameterName(JD_PAGE_REQUEST, paramTypes, paramNames))
|
||||||
|
.append(".requestTotal()\n\t\t\t\t\t\t? ");
|
||||||
createQuery( declaration );
|
createQuery( declaration );
|
||||||
setParameters( declaration, paramTypes );
|
setParameters( declaration, paramTypes, "\t\t\t\t\t");
|
||||||
unwrapQuery( declaration, !isUsingEntityManager() );
|
unwrapQuery( declaration, !isUsingEntityManager() );
|
||||||
declaration
|
declaration
|
||||||
.append("\t\t\t.getResultCount();\n");
|
.append("\t\t\t\t\t\t\t\t.getResultCount()\n\t\t\t\t\t\t: -1;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void collectOrdering(StringBuilder declaration, List<String> paramTypes) {
|
void collectOrdering(StringBuilder declaration, List<String> paramTypes) {
|
||||||
|
@ -679,6 +681,7 @@ public abstract class AbstractQueryMethod implements MetaAttribute {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declaration.append('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String parameterName(String paramType, List<String> paramTypes, List<String> paramNames) {
|
private static String parameterName(String paramType, List<String> paramTypes, List<String> paramNames) {
|
||||||
|
|
|
@ -85,11 +85,7 @@ public class IdFinderMethod extends AbstractFinderMethod {
|
||||||
declaration
|
declaration
|
||||||
.append("\t\t\t.load(")
|
.append("\t\t\t.load(")
|
||||||
.append(paramName)
|
.append(paramName)
|
||||||
.append(");");
|
.append(");\n");
|
||||||
if (dataRepository) {
|
|
||||||
declaration
|
|
||||||
.append("\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findWithNoFetchProfiles(StringBuilder declaration) {
|
private void findWithNoFetchProfiles(StringBuilder declaration) {
|
||||||
|
@ -98,11 +94,7 @@ public class IdFinderMethod extends AbstractFinderMethod {
|
||||||
.append(annotationMetaEntity.importType(entity))
|
.append(annotationMetaEntity.importType(entity))
|
||||||
.append(".class, ")
|
.append(".class, ")
|
||||||
.append(paramName)
|
.append(paramName)
|
||||||
.append(");");
|
.append(");\n");
|
||||||
if (dataRepository) {
|
|
||||||
declaration
|
|
||||||
.append("\n");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void nullCheck(StringBuilder declaration, String parameterName) {
|
private static void nullCheck(StringBuilder declaration, String parameterName) {
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class NaturalIdFinderMethod extends AbstractFinderMethod {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declaration
|
declaration
|
||||||
.append("\t\t\t.load();");
|
.append("\t\t\t.load();\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findReactively(StringBuilder declaration) {
|
private void findReactively(StringBuilder declaration) {
|
||||||
|
@ -130,7 +130,7 @@ public class NaturalIdFinderMethod extends AbstractFinderMethod {
|
||||||
if (composite) {
|
if (composite) {
|
||||||
declaration.append("\n\t\t\t)\n\t");
|
declaration.append("\n\t\t\t)\n\t");
|
||||||
}
|
}
|
||||||
declaration.append(");");
|
declaration.append(");\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isComposite() {
|
private boolean isComposite() {
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class QueryMethod extends AbstractQueryMethod {
|
||||||
tryReturn( declaration, paramTypes, containerType );
|
tryReturn( declaration, paramTypes, containerType );
|
||||||
castResult( declaration, returnType );
|
castResult( declaration, returnType );
|
||||||
createQuery( declaration );
|
createQuery( declaration );
|
||||||
setParameters( declaration, paramTypes );
|
setParameters( declaration, paramTypes, "");
|
||||||
handlePageParameters( declaration, paramTypes, containerType );
|
handlePageParameters( declaration, paramTypes, containerType );
|
||||||
boolean unwrapped = specialNeeds( declaration );
|
boolean unwrapped = specialNeeds( declaration );
|
||||||
unwrapped = applyOrder( declaration, paramTypes, containerType, unwrapped );
|
unwrapped = applyOrder( declaration, paramTypes, containerType, unwrapped );
|
||||||
|
@ -127,7 +127,8 @@ public class QueryMethod extends AbstractQueryMethod {
|
||||||
&& isUsingEntityManager() ) {
|
&& isUsingEntityManager() ) {
|
||||||
// EntityManager.createNativeQuery() does not return TypedQuery,
|
// EntityManager.createNativeQuery() does not return TypedQuery,
|
||||||
// so we need to cast to the entity type
|
// so we need to cast to the entity type
|
||||||
declaration.append("(")
|
declaration
|
||||||
|
.append("(")
|
||||||
.append(returnType)
|
.append(returnType)
|
||||||
.append(") ");
|
.append(") ");
|
||||||
}
|
}
|
||||||
|
@ -139,10 +140,11 @@ public class QueryMethod extends AbstractQueryMethod {
|
||||||
.append("\t\t\t")
|
.append("\t\t\t")
|
||||||
.append(".executeUpdate()");
|
.append(".executeUpdate()");
|
||||||
if ( "boolean".equals(returnTypeName) ) {
|
if ( "boolean".equals(returnTypeName) ) {
|
||||||
declaration.append(" > 0");
|
declaration
|
||||||
|
.append(" > 0");
|
||||||
}
|
}
|
||||||
declaration
|
declaration
|
||||||
.append(';');
|
.append(";\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final boolean mustUnwrap =
|
final boolean mustUnwrap =
|
||||||
|
@ -150,23 +152,21 @@ public class QueryMethod extends AbstractQueryMethod {
|
||||||
|| isNative && returnTypeName != null;
|
|| isNative && returnTypeName != null;
|
||||||
executeSelect( declaration, paramTypes, containerType, unwrapped, mustUnwrap );
|
executeSelect( declaration, paramTypes, containerType, unwrapped, mustUnwrap );
|
||||||
}
|
}
|
||||||
if ( dataRepository ) {
|
|
||||||
declaration
|
|
||||||
.append('\n');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void setParameters(StringBuilder declaration, List<String> paramTypes) {
|
void setParameters(StringBuilder declaration, List<String> paramTypes, String indent) {
|
||||||
for ( int i = 0; i < paramNames.size(); i++ ) {
|
for ( int i = 0; i < paramNames.size(); i++ ) {
|
||||||
final String paramName = paramNames.get(i);
|
final String paramName = paramNames.get(i);
|
||||||
final String paramType = paramTypes.get(i);
|
final String paramType = paramTypes.get(i);
|
||||||
if ( !isSpecialParam(paramType) ) {
|
if ( !isSpecialParam(paramType) ) {
|
||||||
final int ordinal = i+1;
|
final int ordinal = i+1;
|
||||||
if ( queryString.contains(":" + paramName) ) {
|
if ( queryString.contains(":" + paramName) ) {
|
||||||
|
declaration.append(indent);
|
||||||
setNamedParameter( declaration, paramName );
|
setNamedParameter( declaration, paramName );
|
||||||
}
|
}
|
||||||
else if ( queryString.contains("?" + ordinal) ) {
|
else if ( queryString.contains("?" + ordinal) ) {
|
||||||
|
declaration.append(indent);
|
||||||
setOrdinalParameter( declaration, ordinal, paramName );
|
setOrdinalParameter( declaration, ordinal, paramName );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue