パッケージ jakarta.data.repository
インターフェース DataRepository<T,K>
- 型パラメーター:
T- リポジトリのプライマリエンティティクラスの型。K- プライマリエンティティのプロパティの一意の識別子フィールドの型。
- すべての既知のサブインターフェース:
BasicRepository<T,,K> CrudRepository<T,K>
public interface DataRepository<T,K>
他のすべての組み込みリポジトリスーパー型 インターフェースのルートとなる組み込みリポジトリスーパー型。
DataRepository<T,K> の型パラメーターは、リポジトリのプライマリエンティティ型 (T) と、その型の各エンティティを一意に識別するエンティティのフィールドまたはプロパティの型 (K) を取得します。
プライマリエンティティ型は、エンティティ型を明示的に指定しない countBy... や deleteBy... などのリポジトリメソッドに使用されます。
エンティティの例:
@Entity
public class DriverLicense {
@Id
public String licenseNum;
public LocalDate expiry;
...
}
リポジトリの例:
@Repository
public interface DriverLicenses extends DataRepository<DriverLicense, String> {
boolean existsByLicenseNumAndExpiryGreaterThan(String num, LocalDate minExpiry);
@Insert
DriverLicense register(DriverLicense l);
@Update
boolean renew(DriverLicense l);
...
}
使用例:
@Inject
DriverLicenses licenses;
...
DriverLicense license = ...
license = licenses.register(license);
boolean isValid = licenses.existsByLicenseNumAndExpiryGreaterThan(license.licenseNum,
LocalDate.now());
モジュール Javadoc は Jakarta Data の overview を提供します。