Skip to content

Commit

Permalink
Include several fixes related to #40344
Browse files Browse the repository at this point in the history
(cherry picked from commit c62ce05)
  • Loading branch information
aureamunoz authored and gsmet committed Jun 18, 2024
1 parent 921d160 commit 7c09a87
Show file tree
Hide file tree
Showing 14 changed files with 661 additions and 121 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
<hibernate-quarkus-local-cache.version>0.3.0</hibernate-quarkus-local-cache.version>
<flapdoodle.mongo.version>4.14.0</flapdoodle.mongo.version>
<quarkus-spring-api.version>6.1.SP2</quarkus-spring-api.version>
<quarkus-spring-data-api.version>3.2.SP1</quarkus-spring-data-api.version>
<quarkus-spring-data-api.version>3.2.SP2</quarkus-spring-data-api.version>
<quarkus-spring-security-api.version>6.2</quarkus-spring-security-api.version>
<quarkus-spring-boot-api.version>3.2</quarkus-spring-boot-api.version>
<mockito.version>5.12.0</mockito.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public class RepositoryMethodsImplementor implements ResourceMethodsImplementor
public static final MethodDescriptor LIST_PAGED = ofMethod(PagingAndSortingRepository.class, "findAll",
org.springframework.data.domain.Page.class, Pageable.class);

//ListPagingAndSortingRepository
public static final MethodDescriptor LIST_SORTED = ofMethod(ListPagingAndSortingRepository.class, "findAll",
List.class, org.springframework.data.domain.Sort.class);

private static final Class<?> PANACHE_PAGE = io.quarkus.panache.common.Page.class;

private static final Class<?> PANACHE_SORT = io.quarkus.panache.common.Sort.class;
Expand All @@ -83,34 +79,37 @@ public RepositoryMethodsImplementor(IndexView index, EntityClassHelper entityCla
}

// CrudRepository Iterable<T> findAll();
public void implementListIterable(ClassCreator classCreator, String repositoryInterfaceName) {
public void implementIterable(ClassCreator classCreator, String repositoryInterfaceName) {
if (entityClassHelper.isCrudRepository(repositoryInterfaceName)
&& !entityClassHelper.isPagingAndSortingRepository(repositoryInterfaceName)) {
MethodCreator methodCreator = classCreator.getMethodCreator("list", List.class, Page.class, Sort.class,
String.class, Map.class);
ResultHandle repository = getRepositoryInstance(methodCreator, repositoryInterfaceName);
ResultHandle result = methodCreator.invokeInterfaceMethod(LIST_ITERABLE, repository);
methodCreator.returnValue(result);
LOGGER.infof("Method code: %s ", methodCreator.getMethodDescriptor().toString());
LOGGER.debugf("Method code: %s ", methodCreator.getMethodDescriptor().toString());
methodCreator.close();
}
}

//ListCrudRepository List<T> findAll();
public void implementList(ClassCreator classCreator, String repositoryInterfaceName) {
if (entityClassHelper.isListCrudRepository(repositoryInterfaceName)) {
if (entityClassHelper.isListCrudRepository(repositoryInterfaceName)
&& !entityClassHelper.isListPagingAndSortingRepository(repositoryInterfaceName)) {
MethodCreator methodCreator = classCreator.getMethodCreator("list", List.class, Page.class, Sort.class,
String.class, Map.class);
ResultHandle repository = getRepositoryInstance(methodCreator, repositoryInterfaceName);
ResultHandle result = methodCreator.invokeInterfaceMethod(LIST, repository);
methodCreator.returnValue(result);
LOGGER.infof("Method code: %s ", methodCreator.toString());
LOGGER.debugf("Method code: %s ", methodCreator.toString());
methodCreator.close();
}
}

// PagingAndSortingRepository Page<T> findAll(Pageable pageable);
public void implementListPaged(ClassCreator classCreator, String repositoryInterfaceName) {
// PagingAndSortingRepository Iterable<T> findAll(Pageable pageable);
// ListPagingAndSortingRepository List<T> findAll(Sort sort);
public void implementPagedList(ClassCreator classCreator, String repositoryInterfaceName) {
if (entityClassHelper.isPagingAndSortingRepository(repositoryInterfaceName)) {
MethodCreator methodCreator = classCreator.getMethodCreator("list", List.class, Page.class,
io.quarkus.panache.common.Sort.class, String.class, Map.class);
Expand All @@ -124,26 +123,7 @@ public void implementListPaged(ClassCreator classCreator, String repositoryInter
ofMethod(org.springframework.data.domain.Page.class, "getContent", List.class), resultPage);

methodCreator.returnValue(result);
LOGGER.infof("Method code: %s ", methodCreator.toString());
methodCreator.close();
}
}

//ListPagingAndSortingRepository List<T> findAll(Sort sort);
public void implementListSort(ClassCreator classCreator, String repositoryInterfaceName) {
if (entityClassHelper.isListPagingAndSortingRepository(repositoryInterfaceName)) {
MethodCreator methodCreator = classCreator.getMethodCreator("list", List.class, Page.class,
io.quarkus.panache.common.Sort.class, String.class, Map.class);
ResultHandle page = methodCreator.getMethodParam(0);
ResultHandle sort = methodCreator.getMethodParam(1);
ResultHandle pageable = toPageable(methodCreator, page, sort);
ResultHandle repository = getRepositoryInstance(methodCreator, repositoryInterfaceName);
ResultHandle resultPage = methodCreator.invokeInterfaceMethod(LIST_SORTED, repository, pageable);
ResultHandle result = methodCreator.invokeInterfaceMethod(
ofMethod(org.springframework.data.domain.Page.class, "getContent", List.class), resultPage);

methodCreator.returnValue(result);
LOGGER.infof("Method code: %s ", methodCreator.toString());
LOGGER.debugf("Method code: %s ", methodCreator.toString());
methodCreator.close();
}
}
Expand All @@ -163,7 +143,7 @@ public void implementListPageCount(ClassCreator classCreator, String repositoryI
} else {
methodCreator.throwException(RuntimeException.class, "Method not implemented");
}
LOGGER.infof("Method code: %s ", methodCreator.toString());
LOGGER.debugf("Method code: %s ", methodCreator.toString());
methodCreator.close();
}

Expand All @@ -175,7 +155,7 @@ public void implementListById(ClassCreator classCreator, String repositoryInterf
ResultHandle repository = getRepositoryInstance(methodCreator, repositoryInterfaceName);
ResultHandle result = methodCreator.invokeInterfaceMethod(LIST_BY_ID, repository, ids);
methodCreator.returnValue(result);
LOGGER.infof("Method code: %s ", methodCreator.toString());
LOGGER.debugf("Method code: %s ", methodCreator.toString());
methodCreator.close();
}
}
Expand All @@ -191,7 +171,7 @@ public void implementGet(ClassCreator classCreator, String repositoryInterfaceNa
} else {
methodCreator.throwException(RuntimeException.class, "Method not implemented");
}
LOGGER.infof("Method code: %s ", methodCreator.toString());
LOGGER.debugf("Method code: %s ", methodCreator.toString());
methodCreator.close();
}

Expand All @@ -208,7 +188,7 @@ public void implementAdd(ClassCreator classCreator, String repositoryInterfaceNa
methodCreator.throwException(RuntimeException.class, "Method not implemented");

}
LOGGER.infof("Method code: %s ", methodCreator.toString());
LOGGER.debugf("Method code: %s ", methodCreator.toString());
methodCreator.close();
}

Expand All @@ -223,7 +203,7 @@ public void implementAddList(ClassCreator classCreator, String repositoryInterfa
} else {
methodCreator.throwException(RuntimeException.class, "Method not implemented");
}
LOGGER.infof("Method code: %s ", methodCreator.toString());
LOGGER.debugf("Method code: %s ", methodCreator.toString());
methodCreator.close();
}

Expand All @@ -240,7 +220,7 @@ public void implementUpdate(ClassCreator classCreator, String repositoryInterfac
} else {
methodCreator.throwException(RuntimeException.class, "Method not implemented");
}
LOGGER.infof("Method code: %s ", methodCreator.toString());
LOGGER.debugf("Method code: %s ", methodCreator.toString());
methodCreator.close();
}

Expand All @@ -261,7 +241,7 @@ public void implementDelete(ClassCreator classCreator, String repositoryInterfac
} else {
methodCreator.throwException(RuntimeException.class, "Method not implemented");
}
LOGGER.infof("Method code: %s ", methodCreator.toString());
LOGGER.debugf("Method code: %s ", methodCreator.toString());
methodCreator.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static io.quarkus.spring.data.rest.deployment.RepositoryMethodsImplementor.LIST;
import static io.quarkus.spring.data.rest.deployment.RepositoryMethodsImplementor.LIST_ITERABLE;
import static io.quarkus.spring.data.rest.deployment.RepositoryMethodsImplementor.LIST_PAGED;
import static io.quarkus.spring.data.rest.deployment.RepositoryMethodsImplementor.LIST_SORTED;
import static io.quarkus.spring.data.rest.deployment.RepositoryMethodsImplementor.SAVE_LIST;
import static io.quarkus.spring.data.rest.deployment.RepositoryMethodsImplementor.UPDATE;

Expand Down Expand Up @@ -34,8 +33,6 @@ protected Map<String, Predicate<MethodInfo>> getMethodPredicates() {
methodPredicates.put("listPaged", methodInfo -> methodInfo.name().equals(LIST_PAGED.getName())
&& methodInfo.parametersCount() == 1
&& methodInfo.parameterType(0).name().equals(PAGEABLE));
methodPredicates.put("listSorted",
methodInfo -> methodInfo.name().equals(LIST_SORTED.getName()) && methodInfo.parameterTypes().isEmpty());
methodPredicates.put("addAll", methodInfo -> methodInfo.name().equals(SAVE_LIST.getName()));
methodPredicates.put("get", methodInfo -> methodInfo.name().equals(GET.getName()));
methodPredicates.put("add", methodInfo -> methodInfo.name().equals(ADD.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ public String implement(ClassOutput classOutput, String resourceType, String ent
.build();

classCreator.addAnnotation(ApplicationScoped.class);
methodsImplementor.implementListIterable(classCreator, resourceType);
methodsImplementor.implementIterable(classCreator, resourceType);
methodsImplementor.implementList(classCreator, resourceType);
methodsImplementor.implementListSort(classCreator, resourceType);
methodsImplementor.implementListPaged(classCreator, resourceType);
methodsImplementor.implementPagedList(classCreator, resourceType);
methodsImplementor.implementAddList(classCreator, resourceType);
methodsImplementor.implementListById(classCreator, resourceType);
methodsImplementor.implementListPageCount(classCreator, resourceType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ public interface ResourceMethodsImplementor {

void implementList(ClassCreator classCreator, String repositoryInterface);

void implementListIterable(ClassCreator classCreator, String repositoryInterface);
void implementIterable(ClassCreator classCreator, String repositoryInterface);

void implementListPaged(ClassCreator classCreator, String repositoryInterface);
void implementPagedList(ClassCreator classCreator, String repositoryInterface);

void implementListPageCount(ClassCreator classCreator, String repositoryInterface);

void implementListById(ClassCreator classCreator, String repositoryInterface);

public void implementListSort(ClassCreator classCreator, String repositoryInterface);

void implementGet(ClassCreator classCreator, String repositoryInterface);

void implementAdd(ClassCreator classCreator, String repositoryInterface);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ private void implementResources(Capabilities capabilities,
BuildProducer<UnremovableBeanBuildItem> unremovableBeansProducer,
ResourceMethodsImplementor methodsImplementor,
IndexView index,
// ResourcePropertiesProvider propertiesProvider,
List<ClassInfo> repositoriesToImplement) {
ClassOutput classOutput = new GeneratedBeanGizmoAdaptor(implementationsProducer);
ResourceImplementor resourceImplementor = new ResourceImplementor(methodsImplementor);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.quarkus.spring.data.rest;

import org.springframework.data.jpa.repository.JpaRepository;

import io.quarkus.spring.data.rest.paged.Record;

public interface JpaRecordsRepository extends JpaRepository<Record, Long> {
}
Loading

0 comments on commit 7c09a87

Please sign in to comment.