Example usage for org.hibernate Query setResultTransformer

List of usage examples for org.hibernate Query setResultTransformer

Introduction

In this page you can find the example usage for org.hibernate Query setResultTransformer.

Prototype

@Deprecated
Query<R> setResultTransformer(ResultTransformer transformer);

Source Link

Document

Set a strategy for handling the query results.

Usage

From source file:daoImpl.GroupsDAOImpl.java

@Override
public List<Groups> findGroupsByTagName(String searchTerm) {
    Session session = sFac.openSession();
    Query query = session.createQuery("from Groups G left join fetch G.tagses T where T.tagName = :tag");
    query.setParameter("tag", searchTerm);
    query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Groups> groups = query.list();
    session.close();/*from   w  ww.  j a v  a2  s . c om*/
    return groups;
}

From source file:daoImpl.GroupsDAOImpl.java

@Override
public List<Groups> findGroupsByTagID(int id) {
    Session session = sFac.openSession();
    Query query = session.createQuery(" from Groups G left join fetch G.tagses T where T.tagId = :tag");
    query.setParameter("tag", id);
    query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Groups> groups = query.list();
    session.close();//  w w w  .j  a va 2s  .  co  m
    return groups;
}

From source file:Data.Dao.Implementations.CategoryRepository.java

@Override
public List<CategoryDto> FilterByDescription(String description) {
    try {/*  w  w w.j av a2 s. com*/
        beginOperation();
        Query qu = sesion.getNamedQuery("Category.FindByDescription").setString("description",
                "%" + description + "%");
        List<CategoryDto> categories = qu.setResultTransformer(Transformers.aliasToBean(CategoryDto.class))
                .list();
        sesion.close();
        return categories;
    } catch (Exception ex) {
        this.LogSever(ex);
        return null;
    }
}

From source file:Data.Dao.Implementations.CategoryRepository.java

@Override
public List<CategoryDto> ListAll() {
    try {/*w  w w.j  a  va 2  s.c o  m*/
        beginOperation();
        Query qu = sesion.getNamedQuery("Category.FindByDescription").setString("description", "%%");
        List<CategoryDto> categories = qu.setResultTransformer(Transformers.aliasToBean(CategoryDto.class))
                .list();
        sesion.close();
        return categories;
    } catch (Exception ex) {
        this.LogSever(ex);
        return null;
    }
}

From source file:de.elatexam.editor.pages.subtaskdefs.PrivateSubtasksDataProvider.java

License:Open Source License

@Override
public int size() {
    final Session sess = Databinder.getHibernateSession(getFactoryKey());
    final Query q = sess.createQuery(createQueryString());
    q.setResultTransformer(RemoveNullResultTransformer.INSTANCE);
    final int size = q.list().size();
    return size;//from  w  w  w.j a  v  a 2s.co  m
}

From source file:de.elatexam.editor.pages.TaskDefPage.java

License:Open Source License

/**
 * @param tasklistmodel/*  ww  w . j a v a2s .  c  om*/
 * @return
 */
ComplexTaskDefTree getTree() {
    if (tree == null) {
        @SuppressWarnings("unchecked")
        IModel<List<?>> tasklistmodel = new HibernateListModel(new QueryBuilder() {
            public Query build(final Session sess) {
                final Query q = sess.createQuery(String.format(
                        "select tasks from BasicUser u left join u.taskdefs tasks where u.username='%s'",
                        TaskEditorSession.get().getUser().getUsername()));
                q.setResultTransformer(RemoveNullResultTransformer.INSTANCE);
                return q;
            }
        });
        // the admin sees all taskdefs
        if (TaskEditorApplication.isAdmin()) {
            tasklistmodel = new HibernateListModel(BasicUser.class);
        }
        tree = new ComplexTaskDefTree("tree", new ComplexTaskdefTreeProvider(tasklistmodel));
    }
    return tree;
}

From source file:edu.harvard.med.screensaver.db.hqlbuilder.HqlBuilder.java

License:Open Source License

public Query toQuery(Session session, boolean isReadOnly) {
    org.hibernate.Query query = session.createQuery(toHql());
    for (Map.Entry<String, Object> arg : args().entrySet()) {
        if (arg.getKey().endsWith(SET_ARG_SUFFIX)) {
            // HACK: handle 'list' type parameters, used with the 'IN (?)' operator
            query.setParameterList(arg.getKey(), (Set<?>) arg.getValue());
        } else {//from   w  w  w .  j av a2  s  .com
            query.setParameter(arg.getKey(), arg.getValue());
        }
    }
    if (_isDistinctRootEntities) {
        query.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);
    }
    query.setReadOnly(isReadOnly);
    return query;
}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.dao.AbstractAreaDao.java

License:Open Source License

public List<Map<String, Object>> findSelectedAreaColumns(String namedQueryString, List<Long> gids) {
    Query query = getEntityManager().unwrap(Session.class).getNamedQuery(namedQueryString);
    query.setParameterList("ids", gids);
    query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
    return query.list();
}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.dao.AreaLocationTypesDao.java

License:Open Source License

public List findUserAreaLayerMapping() {
    Query query = em.unwrap(Session.class).getNamedQuery(AreaLocationTypesEntity.FIND_USER_AREA_LAYER);
    query.setResultTransformer(Transformers.aliasToBean(UserAreaLayerDto.class));
    return query.list();
}

From source file:eu.europa.ec.fisheries.uvms.spatial.service.dao.AreaLocationTypesDao.java

License:Open Source License

public List<AreaLayerDto> findSystemAreaLayerMapping() {
    Query query = em.unwrap(Session.class).getNamedQuery(AreaLocationTypesEntity.FIND_SYSTEM_AREA_LAYER);
    return query.setResultTransformer(Transformers.aliasToBean(AreaLayerDto.class)).list();
}