package at.arz.latte.rodeo.release.restapi;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import at.arz.latte.rodeo.api.RodeoQuery;
import at.arz.latte.rodeo.release.Release;
import at.arz.latte.rodeo.release.ReleaseName;

public class FindReleaseByNameQuery
		implements RodeoQuery<Release> {

	private ReleaseName releaseName;

	@Override
	public Release execute(EntityManager entityManager) {
		TypedQuery<Release> createQuery = createQuery(entityManager);
		createQuery.setParameter("releaseName", releaseName);
		return createQuery.getSingleResult();
	}

	public void setReleaseName(ReleaseName releaseName) {
		this.releaseName = releaseName;
	}

	TypedQuery<Release> createQuery(EntityManager entityManager) {
		return entityManager.createNamedQuery(Release.SELECT_BY_NAME, Release.class);
	}

}

@@ -78,16 +78,60 @@
 anager;%0A
+import javax.persistence.NoResultException;%0A
 import j
@@ -586,16 +586,25 @@
 eName);%0A
+%09%09try %7B%0A%09
 %09%09return
@@ -635,16 +635,71 @@
 sult();%0A
+%09%09%7D catch (NoResultException e) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%0A
 %09%7D%0A%0A%09pub

fix query return null if no result is found