Example usage for javax.persistence Query toString

List of usage examples for javax.persistence Query toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.solace.data.jpa.GenericDao.java

private E executeSingle(javax.persistence.Query q) throws Exception {

    long now = System.currentTimeMillis();

    E e = (E) q.getSingleResult();//from  w  w w . j  a v a  2s .com

    LOGGER.debug(S_TOOK_D_MS_TO_EXECUTE, q.toString(), System.currentTimeMillis() - now);

    return e;
}

From source file:com.solace.data.jpa.GenericDao.java

/**
 * A simple clocking method//from   ww  w  .  j a  va 2  s. co m
 * 
 * @param q
 *            the query to execute
 * @return
 */
private List<E> executeList(javax.persistence.Query q) throws Exception {

    long now = System.currentTimeMillis();

    List<E> list = (List<E>) q.getResultList();

    LOGGER.debug(S_TOOK_D_MS_TO_EXECUTE_AND_RETURNED_D_ROWS, q.toString(), System.currentTimeMillis() - now,
            list.size());

    return list;
}

From source file:org.codehaus.grepo.query.jpa.generator.QueryGeneratorBase.java

/**
 * {@inheritDoc}/*from  ww w .  ja  va  2s .c  o m*/
 */
@Override
public Query generate(QueryMethodParameterInfo qmpi, JpaQueryExecutionContext context) {
    Query query = createQuery(qmpi, context);
    logger.debug("Using query: {}", query.toString().trim());
    applyQuerySettings(qmpi, context, query);
    return query;
}

From source file:org.medici.bia.dao.document.DocumentDAOJpaImpl.java

/**
 * //from  w w  w .j  a v a  2  s . c  o  m
 */
@Override
public Page searchDocuments(Search searchContainer, PaginationFilter paginationFilter)
        throws PersistenceException {
    // We prepare object of return method.
    Page page = new Page(paginationFilter);

    // We obtain hibernate-search session
    FullTextSession fullTextSession = org.hibernate.search.Search
            .getFullTextSession(((HibernateEntityManager) getEntityManager()).getSession());

    org.apache.lucene.search.Query query = searchContainer.toLuceneQuery();
    logger.info("Lucene Query " + query.toString());

    // We execute search
    org.hibernate.search.FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query,
            Document.class);

    // We set size of result.
    if (paginationFilter.getTotal() == null) {
        page.setTotal(new Long(fullTextQuery.getResultSize()));
    }

    // We set pagination  
    fullTextQuery.setFirstResult(paginationFilter.getFirstRecord());
    fullTextQuery.setMaxResults(paginationFilter.getLength());

    // We manage sorting (this manages sorting on multiple fields)
    paginationFilter = this.generatePaginationFilterHibernateSearch(paginationFilter);
    List<SortingCriteria> sortingCriterias = paginationFilter.getSortingCriterias();
    if (sortingCriterias.size() > 0) {
        SortField[] sortFields = new SortField[sortingCriterias.size()];
        for (int i = 0; i < sortingCriterias.size(); i++) {
            sortFields[i] = new SortField(sortingCriterias.get(i).getColumn(),
                    sortingCriterias.get(i).getColumnType(),
                    (sortingCriterias.get(i).getOrder().equals(Order.ASC) ? true : false));
        }
        fullTextQuery.setSort(new Sort(sortFields));
    }

    // We set search result on return method
    page.setList(fullTextQuery.list());

    return page;
}

From source file:org.medici.bia.dao.image.ImageDAOJpaImpl.java

/**
 * {@inheritDoc}/* ww w  . ja v  a  2  s .c om*/
 */
@Override
public long countImages(Integer volNum, String volLetExt, String imageType, String insertNum, String insertLet,
        Integer folioNum, String folioMod, String rectoVerso) throws PersistenceException {
    Query query = getFindImageQuery(volNum, volLetExt, imageType, insertNum, insertLet, folioNum, folioMod,
            rectoVerso, true);

    Long count;
    try {
        count = (Long) query.getSingleResult();
    } catch (Exception e) {
        throw new PersistenceException(
                "Count Images Query problem: The query [" + query.toString() + "] generates an error!");
    }

    return count;
}

From source file:org.medici.bia.dao.JpaDao.java

/**
 * //from  www.  j  av a2s . c  o  m
 * @param searchContainer
 * @param paginationFilter
 * @return
 * @throws PersistenceException
 */
public Page search(org.medici.bia.common.search.Search searchContainer, PaginationFilter paginationFilter)
        throws PersistenceException {
    // We prepare object of return method.
    Page page = new Page(paginationFilter);

    // We obtain hibernate-search session
    FullTextSession fullTextSession = org.hibernate.search.Search
            .getFullTextSession(((HibernateEntityManager) getEntityManager()).getSession());

    // We convert AdvancedSearchContainer to luceneQuery
    org.apache.lucene.search.Query query = searchContainer.toLuceneQuery();
    logger.info("Lucene Query " + query.toString());

    // We execute search
    org.hibernate.search.FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query, People.class);

    // We set size of result.
    if (paginationFilter.getTotal() == null) {
        page.setTotal(new Long(fullTextQuery.getResultSize()));
    }

    // We set pagination  
    fullTextQuery.setFirstResult(paginationFilter.getFirstRecord());
    fullTextQuery.setMaxResults(paginationFilter.getLength());

    // We manage sorting (this manages sorting on multiple fields)
    List<SortingCriteria> sortingCriterias = paginationFilter.getSortingCriterias();
    if (sortingCriterias.size() > 0) {
        SortField[] sortFields = new SortField[sortingCriterias.size()];
        for (int i = 0; i < sortingCriterias.size(); i++) {
            sortFields[i] = new SortField(sortingCriterias.get(i).getColumn(),
                    sortingCriterias.get(i).getColumnType(),
                    (sortingCriterias.get(i).getOrder().equals(Order.ASC) ? true : false));
        }
        fullTextQuery.setSort(new Sort(sortFields));
    }

    // We set search result on return method
    page.setList(fullTextQuery.list());

    return page;
}

From source file:org.medici.bia.dao.titleoccslist.TitleOccsListDAOJpaImpl.java

/**
 * {@inheritDoc}/*  w  w w.  j  ava2s  .  c om*/
 */
@Override
public Page searchTitleOrOccupation(org.medici.bia.common.search.Search searchContainer,
        PaginationFilter paginationFilter) throws PersistenceException {
    // We prepare object of return method.
    Page page = new Page(paginationFilter);

    // We obtain hibernate-search session
    FullTextSession fullTextSession = org.hibernate.search.Search
            .getFullTextSession(((HibernateEntityManager) getEntityManager()).getSession());

    org.apache.lucene.search.Query query = searchContainer.toLuceneQuery();
    logger.info("Lucene Query " + query.toString());

    // We execute search
    org.hibernate.search.FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query,
            TitleOccsList.class);

    // We set size of result.
    if (paginationFilter.getTotal() == null) {
        page.setTotal(new Long(fullTextQuery.getResultSize()));
    }

    // We set pagination  
    fullTextQuery.setFirstResult(paginationFilter.getFirstRecord());
    fullTextQuery.setMaxResults(paginationFilter.getLength());

    // We manage sorting (this manages sorting on multiple fields)
    List<SortingCriteria> sortingCriterias = paginationFilter.getSortingCriterias();
    if (sortingCriterias.size() > 0) {
        SortField[] sortFields = new SortField[sortingCriterias.size()];
        for (int i = 0; i < sortingCriterias.size(); i++) {
            sortFields[i] = new SortField(sortingCriterias.get(i).getColumn(),
                    sortingCriterias.get(i).getColumnType(),
                    (sortingCriterias.get(i).getOrder().equals(Order.ASC) ? true : false));
        }
        fullTextQuery.setSort(new Sort(sortFields));
    }

    // We set search result on return method
    page.setList(fullTextQuery.list());

    return page;
}

From source file:org.medici.bia.dao.volume.VolumeDAOJpaImpl.java

/**
 * {@inheritDoc}//  w w w .  j a  v  a  2s.  c  o  m
 */
@Override
public Page searchVolumes(Search searchContainer, PaginationFilter paginationFilter)
        throws PersistenceException {
    // We prepare object of return method.
    Page page = new Page(paginationFilter);

    // We obtain hibernate-search session
    FullTextSession fullTextSession = org.hibernate.search.Search
            .getFullTextSession(((HibernateEntityManager) getEntityManager()).getSession());

    // We convert SearchContainer to luceneQuery
    org.apache.lucene.search.Query query = searchContainer.toLuceneQuery();
    logger.info("Lucene Query " + query.toString());

    // We execute search
    org.hibernate.search.FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(query, Volume.class);

    // We set size of result.
    if (paginationFilter.getTotal() == null) {
        page.setTotal(new Long(fullTextQuery.getResultSize()));
    }

    // We set pagination  
    fullTextQuery.setFirstResult(paginationFilter.getFirstRecord());
    fullTextQuery.setMaxResults(paginationFilter.getLength());

    // We manage sorting (this manages sorting on multiple fields)
    paginationFilter = this.generatePaginationFilterHibernateSearch(paginationFilter);
    List<SortingCriteria> sortingCriterias = paginationFilter.getSortingCriterias();
    if (sortingCriterias.size() > 0) {
        SortField[] sortFields = new SortField[sortingCriterias.size()];
        for (int i = 0; i < sortingCriterias.size(); i++) {
            sortFields[i] = new SortField(sortingCriterias.get(i).getColumn(),
                    sortingCriterias.get(i).getColumnType(),
                    (sortingCriterias.get(i).getOrder().equals(Order.ASC) ? true : false));
        }
        fullTextQuery.setSort(new Sort(sortFields));
    }

    // We set search result on return method
    page.setList(fullTextQuery.list());

    return page;
}