List of usage examples for org.hibernate Query setString
@Deprecated @SuppressWarnings("unchecked") default Query<R> setString(String name, String val)
From source file:br.edu.ifes.sr.dw.persistencia.ProdutoDaoHibernate.java
@Override public List<Produto> listarInstituicao(String email) { session.getTransaction().begin();/* w w w .j a v a2s .c o m*/ String hql = "select p from Produto p inner join p.instituicao i where i.email = :email"; Query consulta = session.createQuery(hql); consulta.setString("email", email); List<Produto> lista = (List<Produto>) consulta.list(); session.getTransaction().commit(); session.close(); return lista; }
From source file:br.eti.sw.pontocerto.dao.impl.UsuarioDAOHibernate.java
@Override public Usuario buscarPorEmail(String email) { String hql = "from Usuario u where u.email = :email"; Query consulta = this.session.createQuery(hql); consulta.setString("email", email); return (Usuario) consulta.uniqueResult(); }
From source file:br.eti.sw.pontocerto.dao.impl.UsuarioDAOHibernate.java
@Override public Usuario buscarPorLogin(String login) { String hql = "from Usuario u where u.login = :login"; Query consulta = this.session.createQuery(hql); consulta.setString("login", login); return (Usuario) consulta.uniqueResult(); }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<CpOrgao> consultarPorFiltro(final CpOrgaoDaoFiltro o, final int offset, final int itemPagina) { try {//from w w w . j a va2s. c om final Query query = getSessao().getNamedQuery("consultarPorFiltroCpOrgao"); if (offset > 0) { query.setFirstResult(offset); } if (itemPagina > 0) { query.setMaxResults(itemPagina); } String s = o.getNome(); if (s != null) s = s.replace(' ', '%'); query.setString("nome", s); final List<CpOrgao> l = query.list(); return l; } catch (final NullPointerException e) { return null; } }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
@SuppressWarnings("unchecked") public CpOrgao consultarPorSigla(final CpOrgao o) { final Query query = getSessao().getNamedQuery("consultarPorSiglaCpOrgao"); query.setString("siglaOrgao", o.getSiglaOrgao()); final List<CpOrgao> l = query.list(); if (l.size() != 1) return null; return l.get(0); }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
@SuppressWarnings("unchecked") public CpServico consultarPorSigla(final CpServico o) { final Query query = getSessao().getNamedQuery("consultarPorSiglaCpServico"); query.setString("siglaServico", o.getSiglaServico()); query.setLong("idServicoPai", o.getCpServicoPai() == null ? 0 : o.getCpServicoPai().getIdServico()); // Renato: Comentei a linha abaixo pois nao entendi porque foi feito // dessa forma. // query.setFlushMode(FlushMode.MANUAL); query.setCacheable(true);/*from ww w . ja v a 2 s . c o m*/ query.setCacheRegion(CACHE_QUERY_HOURS); final List<CpServico> l = query.list(); if (l.size() != 1) return null; return l.get(0); }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
@SuppressWarnings("unchecked") public CpServico consultarCpServicoPorChave(String chave) { // Cria uma cache region especifica da classe para garantir que os // objetos armazenados por uma aplicacacao seja recuperados por outra. // Isso causa ClassCastException. final String cRegion = CACHE_CORPORATIVO + "_" + this.getClass().getSimpleName(); Cache cache = CacheManager.getInstance().getCache(cRegion); if (cache == null) { CacheManager manager = CacheManager.getInstance(); manager.addCache(cRegion);/* w w w .ja v a2s . co m*/ cache = manager.getCache(cRegion); CacheConfiguration config; config = cache.getCacheConfiguration(); config.setEternal(true); config.setMaxElementsInMemory(10000); config.setOverflowToDisk(false); config.setMaxElementsOnDisk(0); } Element element; if ((element = cache.get(chave)) != null) { return (CpServico) element.getValue(); } StringBuilder sb = new StringBuilder(50); boolean supress = false; for (int i = 0; i < chave.length(); i++) { final char ch = chave.charAt(i); if (ch == ';') { sb.append('-'); supress = false; continue; } if (ch == ':') { supress = true; continue; } if (!supress) sb.append(ch); } String sigla = sb.toString(); final Query query = getSessao().getNamedQuery("consultarPorSiglaStringCpServico"); query.setString("siglaServico", sigla); query.setCacheable(true); query.setCacheRegion(CACHE_QUERY_HOURS); final List<CpServico> l = query.list(); if (l.size() != 1) return null; // Forca a carga de algums campos para garantir o lazy load. CpServico srv = (CpServico) l.get(0).getImplementation(); Object o1 = srv.getCpServicoPai().getDescricao(); Object o2 = srv.getCpTipoServico().getDscTpServico(); cache.put(new Element(chave, srv)); return l.get(0); }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
public int consultarQuantidade(final CpOrgaoDaoFiltro o) { try {/* w w w .j av a 2s . com*/ final Query query = getSessao().getNamedQuery("consultarQuantidadeCpOrgao"); String s = o.getNome(); if (s != null) s = s.replace(' ', '%'); query.setString("nome", s); final int l = ((Long) query.uniqueResult()).intValue(); return l; } catch (final NullPointerException e) { return 0; } }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<CpOrgaoUsuario> consultarPorFiltro(final CpOrgaoUsuarioDaoFiltro o, final int offset, final int itemPagina) { try {/*from w w w .j av a 2s. c o m*/ final Query query = getSessao().getNamedQuery("consultarPorFiltroCpOrgao"); if (offset > 0) { query.setFirstResult(offset); } if (itemPagina > 0) { query.setMaxResults(itemPagina); } String s = o.getNome(); if (s != null) s = s.replace(' ', '%'); query.setString("nome", s); query.setCacheable(true); query.setCacheRegion(CACHE_QUERY_HOURS); final List<CpOrgaoUsuario> l = query.list(); return l; } catch (final NullPointerException e) { return null; } }
From source file:br.gov.jfrj.siga.dp.dao.CpDao.java
License:Open Source License
@SuppressWarnings("unchecked") public CpOrgaoUsuario consultarPorSigla(final CpOrgaoUsuario o) { final Query query = getSessao().getNamedQuery("consultarSiglaOrgaoUsuario"); query.setString("sigla", o.getSiglaOrgaoUsu()); query.setCacheable(true);/*w w w . j a v a2 s. c o m*/ query.setCacheRegion(CACHE_QUERY_HOURS); final List<CpOrgaoUsuario> l = query.list(); if (l.size() != 1) return null; return l.get(0); }