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:eu.planets_project.tb.impl.persistency.TestbedServiceTemplatePersistencyImpl.java

public Map<String, List<ServiceTag>> getAllTBServiceIDAndTags() {
    Query query = manager.createQuery("from TestbedServiceTemplateImpl where discr='template'");
    Iterator<TestbedServiceTemplate> itTemplates = query.getResultList().iterator();
    Map<String, List<ServiceTag>> ret = new HashMap<String, List<ServiceTag>>();

    while (itTemplates.hasNext()) {
        List<ServiceTag> tags = new Vector<ServiceTag>();
        TestbedServiceTemplate template = itTemplates.next();
        tags.addAll(template.getAllTags());
        ret.put(template.getUUID(), tags);
    }// www .  ja v  a  2  s .  co  m
    return ret;
}

From source file:net.chrissearle.flickrvote.dao.JpaChallengeDao.java

/**
 * Method getVotedChallenge returns a challenge with existing votes. Returns null if none found.
 *
 * @return the challenge with votes.//from   ww w . j a  va2  s  . c  om
 */
@SuppressWarnings("unchecked")
public Challenge getVotedChallenge() {
    Query query = entityManager.createQuery("select distinct c FROM Vote v, IN(v.image) i, IN(i.challenge) c");
    List<Challenge> challenges = (List<Challenge>) query.getResultList();

    if (challenges != null && challenges.size() > 0) {
        return challenges.iterator().next();
    }

    return null;
}

From source file:com.mothsoft.alexis.engine.textual.TFIDFCalculatorImpl.java

@SuppressWarnings("unchecked")
@Transactional//from w  ww  .  java2  s.c  om
public void execute() {
    final long start = System.currentTimeMillis();

    final FullTextSession fullTextSession = Search.getFullTextSession((Session) this.em.getDelegate());
    final SearchFactory searchFactory = fullTextSession.getSearchFactory();
    final IndexReaderAccessor ira = searchFactory.getIndexReaderAccessor();
    final IndexReader reader = ira.open(com.mothsoft.alexis.domain.Document.class);

    final Query query = em.createQuery(
            "select d from Document d join d.documentTerms dt where dt.tfIdf IS NULL ORDER BY d.id ASC");
    final List<Document> documents = query.getResultList();

    final Term luceneTerm = new Term(CONTENT_TEXT_FIELD_NAME);
    int affectedRows = 0;

    try {
        for (final Document document : documents) {
            final Map<String, Float> termTfIdfMap = new HashMap<String, Float>();

            // calculate term TF-IDFs
            for (final DocumentTerm documentTerm : document.getDocumentTerms()) {
                final Term term = luceneTerm.createTerm(documentTerm.getTerm().getValueLowercase());
                Float score = TFIDF.score(documentTerm.getTerm().getValueLowercase(), documentTerm.getCount(),
                        document.getTermCount(), reader.numDocs(), reader.docFreq(term));
                documentTerm.setTfIdf(score);
                termTfIdfMap.put(documentTerm.getTerm().getValueLowercase(), score);
                affectedRows++;
            }

            // update association weights
            for (final DocumentAssociation documentAssociation : document.getDocumentAssociations()) {
                final String a = documentAssociation.getA().getValueLowercase();
                final String b = documentAssociation.getB().getValueLowercase();
                documentAssociation.setAssociationWeight((float) documentAssociation.getAssociationCount()
                        * (termTfIdfMap.get(a) + termTfIdfMap.get(b)));
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        ira.close(reader);
    }

    logger.info("TF-IDF calc took: " + ((System.currentTimeMillis() - start) / 1000.00)
            + " seconds and affected " + affectedRows + " rows.");
}

From source file:com.jd.survey.dao.security.UserDAOImpl.java

@SuppressWarnings("unchecked")
@Transactional/*from   w w  w.  j a  v  a2 s.co  m*/
public Set<User> searchByLastName(String lastName) throws DataAccessException {
    Query query = createNamedQuery("User.searchByLastName", -1, -1, "%" + lastName + "%");
    return new LinkedHashSet<User>(query.getResultList());
}

From source file:com.panguso.lc.analysis.format.dao.impl.DaoImpl.java

@Override
public List<T> find(Map<String, Object> params) {
    StringBuilder qString = new StringBuilder("select model from " + entityClass.getSimpleName() + " model");
    if (params != null && params.size() > 0) {
        qString.append(" where ");
        Iterator<Entry<String, Object>> itr = params.entrySet().iterator();
        while (itr.hasNext()) {
            Entry<String, Object> entry = itr.next();
            if ("java.lang.String".equals(entry.getValue().getClass().getName())) {
                qString.append("model.");
                qString.append(entry.getKey());
                qString.append("=");
                qString.append("'");
                qString.append(entry.getValue());
                qString.append("'");
            } else {
                qString.append("model.");
                qString.append(entry.getKey());
                qString.append("=");
                qString.append(entry.getValue());
            }/*from   ww w . j a v  a  2  s.c  o m*/

            if (itr.hasNext()) {
                qString.append(" and ");
            }
        }
    }

    Query query = em.createQuery(qString.toString());

    return query.getResultList();
}

From source file:com.dhenton9000.birt.persistence.dao.impl.EmployeesDaoImpl.java

@Override
public List<Employees> getEmployeesForOffice(String officeCode) {

    String qString = "select employees from " + "Offices o join o.employees employees "
            + "where o.officeCode = :id ";

    Query q = this.getEntityManager().createQuery(qString);
    q.setParameter("id", officeCode);
    log.debug("office code is " + officeCode);
    List<Employees> officeEmployees = q.getResultList();

    //   http://www.objectdb.com/java/jpa/query/jpql/select

    return officeEmployees;

}

From source file:com.espirit.moddev.examples.uxbridge.newsdrilldown.test.NewsITCase.java

/**
 * Before test./*from w  w  w  .jav  a  2s  .c o m*/
 *
 * @throws Exception the exception
 */
@Before
public void beforeTest() throws Exception {
    EntityManager em = emf.createEntityManager();
    try {
        Query query = em.createQuery(new StringBuilder().append("SELECT x FROM news x").toString());
        List<News> newsList = query.getResultList();
        for (News news : newsList) {
            em.remove(news);
        }

        query = em.createQuery(new StringBuilder().append("SELECT x FROM category x").toString());
        List<NewsCategory> catList = query.getResultList();
        for (NewsCategory temp : catList) {
            em.remove(temp);
        }

        query = em.createQuery(new StringBuilder().append("SELECT x FROM metaCategory x").toString());
        List<NewsMetaCategory> metaList = query.getResultList();
        for (NewsMetaCategory temp : metaList) {
            em.remove(temp);
        }
    } finally {
        em.close();
    }
}

From source file:com.sct.descubriendoturuta.service.UsuarioServiceImpl.java

@Override
@Transactional/*  w w  w. java 2s  .co m*/
public List<Invitacion> obtenerRutasInvitadas(int usuarioId) {

    Query query = em.createQuery("select i from Invitacion i WHERE i.usuario.id = :p");

    query.setParameter("p", usuarioId);

    return query.getResultList();
}

From source file:com.jd.survey.dao.security.UserDAOImpl.java

@SuppressWarnings("unchecked")
@Transactional//  w w w .  j  a  va 2  s  . co  m
public Set<User> searchByFirstName(String firstName) throws DataAccessException {
    Query query = createNamedQuery("User.searchByFirstName", -1, -1, "%" + firstName + "%");
    return new LinkedHashSet<User>(query.getResultList());
}

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

@Override
public List<User> findPersonalDetailByName(String name) {
    Query q = em.createQuery("select u.personalDetail.name from User u where u.personalDetail.name =:name");
    q.setParameter("name", name);
    List<User> users = q.getResultList();
    return users;
}