Example usage for org.hibernate.criterion Projections property

List of usage examples for org.hibernate.criterion Projections property

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections property.

Prototype

public static PropertyProjection property(String propertyName) 

Source Link

Document

A property value projection

Usage

From source file:br.ufmg.hc.telessaude.diagnostico.dominio.dao.ExameDAOLocal.java

public List<Exame> consultar(Integer id, String nomePaciente, Date inicio, Date fim) throws DAOException {
    ArrayList<Criterion> restrict = new ArrayList();
    if (id != null) {
        restrict.add(Restrictions.eq("id", id));
    } else {//from   w w  w .ja va 2 s .  c o m
        if (nomePaciente != null && !nomePaciente.isEmpty()) {
            restrict.add(Restrictions.ilike("pc.nome", nomePaciente, MatchMode.ANYWHERE));
        }
        if (inicio != null) {
            restrict.add(Restrictions.ge("datainclusao", inicio));
        }
        if (fim != null) {
            restrict.add(Restrictions.le("datainclusao", fim));
        }
    }
    try {
        final DetachedCriteria crit = DetachedCriteria.forClass(c);
        final Criteria criteria = crit.getExecutableCriteria(HibernateUtil.currentSession());

        crit.createAlias("paciente", "pc");
        crit.createAlias("status", "st");

        criteria.setProjection(Projections.projectionList().add(Projections.property("id"))
                .add(Projections.property("pc.nome")).add(Projections.property("pc.datanascimento"))
                .add(Projections.property("datainclusao")).add(Projections.property("st.nome")));

        criteria.addOrder(Order.desc("datainclusao"));

        for (final Criterion cri : restrict) {
            criteria.add(cri);
        }

        final List<Object[]> arrays = criteria.list();
        final List<Exame> exames = new ArrayList<>();

        for (Object[] array : arrays) {
            final Exame exame = new Exame(Integer.parseInt(String.valueOf(array[0])));
            exame.setPaciente(new Paciente());
            exame.getPaciente().setNome(String.valueOf(array[1]));
            exame.getPaciente().setDatanascimento((Date) array[2]);
            exame.setDatainclusao((Date) array[3]);
            exame.setStatus(new Status());
            exame.getStatus().setNome(String.valueOf(array[4]));

            exames.add(exame);
        }

        return exames;

    } catch (HibernateException ex) {
        throw new DAOException(ex.getMessage());
    }

}

From source file:br.ufmg.hc.telessaude.diagnostico.dominio.dao.LaudoDAOLocal.java

@Override
public List<Laudo> consultarPorIdExame(Integer id) throws DAOException {
    try {/*w  w w.  java  2 s . c om*/
        final DetachedCriteria crit = DetachedCriteria.forClass(c);
        final Criteria criteria = crit.getExecutableCriteria(HibernateUtil.currentSession());

        criteria.setProjection(Projections.projectionList().add(Projections.property("id"))
                .add(Projections.property("datainicio")).add(Projections.property("conteudo")));

        criteria.add(Restrictions.eq("exame.id", id));

        final List<Object[]> arrays = criteria.list();
        final List<Laudo> laudos = new ArrayList();

        for (Object[] array : arrays) {
            final Laudo laudo = new Laudo(Integer.parseInt(String.valueOf(array[0])));
            laudo.setDatainicio((Date) array[1]);
            laudo.setConteudo(array[2].toString());
            laudos.add(laudo);
        }

        return laudos;

    } catch (HibernateException ex) {
        throw new DAOException(ex.getMessage());
    }

}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.DefaultFullTextIndexer.java

License:Apache License

@SuppressWarnings({ "cast", "unchecked" })
private <T> List<Long> getAllIds(final FullTextSession fullTextSession, final Class<T> clazz) {
    List<Long> result = (List<Long>) createCriteria(fullTextSession, clazz)
            .setProjection(Projections.property(ID_PROPERTY_NAME)).addOrder(Order.asc(ID_PROPERTY_NAME)).list();
    return result;
}

From source file:classes.ReportAction.java

License:Apache License

public String productReport() throws Exception {
    logger.info("Starting productReport()"); //f:log

    ActionContext ac = ActionContext.getContext();
    ServletContext sc = (ServletContext) ac.get(StrutsStatics.SERVLET_CONTEXT);

    JasperReport jasperReport = JasperCompileManager
            .compileReport(sc.getResourceAsStream("/WEB-INF/classes/ProductReport.xml")); //f:jr

    Map<String, Object> parameters = new HashMap<String, Object>(); //f:jr
    parameters.put("ReportTitle", "List of Products"); //f:jr
    parameters.put("DataFile", new Date().toString()); //f:jr

    Session sess = HibernateUtil.getSessionFactory().openSession(); //f:hibernate
    Transaction t = sess.beginTransaction(); //f:hibernate

    Criteria criteria = sess.createCriteria(Product.class); //f:hibernate

    criteria.setProjection(Projections.projectionList().add(Projections.property("id"))
            .add(Projections.property("name")).add(Projections.property("price"))); //f:hibernate

    @SuppressWarnings("unchecked")
    List<Object[]> l = (List<Object[]>) criteria.list(); //f:hibernate

    t.commit(); //f:hibernate
    sess.close(); //f:hibernate

    HibernateQueryResultDataSource ds = new HibernateQueryResultDataSource(l,
            new String[] { "Id", "Name", "Price" }); //f:jr

    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds); //f:jr

    byte b[] = JasperExportManager.exportReportToPdf(jasperPrint); //f:jr

    this.inputStream = new ByteArrayInputStream(b);

    logger.info("Finishing productReport()"); //f:log
    return "download";
}

From source file:classes.ReportAction.java

License:Apache License

public String customerReport() throws Exception {
    logger.info("Starting customerReport()"); //f:log

    ActionContext ac = ActionContext.getContext();
    ServletContext sc = (ServletContext) ac.get(StrutsStatics.SERVLET_CONTEXT);

    JasperReport jasperReport = JasperCompileManager
            .compileReport(sc.getResourceAsStream("/WEB-INF/classes/CustomerReport.xml")); //f:jr

    Map<String, Object> parameters = new HashMap<String, Object>(); //f:jr
    parameters.put("ReportTitle", "List of Customers"); //f:jr
    parameters.put("DataFile", new Date().toString()); //f:jr

    Session sess = HibernateUtil.getSessionFactory().openSession(); //f:hibernate
    Transaction t = sess.beginTransaction(); //f:hibernate

    Criteria criteria = sess.createCriteria(Customer.class); //f:hibernate

    criteria.setProjection(Projections.projectionList().add(Projections.property("id"))
            .add(Projections.property("name")).add(Projections.property("phone"))); //f:hibernate

    @SuppressWarnings("unchecked")
    List<Object[]> l = (List<Object[]>) criteria.list(); //f:hibernate

    t.commit(); //f:hibernate
    sess.close(); //f:hibernate

    HibernateQueryResultDataSource ds = new HibernateQueryResultDataSource(l,
            new String[] { "Id", "Name", "Phone" }); //f:jr

    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds); //f:jr

    byte b[] = JasperExportManager.exportReportToPdf(jasperPrint); //f:jr

    this.inputStream = new ByteArrayInputStream(b);

    logger.info("Finishing customerReport()"); //f:log
    return "download";
}

From source file:co.id.pegadaian.pasg2.util.SusunTree.java

public Set<BigDecimal> listMenuByUser(Session session, String userId) {

    /* Ambil gropu by user */
    Criteria critGroup = session.createCriteria(TblUserGroup.class);
    critGroup.add(Restrictions.eq("id.userId", userId));
    critGroup.setProjection(Projections.projectionList().add(Projections.property("id.groupId")));//"id.groupId"
    List<BigDecimal> l = critGroup.list();
    if (l.size() > 0) {
        //        for(BigDecimal x :l){System.out.println(x);        }
        /*Menu berdasarkan Priviledge */
        Criteria c = session.createCriteria(TblPriviledge.class);
        c.add(Restrictions.in("id.groupId", l));
        c.setProjection(Projections.projectionList().add(Projections.property("id.menuId")));
        Set<BigDecimal> lMenuId = new HashSet();
        List<BigDecimal> k = c.list();
        for (BigDecimal x : k) {
            lMenuId.add(x);//new BigDecimal(x));
            //            System.out.println(x.getid().getMenuId());
            //                  System.out.println(k);
        }//from w  ww.  j  av  a2 s . c o  m
        return lMenuId;
    } else {
        return null;
    }

}

From source file:co.id.pegadaian.pasg2.util.SusunTreeJeasyUI.java

public Set<BigDecimal> listMenuByUser(Session session, String userId) {
    /* Ambil gropu by user */
    Criteria critGroup = session.createCriteria(TblUserGroup.class);
    critGroup.add(Restrictions.eq("id.userId", userId));
    critGroup.setProjection(Projections.projectionList().add(Projections.property("id.groupId")));//"id.groupId"
    List<BigDecimal> l = critGroup.list();
    if (l.size() > 0) {
        /*Menu berdasarkan Priviledge */
        Criteria c = session.createCriteria(TblPriviledge.class);
        c.add(Restrictions.in("id.groupId", l));
        c.setProjection(Projections.projectionList().add(Projections.property("id.menuId")));
        Set<BigDecimal> lMenuId = new HashSet();
        List<BigDecimal> k = c.list();
        for (BigDecimal x : k) {
            lMenuId.add(x);//new BigDecimal(x));
        }/*from  w w  w.j a  va  2s  .c  o m*/
        return lMenuId;
    } else {
        return null;
    }

}

From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java

License:Open Source License

public Collection<String> getAllMacs() {
    Criteria criteria = getSession().createCriteria(IpPoolManagement.class);
    ProjectionList projList = Projections.projectionList();
    projList.add(Projections.property(IpPoolManagement.MAC_PROPERTY));

    criteria.setProjection(projList);/* w ww  . j  a  v  a 2  s.c  om*/
    return criteria.list();
}

From source file:com.all.rds.service.impl.TrackServiceImpl.java

License:Apache License

@SuppressWarnings("unchecked")
@Override//from   w  ww.ja v a 2  s.  com
public List<String> filterTracksByAvailability(final List<String> trackIds) {
    return ht.executeFind(new HibernateCallback<List<String>>() {
        @Override
        public List<String> doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = session.createCriteria(TrackUploadStatus.class);
            criteria.setProjection(Projections.property("trackId"));
            criteria.add(Restrictions.in("trackId", trackIds));
            criteria.add(Restrictions.eq("trackStatus", TrackStatus.Status.UPLOADED));
            return criteria.list();
        }
    });
}

From source file:com.amalto.core.storage.hibernate.StandardQueryHandler.java

License:Open Source License

@Override
public StorageResults visit(Timestamp timestamp) {
    String timeStamp = mappings.getMappingFromDatabase(mainType).getDatabaseTimestamp();
    if (timeStamp != null) {
        projectionList.add(Projections.property(timeStamp));
    } else {/*from  w  w  w .  j  a  v a 2s  . co  m*/
        EMPTY_STRING_CONSTANT.accept(this);
    }
    return null;
}