Interface IdempotencyRecordRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<IdempotencyRecord,,String> org.springframework.data.jpa.repository.JpaRepository<IdempotencyRecord,,String> org.springframework.data.repository.ListCrudRepository<IdempotencyRecord,,String> org.springframework.data.repository.ListPagingAndSortingRepository<IdempotencyRecord,,String> org.springframework.data.repository.PagingAndSortingRepository<IdempotencyRecord,,String> org.springframework.data.repository.query.QueryByExampleExecutor<IdempotencyRecord>,org.springframework.data.repository.Repository<IdempotencyRecord,String>
public interface IdempotencyRecordRepository
extends org.springframework.data.jpa.repository.JpaRepository<IdempotencyRecord,String>
-
Method Summary
Modifier and TypeMethodDescriptionintvoidbooleanintinsertIfNotExistsOrUpdateIfExpired(String key, String data, int ttl) Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
existsByKeyAndNotExpired
@Query(nativeQuery=true, value=" select\n count(r) > 0\n from\n engine.idempotency_records r\n where\n r.key = :key\n and r.expires_at >= now()\n") boolean existsByKeyAndNotExpired(String key) -
insertIfNotExistsOrUpdateIfExpired
@Modifying @Query(nativeQuery=true, value=" insert into\n engine.idempotency_records as r\n (key, data, created_at, expires_at)\n values (\n :key,\n :data ::json,\n now(),\n now() + make_interval(secs => :ttl)\n )\n on conflict (key) do update\n set\n data = :data ::json,\n created_at = now(),\n expires_at = now() + make_interval(secs => :ttl)\n where\n r.expires_at < now()\n") int insertIfNotExistsOrUpdateIfExpired(String key, String data, int ttl) -
deleteExpired
@Modifying @Query(nativeQuery=true, value=" delete from engine.idempotency_records r where r.expires_at < now()\n") void deleteExpired() -
deleteByKeyAndNotExpired
@Modifying @Query(nativeQuery=true, value=" delete from\n engine.idempotency_records r\n where\n r.key = :key\n and r.expires_at >= now()\n") int deleteByKeyAndNotExpired(String key)
-