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:com.exp.tracker.services.impl.GroupServiceImpl.java

@Override
@Transactional/*from w ww.j a v a2  s .co  m*/
public GroupBean addGroup(GroupBean group) {
    GroupBean newGb = null;
    boolean groupExists = true;
    // first find match
    Query queryFindMatch = em.createNamedQuery("findGroupMatch");
    queryFindMatch.setParameter("groupName", group.getGroupName());
    @SuppressWarnings("unused")
    GroupEntity ge = null;
    try {
        ge = (GroupEntity) queryFindMatch.getSingleResult();
    } catch (NoResultException nre) {
        if (logger.isDebugEnabled()) {
            logger.debug("Group does not exist, thus can be added - " + group.getGroupName());
        }
        groupExists = false;
    }
    if (!groupExists) {
        GroupEntity ge1 = group.getGroupEntity();
        Calendar calendar = Calendar.getInstance();
        ge1.setCreationDate(calendar.getTime());
        ge1.setLastUpdatedDate(calendar.getTime());

        em.persist(ge1);
        if (logger.isDebugEnabled()) {
            logger.debug("Group added succesfuly - " + group.getGroupName());
        }
        newGb = new GroupBean(ge1);
    }
    return newGb;
}

From source file:com.cimpoint.mes.server.repositories.TransitionRepository.java

public ETransition findTransitionByName(String routingName, String transitionName) {
    try {//from w ww . j  a v a 2 s. c o m
        Query qry = getEntityManager()
                .createQuery("select o from ETransition o where o.routingName = ?1 and o.name = ?2")
                .setParameter(1, routingName).setParameter(2, transitionName).setMaxResults(1);
        ETransition trsn = (ETransition) qry.getSingleResult();
        return trsn;
    } catch (NoResultException ex) {
        return null;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:org.apache.cxf.fediz.service.idp.service.jpa.TrustedIdpDAOJPAImpl.java

@Override
public void deleteTrustedIDP(String realm) {
    Query query = null;
    query = em.createQuery("select t from TrustedIDP t where t.realm=:realm");
    query.setParameter("realm", realm);

    //@SuppressWarnings("rawtypes")
    Object trustedIdpObj = query.getSingleResult();
    em.remove(trustedIdpObj);// w  w  w  .  j a v a2s. co  m

    LOG.debug("Trusted IDP '" + realm + "' deleted");
}

From source file:com.june.app.cmn.repository.jpa.FileRepositoryImpl.java

@Override
public FileDetail fileSingle(FileDetail filedetail) {
    String atchFileId = filedetail.getAtchFileId();
    int fileSn = filedetail.getFileSn();
    Query query = this.em.createQuery(
            "SELECT fileDetail FROM FileDetail fileDetail WHERE fileDetail.atchFileId =:atchFileId and fileDetail.fileSn =:fileSn");
    query.setParameter("atchFileId", atchFileId);
    query.setParameter("fileSn", fileSn);
    return (FileDetail) query.getSingleResult();

}

From source file:org.kuali.mobility.maps.dao.LocationDaoImpl.java

public Location findLocationById(Long locationId) {
    Query query = entityManager.createQuery("select loc from Location loc where loc.locationId = :id");
    query.setParameter("id", locationId);
    return (Location) query.getSingleResult();
}

From source file:mx.edu.ittepic.proyectofinal.ejbs.webservicesusers.java

@GET
@Path("/login/{usermame}/{password}")
@Produces({ MediaType.TEXT_PLAIN })/*from w  ww  . j a  v a2 s  .c  om*/
public String getLogin(@PathParam("usermame") String username, @PathParam("password") String password) {
    Message m = new Message();
    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();

    try {
        Users users;
        Query q = entity.createNamedQuery("Users.getUser").setParameter("username", username)
                .setParameter("password", password);

        users = (Users) q.getSingleResult();
        users.setSaleList(null);

        m.setCode(200);
        m.setMsg("Si tiene acceso al sistema");
        m.setDetail(users.getApikey());

    } catch (NoResultException e) {
        m.setCode(401);
        m.setMsg("No tiene acceso al sistema");
        m.setDetail(e.toString());
    }
    return gson.toJson(m);
}

From source file:org.kuali.mobility.maps.dao.LocationDaoImpl.java

public MapsGroup getMapsGroupById(Long groupId) {
    Query query = entityManager.createQuery("select group from MapsGroup group where group.groupId = :id");
    query.setParameter("id", groupId);
    return (MapsGroup) query.getSingleResult();
}

From source file:com.iselect.kernal.pageflow.dao.PageRequestDaoImpl.java

@Override
public PageRequestModel getPageRequest(String actionPath, String actionMethod) throws ISelectDaoException {
    Query query = em.createNamedQuery(PageRequestModel.QUERY_BY_PATH_METHOD);
    query.setParameter(PageRequestModel.PARAM_ACTION_METHOD, actionPath);
    query.setParameter(PageRequestModel.PARAM_ACTION_METHOD, actionMethod);
    return (PageRequestModel) query.getSingleResult();
}

From source file:de.berlios.jhelpdesk.dao.jpa.TicketCategoryDAOJpa.java

@Transactional(readOnly = false)
public void insertRootCategory(final TicketCategory rootCategory) {
    this.jpaTemplate.execute(new JpaCallback() {
        public Object doInJpa(EntityManager em) throws PersistenceException {
            Query getMaxTRightQuery = em.createNativeQuery("SELECT max(t_right) FROM ticket_category",
                    Long.class);
            final Long maxTRight = (Long) getMaxTRightQuery.getSingleResult();

            rootCategory.setLeft(new Long(maxTRight.longValue() + 1));
            rootCategory.setRight(new Long(maxTRight.longValue() + 2));
            rootCategory.setDepth(0);/*from  w ww.ja v  a  2  s. c  o m*/
            em.persist(rootCategory);
            return null;
        }
    });
}

From source file:com.appdynamicspilot.persistence.CartPersistence.java

/**
 * Deletes Items from cart - v2//from   w  w  w .  j ava2  s .  c  o  m
 *
 * @param username
 * @param item     id
 */
public Integer deleteItemInCartV2(String username, Long id) {
    Query q = getEntityManager().createQuery("SELECT c FROM Cart c where c.user.email = :userid");
    q.setParameter("userid", username);
    if (q.getResultList().size() > 0) {
        Cart c = (Cart) q.getSingleResult();
        Item i = getEntityManager().find(Item.class, id);
        c.removeItem(i);
        update(c);
        return 0;
    }
    return 1;
}