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

tv.hd3g.jobkit.watchfolder.mod.repository.WatchedFileEntityRepository Maven / Gradle / Ivy

Go to download

Keep in a database JobKit Watchfolder's detected and tracked files persistent as reboot

There is a newer version: 22.0.0
Show newest version
/*
 * This file is part of AuthKit.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * Copyright (C) hdsdi3g for hd3g.tv 2019
 *
 */
package tv.hd3g.jobkit.watchfolder.mod.repository;

import java.util.Set;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import tv.hd3g.jobkit.watchfolder.mod.entity.WatchedFileEntity;

public interface WatchedFileEntityRepository extends JpaRepository {

	@Query("SELECT w FROM WatchedFileEntity w WHERE w.hashPath IN :hashPath")
	Set getByHashPath(Set hashPath);

	@Query("""
			SELECT w FROM WatchedFileEntity w
			WHERE w.markedAsDone = false
			AND ((w.directory = true AND :pickUpDirs = true) OR (w.directory = false AND :pickUpFiles = true))
			AND w.hashPath NOT IN :detectedHashPath
			AND w.folderLabel = :folderLabel
			""")
	Set getLostedByHashPath(Set detectedHashPath,
											   boolean pickUpDirs,
											   boolean pickUpFiles,
											   String folderLabel);

	@Query("""
			SELECT w FROM WatchedFileEntity w
			WHERE w.markedAsDone = false
			AND ((w.directory = true AND :pickUpDirs = true) OR (w.directory = false AND :pickUpFiles = true))
			AND w.folderLabel = :folderLabel
			""")
	Set getLostedForEmptyDir(boolean pickUpDirs,
												boolean pickUpFiles,
												String folderLabel);

	@Query("SELECT w.hashPath FROM WatchedFileEntity w WHERE w.folderLabel = :folderLabel")
	Set getAllHashPathByFolderLabel(String folderLabel);

	@Query("DELETE FROM WatchedFileEntity WHERE hashPath IN :detectedHashPath")
	@Modifying
	void deleteByHashPath(Set detectedHashPath);

	@Query("SELECT COUNT(w) FROM WatchedFileEntity w WHERE w.folderLabel = :folderLabel")
	int countByFolderLabel(String folderLabel);

	@Query("""
			SELECT COUNT(w) FROM WatchedFileEntity w
			WHERE ((w.directory = true AND :pickUpDirs = true) OR (w.directory = false AND :pickUpFiles = true))
			AND w.folderLabel = :folderLabel
			""")
	int countByFolderLabel(boolean pickUpDirs, boolean pickUpFiles, String folderLabel);

	@Query("DELETE FROM WatchedFileEntity WHERE folderLabel NOT IN :folderLabelToKeep")
	@Modifying
	void deleteFolderLabelsNotInSet(Set folderLabelToKeep);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy