001package co.codewizards.cloudstore.local.persistence; 002 003import static java.util.Objects.*; 004 005import java.util.ArrayList; 006import java.util.Collection; 007 008import javax.jdo.Query; 009 010public class NormalFileDao extends Dao<NormalFile, NormalFileDao> { 011 /** 012 * Get those {@link RepoFile}s whose {@link RepoFile#getSha1() sha1} and {@link RepoFile#getLength() length} 013 * match the given parameters. 014 * @param sha1 the {@link RepoFile#getSha1() sha1} for which to query. Must not be <code>null</code>. 015 * @param length the {@link RepoFile#getLength() length} for which to query. 016 * @return those {@link RepoFile}s matching the given criteria. Never <code>null</code>; but maybe empty. 017 */ 018 public Collection<NormalFile> getNormalFilesForSha1(final String sha1, final long length) { 019 requireNonNull(sha1, "sha1"); 020 final Query query = pm().newNamedQuery(getEntityClass(), "getNormalFiles_sha1_length"); 021 try { 022 @SuppressWarnings("unchecked") 023 final 024 Collection<NormalFile> repoFiles = (Collection<NormalFile>) query.execute(sha1, length); 025 return new ArrayList<NormalFile>(repoFiles); 026 } finally { 027 query.closeAll(); 028 } 029 } 030 031 @Override 032 public void deletePersistent(final NormalFile entity) { 033 throw new UnsupportedOperationException("Use RepoFileDao for this operation!"); 034 } 035 036 @Override 037 public <P extends NormalFile> P makePersistent(final P entity) { 038 throw new UnsupportedOperationException("Use RepoFileDao for this operation!"); 039 } 040}