fr.ouestfrance.querydsl.postgrest.Repository Maven / Gradle / Ivy
package fr.ouestfrance.querydsl.postgrest;
import fr.ouestfrance.querydsl.postgrest.model.BulkOptions;
import fr.ouestfrance.querydsl.postgrest.model.BulkResponse;
import fr.ouestfrance.querydsl.postgrest.model.Page;
import fr.ouestfrance.querydsl.postgrest.model.Pageable;
import fr.ouestfrance.querydsl.postgrest.model.exceptions.PostgrestRequestException;
import java.util.List;
import java.util.Optional;
/**
* Repository interface
*
* @param type of return object
*/
public interface Repository {
/**
* Search from criteria object
*
* @param criteria search criteria
* @return page result
*/
default Page search(Object criteria) {
return search(criteria, Pageable.unPaged());
}
/**
* Count all items
*
* @return count result
*/
default long count() {
return count(null);
}
/**
* Count from criteria object
*
* @param criteria search criteria
* @return count result
*/
long count(Object criteria);
/**
* Search from criteria object with pagination
*
* @param criteria search criteria
* @param pageable pagination data
* @return page result
*/
Page search(Object criteria, Pageable pageable);
/**
* Find one object using criteria, method can return one or empty
*
* @param criteria search criteria
* @return Optional result
* @throws PostgrestRequestException when search criteria result gave more than one item
*/
Optional findOne(Object criteria);
/**
* Get one object using criteria, method should return the response
*
* @param criteria search criteria
* @return Result object
* @throws PostgrestRequestException no element found, or more than one item
*/
T getOne(Object criteria);
/**
* Post a value
*
* @param value to post
* @return value inserted
*/
default T post(Object value) {
BulkResponse post = post(List.of(value));
if (post == null) {
return null;
}
return post.stream().findFirst().orElse(null);
}
/**
* Post multiple values
*
* @param values values to post
* @return values inserted
*/
default BulkResponse post(List