Example usage for javax.persistence Query getSingleResult

List of usage examples for javax.persistence Query getSingleResult

Introduction

In this page you can find the example usage for javax.persistence Query getSingleResult.

Prototype

Object getSingleResult();

Source Link

Document

Execute a SELECT query that returns a single untyped result.

Usage

From source file:eu.domibus.common.dao.AttachmentDAO.java

public byte[] loadBinaryData(int entityId) {
    Query q = this.em.createNamedQuery("PartInfo.loadBinaryData");
    q.setParameter("ENTITY_ID", entityId);
    return (byte[]) q.getSingleResult();
}

From source file:com.june.app.site.repository.jpa.VideoRepositoryImpl.java

@Override
public long videoListCnt(Video vo) {

    String queryString = "SELECT count(*) FROM Video video WHERE video.useYn ='Y'";
    Query query = this.em.createQuery(queryString);
    Long count = (Long) query.getSingleResult();
    return count;

}

From source file:com.thingtrack.konekti.dao.impl.internal.SupplierDaoImpl.java

@Override
public Supplier getByUser(User user) throws Exception {

    String queryString = "SELECT p";
    queryString += " FROM " + getEntityName() + " p";
    queryString += " WHERE p.user = :user";

    Query query = (Query) getEntityManager().createQuery(queryString).setParameter("user", user);

    return (Supplier) query.getSingleResult();

}

From source file:cz.fi.muni.pa036.airticketbooking.dao.impl.AirlineDaoImpl.java

@Override
public Airline getMainAirline() {
    try {//from   ww  w . j  a va  2  s. c o m
        Query q = em.createQuery("FROM Airline WHERE main_airline='1'");
        Airline airlineTemp = (Airline) q.getSingleResult();

        return airlineTemp;
    } catch (PersistenceException | IllegalArgumentException ex) {
        throw new DataAccessException(ex.getMessage(), ex) {
        };
    }
}

From source file:springchat.test.MessagesServiceTest.java

@Test
public void testPersistence() {
    List<MessageEntity> msgs = messages.getMessages();
    final Long uid = messages.save(System.currentTimeMillis(), "botossauro", "Hi there!").getUid();
    Assert.assertNotNull(uid);/* w w  w.j a v a  2  s.  co  m*/
    Assert.assertEquals("botossauro", eao.withQuery("SELECT e FROM MessageEntity e WHERE e.uid = :puid",
            new BaseEAO.ExecutableQuery<MessageEntity>() {
                @Override
                public MessageEntity execute(Query query) {
                    query.setParameter("puid", uid);
                    return (MessageEntity) query.getSingleResult();
                }
            }).getUser());
    Assert.assertTrue(messages.getMessages().size() == msgs.size() + 1);
}

From source file:org.messic.server.datamodel.jpaimpl.DAOJPA.java

@Transactional(readOnly = true)
public long getCount() {
    Query q = entityManager.createQuery("SELECT COUNT(e) FROM " + type.getName() + " e");
    return (Long) q.getSingleResult();
}

From source file:net.anthonychaves.bookmarks.web.FakeLoginController.java

@RequestMapping(method = RequestMethod.POST)
public String fakeLogin(HttpSession session, @RequestParam("username") String username) {
    EntityManager em = emf.createEntityManager();
    Query q = em.createQuery("select u from User u where u.firstName = ?1").setParameter(1, username);

    User u = (User) q.getSingleResult();

    if (u != null) {
        session.setAttribute("user", u);
        return "redirect:user";
    } else {/*from w  w  w  .ja v a2  s  .c om*/
        return "redirect:/b/user/new";
    }
}

From source file:cz.fi.muni.pa036.airticketbooking.dao.impl.UserRoleDaoImpl.java

@Override
public UserRole find(long id) {
    final Query query = em.createQuery("from UserRole where id = :id");
    query.setParameter("id", id);
    return (UserRole) query.getSingleResult();
}

From source file:com.healthcit.cacure.dao.QuestionTableDao.java

/**
 * @return Next Ord Number in ordered entities.
 *//*from   w  ww.  j  av a  2 s. com*/
@Transactional(propagation = Propagation.SUPPORTS)
public Integer calculateNextOrdNumber(Long formId) {
    String jpql = "select MAX(ord + 1) from TableQuestion q, FormElement e where q.parent_id=e.id and e.form.id = :formId";
    Query query = em.createQuery(jpql);
    query.setParameter("formId", formId);
    return (Integer) query.getSingleResult();

}

From source file:com.gymadmin.persistence.dao.impl.PaymentMethodDaoImpl.java

public PaymentPlanEntity findByName(String name) {
    Query namedQuery = em.createNamedQuery("PaymentMethodEntity.findByName");
    namedQuery.setParameter("name", name);
    return (PaymentPlanEntity) namedQuery.getSingleResult();
}