List of usage examples for javax.persistence TypedQuery getSingleResult
X getSingleResult();
From source file:com.netflix.genie.core.jpa.services.JpaJobSearchServiceImpl.java
/** * {@inheritDoc}//from w ww . j ava2s .c om */ @Override public JobStatus getJobStatus(@NotBlank final String id) throws GenieException { log.debug("Called with id {}", id); final TypedQuery<JobStatus> query = entityManager.createNamedQuery(JobEntity.QUERY_GET_STATUS_BY_ID, JobStatus.class); query.setParameter("id", id); try { return query.getSingleResult(); } catch (NoResultException e) { throw new GenieNotFoundException("No job with id " + id + " exists."); } }
From source file:org.openmeetings.app.data.basic.dao.LdapConfigDaoImpl.java
public LdapConfig getLdapConfigById(Long ldapConfigId) { try {/* w w w . ja v a2 s .c o m*/ String hql = "select c from LdapConfig c " + "WHERE c.ldapConfigId = :ldapConfigId " + "AND c.deleted LIKE :deleted"; TypedQuery<LdapConfig> query = em.createQuery(hql, LdapConfig.class); query.setParameter("ldapConfigId", ldapConfigId); query.setParameter("deleted", "false"); LdapConfig ldapConfig = null; try { ldapConfig = query.getSingleResult(); } catch (NoResultException ex) { } return ldapConfig; } catch (Exception ex2) { log.error("[getLdapConfigById]: ", ex2); } return null; }
From source file:io.hops.hopsworks.common.dao.certificates.CertsFacade.java
public ProjectGenericUserCerts findProjectGenericUserCerts(String projectGenericUsername) { TypedQuery<ProjectGenericUserCerts> query = em.createNamedQuery( "ProjectGenericUserCerts.findByProjectGenericUsername", ProjectGenericUserCerts.class); query.setParameter("projectGenericUsername", projectGenericUsername); try {/*from w w w . j av a2 s . co m*/ return query.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:eu.domibus.ebms3.common.dao.PModeDao.java
protected String findAgreementRef(final AgreementRef agreementRef) throws EbMS3Exception { if (agreementRef == null || agreementRef.getValue() == null || agreementRef.getValue().isEmpty()) { return ""; //AgreementRef is optional }//from ww w .ja va 2s .com final String value = agreementRef.getValue(); final String pmode = agreementRef.getPmode(); //FIXME? This value is ignored! final String type = agreementRef.getType(); final TypedQuery<String> query = this.entityManager.createNamedQuery("Agreement.findByValueAndType", String.class); query.setParameter("VALUE", value); query.setParameter("TYPE", (type == null) ? "" : type); try { return query.getSingleResult(); } catch (final NoResultException e) { PModeDao.LOG.info("No matching agreementRef found", e); } throw new EbMS3Exception(EbMS3Exception.EbMS3ErrorCode.EBMS_0001, "No matching agreementRef found", null, null, null);//FIXME: Throw ValueInconsistent if CPA not recognized [5.2.2.7] }
From source file:ch.puzzle.itc.mobiliar.business.resourcerelation.boundary.RelationEditor.java
public ResourceGroupEntity getResourceGroupWithAllResources(Integer resourceGroupId) { try {/*w w w. j a va2s . c o m*/ TypedQuery<ResourceGroupEntity> resGroupQuery = entityManager.createQuery( "select rg from ResourceGroupEntity rg left join fetch rg.resources where rg.id=:id", ResourceGroupEntity.class).setParameter("id", resourceGroupId); return resGroupQuery.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:org.easyj.orm.jpa.SingleJPAEntityDao.java
@Override protected <E> E getSingleResultByQuery(String query, Class<E> klazz, Map<String, Object> params, QueryType queryType) {//from w ww . ja v a 2 s . co m E entity = null; TypedQuery<E> q = null; try { if (QueryType.JPQL.equals(queryType)) { q = getEm().createQuery(query, klazz); } else if (QueryType.NAMED.equals(queryType)) { q = getEm().createNamedQuery(query, klazz); } if (setParameters(q, params)) { entity = q.getSingleResult(); } } finally { closeEm(); } return entity; }
From source file:org.openmeetings.app.data.conference.dao.RoomModeratorsDaoImpl.java
/** * get all available RoomTypes/*from ww w . j a v a2 s. c om*/ * * @return List of RoomTypes */ public RoomModerators getRoomModeratorById(Long roomModeratorsId) { try { String hql = "select c from RoomModerators as c where c.roomModeratorsId = :roomModeratorsId"; TypedQuery<RoomModerators> query = em.createQuery(hql, RoomModerators.class); query.setParameter("roomModeratorsId", roomModeratorsId); RoomModerators roomModerators = null; try { roomModerators = query.getSingleResult(); } catch (NoResultException ex) { } return roomModerators; } catch (Exception ex2) { log.error("[getRoomModeratorById] ", ex2); } return null; }
From source file:org.openmeetings.app.data.user.dao.UserContactsDaoImpl.java
public UserContacts getUserContacts(Long userContactId) { try {// ww w. j a v a 2 s . c o m String hql = "select c from UserContacts c " + "where c.userContactId = :userContactId"; TypedQuery<UserContacts> query = em.createQuery(hql, UserContacts.class); query.setParameter("userContactId", userContactId); UserContacts userContacts = null; try { userContacts = query.getSingleResult(); } catch (NoResultException ex) { } return userContacts; } catch (Exception e) { log.error("[getUserContacts]", e); } return null; }
From source file:ch.puzzle.itc.mobiliar.business.resourcegroup.control.ResourceGroupRepository.java
/** * Fetches the resourceGroup as required for the create deployment popup of the deploy screen *///from w w w .j a va2 s. c om public ResourceGroupEntity getResourceGroupForCreateDeploy(Integer groupId) { TypedQuery<ResourceGroupEntity> q = entityManager.createQuery("select r from ResourceGroupEntity r" + " left join fetch r.resources res" + " left join fetch res.consumedMasterRelations" + " left join fetch res.resourceTags" + " where r.id=:id", ResourceGroupEntity.class); q.setParameter("id", groupId); return q.getSingleResult(); }
From source file:org.openmeetings.app.data.user.dao.UsersDaoImpl.java
public Users getUserByName(String login) { try {//from w w w . j av a 2 s . c o m String hql = "SELECT u FROM Users as u " + " where u.login = :login" + " AND u.deleted <> :deleted"; TypedQuery<Users> query = em.createQuery(hql, Users.class); query.setParameter("login", login); query.setParameter("deleted", "true"); Users us = null; try { us = query.getSingleResult(); } catch (NoResultException ex) { } return us; } catch (Exception e) { log.error("[getUserByAdressesId]", e); } return null; }