dev.soffa.foundation.data.EntityRepository Maven / Gradle / Ivy
package dev.soffa.foundation.data;
import com.google.common.collect.ImmutableMap;
import dev.soffa.foundation.error.ResourceNotFoundException;
import dev.soffa.foundation.model.TenantId;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@SuppressWarnings({"UnusedReturnValue", "unused"})
public interface EntityRepository {
long count();
default long count(Map filter) {
return count(Criteria.of(filter));
}
default long count(Criteria criteria) {
return count(TenantId.CONTEXT, criteria);
}
long count(TenantId tennant, Criteria criteria);
default List findAll() {
return findAll(TenantId.CONTEXT);
}
List findAll(TenantId tenantId);
List find(TenantId tenant, Criteria criteria);
default List find(Criteria criteria) {
return find(TenantId.CONTEXT, criteria);
}
default List find(Map filter) {
return find(Criteria.of(filter));
}
Optional get(Criteria criteria);
Optional get(TenantId tenant, Criteria criteria);
default Optional get(Map filter) {
return get(Criteria.of(filter));
}
default Optional get(TenantId tenant, Map filter) {
return get(tenant, Criteria.of(filter));
}
default E get(I id) {
return findById(id).orElseThrow(() -> new ResourceNotFoundException("Resource does not exists"));
}
Optional findById(I id);
Optional findById(TenantId tenant, I id);
E insert(E entity);
E insert(TenantId tenant, E entity);
E update(E entity);
E update(TenantId tenant, E entity);
int delete(E entity);
int delete(TenantId tenant, E entity);
default int delete(Map filter) {
return delete(Criteria.of(filter));
}
int delete(Criteria criteria);
default boolean exists(Map filter) {
return exists(Criteria.of(filter));
}
default boolean exists(Criteria criteria) {
return count(criteria) > 0;
}
default boolean exists(I id) {
return exists(ImmutableMap.of("id", id));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy