Skip to content

Crud List repository service

Marco Collovati edited this page Dec 3, 2023 · 2 revisions

CrudRepositoryService And ListRepositoryService Support

Quarkus-Hilla provides specialized implementations of CrudRepositoryService and ListRepositoryService designed for seamless integration with both quarkus-spring-data-jpa and quarkus-hibernate-orm-panache extensions. This integration simplifies the usage of Hilla Auto Crud, Auto Grid, and Auto Form components in your Quarkus project.

quarkus-spring-data-jpa

The custom implementation for quarkus-spring-data-jpa involves wrapping Spring Data JPA’s CrudRepository. These custom services seamlessly integrate with Hilla’s CrudService, ListService<T>, GetService, and CountService. Additionally, they implement the FilterableRepository from quarkus-hilla, with methods dynamically implemented at build time through byte-code manipulation.

Usage Example

Given a User JPA entity with an identifier of type Long, define a Spring Data JPA repository:

import org.springframework.data.repository.CrudRepository;
import com.github.mcollovati.quarkus.hilla.crud.spring.FilterableRepository;

public interface UserRepository extends CrudRepository<User, Long>, FilterableRepository<User, Long> {}

Then create a service class extending CrudRepositoryService:

import com.vaadin.flow.server.auth.AnonymousAllowed;
import dev.hilla.BrowserCallable;

import com.github.mcollovati.quarkus.hilla.crud.spring.CrudRepositoryService;

@BrowserCallable
@AnonymousAllowed
public class UserService extends CrudRepositoryService<User, Long, UserRepository> {}

quarkus-hibernate-orm-panache

In the context of quarkus-hibernate-orm-panache, the custom implementation of CrudRepositoryService and ListRepositoryService follows a similar approach. These services implement Hilla interfaces while wrapping a FilterableRepository, an extension of PanacheRepositoryBase. The methods of the FilterableRepository are dynamically implemented at build time through byte-code manipulation by the quarkus-hilla extension.

Usage Example

Given a User JPA entity with an identifier of type Long, create a repository class implementing FilterableRepository:

import jakarta.enterprise.context.ApplicationScoped;
import com.github.mcollovati.quarkus.hilla.crud.panache.FilterableRepository;

@ApplicationScoped
public class UserRepository implements FilterableRepository<User, Long> {}

Then extend CrudRepositoryService in your service class:

import com.vaadin.flow.server.auth.AnonymousAllowed;
import dev.hilla.BrowserCallable;
import com.github.mcollovati.quarkus.hilla.crud.panache.CrudRepositoryService;

@BrowserCallable
@AnonymousAllowed
public class UserService extends CrudRepositoryService<User, Long, UserRepository> {}

By adhering to this structure, you seamlessly integrate quarkus-hibernate-orm-panache with Hilla, benefiting from the custom implementations of CrudRepositoryService and ListRepositoryService provided by quarkus-hilla.