Example usage for org.hibernate SQLQuery setResultTransformer

List of usage examples for org.hibernate SQLQuery setResultTransformer

Introduction

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

Prototype

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

Source Link

Document

Set a strategy for handling the query results.

Usage

From source file:apm.common.core.DaoImpl.java

License:Open Source License

/**
 * /*from  www  .j  a  v a 2  s  .  c o m*/
 * @param query
 * @param resultClass
 */
private void setResultTransformer(SQLQuery 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 {
            query.addEntity(resultClass);
        }
    }
}

From source file:br.com.sgejs.dao.DaoAluno.java

public List listar(int id_arquivo) throws HibernateException {
    SQLQuery query = sessao.createSQLQuery(
            "select * from aluno where id in(select aluno_id from arquivo_alunos where arquivo_id=:id)");
    return query.setResultTransformer(new AliasToBeanResultTransformer(classe)).setInteger("id", id_arquivo)
            .list();//w w w .j  a v  a 2 s .com
}

From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public <T> List<T> findByNativeQueryTransformer(final Class<T> transformerClass, final String queryString,
        final int firstResult, final int maxResults, final Map values) {
    final List<T> list = getHibernateTemplate().executeFind(new HibernateCallback() {

        @Override/*w  w w  .  j a v a2 s . co  m*/
        public Object doInHibernate(Session session) throws HibernateException {
            final SQLQuery query = session.createSQLQuery(queryString);
            query.setResultTransformer(Transformers.aliasToBean(transformerClass));
            setPagination(query, firstResult, maxResults);
            setNamedParameters(values, query);
            return query.list();
        }
    });
    traceResults(list);
    return list;
}

From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateDao.java

License:Open Source License

@Override
public <T> List<T> findByNativeQueryTransformerWithListParametersSupport(final Class<T> transformerClass,
        final String sqlQueryString, final Map values, final int firstResult, final int maxResults) {

    @SuppressWarnings("unchecked")
    final List<T> list = getHibernateTemplate().executeFind(new HibernateCallback() {

        @Override// w  ww. j  a  v  a 2s.  co m
        public Object doInHibernate(Session session) throws HibernateException {
            final SQLQuery query = session.createSQLQuery(sqlQueryString);
            query.setResultTransformer(Transformers.aliasToBean(transformerClass));
            setPagination(query, firstResult, maxResults);
            setNamedParametersWithListSupport(values, query);
            return query.list();
        }
    });
    traceResults(list);
    return list;
}

From source file:com.bryan.crud.dao.impl.AmbitoDAOImpl.java

@Override
public ArrayList allAmbitos() {
    String sql = "SELECT N_AMBITO_PK AS id, C_NOMBRE_AMBITO AS nombreAmbito, N_TIPO_AMBITO AS tipoAmbito, N_CATEGORIA AS categoria, C_UBIGEO AS ubigeo,"
            + " C_DEPARTAMENTO AS departamento, C_PROVINCIA AS provincia, C_DISTRITO AS distrito "
            + " FROM TAB_AMBITO";
    String sql2 = "SELECT * FROM TAB_AMBITO";
    SQLQuery query = getSession().createSQLQuery(sql);
    query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    return new ArrayList(query.list());
}

From source file:com.bryan.crud.dao.impl.UserDaoImpl.java

@Override
public ArrayList allUsers() {
    String sql = "SELECT A.N_USUARIO_PK AS id, A.C_APELLIDO_MATERNO AS apellidoMaterno, A.C_APELLIDO_PATERNO AS apellidoPaterno, A.C_NOMBRE AS nombre"
            + " , B.C_NOMBRE_PERFIL as nombrePerfil, B.N_ESTADO as estado" + " FROM TAB_USUARIO A"
            + " LEFT OUTER JOIN TAB_PERFIL B ON A.N_PERFIL = B.N_PERFIL_PK";
    SQLQuery query = getSession().createSQLQuery(sql);
    query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
    ArrayList list = new ArrayList(query.list());
    return list;/* w  w w  .j  a va 2s .c o  m*/
}

From source file:com.cms.dao.AppParamsDAO.java

License:Open Source License

public List<AppParamsDTO> getListProviderFromMineName(String mineName, Map<String, String> map) {
    List<AppParamsDTO> listAppParams = null;
    String taxAuthority = map.get("taxAuthority");
    String startFromDate = map.get("startFromDate");
    String endFromDate = map.get("endFromDate");
    String startToDate = map.get("startToDate");
    String endToDate = map.get("endToDate");
    String fromDateRegister = map.get("fromDateRegister");
    String toDateRegister = map.get("toDateRegister");
    StringBuilder sb = new StringBuilder();
    sb.append("      SELECT    PAR_ID parId,   ");
    sb.append("              DESCRIPTION description,   ");
    sb.append("              PAR_CODE parCode,   ");
    sb.append("              PAR_NAME parName,   ");
    sb.append("              PAR_ORDER parOrder,   ");
    sb.append("              PAR_TYPE parType,   ");
    sb.append("              STATUS status   ");
    sb.append("        FROM APP_PARAMS a   ");
    sb.append("        WHERE a.PAR_TYPE = 'PROVIDER' ");
    sb.append("                     AND lower(a.PAR_CODE) = ANY   ");
    sb.append("              (SELECT DISTINCT lower(ti.PROVIDER)   ");
    sb.append("                 FROM TERM_INFORMATION ti   ");
    sb.append(//from w  w  w. j  a  v a  2s.c  om
            "                 LEFT JOIN CUSTOMER_STATUS cs on ti.TAX_CODE=cs.TAX_CODE and ti.MINE_NAME = cs.MINE_NAME ");
    sb.append("                 JOIN CUSTOMER c on c.TAX_CODE = ti.TAX_CODE ");
    sb.append("                 WHERE ti.IS_CONTACT_INFO is null AND cs.TAX_CODE IS NULL   ");
    sb.append("                 AND ti.MINE_NAME = ANY (:mineName)   ");

    if (!DataUtil.isStringNullOrEmpty(taxAuthority)) {
        sb.append("         and c.TAX_AUTHORITY = ANY(:taxAuthority)   ");
    }

    if (!DataUtil.isStringNullOrEmpty(startFromDate)) {
        sb.append("         and ti.START_TIME >= TO_DATE(:startFromDate,'dd/MM/yyyy') - 1   ");
    }
    if (!DataUtil.isStringNullOrEmpty(endFromDate)) {
        sb.append("         and ti.START_TIME <= TO_DATE(:endFromDate,'dd/MM/yyyy')   + 1 ");
    }
    if (!DataUtil.isStringNullOrEmpty(startToDate)) {
        sb.append("         and ti.END_TIME >= TO_DATE(:startToDate,'dd/MM/yyyy') - 1    ");
    }
    if (!DataUtil.isStringNullOrEmpty(endToDate)) {
        sb.append("         and ti.END_TIME <= TO_DATE(:endToDate,'dd/MM/yyyy') + 1   ");
    }
    if (!DataUtil.isStringNullOrEmpty(fromDateRegister)) {
        sb.append("   AND ti.DATE_REGISTER >= TO_DATE(:fromDateRegister,'dd/MM/yyyy') - 1 ");
    }
    if (!DataUtil.isStringNullOrEmpty(toDateRegister)) {
        sb.append("   AND ti.DATE_REGISTER <= TO_DATE(:toDateRegister,'dd/MM/yyyy') + 1");
    }
    sb.append("              )   ");
    sb.append("        ORDER BY a.PAR_CODE asc   ");
    SQLQuery query;
    try {
        query = getSession().createSQLQuery(sb.toString());
        //Thuc hien chuyen du lieu lay ve thanh thanh doi tuong            
        query.setResultTransformer(Transformers.aliasToBean(AppParamsDTO.class));
        query.addScalar("parId", new StringType());
        query.addScalar("description", new StringType());
        query.addScalar("parCode", new StringType());
        query.addScalar("parName", new StringType());
        query.addScalar("parOrder", new StringType());
        query.addScalar("parType", new StringType());
        query.addScalar("status", new StringType());
        query.setParameterList("mineName", DataUtil.parseInputListString(mineName));
        if (!DataUtil.isStringNullOrEmpty(taxAuthority)) {
            query.setParameterList("taxAuthority", DataUtil.parseInputListString(taxAuthority));
        }
        if (!DataUtil.isStringNullOrEmpty(startFromDate)) {
            query.setString("startFromDate", startFromDate);
        }
        if (!DataUtil.isStringNullOrEmpty(endFromDate)) {
            query.setString("endFromDate", endFromDate);
        }
        if (!DataUtil.isStringNullOrEmpty(startToDate)) {
            query.setString("startToDate", startToDate);
        }
        if (!DataUtil.isStringNullOrEmpty(endToDate)) {
            query.setString("endToDate", endToDate);
        }
        if (!DataUtil.isStringNullOrEmpty(fromDateRegister)) {
            query.setString("fromDateRegister", fromDateRegister);
        }
        if (!DataUtil.isStringNullOrEmpty(toDateRegister)) {
            query.setString("toDateRegister", toDateRegister);
        }
        listAppParams = query.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return listAppParams;
}

From source file:com.cms.dao.AppParamsDAO.java

License:Open Source License

public List<AppParamsDTO> getProviderFromStaffCode(String staffCode, String mineName) {
    List<AppParamsDTO> lstCategoryList = null;
    StringBuilder sb = new StringBuilder();
    sb.append("   SELECT    PAR_ID parId,   ");
    sb.append("           DESCRIPTION description,   ");
    sb.append("           PAR_CODE parCode,   ");
    sb.append("           PAR_NAME parName,   ");
    sb.append("           PAR_ORDER parOrder,   ");
    sb.append("           PAR_TYPE parType,   ");
    sb.append("           STATUS status   ");
    sb.append("        FROM APP_PARAMS a   ");
    sb.append("    WHERE        a.PAR_TYPE       = 'PROVIDER' ");
    sb.append("         AND a.STATUS = '1' ");
    sb.append("         AND lower(a.PAR_CODE) IN ");
    sb.append("      ( SELECT DISTINCT lower(ti.provider) ");
    sb.append("        FROM TERM_INFORMATION ti ");
    sb.append("        WHERE ti.IS_CONTACT_INFO is NULL AND exists ");
    sb.append("             (   SELECT DISTINCT cs.tax_code ");
    sb.append("                 FROM customer_status cs ");
    sb.append("                 WHERE 1 = 1 ");
    sb.append("                 AND cs.tax_code = ti.tax_code  ");
    if (!StringUtils.isStringNullOrEmpty(staffCode)) {
        sb.append("             AND cs.staff_code = :staffCode ");
    } else { //Add 15/04/2017 Them dieu kien neu la admin
        return getProviderFromMineName(mineName);
    }/*from ww w . ja va  2 s  .c om*/
    if (!StringUtils.isStringNullOrEmpty(mineName)) {
        if (mineName.contains(",")) {
            sb.append("             AND cs.mine_name IN (:mineName) ");
        } else {
            sb.append("             AND cs.mine_name = :mineName ");
        }
    }
    sb.append("             ) ");
    sb.append("      ) ");
    try {
        SQLQuery query = getSession().createSQLQuery(sb.toString());
        //            if (!DataUtil.isStringNullOrEmpty(mineName)) {
        //                
        //                query.setParameter("mineName", mineName);
        //            }
        if (!DataUtil.isStringNullOrEmpty(mineName)) {
            if (mineName.contains(",")) {
                query.setParameterList("mineName", DataUtil.parseInputListString(mineName));
            } else {
                query.setParameter("mineName", mineName);
            }
        }
        if (!StringUtils.isStringNullOrEmpty(staffCode)) {
            query.setParameter("staffCode", staffCode);
        }
        query.setResultTransformer(Transformers.aliasToBean(AppParamsDTO.class));
        query.addScalar("parId", new StringType());
        query.addScalar("description", new StringType());
        query.addScalar("parCode", new StringType());
        query.addScalar("parName", new StringType());
        query.addScalar("parOrder", new StringType());
        query.addScalar("parType", new StringType());
        query.addScalar("status", new StringType());
        lstCategoryList = query.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return lstCategoryList;
}

From source file:com.cms.dao.AppParamsDAO.java

License:Open Source License

public List<AppParamsDTO> getProviderFromStaffCodeAndConditions(String staffCode, Map<String, String> map) {

    List<AppParamsDTO> lstCategoryList = null;
    String mineName = map.get("mineName");
    String taxAuthority = map.get("taxAuthority");
    String status = map.get("status");

    if (StringUtils.isStringNullOrEmpty(staffCode)) {
        //Add 17/04/2017 Them dieu kien neu la admin + cac dieu kien status, tinh
        return getProviderFromOtherConditions(mineName, taxAuthority, status);
    }//from  w  w w  .  j av  a 2s  .  c  o  m
    StringBuilder sb = new StringBuilder();
    sb.append("   SELECT    PAR_ID parId,   ");
    sb.append("           DESCRIPTION description,   ");
    sb.append("           PAR_CODE parCode,   ");
    sb.append("           PAR_NAME parName,   ");
    sb.append("           PAR_ORDER parOrder,   ");
    sb.append("           PAR_TYPE parType,   ");
    sb.append("           STATUS status   ");
    sb.append("        FROM APP_PARAMS a   ");
    sb.append("    WHERE        a.PAR_TYPE       = 'PROVIDER' ");
    sb.append("         AND a.STATUS = '1' ");
    sb.append("         AND lower(a.PAR_CODE) IN ");
    sb.append("      ( SELECT DISTINCT lower(ti.provider) ");
    sb.append("        FROM TERM_INFORMATION ti ");

    if (!StringUtils.isStringNullOrEmpty(taxAuthority)) {
        sb.append("        INNER JOIN CUSTOMER c ON c.TAX_CODE = ti.TAX_CODE ");
    }
    sb.append("        WHERE 1= 1 ");
    if (!StringUtils.isStringNullOrEmpty(taxAuthority)) {
        sb.append("    AND c.TAX_AUTHORITY = ANY(:taxAuthority) ");
    }
    sb.append("        AND  exists ");
    sb.append("             (   SELECT DISTINCT cs.tax_code ");
    sb.append("                 FROM customer_status cs ");
    sb.append("                 WHERE 1 = 1  ");
    sb.append("                 AND cs.tax_code = ti.tax_code  ");
    if (!StringUtils.isStringNullOrEmpty(status)) {
        sb.append("                 AND cs.status = ANY (:status) ");
    }
    if (!StringUtils.isStringNullOrEmpty(staffCode)) {
        sb.append("             AND cs.staff_code = :staffCode ");
    } else { //Add 17/04/2017 Them dieu kien neu la admin + cac dieu kien status, tinh
        return getProviderFromOtherConditions(mineName, taxAuthority, status);
    }
    if (!StringUtils.isStringNullOrEmpty(mineName)) {
        if (mineName.contains(",")) {
            sb.append("             AND cs.mine_name IN (:mineName) ");
        } else {
            sb.append("             AND cs.mine_name = :mineName ");
        }
    }
    sb.append("             ) ");
    sb.append("      ) ");
    try {
        SQLQuery query = getSession().createSQLQuery(sb.toString());
        if (!DataUtil.isStringNullOrEmpty(mineName)) {
            if (mineName.contains(",")) {
                query.setParameterList("mineName", DataUtil.parseInputListString(mineName));
            } else {
                query.setParameter("mineName", mineName);
            }
        }
        if (!StringUtils.isStringNullOrEmpty(staffCode)) {
            query.setParameter("staffCode", staffCode);
        }
        if (!StringUtils.isStringNullOrEmpty(status)) {
            query.setParameterList("status", DataUtil.parseInputListString(status));
        }
        if (!StringUtils.isStringNullOrEmpty(taxAuthority)) {
            query.setParameterList("taxAuthority", DataUtil.parseInputListString(taxAuthority));
        }
        query.setResultTransformer(Transformers.aliasToBean(AppParamsDTO.class));
        query.addScalar("parId", new StringType());
        query.addScalar("description", new StringType());
        query.addScalar("parCode", new StringType());
        query.addScalar("parName", new StringType());
        query.addScalar("parOrder", new StringType());
        query.addScalar("parType", new StringType());
        query.addScalar("status", new StringType());
        lstCategoryList = query.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return lstCategoryList;
}

From source file:com.cms.dao.AppParamsDAO.java

License:Open Source License

public List<AppParamsDTO> getProviderFromMineName(String mineName) {
    List<AppParamsDTO> lstCategoryList = null;
    StringBuilder sb = new StringBuilder();
    sb.append("   SELECT    ap.PAR_ID parId,   ");
    sb.append("           ap.DESCRIPTION description,   ");
    sb.append("           ap.PAR_CODE parCode,   ");
    sb.append("           ap.PAR_NAME parName,   ");
    sb.append("           ap.PAR_ORDER parOrder,   ");
    sb.append("           ap.PAR_TYPE parType,   ");
    sb.append("           ap.STATUS status   ");
    sb.append("   FROM APP_PARAMS ap ");
    sb.append("   WHERE PAR_CODE IN ");
    sb.append("     (SELECT DISTINCT provider ");
    sb.append("     FROM term_information ti ");
    sb.append("     WHERE ti.IS_CONTACT_INFO is NULL AND lower(ti.PROVIDER) LIKE (lower(ap.par_code)||'%') ");
    if (!StringUtils.isStringNullOrEmpty(mineName)) {
        if (mineName.contains(",")) {
            sb.append("             AND ti.mine_name IN (:mineName) ");
        } else {//from ww w .ja  v a  2 s  .  com
            sb.append("             AND ti.mine_name = :mineName ");
        }
        //            sb.append("     AND ti.MINE_NAME = :mineName ");
    }
    sb.append("     ) ");
    sb.append("   ORDER BY ap.PAR_ORDER ");

    try {
        SQLQuery query = getSession().createSQLQuery(sb.toString());
        if (!DataUtil.isStringNullOrEmpty(mineName)) {
            if (mineName.contains(",")) {
                query.setParameterList("mineName", DataUtil.parseInputListString(mineName));
            } else {
                query.setParameter("mineName", mineName);
            }
        }

        query.setResultTransformer(Transformers.aliasToBean(AppParamsDTO.class));
        query.addScalar("parId", new StringType());
        query.addScalar("description", new StringType());
        query.addScalar("parCode", new StringType());
        query.addScalar("parName", new StringType());
        query.addScalar("parOrder", new StringType());
        query.addScalar("parType", new StringType());
        query.addScalar("status", new StringType());
        lstCategoryList = query.list();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return lstCategoryList;
}