List of usage examples for javax.persistence Query getSingleResult
Object getSingleResult();
From source file:net.chrissearle.flickrvote.dao.JpaChallengeDao.java
/** * Method findByTag returns the challenge with the given tag. Null if no matching challenge found. * * @param tag of type String/*from w w w . ja v a 2 s.c o m*/ * @return Challenge */ @SuppressWarnings("unchecked") public Challenge findByTag(String tag) { Query query = entityManager.createQuery("select c from Challenge c where c.tag = :tag"); query.setParameter("tag", tag); try { return (Challenge) query.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:ch.javaee.basicMvc.repository.UserRepositoryImpl.java
@Override @Transactional(readOnly = true)/*ww w . jav a2 s. co m*/ public boolean isSecurityCodeValid(String email, String securityCode) { Query query = em.createQuery("select count(u) from user u join u.securityCode as sec where u.email = :email" + " and sec.code = :code").setParameter("email", email).setParameter("code", securityCode); Long count = (Long) query.getSingleResult(); return count == 1; }
From source file:org.kuali.mobility.emergencyinfo.dao.EmergencyInfoDaoImpl.java
public EmergencyInfo findEmergencyInfoById(Long id) { Query query = entityManager .createQuery("select ei from MaintEmergencyInfo ei where ei.emergencyInfoId = :id"); query.setParameter("id", id); try {//from w w w. jav a 2 s . com return (EmergencyInfo) query.getSingleResult(); } catch (NoResultException e) { return null; } }
From source file:eu.xipi.bro4xipi.brokermodel.BrokerJpaController.java
public Broker read(final String name) { Query q = entityManager.createQuery("SELECT m FROM Broker m WHERE m.name='" + name + "'"); //q.setFirstResult(1); //comment//from w w w.jav a2s . co m return (Broker) q.getSingleResult(); }
From source file:com.cimpoint.mes.server.repositories.WorkOrderRepository.java
public String getNextWorkOrderNumber() throws Exception { Query qry = getEntityManager().createQuery("select o from EWorkOrder o order by o.number desc") .setMaxResults(1);/* ww w . ja va2s . c o m*/ try { EWorkOrder wo = (EWorkOrder) qry.getSingleResult(); return String.valueOf(Integer.parseInt(wo.getNumber()) + 1); } catch (NoResultException ex) { return this.getInitWorkOrderNumber(); } catch (Exception ex) { ex.printStackTrace(); throw ex; } }
From source file:be.fedict.trust.service.dao.bean.CertificateAuthorityDAOBean.java
public long getTotalCachedCertificates() { /*//from w w w. ja va 2 s . co m * Oracle has problems executing this query. So we no longer use it * within the admin portal. */ Query query = this.entityManager.createNamedQuery(RevokedCertificateEntity.QUERY_COUNT_ALL); return (Long) query.getSingleResult(); }
From source file:co.sip.dmesmobile.bs.ScStopDao.java
@Override public ScStopMachine getStopMachine(String idMachine, String state) throws Exception { entityManager = Factory.getEntityManagerFactory().createEntityManager(); ScStopMachine result = null;/* w w w. j a v a 2 s . c o m*/ String stringQuery = "SELECT * FROM (SELECT sm.id_stop_machine, sm.id_maintenance, " + "sm.reason, sm.state, sm.password, g.type AS type_group, ROW_NUMBER() OVER " + "(ORDER BY sm.id_stop_machine DESC) AS item\n" + "FROM dmes.sc_stop_machine sm, dmes.sc_notification n, dmes.sc_group g WHERE " + "sm.state = " + state + " AND n.id_stop_machine = sm.id_stop_machine\n" + "AND n.id_group = g.id_group\n" + "AND n.id_machine = " + idMachine + ") AS STOP_MACHINE WHERE item = 1"; Query query = entityManager.createNativeQuery(stringQuery); Object object = query.getSingleResult(); if (object != null) { result = new ScStopMachine(); result.setIdStopMachine(new Long(((Object[]) object)[0].toString())); //Extraigo el id result.setReason(((Object[]) object)[2].toString()); //Extraigo la razn result.setState(new Short(((Object[]) object)[3].toString())); result.setPassword(((Object[]) object)[4].toString()); if (((Object[]) object)[1] != null) { result.setIdMaintenance(new Long(((Object[]) object)[1].toString())); } else if (((Object[]) object)[5].toString().equals("1")) { result.setIdMaintenance(-1L); } } return result; }
From source file:be.fedict.trust.service.dao.bean.CertificateAuthorityDAOBean.java
public long getTotalActiveCachedCAs() { Query query = this.entityManager.createNamedQuery(CertificateAuthorityEntity.QUERY_COUNT_ACTIVE); return (Long) query.getSingleResult(); }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.EntitlementDAOJPAImpl.java
@Override public void deleteEntitlement(String name) { Query query = null; query = em.createQuery("select e from Entitlement e where e.name=:name"); query.setParameter("name", name); //@SuppressWarnings("rawtypes") Object entitlementObj = query.getSingleResult(); em.remove(entitlementObj);/*from ww w . j a v a 2 s.c o m*/ LOG.debug("Entitlement '{}' deleted", name); }
From source file:edu.iu.m.news.dao.NewsDaoImpl.java
@Override public NewsSource getNewsSourceById(String rssShortCode) { Query query = entityManager.createQuery( "select r from MaintRss r where r.shortCode like :rssShortCode and r.type like 'NEWS'"); query.setParameter("rssShortCode", rssShortCode); try {//from ww w . jav a2 s .com return convertMaintRssToNewsSource((MaintRss) query.getSingleResult()); } catch (NoResultException e) { return null; } }