List of usage examples for org.hibernate Query setShort
@Deprecated @SuppressWarnings("unchecked") default Query<R> setShort(String name, short val)
From source file:gcom.atendimentopublico.RepositorioAtendimentoPublicoHBM.java
License:Open Source License
/** * [UC1056] Gerar Relatrio de Acompanhamento dos Registros de Atendimento * // ww w. j a va 2 s . c om * @author Hugo Leonardo, Diogo Peixoto * @date 01/10/2010, 28/04/2011 * * @param FiltrarAcompanhamentoRegistroAtendimentoHelper * @return Collection * @throws ErroRepositorioException */ public Collection pesquisarRelatorioAcompanhamentoRASinteticoAberto( FiltrarAcompanhamentoRegistroAtendimentoHelper helper) throws ErroRepositorioException { Collection retorno = null; String consulta = ""; Query query = null; Session session = HibernateUtil.getSession(); String joinMunicipio = ""; if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados()) && (helper.getIdUnidadeAtendimento() == null || helper.getIdUnidadeAtendimento().equals(""))) { consulta += " select rau.unidadeOrganizacional.descricao, " + " muni.nome, " + " count(distinct ra.id) " + " from gcom.atendimentopublico.registroatendimento.RegistroAtendimento ra " + " inner join ra.solicitacaoTipoEspecificacao step " + " left join ra.atendimentoMotivoEncerramento ame "; consulta += " inner join ra.localidade loc " + " inner join loc.municipio muni "; } else { consulta += " select rau.unidadeOrganizacional.descricao, "; if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { consulta += " muni.nome, "; joinMunicipio = " inner join ra.localidade loc " + " inner join loc.municipio muni "; } consulta += " count(distinct ra.id) " + " from gcom.atendimentopublico.registroatendimento.RegistroAtendimento ra " + " inner join ra.solicitacaoTipoEspecificacao step " + " left join ra.atendimentoMotivoEncerramento ame "; } consulta += joinMunicipio + " inner join ra.registroAtendimentoUnidades rau " + " inner join rau.unidadeOrganizacional uni " + " where ra.unidadeAtual = uni.id and "; try { if (Util.verificarNaoVazio(helper.getIdUnidadeAtendimento())) { consulta += " rau.unidadeOrganizacional = :unidade and " + " rau.atendimentoRelacaoTipo = 1 and "; } if (!Util.isVazioOrNulo(helper.getIdsMotivoEncerramentoSelecionados())) { consulta += " ame.id in (:motivo) and "; } if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { consulta += " muni.id in (:municipios) and "; } if (helper.getPeriodoAtendimentoInicial() != null && helper.getPeriodoAtendimentoFinal() != null) { consulta += " (ra.registroAtendimento between :dtAtendimentoIncial and :dtAtendimentoFinal) and "; } if (helper.getPeriodoEncerramentoInicial() != null && helper.getPeriodoEncerramentoFinal() != null) { consulta += " (ra.dataEncerramento between :dtEncerramentoIncial and :dtEncerramentoFinal) and "; } if (Util.verificarNaoVazio(helper.getSituacaoRA())) { consulta += " ra.codigoSituacao = :situacao and "; } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && helper.getSituacaoRAAbertos().equals("1")) { consulta += " (ra.dataPrevistaAtual >= :dtCorrente " + " or ra.dataPrevistaOriginal >= :dtCorrente) and "; } else if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && helper.getSituacaoRAAbertos().equals("0")) { consulta += " (ra.dataPrevistaAtual < :dtCorrente " + " or ra.dataPrevistaOriginal < :dtCorrente) and "; } // remove o ltimo AND consulta = Util.removerUltimosCaracteres(consulta, 4); if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados()) && (helper.getIdUnidadeAtendimento() == null || helper.getIdUnidadeAtendimento().equals(""))) { consulta += " GROUP BY muni.nome, rau.unidadeOrganizacional.descricao " + " ORDER BY muni.nome, rau.unidadeOrganizacional.descricao "; } else { String groupBy = " GROUP BY "; String orderBy = " ORDER BY "; if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { groupBy += " muni.nome, "; orderBy += " muni.nome, "; } groupBy += " rau.unidadeOrganizacional.descricao "; orderBy += " rau.unidadeOrganizacional.descricao "; consulta += groupBy + orderBy; } query = (Query) session.createQuery(consulta); if (Util.verificarNaoVazio(helper.getIdUnidadeAtendimento())) { query.setString("unidade", helper.getIdUnidadeAtendimento().toString()); } if (!Util.isVazioOrNulo(helper.getIdsMotivoEncerramentoSelecionados())) { query.setParameterList("motivo", helper.getIdsMotivoEncerramentoSelecionados()); } if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { query.setParameterList("municipios", helper.getMunicipiosAssociados()); } if (helper.getPeriodoAtendimentoInicial() != null && helper.getPeriodoAtendimentoFinal() != null) { query.setDate("dtAtendimentoIncial", Util.formatarDataInicial(helper.getPeriodoAtendimentoInicial())); query.setDate("dtAtendimentoFinal", Util.formatarDataFinal(helper.getPeriodoAtendimentoFinal())); } if (helper.getPeriodoEncerramentoInicial() != null && helper.getPeriodoEncerramentoFinal() != null) { query.setDate("dtEncerramentoIncial", Util.formatarDataInicial(helper.getPeriodoEncerramentoInicial())); query.setDate("dtEncerramentoFinal", Util.formatarDataFinal(helper.getPeriodoEncerramentoFinal())); } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && (helper.getSituacaoRAAbertos().equals("0") || helper.getSituacaoRAAbertos().equals("1"))) { query.setDate("dtCorrente", new Date()); } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0")) { query.setShort("situacao", RegistroAtendimento.SITUACAO_PENDENTE); } else if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("1")) { query.setShort("situacao", RegistroAtendimento.SITUACAO_ENCERRADO); } retorno = query.list(); } catch (HibernateException e) { throw new ErroRepositorioException(e, "Erro no Hibernate"); } finally { HibernateUtil.closeSession(session); } return retorno; }
From source file:gcom.atendimentopublico.RepositorioAtendimentoPublicoHBM.java
License:Open Source License
/** * [UC1056] Gerar Relatrio de Acompanhamento dos Registros de Atendimento * //from w w w. j av a 2 s . co m * @author Hugo Leonardo, Diogo Peixoto * @date 01/10/2010, 28/04/2011 * * @param FiltrarAcompanhamentoRegistroAtendimentoHelper * @return Collection * @throws ErroRepositorioException */ public Collection pesquisarRelatorioAcompanhamentoRASinteticoEncerrado( FiltrarAcompanhamentoRegistroAtendimentoHelper helper) throws ErroRepositorioException { Collection retorno = null; String consulta = ""; Query query = null; Session session = HibernateUtil.getSession(); String selectMunicipio = ""; String joinMunicipio = ""; if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { selectMunicipio = ", muni.nome"; joinMunicipio = " inner join ra.localidade loc inner join loc.municipio muni "; } try { consulta += " select rau.unidadeOrganizacional.descricao, ame.descricao, " + " count(distinct ra.id) " + selectMunicipio + " from gcom.atendimentopublico.registroatendimento.RegistroAtendimento ra " + " inner join ra.solicitacaoTipoEspecificacao step " + " left join ra.atendimentoMotivoEncerramento ame "; consulta += " inner join ra.registroAtendimentoUnidades rau " + " inner join rau.unidadeOrganizacional uni " + joinMunicipio + " where ra.unidadeAtual = uni.id and "; if (Util.verificarNaoVazio(helper.getIdUnidadeAtendimento())) { consulta += " rau.unidadeOrganizacional = :unidade and " + " rau.atendimentoRelacaoTipo = 1 and "; } if (!Util.isVazioOrNulo(helper.getIdsMotivoEncerramentoSelecionados())) { consulta += " ame.id in (:motivo) and "; } if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { consulta += " muni.id in (:municipios) and "; } if (helper.getPeriodoAtendimentoInicial() != null && helper.getPeriodoAtendimentoFinal() != null) { consulta += " (ra.registroAtendimento between :dtAtendimentoIncial and :dtAtendimentoFinal) and "; } if (helper.getPeriodoEncerramentoInicial() != null && helper.getPeriodoEncerramentoFinal() != null) { consulta += " (ra.dataEncerramento between :dtEncerramentoIncial and :dtEncerramentoFinal) and "; } if (Util.verificarNaoVazio(helper.getSituacaoRA())) { consulta += " ra.codigoSituacao = :situacao and "; } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && helper.getSituacaoRAAbertos().equals("1")) { consulta += " (ra.dataPrevistaAtual >= :dtCorrente " + " or ra.dataPrevistaOriginal >= :dtCorrente) and "; } else if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && helper.getSituacaoRAAbertos().equals("0")) { consulta += " (ra.dataPrevistaAtual < :dtCorrente " + " or ra.dataPrevistaOriginal < :dtCorrente) and "; } // remove o ltimo AND consulta = Util.removerUltimosCaracteres(consulta, 4); if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados()) && (helper.getIdUnidadeAtendimento() == null || helper.getIdUnidadeAtendimento().equals(""))) { consulta += " GROUP BY muni.nome, rau.unidadeOrganizacional.descricao, ame.descricao " + " ORDER BY muni.nome, rau.unidadeOrganizacional.descricao, ame.descricao "; } else { String groupBy = " GROUP BY "; String orderBy = " ORDER BY "; if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { groupBy += " muni.nome, "; orderBy += " muni.nome, "; } groupBy += " rau.unidadeOrganizacional.descricao, ame.descricao "; orderBy += " rau.unidadeOrganizacional.descricao, ame.descricao "; consulta += groupBy + orderBy; } query = (Query) session.createQuery(consulta); if (Util.verificarNaoVazio(helper.getIdUnidadeAtendimento())) { query.setString("unidade", helper.getIdUnidadeAtendimento().toString()); } if (!Util.isVazioOrNulo(helper.getIdsMotivoEncerramentoSelecionados())) { query.setParameterList("motivo", helper.getIdsMotivoEncerramentoSelecionados()); } if (!Util.isVazioOrNulo(helper.getMunicipiosAssociados())) { query.setParameterList("municipios", helper.getMunicipiosAssociados()); } if (helper.getPeriodoAtendimentoInicial() != null && helper.getPeriodoAtendimentoFinal() != null) { query.setDate("dtAtendimentoIncial", Util.formatarDataInicial(helper.getPeriodoAtendimentoInicial())); query.setDate("dtAtendimentoFinal", Util.formatarDataFinal(helper.getPeriodoAtendimentoFinal())); } if (helper.getPeriodoEncerramentoInicial() != null && helper.getPeriodoEncerramentoFinal() != null) { query.setDate("dtEncerramentoIncial", Util.formatarDataInicial(helper.getPeriodoEncerramentoInicial())); query.setDate("dtEncerramentoFinal", Util.formatarDataFinal(helper.getPeriodoEncerramentoFinal())); } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0") && Util.verificarNaoVazio(helper.getSituacaoRAAbertos()) && (helper.getSituacaoRAAbertos().equals("0") || helper.getSituacaoRAAbertos().equals("1"))) { query.setDate("dtCorrente", new Date()); } if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("0")) { query.setShort("situacao", RegistroAtendimento.SITUACAO_PENDENTE); } else if (Util.verificarNaoVazio(helper.getSituacaoRA()) && helper.getSituacaoRA().equals("1")) { query.setShort("situacao", RegistroAtendimento.SITUACAO_ENCERRADO); } retorno = query.list(); } catch (HibernateException e) { throw new ErroRepositorioException(e, "Erro no Hibernate"); } finally { HibernateUtil.closeSession(session); } return retorno; }
From source file:org.jpos.gl.GLSession.java
License:Open Source License
private Iterator findSummarizedGLEntries(Journal journal, Date start, Date end, boolean credit, short layer) throws HibernateException, GLException { StringBuffer qs = new StringBuffer( "select entry.account, sum(entry.amount)" + " from org.jpos.gl.GLEntry entry," + " org.jpos.gl.GLTransaction txn" + " where txn.id = entry.transaction" + " and credit = :credit" + " and txn.journal = :journal" + " and entry.layer = :layer"); boolean equalDate = start.equals(end); if (equalDate) { qs.append(" and txn.postDate = :date"); } else {//from ww w .j ava 2 s .co m qs.append(" and txn.postDate >= :start"); qs.append(" and txn.postDate <= :end"); } qs.append(" group by entry.account"); Query q = session.createQuery(qs.toString()); q.setLong("journal", journal.getId()); q.setParameter("credit", credit ? "Y" : "N"); q.setShort("layer", layer); if (equalDate) q.setParameter("date", start); else { q.setParameter("start", start); q.setParameter("end", end); } return q.iterate(); }
From source file:org.mifos.accounts.persistence.LegacyAccountDao.java
License:Open Source License
public int getCountForGlCode(Short glCodeId) throws PersistenceException { Session session = StaticHibernateUtil.getSessionTL(); int count = -1; try {//from w w w. java 2s. co m Query query = session.getNamedQuery(NamedQueryConstants.COUNT_GL_CODE_REFERENCES); query.setShort("glCodeId", glCodeId); count = (Integer) query.uniqueResult(); } catch (HibernateException ex) { throw new PersistenceException(ex); } return count; }
From source file:org.mifos.accounts.persistence.LegacyAccountDao.java
License:Open Source License
public void deleteLedgerAccount(Short accountId) throws PersistenceException { Session session = StaticHibernateUtil.getSessionTL(); Transaction transaction = session.beginTransaction(); try {// w w w .jav a 2 s . c om COABO coa = (COABO) session.load(COABO.class, accountId); COABO parent = coa.getCoaHierarchy().getParentAccount().getCoa(); Short parentId = parent.getAccountId(); Short glCodeId = coa.getAssociatedGlcode().getGlcodeId(); Query query = session.getNamedQuery(NamedQueryConstants.REMOVE_COA_PARENT); query.setShort("coa_id", coa.getAccountId().shortValue()); query.setShort("parent_id", parentId); query.executeUpdate(); query = session.getNamedQuery(NamedQueryConstants.REMOVE_COA); query.setShort("coa_id", coa.getAccountId().shortValue()); query.executeUpdate(); query = session.getNamedQuery(NamedQueryConstants.REMOVE_GLCODE); query.setShort("glcode_id", glCodeId); query.executeUpdate(); transaction.commit(); session.flush(); } catch (HibernateException e) { transaction.rollback(); throw new PersistenceException(e); } }
From source file:org.mifos.accounts.persistence.LegacyAccountDao.java
License:Open Source License
public void updateLedgerAccount(COABO coaBo, String accountName, String glCode, String parentGlCode) throws PersistenceException { Session session = StaticHibernateUtil.getSessionTL(); Transaction transaction = session.beginTransaction(); try {//from w w w . ja v a 2s . co m Short newParentId = getAccountIdFromGlCode(parentGlCode); coaBo.setAccountName(accountName); GLCodeEntity glCodeEntity = coaBo.getAssociatedGlcode(); createOrUpdate(coaBo); glCodeEntity.setGlcode(glCode); createOrUpdate(glCodeEntity); Query query = session.getNamedQuery(NamedQueryConstants.SET_COA_PARENT); query.setShort("parentId", newParentId); query.setShort("id", coaBo.getAccountId()); query.executeUpdate(); transaction.commit(); } catch (HibernateException ex) { transaction.rollback(); throw new PersistenceException(ex); } }
From source file:org.mifos.application.master.persistence.LegacyMasterDao.java
License:Open Source License
@SuppressWarnings("unchecked") private List<CustomValueListElementDto> getCustomValueListElements(final String entityName, final String entityClass, final String column, final Session session) { Query queryEntity = session .createQuery("select new org.mifos.application.master.business.CustomValueListElementDto(" + "mainTable." + column + " ,lookup.lookUpId,lookupvalue.lookUpValue,lookup.lookUpName) " + "from org.mifos.application.master.business.LookUpValueEntity lookup," + "org.mifos.application.master.business.LookUpValueLocaleEntity lookupvalue," + entityClass + " mainTable " + "where mainTable.lookUpId = lookup.lookUpId" + " and lookup.lookUpEntity.entityType = ?" + " and lookup.lookUpId = lookupvalue.lookUpId" + " and lookupvalue.localeId = ?"); queryEntity.setString(0, entityName); queryEntity.setShort(1, (short) 1); List<CustomValueListElementDto> entityList = queryEntity.list(); return entityList; }
From source file:org.mifos.application.master.persistence.MasterPersistence.java
License:Open Source License
private List<CustomValueListElement> getCustomValueListElements(final String entityName, final String entityClass, final String column, final Session session) { Query queryEntity = session .createQuery("select new org.mifos.application.master.business.CustomValueListElement(" + "mainTable." + column + " ,lookup.lookUpId,lookupvalue.lookUpValue,lookup.lookUpName) " + "from org.mifos.application.master.business.LookUpValueEntity lookup," + "org.mifos.application.master.business.LookUpValueLocaleEntity lookupvalue," + entityClass + " mainTable " + "where mainTable.lookUpId = lookup.lookUpId" + " and lookup.lookUpEntity.entityType = ?" + " and lookup.lookUpId = lookupvalue.lookUpId" + " and lookupvalue.localeId = ?"); queryEntity.setString(0, entityName); // Jan 16, 2008 work in progress // all override or custom values are now stored in locale 1 // queryEntity.setShort(1, localeId); queryEntity.setShort(1, (short) 1); List<CustomValueListElement> entityList = queryEntity.list(); return entityList; }
From source file:org.mifos.application.rolesandpermission.business.RoleActivityEntityIntegrationTest.java
License:Open Source License
private RoleActivityEntity getRoleActivity(Short roleId, Short activityId) { Query query = StaticHibernateUtil.getSessionTL().createQuery( "from org.mifos.application.rolesandpermission.business.RoleActivityEntity roleActivity where roleActivity.role=? and roleActivity.activity=?"); query.setShort(0, roleId); query.setShort(1, activityId);/* w w w . j a v a2 s . co m*/ RoleActivityEntity roleActivityEntity = (RoleActivityEntity) query.uniqueResult(); return roleActivityEntity; }
From source file:org.mifos.framework.components.batchjobs.helpers.ProductStatusHelper.java
License:Open Source License
@Override public void execute(long timeInMillis) throws BatchJobException { Session session;//from w w w . jav a2 s . co m String hqlUpdate; Query query; try { session = StaticHibernateUtil.getSessionTL(); StaticHibernateUtil.startTransaction(); hqlUpdate = "update PrdOfferingBO p set p.prdStatus=:activeLoanStatus " + "where p.prdType.productTypeID=:loan and p.startDate=:currentDate"; query = session.createQuery(hqlUpdate); query.setShort("activeLoanStatus", PrdStatus.LOAN_ACTIVE.getValue()); query.setShort("loan", ProductType.LOAN.getValue()); query.setDate("currentDate", new Date(timeInMillis)); query.executeUpdate(); hqlUpdate = "update PrdOfferingBO p set p.prdStatus=:inActiveLoanStatus " + "where p.prdType.productTypeID=:loan and p.endDate=:currentDate"; query = session.createQuery(hqlUpdate); query.setShort("inActiveLoanStatus", PrdStatus.LOAN_INACTIVE.getValue()); query.setShort("loan", ProductType.LOAN.getValue()); query.setDate("currentDate", new Date(timeInMillis)); query.executeUpdate(); hqlUpdate = "update PrdOfferingBO p set p.prdStatus=:activeSavingStatus " + "where p.prdType.productTypeID=:saving and p.startDate=:currentDate"; query = session.createQuery(hqlUpdate); query.setShort("activeSavingStatus", PrdStatus.SAVINGS_ACTIVE.getValue()); query.setShort("saving", ProductType.SAVINGS.getValue()); query.setDate("currentDate", new Date(timeInMillis)); query.executeUpdate(); hqlUpdate = "update PrdOfferingBO p set p.prdStatus=:inActiveSavingStatus " + "where p.prdType.productTypeID=:saving and p.endDate=:currentDate"; query = session.createQuery(hqlUpdate); query.setShort("inActiveSavingStatus", PrdStatus.SAVINGS_INACTIVE.getValue()); query.setShort("saving", ProductType.SAVINGS.getValue()); query.setDate("currentDate", new Date(timeInMillis)); query.executeUpdate(); StaticHibernateUtil.commitTransaction(); } catch (Exception e) { StaticHibernateUtil.rollbackTransaction(); throw new BatchJobException(e); } }