Interface JpaFileRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<FileEntity,Long>, org.springframework.data.jpa.repository.JpaRepository<FileEntity,Long>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<FileEntity>, org.springframework.data.repository.PagingAndSortingRepository<FileEntity,Long>, org.springframework.data.repository.query.QueryByExampleExecutor<FileEntity>, org.springframework.data.repository.Repository<FileEntity,Long>

public interface JpaFileRepository
Repository for file references.
Since:
3.3.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The query used to select any dangling file references.
  • Method Summary

    Modifier and Type
    Method
    Description
    Delete all files from the database that are in the current set of ids.
    boolean
    Find out whether a file entity with the given file value exists.
    Find a file by its unique file value.
    Find file entities where the file value is in the given set of files.
    findUnusedFiles(Instant createdThresholdLowerBound, Instant createdThresholdUpperBound, int limit)
    Find the ids of all files from the database that aren't referenced which were created before the supplied created threshold.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, findAll, findAll, findAllById, flush, getById, getOne, getReferenceById, saveAll, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor

    count, exists, findAll, findAll, findAll, findOne

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Field Details

    • SELECT_FOR_UPDATE_UNUSED_FILES_SQL

      static final String SELECT_FOR_UPDATE_UNUSED_FILES_SQL
      The query used to select any dangling file references.
      See Also:
  • Method Details

    • findByFile

      Optional<FileEntity> findByFile(String file)
      Find a file by its unique file value.
      Parameters:
      file - The file value to search for
      Returns:
      An Optional of a FileEntity
    • existsByFile

      boolean existsByFile(String file)
      Find out whether a file entity with the given file value exists.
      Parameters:
      file - The file value to check for
      Returns:
      True if the file exists
    • findByFileIn

      Set<FileEntity> findByFileIn(Set<String> files)
      Find file entities where the file value is in the given set of files.
      Parameters:
      files - The files to find entities for
      Returns:
      The file entities
    • findUnusedFiles

      @Query(value="SELECT id FROM files WHERE id NOT IN (SELECT DISTINCT(setup_file) FROM applications WHERE setup_file IS NOT NULL) AND id NOT IN (SELECT DISTINCT(file_id) FROM applications_configs) AND id NOT IN (SELECT DISTINCT(file_id) FROM applications_dependencies) AND id NOT IN (SELECT DISTINCT(setup_file) FROM clusters WHERE setup_file IS NOT NULL) AND id NOT IN (SELECT DISTINCT(file_id) FROM clusters_configs) AND id NOT IN (SELECT DISTINCT(file_id) FROM clusters_dependencies) AND id NOT IN (SELECT DISTINCT(setup_file) FROM commands WHERE setup_file IS NOT NULL) AND id NOT IN (SELECT DISTINCT(file_id) FROM commands_configs) AND id NOT IN (SELECT DISTINCT(file_id) FROM commands_dependencies) AND id NOT IN (SELECT DISTINCT(setup_file) FROM jobs WHERE setup_file IS NOT NULL) AND id NOT IN (SELECT DISTINCT(file_id) FROM jobs_configs) AND id NOT IN (SELECT DISTINCT(file_id) FROM jobs_dependencies) AND created <= :createdThresholdUpperBound AND created >= :createdThresholdLowerBound LIMIT :limit FOR UPDATE;", nativeQuery=true) Set<Number> findUnusedFiles(@Param("createdThresholdLowerBound") Instant createdThresholdLowerBound, @Param("createdThresholdUpperBound") Instant createdThresholdUpperBound, @Param("limit") int limit)
      Find the ids of all files from the database that aren't referenced which were created before the supplied created threshold.
      Parameters:
      createdThresholdLowerBound - The instant in time when files created after this time that aren't referenced will be selected. Inclusive.
      createdThresholdUpperBound - The instant in time when files created before this time that aren't referenced will be selected. Inclusive.
      limit - The maximum number of file ids to retrieve
      Returns:
      The ids of the files which should be deleted
    • deleteByIdIn

      @Modifying Long deleteByIdIn(Set<Long> ids)
      Delete all files from the database that are in the current set of ids.
      Parameters:
      ids - The unique ids of the files to delete
      Returns:
      The number of files deleted