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; 007import java.util.Date; 008import java.util.UUID; 009 010import javax.jdo.Query; 011 012public class RemoteRepositoryRequestDAO extends DAO<RemoteRepositoryRequest, RemoteRepositoryRequestDAO> { 013 014 public RemoteRepositoryRequest getRemoteRepositoryRequest(UUID repositoryId) { 015 String repositoryIdString = repositoryId == null ? null : repositoryId.toString(); 016 Query query = pm().newNamedQuery(getEntityClass(), "getRemoteRepositoryRequest_repositoryId"); 017 try { 018 RemoteRepositoryRequest remoteRepositoryRequest = (RemoteRepositoryRequest) query.execute(repositoryIdString); 019 return remoteRepositoryRequest; 020 } finally { 021 query.closeAll(); 022 } 023 } 024 025 public RemoteRepositoryRequest getRemoteRepositoryRequestOrFail(UUID repositoryId) { 026 RemoteRepositoryRequest remoteRepositoryRequest = getRemoteRepositoryRequest(repositoryId); 027 if (remoteRepositoryRequest == null) 028 throw new IllegalArgumentException(String.format("There is no RemoteRepositoryRequest with repositoryId='%s'!", repositoryId)); 029 030 return remoteRepositoryRequest; 031 } 032 033 public Collection<RemoteRepositoryRequest> getRemoteRepositoryRequestsChangedBefore(Date changed) { 034 assertNotNull("changed", changed); 035 Query query = pm().newNamedQuery(getEntityClass(), "getRemoteRepositoryRequestsChangedBefore_changed"); 036 try { 037 @SuppressWarnings("unchecked") 038 Collection<RemoteRepositoryRequest> c = (Collection<RemoteRepositoryRequest>) query.execute(changed); 039 return new ArrayList<RemoteRepositoryRequest>(c); 040 } finally { 041 query.closeAll(); 042 } 043 } 044}