package com.oguerreiro.resilient.repository;

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

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.oguerreiro.resilient.domain.VariableUnits;

/**
 * Spring Data JPA repository for the VariableUnits entity.
 */
@Repository
public interface VariableUnitsRepository extends ResilientJpaRepository<VariableUnits, Long> {
  /* Interface ResilientJpaRepository eager fetching Override methods */
  /* **************************************************************** */
  @Override
  @Query(value = "select variableUnits from VariableUnits variableUnits left join fetch variableUnits.variable left join fetch variableUnits.unit", countQuery = "select count(variableUnits) from VariableUnits variableUnits")
  Page<VariableUnits> findAllWithEagerRelationships(Pageable pageable);

  @Override
  @Query("select variableUnits from VariableUnits variableUnits left join fetch variableUnits.variable left join fetch variableUnits.unit")
  List<VariableUnits> findAllWithEagerRelationships();

  @Override
  @Query("select variableUnits from VariableUnits variableUnits left join fetch variableUnits.variable left join fetch variableUnits.unit where variableUnits.id =:id")
  Optional<VariableUnits> findOneWithEagerRelationships(@Param("id") Long id);
}
