All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hypersistence.utils.spring.repository.BaseJpaRepository Maven / Gradle / Ivy

There is a newer version: 3.7.6
Show newest version
package io.hypersistence.utils.spring.repository;

import javax.persistence.LockModeType;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.QueryByExampleExecutor;

import java.util.List;
import java.util.Optional;

/**
 * The {@code BaseJpaRepository} fixes many of the problems that the default Spring Data {@code JpaRepository}
 * suffers from.
 * 

* For more details about how to use it, check out this article on vladmihalcea.com. * * @author Vlad Mihalcea * @version 2.21.0 */ @NoRepositoryBean public interface BaseJpaRepository extends Repository, QueryByExampleExecutor { Optional findById(ID id); boolean existsById(ID id); T getReferenceById(ID id); List findAllById(Iterable ids); long count(); void delete(T entity); void deleteAllInBatch(Iterable entities); void deleteById(ID id); void deleteAllByIdInBatch(Iterable ids); void flush(); /** * The persist method allows you to pass the provided entity to the {@code persist} method of the * underlying JPA {@code EntityManager}. * * @param entity entity to persist * @param entity type * @return entity */ S persist(S entity); /** * The persistAndFlush method allows you to pass the provided entity to the {@code persist} method of the * underlying JPA {@code EntityManager} and call {@code flush} afterwards. * * @param entity entity to persist * @param entity type * @return entity */ S persistAndFlush(S entity); /** * The persistAll method allows you to pass the provided entities to the {@code persist} method of the * underlying JPA {@code EntityManager}. * * @param entities entities to persist * @param entity type * @return entities */ List persistAll(Iterable entities); /** * The persistAll method allows you to pass the provided entities to the {@code persist} method of the * underlying JPA {@code EntityManager} and call {@code flush} afterwards. * * @param entities entities to persist * @param entity type * @return entities */ List persistAllAndFlush(Iterable entities); /** * The persist method allows you to pass the provided entity to the {@code merge} method of the * underlying JPA {@code EntityManager}. * * @param entity entity to merge * @param entity type * @return entity */ S merge(S entity); /** * The mergeAndFlush method allows you to pass the provided entity to the {@code merge} method of the * underlying JPA {@code EntityManager} and call {@code flush} afterwards. * * @param entity entity to merge * @param entity type * @return entity */ S mergeAndFlush(S entity); /** * The mergeAll method allows you to pass the provided entities to the {@code merge} method of the * underlying JPA {@code EntityManager}. * * @param entities entities to merge * @param entity type * @return entities */ List mergeAll(Iterable entities); /** * The mergeAllAndFlush method allows you to pass the provided entities to the {@code merge} method of the * underlying JPA {@code EntityManager} and call {@code flush} afterwards. * * @param entities entities to persist * @param entity type * @return entities */ List mergeAllAndFlush(Iterable entities); /** * The update method allows you to pass the provided entity to the {@code update} method of the * underlying JPA {@code EntityManager}. * * @param entity entity to update * @param entity type * @return entity */ S update(S entity); /** * The updateAndFlush method allows you to pass the provided entity to the {@code update} method of the * underlying JPA {@code EntityManager} and call {@code flush} afterwards. * * @param entity entity to update * @param entity type * @return entity */ S updateAndFlush(S entity); /** * The updateAll method allows you to pass the provided entities to the {@code update} method of the * underlying JPA {@code EntityManager}. * * @param entities entities to update * @param entity type * @return entities */ List updateAll(Iterable entities); /** * The updateAllAndFlush method allows you to pass the provided entities to the {@code update} method of the * underlying JPA {@code EntityManager} and call {@code flush} afterwards. * * @param entities entities to update * @param entity type * @return entities */ List updateAllAndFlush(Iterable entities); /** * Lock the entity with the provided identifier. * * @param id entity identifier * @param lockMode entity lock mode * @return entity */ T lockById(ID id, LockModeType lockMode); }