Example usage for javax.persistence Query getResultList

List of usage examples for javax.persistence Query getResultList

Introduction

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

Prototype

List getResultList();

Source Link

Document

Execute a SELECT query and return the query results as an untyped List.

Usage

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

/**
 * Deletes Items from cart - v2//from   w ww.j  ava 2 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;
}

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

public List<Location> getAllUngroupedLocations() {
    Query query = entityManager.createQuery("select loc from Location loc where loc.mapsGroups is empty");
    return query.getResultList();
    //      return null;
}

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

@Override
@Transactional//from w w w . j  a  v a2s  . c  o m
public List<MDOPlaylist> getAll(String username) {
    Query query = entityManager.createQuery("from MDOPlaylist as a where (a.owner.login = :userName)");
    query.setParameter("userName", username);

    @SuppressWarnings("unchecked")
    List<MDOPlaylist> results = query.getResultList();
    return results;
}

From source file:org.mifos.loan.repository.StandardLoanDao.java

@Override
@Transactional(readOnly = true)/*from   w w w .  j  av a  2  s . c  o m*/
public Boolean loansExistForLoanProduct(Integer loanProductId) {
    Query query = entityManager
            .createQuery("select count(*) from Loan loan where loan.loanProduct.id = :loanProductId");
    query.setParameter("loanProductId", loanProductId);
    return Boolean.valueOf(((Long) query.getResultList().get(0)) > 0);
}

From source file:Professor.java

  public Collection<Project> findAllProjects() {
  Query query = em.createQuery("SELECT p FROM Project p");
  return (Collection<Project>) query.getResultList();
}

From source file:com.impetus.kwitter.service.TwitterService.java

@Override
public List<User> getFollowers(String userId) {
    Query q = em.createQuery("select u from User u where u.userId =:userId");
    q.setParameter("userId", userId);
    List<User> users = q.getResultList();
    if (users == null || users.isEmpty()) {
        return null;
    }/*  www .j a  va2s. c  o  m*/
    return users.get(0).getFollowers();
}

From source file:com.impetus.kwitter.service.TwitterService.java

@Override
public List<Tweet> getAllTweets(String userId) {
    Query q = em.createQuery("select u from User u where u.userId =:userId");
    q.setParameter("userId", userId);
    List<User> users = q.getResultList();
    if (users == null || users.isEmpty()) {
        return null;
    } else {//from  ww w  . ja  v a  2  s.  co m
        return users.get(0).getTweets();
    }
}

From source file:org.syncope.core.persistence.dao.impl.DerSchemaDAOImpl.java

@Override
public <T extends AbstractDerAttr> List<T> getAttributes(final AbstractDerSchema derivedSchema,
        final Class<T> reference) {

    Query query = entityManager.createQuery(
            "SELECT e FROM " + reference.getSimpleName() + " e" + " WHERE e.derivedSchema=:schema");

    query.setParameter("schema", derivedSchema);

    return query.getResultList();
}

From source file:com.rambird.repository.jpa.JpaOwnerRepositoryImpl.java

/**
 * Important: in the current version of this method, we load Owners with all their Pets and Visits while 
 * we do not need Visits at all and we only need one property from the Pet objects (the 'name' property).
 * There are some ways to improve it such as:
 * - creating a Ligtweight class (example here: https://community.jboss.org/wiki/LightweightClass)
 * - Turning on lazy-loading and using {@link OpenSessionInViewFilter}
 *//* www .jav a 2  s. co m*/
@SuppressWarnings("unchecked")
public Collection<Owner> findByLastName(String lastName) {
    // using 'join fetch' because a single query should load both owners and pets
    // using 'left join fetch' because it might happen that an owner does not have pets yet
    Query query = this.em.createQuery(
            "SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE upper(owner.lastName) LIKE upper(:lastName)");
    query.setParameter("lastName", lastName + "%");
    return query.getResultList();
}

From source file:fr.mby.opa.picsimpl.dao.DbAlbumDao.java

@Override
@SuppressWarnings("unchecked")
public Collection<Album> findAllAlbums() {
    final EmCallback<Collection<Album>> emCallback = new EmCallback<Collection<Album>>(this.getEmf()) {

        @Override//  w w w  . ja v a 2  s .  c o m
        protected Collection<Album> executeWithEntityManager(final EntityManager em)
                throws PersistenceException {
            final Query findAllQuery = em.createNamedQuery(Album.FIND_ALL_ALBUMS_ORDER_BY_DATE);
            return findAllQuery.getResultList();
        }
    };

    Collection<Album> albums = emCallback.getReturnedValue();

    if (albums == null) {
        albums = Collections.emptyList();
    }

    return albums;
}