001package co.codewizards.cloudstore.local.persistence;
002
003import static co.codewizards.cloudstore.core.util.Util.assertNotNull;
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(String sha1, long length) {
019                assertNotNull("sha1", sha1);
020                Query query = pm().newNamedQuery(getEntityClass(), "getNormalFiles_sha1_length");
021                try {
022                        @SuppressWarnings("unchecked")
023                        Collection<NormalFile> repoFiles = (Collection<NormalFile>) query.execute(sha1, length);
024                        return new ArrayList<NormalFile>(repoFiles);
025                } finally {
026                        query.closeAll();
027                }
028        }
029
030        @Override
031        public void deletePersistent(NormalFile entity) {
032                throw new UnsupportedOperationException("Use RepoFileDAO for this operation!");
033        }
034
035        @Override
036        public <P extends NormalFile> P makePersistent(P entity) {
037                throw new UnsupportedOperationException("Use RepoFileDAO for this operation!");
038        }
039}