Package javax.persistence

Examples of javax.persistence.Query


        StringBuilder queryString = new StringBuilder();
        queryString.append("select n from WikiNode n where n.parent = :parent").append(" ");
        queryString.append("order by n.").append(orderBy.name()).append(" ").append(orderAscending ? "asc" : "desc");

        Query query = restrictedEntityManager
        .createQuery(queryString.toString())
        .setHint("org.hibernate.comment", "Find wikinode children order by "+orderBy.name())
        .setParameter("parent", node)
        .setHint("org.hibernate.cacheable", false)
        .setFirstResult(firstResult);
       
        if (maxResults > 0)
        {
           query.setMaxResults(maxResults);
        }
       
        return query.getResultList();
    }
View Full Code Here


       {
          if (criteria.length() > 0) criteria.append(" and ");
          criteria.append("c.fromUserHomepage = :fromUserHomepage");
       }
      
       Query query = restrictedEntityManager.createQuery("select c from WikiComment c " + criteria.toString());
      
       if (fromUserName != null) query.setParameter("fromUserName", fromUserName);
       if (fromUserEmail != null) query.setParameter("fromUserEmail", fromUserEmail);
       if (fromUserHomepage != null) query.setParameter("fromUserHomepage", fromUserHomepage);
      
       return (List<WikiComment>) query.getResultList();
    }
View Full Code Here

        }
        return null;
    }

    public long findTotalNoOfUsers() {
        Query q = entityManager.createQuery("select count(u) from User u");
        q.setHint("org.hibernate.comment", "Find number of users");
        q.setHint("org.hibernate.cacheable", true);
        return (Long)q.getSingleResult();
    }
View Full Code Here

        for (String username : usernames) {
            usernamesToQuery.add(username);
            i++;
            if (i % batchsize == 0 || usernames.size() < batchsize) {
                // Query and clear
                Query q = entityManager.createQuery("select u from User u left join fetch u.profile where u.username in(:usernames)");
                q.setParameter("usernames", usernamesToQuery);
                users.addAll(q.getResultList());
                usernamesToQuery.clear();
            }
        }
        return users;
    }
View Full Code Here

        return "pretty:create";
    }

    @SuppressWarnings("unchecked")
    public TinyLink getByKey(final String key) {
        Query query = em.createQuery("from TinyLink t where t.name=:key", TinyLink.class);
        query.setParameter("key", key);
        List<TinyLink> resultList = query.getResultList();
        if (resultList.isEmpty()) {
            return new TinyLink();
        }
        return resultList.get(0);
    }
View Full Code Here

   * @return <code>true</code> if the object is found in the datastore and
   *         deleted, <code>false</code> if the item is not found.
   */
  protected boolean _removeById(Class<?> type, Serializable id) {
    if (id != null) {
      Query query = em().createQuery("select _it_.id from " + getMetadataUtil().get(type).getEntityName() + " _it_ where _it_.id = ?").setParameter(1, id);
      if (query.getResultList().size() != 0) {
        em().remove(em().getReference(type, id));
        return true;
      }
    }
    return false;
View Full Code Here

    if (type == null)
      throw new NullPointerException("Type is null.");
    if (!validId(id))
      return false;

    Query query = em().createQuery("select _it_.id from " + getMetadataUtil().get(type).getEntityName() + " _it_ where _it_.id = :id");
    query.setParameter("id", id);
    return query.getResultList().size() == 1;
  }
View Full Code Here

      }
    }
    if (nonNulls.size() == 0)
      return new ArrayList<Object>(0);

    Query query = em().createQuery(sb.toString());
    int idx = 1;
    for (Serializable id : nonNulls) {
      query.setParameter(idx++, id);
    }
    return query.getResultList();
  }
View Full Code Here

    if (searchClass == null || search == null)
      return null;

    List<Object> paramList = new ArrayList<Object>();
    String ql = generateQL(searchClass, search, paramList);
    Query query = entityManager.createQuery(ql);
    addParams(query, paramList);
    addPaging(query, search);

    return transformResults(query.getResultList(), search);
  }
View Full Code Here

    List<Object> paramList = new ArrayList<Object>();
    String ql = generateRowCountQL(searchClass, search, paramList);
    if (ql == null) { // special case where the query uses column operators
      return 1;
    }
    Query query = entityManager.createQuery(ql);
    addParams(query, paramList);

    return ((Number) query.getSingleResult()).intValue();
  }
View Full Code Here

TOP

Related Classes of javax.persistence.Query

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.