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:eu.europa.ec.fisheries.uvms.spatial.service.dao.AreaLocationTypesDao.java

License:Open Source License

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

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

License:Open Source License

public List<ProjectionDto> findProjectionById(Long id) {
    Map<String, Object> parameters = ImmutableMap.<String, Object>builder().put("id", id).build();
    Query query = em.unwrap(Session.class).getNamedQuery(ProjectionEntity.FIND_PROJECTION_BY_ID);
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        query.setParameter(entry.getKey(), entry.getValue());
    }/*from w  w  w. ja  v a  2s  .c  om*/
    query.setResultTransformer(Transformers.aliasToBean(ProjectionDto.class));
    return query.list();
}

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

License:Open Source License

public List<ProjectionDto> findProjectionByMap(long reportId) {
    Map<String, Object> parameters = ImmutableMap.<String, Object>builder().put(REPORT_ID, reportId).build();
    Query query = em.unwrap(Session.class).getNamedQuery(ReportConnectSpatialEntity.FIND_MAP_PROJ_BY_ID);
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        query.setParameter(entry.getKey(), entry.getValue());
    }//from  w  ww.  j  ava 2s  . co m
    query.setResultTransformer(Transformers.aliasToBean(ProjectionDto.class));
    return query.list();
}

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

License:Open Source License

private <T> Query createNamedQueryWithParameterList(String nativeQuery, String parameterName,
        List<?> parameters, Class<T> dtoClass) {
    Query query = em.unwrap(Session.class).getNamedQuery(nativeQuery);
    query.setParameterList(parameterName, parameters);
    query.setResultTransformer(Transformers.aliasToBean(dtoClass));
    return query;
}

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

License:Open Source License

public List<AreaDto> getAllUserAreas(String userName, String scopeName) {
    Map<String, Object> parameters = ImmutableMap.<String, Object>builder().put(USER_NAME, userName)
            .put(SCOPE_NAME, scopeName).build();
    Query query = createNamedNativeQuery(UserAreasEntity.FIND_ALL_USER_AREAS, parameters);
    query.setResultTransformer(Transformers.aliasToBean(AreaDto.class));
    return query.list();
}

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

License:Open Source License

public List<AreaDto> getAllUserAreaGroupName(String userName, String scopeName) {
    Map<String, Object> parameters = ImmutableMap.<String, Object>builder().put(USER_NAME, userName)
            .put(SCOPE_NAME, scopeName).build();
    Query query = createNamedNativeQuery(UserAreasEntity.FIND_ALL_USER_AREAS_GROUP, parameters);
    query.setResultTransformer(Transformers.aliasToBean(AreaDto.class));
    return query.list();
}

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

License:Open Source License

public List<AreaDto> findAllUserAreasByGids(List<Long> gids) {
    Query query = getSession().getNamedQuery(UserAreasEntity.FIND_ALL_USER_AREAS_BY_GIDS);
    query.setParameterList(GID_LIST, gids);
    query.setResultTransformer(Transformers.aliasToBean(AreaDto.class));
    return query.list();
}

From source file:form.mydemik.com.FSurat.java

public final void cari(final String nim) {
    try {//from w  w  w. j av a 2s .com
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session s = sf.openSession();
        Transaction tx = s.beginTransaction();
        // String sql="FROM Barang b where b.kodeBarang=:kodeBarang";
        String sql = "select * from mahasiswa where nim=:nim";
        Query q = s.createSQLQuery(sql);
        q.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
        q.setParameter("nim", nim);
        List mhs = q.list();
        if (txtNim.getText().equals("")) {
            FMhs f = new FMhs();
            f.setVisible(rootPaneCheckingEnabled);
            this.setVisible(false);
        } else if (mhs.isEmpty()) {
            int dialogbtn = JOptionPane.YES_NO_OPTION;
            int dr = JOptionPane.showConfirmDialog(this, "Form Pencarian.", "Pertanyaan", dialogbtn);
            if (dr == 0) {
                FMhs f = new FMhs();
                f.setModalExclusionType(Dialog.ModalExclusionType.NO_EXCLUDE);
                f.setVisible(rootPaneCheckingEnabled);
                f.txtCari.setText("");
                f.txtCari.requestFocus();
                this.setVisible(false);
            } else {
                txtNim.setText("");
                txtNim.requestFocus();
            }

        } else {
            for (Object br : mhs) {
                Map row = (Map) br;
                idmhs = Integer.parseInt(row.get("idMahasiswa").toString());
                lbNim.setText(row.get("nim").toString());
                lbNama.setText(row.get("nama").toString());
                lbTlp.setText(row.get("tlp").toString());
                lbAlamat.setText(row.get("alamat").toString());

                // a=Float.parseFloat(row.get("Harga").toString());
                //lbHarga.setText(NumberFormat.getNumberInstance().format(a));
                //txtJml.requestFocus();
            }
            s.flush();
            tx.commit();
            s.close();
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:me.repository.common.CommonDao.java

License:Open Source License

private void setResultTransformer(Query query, Class<?> resultClass) {
    if (resultClass != null) {
        if (resultClass == Map.class) {
            query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
        } else if (resultClass == List.class) {
            query.setResultTransformer(Transformers.TO_LIST);
        } else {/*www  .  ja v a 2  s.  co m*/
            query.setResultTransformer(Transformers.aliasToBean(resultClass));
        }
    }
}

From source file:mx.com.tubocreto.dao.Impl.OportunidadDaoImpl.java

@Override
public List<Oportunidad> oportunidadParaEnvio() throws DAOException {
    // List<Oportunidad> lista = getHibernateTemplate().find("select id, numeroOportunidad from Oportunidad");
    Query queryObject = sessionFactory.getCurrentSession()
            .createQuery("SELECT numeroOportunidad AS numeroOportunidad " + "FROM Oportunidad "
                    + "WHERE numeroOportunidad!='null' and status='monitorear' and cotizado='si' and enviado='no'"
                            .toString());
    queryObject.setResultTransformer(Transformers.aliasToBean(Oportunidad.class));
    /*/*from   w  w w . j  a  va  2 s .co  m*/
     * queryObject.setFetchSize(10); // se obtendrn 10 resultados en cada
     * acceso a la base. Iterator iter = queryObject.iterate(); while
     * (iter.hasNext()) {
     *
     * Oportunidad o = (Oportunidad) iter.next(); // fetch the object }
     */
    return queryObject.list();
    //    return (List<Oportunidad>) queryObject;
}