Example usage for org.hibernate.transform Transformers aliasToBean

List of usage examples for org.hibernate.transform Transformers aliasToBean

Introduction

In this page you can find the example usage for org.hibernate.transform Transformers aliasToBean.

Prototype

public static ResultTransformer aliasToBean(Class target) 

Source Link

Document

Creates a resulttransformer that will inject aliased values into instances of Class via property methods or fields.

Usage

From source file:com.minhafazenda.model.MfAuditoriaConfiguracaoModel.java

public List<MfAuditoriaView> findAUditoria(String nomeTabela) {
    Session objSession = this.objSessionFactory.openSession();
    Query query = objSession/*from   w  w  w.  j  av a2 s .  co  m*/
            .createSQLQuery("SELECT id, usuario, chave_primaria_1, chave_primaria_2, acao, data_hora  FROM "
                    + nomeTabela + "_AUDITORIA_VIEW")
            .addScalar("id", new IntegerType()).addScalar("usuario", new StringType())
            .addScalar("chave_primaria_1", new StringType()).addScalar("chave_primaria_2", new StringType())
            .addScalar("acao", new StringType()).addScalar("data_hora", new DateType())
            .setResultTransformer(Transformers.aliasToBean(MfAuditoriaView.class));

    return query.list();
}

From source file:com.minhafazenda.model.MfAuditoriaViewItemModel.java

public List<MfAuditoriaViewItem> findByDescricao(Integer idAuditoria, String nomeTabela, String descricao) {

    Session objSession = this.objSessionFactory.openSession();
    Query query = objSession/*  w  ww  .  j  a va2  s  . co m*/
            .createSQLQuery(" SELECT id_auditoria_item, id, campo, valor_antigo, valor_novo " + " FROM "
                    + nomeTabela + "_AUDITORIA_VIEW_item" + " WHERE id = " + idAuditoria + " AND ("
                    + "       campo like '%" + descricao + "%' OR " + "       valor_antigo like '%" + descricao
                    + "%' OR " + "       valor_novo like '%" + descricao + "%')")
            .addScalar("id_auditoria_item", new IntegerType()).addScalar("id", new IntegerType())
            .addScalar("campo", new StringType()).addScalar("valor_antigo", new StringType())
            .addScalar("valor_novo", new StringType())
            .setResultTransformer(Transformers.aliasToBean(MfAuditoriaViewItem.class));

    return query.list();
}

From source file:com.minhafazenda.model.MfAuditoriaViewItemModel.java

public List<MfAuditoriaViewItem> findAUditoria(Integer idAuditoria, String nomeTabela) {
    Session objSession = this.objSessionFactory.openSession();
    Query query = objSession/* www.j a va 2  s  .  co m*/
            .createSQLQuery("SELECT id_auditoria_item, id, campo, valor_antigo, valor_novo " + " FROM "
                    + nomeTabela + "_AUDITORIA_VIEW_item" + " WHERE id = " + idAuditoria)
            .addScalar("id_auditoria_item", new IntegerType()).addScalar("id", new IntegerType())
            .addScalar("campo", new StringType()).addScalar("valor_antigo", new StringType())
            .addScalar("valor_novo", new StringType())
            .setResultTransformer(Transformers.aliasToBean(MfAuditoriaViewItem.class));

    return query.list();
}

From source file:com.minhafazenda.model.MfAuditoriaViewModel.java

public List<MfAuditoriaView> findByDescricao(String nomeTabela, String descricao) {

    Session objSession = this.objSessionFactory.openSession();
    Query query = objSession/*from   w  w w .  j ava  2  s.c om*/
            .createSQLQuery(" SELECT id, usuario, chave_primaria_1, chave_primaria_2, acao, data_hora  "
                    + " FROM " + nomeTabela + "_AUDITORIA_VIEW" + " WHERE usuario like '%" + descricao
                    + "%' OR " + "       chave_primaria_1 like '%" + descricao + "%' OR "
                    + "       chave_primaria_2 like '%" + descricao + "%' OR " + "       acao like '%"
                    + descricao + "%'")
            .addScalar("id", new IntegerType()).addScalar("usuario", new StringType())
            .addScalar("chave_primaria_1", new StringType()).addScalar("chave_primaria_2", new StringType())
            .addScalar("acao", new StringType()).addScalar("data_hora", new DateType())
            .setResultTransformer(Transformers.aliasToBean(MfAuditoriaView.class));

    return query.list();
}

From source file:com.minhafazenda.model.MfAuditoriaViewModel.java

public List<MfAuditoriaView> findAUditoria(String nomeTabela) {
    Session objSession = this.objSessionFactory.openSession();
    Query query = objSession//from   w w  w  .  j ava2 s .c  o m
            .createSQLQuery("SELECT id, usuario, chave_primaria_1, chave_primaria_2, acao, data_hora  FROM "
                    + nomeTabela + "_AUDITORIA_VIEW")
            .addScalar("id", new IntegerType()).addScalar("usuario", new StringType())
            .addScalar("chave_primaria_1", new StringType()).addScalar("chave_primaria_2", new StringType())
            .addScalar("acao", new StringType()).addScalar("data_hora", new DateType())
            .setResultTransformer(Transformers.aliasToBean(MfAuditoriaView.class));

    //        List<MfAuditoriaView> list = query.list();
    //        for (MfAuditoriaView list_ : list) {
    //            System.out.print(list_.getAcao());
    //            System.out.print(list_.getChave_primaria_1());
    //            System.out.println(list_.getId());
    //            
    //        }

    return query.list();
}

From source file:com.muslim.family.dao.impl.QuestionDAOImpl.java

public List<Question_tbl> getPaginatedQuestionsDao(int start, int length) {

    Criteria cr = sessionFactory.getCurrentSession().createCriteria(Question_tbl.class)
            .setProjection(Projections.projectionList().add(Projections.property("id"), "id")
                    .add(Projections.property("subject"), "Subject")
                    .add(Projections.property("views"), "Views"))
            .setResultTransformer(Transformers.aliasToBean(Question_tbl.class));
    cr.setFirstResult(start);//from  ww  w.  ja v a  2s . c o m
    cr.setMaxResults(length);

    return cr.list();

}

From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java

/**
 * ? ?? ?//from w w  w. j av a 2  s .c  o  m
 * ? ???
 */

@Deprecated
public PageModel toPageDetachedCriteria(Class claz, DetachedCriteria dca, ProjectionList pList, Integer curPage,
        Integer pageSize) throws QueryException {
    Criteria query = dca.getExecutableCriteria(getCurrentSession());
    long rowCount = ((Long) query.setProjection(Projections.rowCount()).uniqueResult()).longValue();
    PageModel pm = new PageModel(curPage, pageSize, rowCount);
    if (pList != null) {
        query.setProjection(pList);
    } else {
        query.setProjection(null);
    }

    query.setResultTransformer(Transformers.aliasToBean(claz));
    query.setFirstResult(pm.getStartNum());
    query.setMaxResults(pageSize);
    pm.setDatas(query.list());
    return pm;
}

From source file:com.nec.harvest.service.impl.ActualViewServiceImpl.java

License:Open Source License

/** {@inheritDoc}*/
@Override//from w w  w. ja  va  2s .c o m
public List<VJiseki> findByOrgCodeAndMonthies(String orgCode, String... monthlies) throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException("Organization must not be null or empty");
    }
    if (ArrayUtils.isEmpty(monthlies)) {
        throw new IllegalArgumentException("The monthlies must not be null");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<VJiseki> jisekis = new ArrayList<>();
    try {
        tx = session.beginTransaction();
        Query query = repository.getSQLQuery(session,
                "SELECT  UriSkKG as uriSkKG, KtSkKG as ktSkKG, IdoSkKGU as idoSkKGU, IdoSkKGH as idoSkKGH, UriKrKG as uriKrKG,"
                        + " KtKrKG as ktKrKG, KnSrKG as knSrKG, KtSrKG as ktSrKG, KgcSrKG as kgcSrKG, IdoSrKGU as idoSrKGU, IdoSrKGH as idoSrKGH, KtJkKG as ktJkKG, JkJkKG as jkJkKG, KgcJkKG as kgcJkKG, IdoJkKGU as idoJkKGU, IdoJkKGH as idoJkKGH, HelpJkKGU as helpJkKGU, "
                        + " HelpJkKGH as helpJkKGH, KtKhKG as ktKhKG, KnKhKG as knKhKG, KgcKhKG as kgcKhKG, IdoKhKGU as idoKhKGU, IdoKhKGH as idoKhKGH, UriKhKG as uriKhKG FROM V_JISEKI WHERE StrCode = :strCode AND Getsudo in (:monthlies)");
        query.setParameter("strCode", orgCode);
        query.setParameterList("monthlies", monthlies);
        query.setResultTransformer(Transformers.aliasToBean(VJiseki.class));

        jisekis = repository.findByQuery(query);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(jisekis)) {
            throw new ObjectNotFoundException("There is no actual view object");
        }
    } catch (SQLGrammarException | GenericJDBCException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException(
                "An exception occured while getting VJiseki data for the organization " + orgCode, ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return jisekis;
}

From source file:com.nec.harvest.service.impl.ActualViewServiceImpl.java

License:Open Source License

/** {@inheritDoc}*/
@Override/*from   w  w  w .ja  va 2 s . c om*/
public List<VJiseki> findByOrgCodeAndPeriodMonthly(String orgCode, String startMonth, String endMonth)
        throws ServiceException {
    if (StringUtils.isEmpty(orgCode)) {
        throw new IllegalArgumentException("Organization must not be null or empty");
    }
    if (StringUtils.isEmpty(startMonth)) {
        throw new IllegalArgumentException("Start month must not be null or empty");
    }
    if (StringUtils.isEmpty(endMonth)) {
        throw new IllegalArgumentException("End month must not be null or empty");
    }

    //
    logger.info(" Find soneki suii by organization's code " + orgCode + " startMonth " + startMonth
            + " endMonth " + endMonth);

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<VJiseki> jisekis = new ArrayList<>();
    try {
        tx = session.beginTransaction();
        StringBuilder sql = new StringBuilder(
                " SELECT c.pk.organization.strCode as strCode, c.pk.getSudo as getSudo, c.uriSkKG as uriSkKG, c.KtSkKG as ktSkKG, c.IdoSkKGU as idoSkKGU, c.IdoSkKGH as idoSkKGH, c.uriKrKG as uriKrKG, c.ktKrKG as ktKrKG, c.knSrKG as knSrKG, ");
        sql.append(
                " c.ktSrKG as ktSrKG, c.kgcSrKG as kgcSrKG, c.idoSrKGU as idoSrKGU, c.idoSrKGH as idoSrKGH, c.ktJkKG as ktJkKG, c.jkJkKG as jkJkKG, c.kgcJkKG as kgcJkKG, c.idoJkKGU as idoJkKGU, c.idoJkKGH as idoJkKGH, c.helpJkKGU as helpJkKGU, c.helpJkKGH as helpJkKGH, c.ktKhKG as ktKhKG, ");
        sql.append(
                " c.knKhKG as knKhKG, c.kgcKhKG as kgcKhKG, c.idoKhKGU as idoKhKGU, c.idoKhKGH as idoKhKGH, c.uriKhKG as uriKhKG ");
        sql.append(" FROM VJiseki c ");
        sql.append(" WHERE c.pk.organization.strCode = :strCode ");
        sql.append(" AND c.pk.getSudo >= :startMonth ");
        sql.append(" AND c.pk.getSudo <= :endMonth ORDER BY c.pk.getSudo");

        // 
        Query query = repository.getQuery(session, sql.toString());
        query.setParameter("strCode", orgCode);
        query.setParameter("startMonth", startMonth);
        query.setParameter("endMonth", endMonth);
        query.setResultTransformer(Transformers.aliasToBean(VJiseki.class));

        // 
        jisekis = repository.findByQuery(query);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(jisekis)) {
            throw new ObjectNotFoundException("There is no actual view object");
        }
    } catch (HibernateException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException("An exception occured while getting the data for organization " + orgCode,
                ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return jisekis;
}

From source file:com.nec.harvest.service.impl.ActualViewServiceImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override//w  ww  .j a v a 2  s  .c  o  m
public List<VJiseki> findByOrgCodesAndMonth(String month, String... orgCodes) throws ServiceException {
    if (StringUtils.isEmpty(month)) {
        throw new IllegalArgumentException("Can not find actual view objects with month empty");
    }
    if (ArrayUtils.isEmpty(orgCodes)) {
        throw new IllegalArgumentException("Can not find actual view objects with organization codes null");
    }

    final Session session = HibernateSessionManager.getSession();
    Transaction tx = null;

    List<VJiseki> jisekis = new ArrayList<>();
    try {
        tx = session.beginTransaction();
        Query query = repository.getSQLQuery(session,
                " SELECT StrCode as strCode, UriSkKG as uriSkKG, KtSkKG as ktSkKG, IdoSkKGU as idoSkKGU, IdoSkKGH as idoSkKGH, UriKrKG as uriKrKG, "
                        + " KtKrKG as ktKrKG, KnSrKG as knSrKG, KtSrKG as ktSrKG, "
                        + " KgcSrKG as kgcSrKG, IdoSrKGU as idoSrKGU, IdoSrKGH as idoSrKGH, "
                        + " KtJkKG as ktJkKG, JkJkKG as jkJkKG, KgcJkKG as kgcJkKG, "
                        + " IdoJkKGU as idoJkKGU, IdoJkKGH as idoJkKGH, HelpJkKGU as helpJkKGU, HelpJkKGH as helpJkKGH, "
                        + " KtKhKG as ktKhKG, KnKhKG as knKhKG, KgcKhKG as kgcKhKG, "
                        + " IdoKhKGU as idoKhKGU, IdoKhKGH as idoKhKGH, UriKhKG as uriKhKG "
                        + " FROM V_JISEKI WHERE StrCode IN (:orgCodes) AND Getsudo = :month");

        query.setParameterList("orgCodes", orgCodes);
        query.setString("month", month);
        query.setResultTransformer(Transformers.aliasToBean(VJiseki.class));

        // 
        jisekis = repository.findByQuery(query);
        // Release transaction
        tx.commit();
        if (CollectionUtils.isEmpty(jisekis)) {
            throw new ObjectNotFoundException("No jisekis (actual view object) found");
        }
    } catch (SQLGrammarException | GenericJDBCException ex) {
        if (tx != null) {
            tx.rollback();
        }
        throw new ServiceException(
                "An exception occur when get a list of actual view objects of multi organization and month",
                ex);
    } finally {
        HibernateSessionManager.closeSession(session);
    }
    return jisekis;
}