List of usage examples for org.hibernate Query setMaxResults
@Override
Query<R> setMaxResults(int maxResult);
From source file:com.inkubator.hrm.dao.impl.JabatanDaoImpl.java
@Override public List<KompetensiJabatanViewModel> getByParamForKompetensiJabatan( KompetensiJabatanSearchParameter searchParameter, int firstResult, int maxResults, Order order) { final StringBuilder query = new StringBuilder("SELECT jabatan.code AS jabatanCode,"); query.append(" jabatan.id AS id,"); query.append(" jabatan.name AS jabatanName,"); query.append(" golonganJabatan.code AS golonganJabatanCode "); query.append(" FROM Jabatan jabatan "); query.append(" INNER JOIN jabatan.golonganJabatan golonganJabatan "); //filter by search param query.append(doSearchByParamForKompetensiJabatan(searchParameter)); query.append(" ORDER BY " + order); Query hbm = getCurrentSession().createQuery(query.toString()); hbm = this.setValueQueryKompetensiJabatanViewModelByParam(hbm, searchParameter); return hbm.setMaxResults(maxResults).setFirstResult(firstResult) .setResultTransformer(Transformers.aliasToBean(KompetensiJabatanViewModel.class)).list(); }
From source file:com.inkubator.hrm.dao.impl.LogWtAttendanceRealizationDaoImpl.java
@Override public List<TempAttendanceRealizationViewModel> getListTempAttendanceRealizationViewModelByWtPeriodId( WtAttendanceCalculationSearchParameter searchParameter, Long wtPeriodId, int firstResult, int maxResults, Order orderable) { final StringBuilder query = new StringBuilder("SELECT logAttendanceRealization.id as id,"); query.append(" logAttendanceRealization.wtPeriodeId AS wtPeriodId,"); query.append(" logAttendanceRealization.wtGroupWorkingId AS wtGroupWorkingId,"); query.append(" logAttendanceRealization.wtGroupWorkingName AS wtGroupWorkingName,"); query.append(" logAttendanceRealization.empDataId AS empId,"); query.append(" logAttendanceRealization.empNik AS nik,"); query.append(" logAttendanceRealization.empName AS empName,"); query.append(" logAttendanceRealization.attendanceDaysSchedule AS attendanceDaysSchedule,"); query.append(" logAttendanceRealization.attendanceDaysPresent AS attendanceDaysPresent,"); query.append(" logAttendanceRealization.leaves AS leaves,"); query.append(" logAttendanceRealization.overtime AS overTime,"); query.append(" logAttendanceRealization.permit AS permit,"); query.append(" logAttendanceRealization.sick AS sick,"); query.append(" logAttendanceRealization.duty AS duty"); query.append(" FROM LogWtAttendanceRealization logAttendanceRealization"); query.append(" WHERE logAttendanceRealization.wtPeriodeId = :wtPeriodId "); //filter by search param query.append(doSearchLogWtAttendanceCalculationByParam(searchParameter)); query.append("ORDER BY " + orderable); Query hbm = getCurrentSession().createQuery(query.toString()).setParameter("wtPeriodId", wtPeriodId); hbm = this.setValueQueryLogWtAttendanceCalculationByParam(hbm, searchParameter); return hbm.setMaxResults(maxResults).setFirstResult(firstResult) .setResultTransformer(Transformers.aliasToBean(TempAttendanceRealizationViewModel.class)).list(); }
From source file:com.inkubator.hrm.dao.impl.RecruitSelectionApplicantInitialDaoImpl.java
@Override public List<RecruitmentScheduleSettingViewModel> getByParamForRecruitmentScheduleSetting( RecruitmentScheduleSettingSearchParameter searchParameter, int firstResult, int maxResults, Order orderable) {// w w w .j a v a 2s . c o m final StringBuilder query = new StringBuilder("SELECT recruitHireApply.id AS id,"); query.append(" jabatan.id AS jabatanId,"); query.append(" jabatan.name AS jabatanName,"); query.append(" recruitMppPeriod.id AS mppPeriodId,"); query.append(" COUNT(recruitSelectionApplicantInitial.id) AS totalApplicant,"); query.append(" recruitHireApply.candidateCountRequest AS candidateCountRequest,"); query.append(" recruitMppPeriod.periodeStart AS startMppPeriodDate,"); query.append(" recruitMppPeriod.periodeEnd as endMppPeriodDate"); query.append(" FROM RecruitSelectionApplicantInitial recruitSelectionApplicantInitial"); query.append(" INNER JOIN recruitSelectionApplicantInitial.recruitApplicant recruitApplicant"); query.append(" INNER JOIN recruitSelectionApplicantInitial.recruitHireApply recruitHireApply"); query.append(" INNER JOIN recruitHireApply.jabatan jabatan"); query.append(" INNER JOIN recruitHireApply.recruitMppPeriod recruitMppPeriod"); query.append(this.setWhereQueryRecruitmentScheduleSettingByParam(searchParameter)); query.append(" GROUP BY recruitHireApply.id "); query.append(" ORDER BY " + orderable); Query hbm = getCurrentSession().createQuery(query.toString()); hbm = this.setValueQueryRecruitmentScheduleSettingByParam(hbm, searchParameter); return hbm.setMaxResults(maxResults).setFirstResult(firstResult) .setResultTransformer(Transformers.aliasToBean(RecruitmentScheduleSettingViewModel.class)).list(); }
From source file:com.inkubator.hrm.dao.impl.TempAttendanceRealizationDaoImpl.java
@Override public List<TempAttendanceRealizationViewModel> getListTempAttendanceRealizationViewModelByWtPeriodId( WtAttendanceCalculationSearchParameter searchParameter, Long wtPeriodId, int firstResult, int maxResults, Order orderable) { final StringBuilder query = new StringBuilder("SELECT tempAttendanceRealization.id as id,"); query.append(" wtPeriod.id AS wtPeriodId,"); query.append(" wtGroupWorking.id AS wtGroupWorkingId,"); query.append(" wtGroupWorking.name AS wtGroupWorkingName,"); query.append(" empData.id AS empId,"); query.append(" empData.nik AS nik,"); query.append(" CONCAT(bioData.firstName, ' ', bioData.lastName) AS empName,"); query.append(" tempAttendanceRealization.attendanceDaysSchedule AS attendanceDaysSchedule,"); query.append(" tempAttendanceRealization.attendanceDaysPresent AS attendanceDaysPresent,"); query.append(" tempAttendanceRealization.leave AS leaves,"); query.append(" tempAttendanceRealization.overtime AS overTime,"); query.append(" tempAttendanceRealization.permit AS permit,"); query.append(" tempAttendanceRealization.sick AS sick,"); query.append(" tempAttendanceRealization.duty AS duty,"); query.append(" wtPeriod.absen AS absenStatus"); query.append(" FROM TempAttendanceRealization tempAttendanceRealization"); query.append(" INNER JOIN tempAttendanceRealization.empData empData"); query.append(" INNER JOIN empData.bioData bioData"); query.append(" INNER JOIN tempAttendanceRealization.wtGroupWorking wtGroupWorking"); query.append(" INNER JOIN tempAttendanceRealization.wtPeriod wtPeriod"); query.append(" WHERE wtPeriod.id = :wtPeriodId "); //filter by search param query.append(doSearchWtAttendanceCalculationByParam(searchParameter)); query.append("ORDER BY " + orderable); Query hbm = getCurrentSession().createQuery(query.toString()).setParameter("wtPeriodId", wtPeriodId); hbm = this.setValueQueryWtAttendanceCalculationByParam(hbm, searchParameter); return hbm.setMaxResults(maxResults).setFirstResult(firstResult) .setResultTransformer(Transformers.aliasToBean(TempAttendanceRealizationViewModel.class)).list(); }
From source file:com.iqtb.validacion.managedbean.MbCfdisEmitidos.java
@PostConstruct public void init() { lazyDataCfdis = new LazyDataModel<AuxCfdiEmitido>() { @Override/*from w ww. j a va2s.c o m*/ public List<AuxCfdiEmitido> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); listaCfdiE = new ArrayList<AuxCfdiEmitido>(); listaCfdi = new ArrayList<Cfdis>(); try { queryCount = "select count(idCfdis) "; query = "from Cfdis c, Sucursales s where c.idSucursal = s.idSucursal and s.idEmpresa = " + empresa.getIdEmpresa(); if (!filters.isEmpty()) { Iterator it = filters.keySet().iterator(); while (it.hasNext()) { filterProperty = (String) it.next(); filterValue = filters.get(filterProperty); if (filterProperty.equals("folio")) { query = query + " and c." + filterProperty + " = " + filterValue; } if (filterProperty.equals("serie") || filterProperty.equals("estado")) { query = query + " and c." + filterProperty + " = '" + filterValue + "'"; } if (filterProperty.equals("fecha") || filterProperty.equals("rfcEmisor") || filterProperty.equals("rfcReceptor")) { query = query + " and c." + filterProperty + " like '" + filterValue + "%'"; } if (filterProperty.equals("rfcSocioComercial")) { listaIdSocio = daoSociosComerciales .filtroSocioComercialByRFC(empresa.getIdEmpresa(), filterValue); if (listaIdSocio != null) { boolean isFirst = true; for (Integer idSocio : listaIdSocio) { if (isFirst) { query = query + " and (c.idSocioComercial = " + idSocio; isFirst = false; } else { query = query + " or c.idSocioComercial = " + idSocio; } } query = query + ")"; } } if (filterProperty.equals("nombreSucursal")) { listaidSucursal = daoSucursales.listaIdSucursalByNombre(empresa.getIdEmpresa(), filterValue); if (listaidSucursal != null) { boolean isFirst = true; for (Integer idSucursal : listaidSucursal) { if (isFirst) { query = query + " and (c.idSucursal = " + idSucursal; } else { query = query + " or c.idSucursal = " + idSucursal; } } query = query + ")"; } } } } if (sortField != null && !sortField.isEmpty()) { if (sortOrder.equals(SortOrder.ASCENDING)) { query = query + " ORDER BY c." + sortField + " ASC"; } else { query = query + " ORDER BY c." + sortField + " DESC"; } } else { query = query + " ORDER BY c.fecha DESC"; } queryCount = queryCount + query; Query result = session.createQuery("select c " + query); result.setFirstResult(first); result.setMaxResults(pageSize + first); this.setRowCount(((Long) session.createQuery(queryCount).uniqueResult()).intValue()); listaCfdi = result.list(); tx.commit(); if (listaCfdi.isEmpty()) { logger.info("No existen CFDI Emitidos para mostar"); } else { for (Cfdis cfdi : listaCfdi) { cfdiE = new AuxCfdiEmitido(); cfdiE.setIdCfdis(cfdi.getIdCfdis()); cfdiE.setIdSucursal(cfdi.getIdSucursal()); cfdiE.setIdSocioComercial(cfdi.getIdSocioComercial()); cfdiE.setSerie(cfdi.getSerie()); cfdiE.setFolio(cfdi.getFolio()); cfdiE.setUuid(cfdi.getUuid()); cfdiE.setFecha(cfdi.getFecha()); cfdiE.setNumeroAprobacion(cfdi.getNumeroAprobacion()); cfdiE.setAnioAprobacion(cfdi.getAnioAprobacion()); cfdiE.setSubtotal(cfdi.getSubtotal()); cfdiE.setDescuento(cfdi.getDescuento()); cfdiE.setTotal(cfdi.getTotal()); cfdiE.setTipoMoneda(cfdi.getTipoMoneda()); cfdiE.setTipoCambio(cfdi.getTipoCambio()); cfdiE.setIva(cfdi.getIva()); cfdiE.setEstadoFiscal(cfdi.getEstadoFiscal()); cfdiE.setEstado(cfdi.getEstado()); cfdiE.setFechaCancelacion(cfdi.getFechaCancelacion()); cfdiE.setFechaModificacion(cfdi.getFechaModificacion()); cfdiE.setEstadoImpresion(cfdi.getEstadoImpresion()); cfdiE.setPedimento(cfdi.getPedimento()); cfdiE.setFechaPedimento(cfdi.getFechaPedimento()); cfdiE.setAduana(cfdi.getAduana()); cfdiE.setGenerationDate(cfdi.getGenerationDate()); cfdiE.setTicket(cfdi.getTicket()); cfdiE.setEstadoContable(cfdi.getEstadoContable()); cfdiE.setFechaVencimiento(cfdi.getFechaVencimiento()); cfdiE.setRfcEmisor(cfdi.getRfcEmisor()); cfdiE.setRfcReceptor(cfdi.getRfcReceptor()); cfdiE.setNombreSocioComercial( daoSociosComerciales.getNombreSociobyIdSocio(cfdi.getIdSocioComercial())); cfdiE.setNombreSucursal(daoSucursales.nombreSucursalByIdSucursal(cfdi.getIdSucursal())); listaCfdiE.add(cfdiE); } } } catch (HibernateException he) { descBitacora = "[CFDI_EMITIDO - init] HibernateException ERROR: " + he.getMessage(); registrarBitacora(usuario.getIdUsuario(), null, empresa.getIdEmpresa(), descBitacora, BitacoraTipo.ERROR.name()); logger.error(descBitacora); tx.rollback(); } catch (Exception ex) { descBitacora = "[CFDI_EMITIDO - init] ERROR: " + ex.getMessage(); registrarBitacora(usuario.getIdUsuario(), null, empresa.getIdEmpresa(), descBitacora, BitacoraTipo.ERROR.name()); logger.error(descBitacora); } finally { if (session.isOpen()) { session.clear(); session.close(); } } return listaCfdiE; } }; }
From source file:com.iqtb.validacion.managedbean.MbCfdisRecibidos.java
@PostConstruct public void init() { cfdiDataList = new LazyDataModel<AuxCfdiRecibido>() { @Override// w ww . j a v a 2 s . com public List<AuxCfdiRecibido> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); lista = new ArrayList<AuxCfdiRecibido>(); rfcByIdSocio = null; try { queryCount = "select count(idCfdiRecibido) "; query = "from CfdisRecibidos where idEmpresa = " + empresa.getIdEmpresa() + " and (estado != 'ELIMINADO' and estado != 'CANCELADO')"; if (rolUsuario.getTipo().equals(RolTipo.SOCIO_COMERCIAL.name())) { query = query + " and idSocioComercial = " + usuario.getIdSocioComercial(); } if (!filters.isEmpty()) { it = filters.keySet().iterator(); while (it.hasNext()) { filterProperty = (String) it.next(); filterValue = filters.get(filterProperty); if (filterProperty.equals("folio")) { query = query + " and " + filterProperty + " = " + filterValue; } if (filterProperty.equals("serie") || filterProperty.equals("estado")) { query = query + " and " + filterProperty + " = '" + filterValue + "'"; } if (filterProperty.equals("fecha") || filterProperty.equals("fechaRecepcion")) { query = query + " and " + filterProperty + " like '" + filterValue + "%'"; } if (filterProperty.equals("rfcSocioComercial")) { rfcByIdSocio = daoSociosComerciales .filtroSocioComercialByRFC(empresa.getIdEmpresa(), filterValue); if (rfcByIdSocio != null) { boolean isFirst = true; for (Integer idSocio : rfcByIdSocio) { if (isFirst) { query = query + " and (idSocioComercial = " + idSocio; isFirst = false; } else { query = query + " or idSocioComercial = " + idSocio; } } query = query + ")"; } rfcByIdSocio = null; } if (filterProperty.equals("nombreSocioComercial")) { rfcByIdSocio = daoSociosComerciales .filtroSocioComercialByNombre(empresa.getIdEmpresa(), filterValue); if (rfcByIdSocio != null) { boolean isFirst = true; for (Integer idSocio : rfcByIdSocio) { if (isFirst) { query = query + " and (idSocioComercial = " + idSocio; isFirst = false; } else { query = query + " or idSocioComercial = " + idSocio; } } query = query + ")"; } rfcByIdSocio = null; } } } if (sortField != null && !sortField.isEmpty()) { if (sortOrder.equals(SortOrder.ASCENDING)) { query = query + " ORDER BY " + sortField + " ASC"; } else { query = query + " ORDER BY " + sortField + " DESC"; } } else { query = query + " ORDER BY fechaRecepcion DESC"; } queryCount = queryCount + query; Query result = session.createQuery( "select new CfdisRecibidos(idCfdiRecibido, idSocioComercial, serie, folio, fecha, fechaRecepcion, estado, tiposWarn) " + query); result.setFirstResult(first); result.setMaxResults(pageSize + first); this.setRowCount(((Long) session.createQuery(queryCount).uniqueResult()).intValue()); listaCFDIs = result.list(); tx.commit(); if (listaCFDIs == null || listaCFDIs.size() <= 0) { logger.info("listaCfdisCriteria - No existen CfdisRecibidos para mostrar"); return lista; } for (CfdisRecibidos item : listaCFDIs) { auxCfdiR = new AuxCfdiRecibido(); auxCfdiR.setIdCfdiRecibido(item.getIdCfdiRecibido()); auxCfdiR.setIdSocioComercial(item.getIdSocioComercial()); auxCfdiR.setSerie(item.getSerie()); auxCfdiR.setFolio(item.getFolio()); auxCfdiR.setFecha(item.getFecha()); auxCfdiR.setFechaRecepcion(item.getFechaRecepcion()); auxCfdiR.setEstado(item.getEstado()); auxCfdiR.setTiposWarn(item.getTiposWarn()); auxCfdiR.setRfcSocioComercial( daoSociosComerciales.getRFCSociobyIdSocio(item.getIdSocioComercial())); auxCfdiR.setNombreSocioComercial( daoSociosComerciales.getNombreSociobyIdSocio(item.getIdSocioComercial())); lista.add(auxCfdiR); } } catch (HibernateException he) { descBitacora = "[CFDI_RECIBIDO - init] " + usuario.getUserid() + " cfdiDataList HibernateException ERROR " + he.getMessage(); registrarBitacora(usuario.getIdUsuario(), null, empresa.getIdEmpresa(), descBitacora, BitacoraTipo.ERROR.name()); logger.error(descBitacora); tx.rollback(); } catch (Exception ex) { descBitacora = "[CFDI_RECIBIDO - init] " + usuario.getUserid() + " cfdiDataList ERROR " + ex.getMessage(); registrarBitacora(usuario.getIdUsuario(), null, empresa.getIdEmpresa(), descBitacora, BitacoraTipo.ERROR.name()); logger.error(descBitacora); } finally { listaCFDIs = null; if (session.isOpen()) { session.clear(); session.close(); } } return lista; } }; lazyCfdisEliminados = new LazyDataModel<AuxCfdiRecibido>() { @Override public List<AuxCfdiRecibido> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); listaE = new ArrayList<AuxCfdiRecibido>(); rfcByIdSocio = null; try { queryCount = "select count(idCfdiRecibido) "; query = "from CfdisRecibidos where idEmpresa = " + empresa.getIdEmpresa() + " and (estado ='ELIMINADO' or estado ='CANCELADO')"; if (rolUsuario.getTipo().equals(RolTipo.SOCIO_COMERCIAL.name())) { query = query + " and idSocioComercial = " + usuario.getIdSocioComercial(); } if (!filters.isEmpty()) { it = filters.keySet().iterator(); while (it.hasNext()) { filterProperty = (String) it.next(); filterValue = filters.get(filterProperty); if (filterProperty.equals("folio")) { query = query + " and " + filterProperty + " = " + filterValue; } if (filterProperty.equals("serie") || filterProperty.equals("estado")) { query = query + " and " + filterProperty + " = '" + filterValue + "'"; } if (filterProperty.equals("fecha") || filterProperty.equals("fechaRecepcion")) { query = query + " and " + filterProperty + " like '" + filterValue + "%'"; } if (filterProperty.equals("rfcSocioComercial")) { rfcByIdSocio = daoSociosComerciales .filtroSocioComercialByRFC(empresa.getIdEmpresa(), filterValue); if (rfcByIdSocio != null) { boolean isFirst = true; for (Integer idSocio : rfcByIdSocio) { if (isFirst) { query = query + " and (idSocioComercial = " + idSocio; isFirst = false; } else { query = query + " or idSocioComercial = " + idSocio; } } query = query + ")"; } rfcByIdSocio = null; } if (filterProperty.equals("nombreSocioComercial")) { rfcByIdSocio = daoSociosComerciales .filtroSocioComercialByNombre(empresa.getIdEmpresa(), filterValue); if (rfcByIdSocio != null) { boolean isFirst = true; for (Integer idSocio : rfcByIdSocio) { if (isFirst) { query = query + " and (idSocioComercial = " + idSocio; isFirst = false; } else { query = query + " or idSocioComercial = " + idSocio; } } query = query + ")"; } rfcByIdSocio = null; } } } if (sortField != null && !sortField.isEmpty()) { if (sortOrder.equals(SortOrder.ASCENDING)) { query = query + " ORDER BY " + sortField + " ASC"; } else { query = query + " ORDER BY " + sortField + " DESC"; } } else { query = query + " ORDER BY fechaRecepcion DESC"; } queryCount = queryCount + query; Query result = session.createQuery( "select new CfdisRecibidos(idCfdiRecibido, idSocioComercial, serie, folio, fecha, fechaRecepcion, estado, tiposWarn) " + query); result.setFirstResult(first); result.setMaxResults(pageSize + first); this.setRowCount(((Long) session.createQuery(queryCount).uniqueResult()).intValue()); listaCFDIsE = result.list(); tx.commit(); if (listaCFDIsE == null || listaCFDIsE.size() <= 0) { logger.info("listaCfdisCriteriaE - No existen CfdisRecibidos para mostrar"); return listaE; } for (CfdisRecibidos item : listaCFDIsE) { auxCfdiR = new AuxCfdiRecibido(); auxCfdiR.setIdCfdiRecibido(item.getIdCfdiRecibido()); auxCfdiR.setIdSocioComercial(item.getIdSocioComercial()); auxCfdiR.setSerie(item.getSerie()); auxCfdiR.setFolio(item.getFolio()); auxCfdiR.setFecha(item.getFecha()); auxCfdiR.setFechaRecepcion(item.getFechaRecepcion()); auxCfdiR.setEstado(item.getEstado()); auxCfdiR.setError(item.getError()); auxCfdiR.setRfcSocioComercial( daoSociosComerciales.getRFCSociobyIdSocio(item.getIdSocioComercial())); auxCfdiR.setNombreSocioComercial( daoSociosComerciales.getNombreSociobyIdSocio(item.getIdSocioComercial())); listaE.add(auxCfdiR); } } catch (HibernateException he) { descBitacora = "[CFDI_RECIBIDO - init] " + usuario.getUserid() + " lazyCfdisEliminados HibernateException ERROR " + he.getMessage(); registrarBitacora(usuario.getIdUsuario(), null, empresa.getIdEmpresa(), descBitacora, BitacoraTipo.ERROR.name()); logger.error(descBitacora); tx.rollback(); } catch (Exception ex) { descBitacora = "[CFDI_RECIBIDO - init] " + usuario.getUserid() + " lazyCfdisEliminados ERROR " + ex.getMessage(); registrarBitacora(usuario.getIdUsuario(), null, empresa.getIdEmpresa(), descBitacora, BitacoraTipo.ERROR.name()); logger.error(descBitacora); } finally { listaCFDIsE = null; if (session.isOpen()) { session.clear(); session.close(); } } return listaE; } }; }
From source file:com.iqtb.validacion.managedbean.MbContabilidadElectronica.java
@PostConstruct public void init() { modelDataList = new LazyDataModel<ContabilidadElectronica>() { @Override/*from www.j a v a2 s.co m*/ public List<ContabilidadElectronica> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) { listaContabilidad = new ArrayList<ContabilidadElectronica>(); session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); try { queryCount = "select count(idContabilidad) "; query = "from ContabilidadElectronica where idEmpresa = " + empresa.getIdEmpresa(); if (!filters.isEmpty()) { it = filters.keySet().iterator(); while (it.hasNext()) { filterProperty = (String) it.next(); filterValue = filters.get(filterProperty); if (filterProperty.equals("anio")) { query = query + " and " + filterProperty + " = " + filterValue; } if (filterProperty.equals("tipoArchivo") || filterProperty.equals("estado") || filterProperty.equals("mes")) { query = query + " and " + filterProperty + " = '" + filterValue + "'"; } if (filterProperty.equals("fechaRecepcion") || filterProperty.equals("nombreRecibido") || filterProperty.equals("nombreGenerado")) { query = query + " and " + filterProperty + " like '" + filterValue + "%'"; } } } if (sortField != null && !sortField.isEmpty()) { if (sortOrder.equals(SortOrder.ASCENDING)) { query = query + " ORDER BY " + sortField + " ASC"; } else { query = query + " ORDER BY " + sortField + " DESC"; } } else { query = query + " ORDER BY fechaRecepcion DESC"; } queryCount = queryCount + query; Query result = session.createQuery( "select new ContabilidadElectronica(idContabilidad, estado, tipoArchivo, nombreRecibido, nombreGenerado, fechaRecepcion, mes, anio) " + query); result.setFirstResult(first); result.setMaxResults(pageSize + first); this.setRowCount(((Long) session.createQuery(queryCount).uniqueResult()).intValue()); listaContabilidad = result.list(); tx.commit(); } catch (HibernateException he) { descBitacora = "[CONT_ELECTRONICA - init] " + usuario.getUserid() + " HibernateException ERROR " + he.getMessage(); registrarBitacora(usuario.getIdUsuario(), null, empresa.getIdEmpresa(), descBitacora, BitacoraTipo.ERROR.name()); logger.error(descBitacora); tx.rollback(); } finally { if (session.isOpen()) { session.clear(); session.close(); } } return listaContabilidad; } }; }
From source file:com.iqtb.validacion.managedbean.MbOrdenCompra.java
@PostConstruct public void init() { lazyDataOrden = new LazyDataModel<AuxOrdenCompra>() { @Override/* w ww.j a va 2 s .c om*/ public List<AuxOrdenCompra> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); listaAuxOrden = new ArrayList<AuxOrdenCompra>(); listaOrden = new ArrayList<OrdenesCompra>(); try { queryCount = "select count(idOrdenCompra) "; query = "from OrdenesCompra where idEmpresa = " + empresa.getIdEmpresa(); if (!filters.isEmpty()) { Iterator it = filters.keySet().iterator(); while (it.hasNext()) { filterProperty = (String) it.next(); filterValue = filters.get(filterProperty); if (filterProperty.equals("numeroOc")) { query = query + " and " + filterProperty + " = '" + filterValue + "'"; } if (filterProperty.equals("rfcVendedor") || filterProperty.equals("total") || filterProperty.equals("tipoCambio") || filterProperty.equals("tipoMoneda")) { query = query + " and " + filterProperty + " like '" + filterValue + "%'"; } if (filterProperty.equals("rfcSocioComercial")) { listaIdSocio = daoSociosComerciales .filtroSocioComercialByRFC(empresa.getIdEmpresa(), filterValue); for (Integer idSocio : listaIdSocio) { query = query + " and idSocioComercial = " + idSocio; } } } } if (sortField != null && !sortField.isEmpty()) { if (sortOrder.equals(SortOrder.ASCENDING)) { query = query + " ORDER BY " + sortField + " ASC"; } else { query = query + " ORDER BY " + sortField + " DESC"; } } else { query = query + " ORDER BY idOrdenCompra DESC"; } queryCount = queryCount + query; Query result = session.createQuery(query); result.setMaxResults(pageSize + first); result.setFirstResult(first); this.setRowCount(((Long) session.createQuery(queryCount).uniqueResult()).intValue()); listaOrden = result.list(); tx.commit(); if (listaOrden.isEmpty()) { logger.info("No existen Ordenes de Compra para mostar"); } else { for (OrdenesCompra ordenCompra : listaOrden) { auxOrdenCompra = new AuxOrdenCompra(); auxOrdenCompra.setIdOrdenCompra(ordenCompra.getIdOrdenCompra()); auxOrdenCompra.setIdEmpresa(ordenCompra.getIdEmpresa()); auxOrdenCompra.setIdSocioComercial(ordenCompra.getIdSocioComercial()); auxOrdenCompra.setNumeroOc(ordenCompra.getNumeroOc()); auxOrdenCompra.setTotal(ordenCompra.getTotal()); auxOrdenCompra.setTipoMoneda(ordenCompra.getTipoMoneda()); auxOrdenCompra.setTipoCambio(ordenCompra.getTipoCambio()); auxOrdenCompra.setRfcVendedor(ordenCompra.getRfcVendedor()); auxOrdenCompra.setRfcSocioComercial( daoSociosComerciales.getRFCSociobyIdSocio(ordenCompra.getIdSocioComercial())); listaAuxOrden.add(auxOrdenCompra); } } } catch (HibernateException he) { descBitacora = "[ORDEN_COMPRA - init] HibernateException ERROR: " + he.getMessage(); registrarBitacora(usuario.getIdUsuario(), null, empresa.getIdEmpresa(), descBitacora, BitacoraTipo.ERROR.name()); logger.error(descBitacora); tx.rollback(); } catch (Exception ex) { descBitacora = "[ORDEN_COMPRA - init] ERROR: " + ex.getMessage(); registrarBitacora(usuario.getIdUsuario(), null, empresa.getIdEmpresa(), descBitacora, BitacoraTipo.ERROR.name()); logger.error(descBitacora); } finally { if (session.isOpen()) { session.clear(); session.close(); } } return listaAuxOrden; } }; }
From source file:com.iqtb.validacion.managedbean.MbOrdenCompra.java
public void dataLazyCfdi() { lazyDataCfdi = new LazyDataModel<CfdisRecibidos>() { @Override//from w w w. j a v a 2s .c o m public List<CfdisRecibidos> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); listaCFDIs = new ArrayList<CfdisRecibidos>(); try { queryCount = "select count(idCfdiRecibido) "; query = "from CfdisRecibidos where idEmpresa = " + empresa.getIdEmpresa() + " and idOrdenCompra = " + auxOrdenCompra.getIdOrdenCompra(); if (!filters.isEmpty()) { Iterator it = filters.keySet().iterator(); while (it.hasNext()) { filterProperty = (String) it.next(); filterValue = filters.get(filterProperty); if (filterProperty.equals("serie") || filterProperty.equals("estado")) { query = query + " and " + filterProperty + " = '" + filterValue + "'"; } if (filterProperty.equals("folio")) { //|| filterProperty.equals("total") query = query + " and " + filterProperty + " = " + filterValue; } if (filterProperty.equals("fecha") || filterProperty.equals("fechaRecepcion") || filterProperty.equals("total")) { query = query + " and " + filterProperty + " like '" + filterValue + "%'"; } } } if (sortField != null && !sortField.isEmpty()) { if (sortOrder.equals(SortOrder.ASCENDING)) { query = query + " ORDER BY " + sortField + " ASC"; } else { query = query + " ORDER BY " + sortField + " DESC"; } } else { query = query + " ORDER BY fechaRecepcion DESC"; } queryCount = queryCount + query; Query result = session.createQuery( "select new CfdisRecibidos(idCfdiRecibido, idSocioComercial, serie, folio, fecha, total, fechaRecepcion, estado, tiposWarn)" + query); this.setRowCount(((Long) session.createQuery(queryCount).uniqueResult()).intValue()); result.setFirstResult(first); result.setMaxResults(pageSize + first); listaCFDIs = result.list(); } catch (HibernateException e) { logger.error(usuario.getUserid() + " dataLazyCfdi ERROR " + e); } finally { if (session.isOpen()) { session.clear(); session.close(); } } return listaCFDIs; } }; }
From source file:com.itrus.ca.common.persistence.BaseDaoImpl.java
License:Open Source License
/** * QL //from w w w.j av a 2 s .com * * @param page * @param qlString * @param parameter * @return */ @SuppressWarnings("unchecked") public <E> Page<E> find(Page<E> page, String qlString, Object... parameter) { // get count if (!page.isDisabled() && !page.isNotCount()) { String countQlString = "select count(*) " + removeSelect(removeOrders(qlString)); // page.setCount(Long.valueOf(createQuery(countQlString, // parameter).uniqueResult().toString())); Query query = createQuery(countQlString, parameter); List<Object> list = query.list(); if (list.size() > 0) { page.setCount(Long.valueOf(list.get(0).toString())); } else { page.setCount(list.size()); } if (page.getCount() < 1) { return page; } } // order by String ql = qlString; if (StringUtils.isNotBlank(page.getOrderBy())) { ql += " order by " + page.getOrderBy(); } Query query = createQuery(ql, parameter); // set page if (!page.isDisabled()) { query.setFirstResult(page.getFirstResult()); query.setMaxResults(page.getMaxResults()); } page.setList(query.list()); return page; }