Module jakarta.data

Interface DataRepository<T,K>

Type Parameters:
T - the type of the primary entity class of the repository.
K - the type of the unique identifier field of property of the primary entity.
All Known Subinterfaces:
BasicRepository<T,K>, CrudRepository<T,K>

public interface DataRepository<T,K>

A built-in repository supertype that is the root of all other built-in repository supertype interfaces.

The type parameters of DataRepository<T,K> capture the primary entity type (T) for the repository and the type (K) of the field or property of the entity which uniquely identifies each entity of that type.

The primary entity type is used for repository methods, such as countBy... and deleteBy..., which do not explicitly specify an entity type.

Example entity:

 @Entity
 public class DriverLicense {
     @Id
     public String licenseNum;
     public LocalDate expiry;
     ...
 }
 

Example repository:

 @Repository
 public interface DriverLicenses extends DataRepository<DriverLicense, String> {

     boolean existsByLicenseNumAndExpiryGreaterThan(String num, LocalDate minExpiry);

     @Insert
     DriverLicense register(DriverLicense l);

     @Update
     boolean renew(DriverLicense l);

     ...
 }
 

Example usage:

 @Inject
 DriverLicenses licenses;

 ...

 DriverLicense license = ...
 license = licenses.register(license);

 boolean isValid = licenses.existsByLicenseNumAndExpiryGreaterThan(license.licenseNum,
                                                                   LocalDate.now());
 

The module Javadoc provides an overview of Jakarta Data.