List of usage examples for org.hibernate Query setParameter
@SuppressWarnings("unchecked") Query<R> setParameter(int position, Object val);
From source file:br.com.easypoint.dao.CidadeDAO.java
public List<Cidade> preencheCidade(Long idEstado) throws Exception { try {// ww w. j a va 2 s . com session = HibernateUtil.getSessionFactory().openSession(); String jpql = "FROM br.com.easypoint.model.Cidade WHERE estado_id = :idEstado"; Query query = session.createQuery(jpql); query.setParameter("idEstado", idEstado); if (!query.list().isEmpty()) { return (List<Cidade>) query.list(); } } catch (Exception e) { throw e; } return null; }
From source file:br.com.easypoint.dao.EstadoDAO.java
public List<Estado> preencheEstado(Long idPais) throws Exception { try {//from w ww . ja v a2s . com session = HibernateUtil.getSessionFactory().openSession(); String jpql = "FROM br.com.easypoint.model.Estado WHERE pais_id = :idPais order by nome"; Query query = session.createQuery(jpql); query.setParameter("idPais", idPais); if (!query.list().isEmpty()) { return (List<Estado>) query.list(); } } catch (Exception e) { throw e; } return null; }
From source file:br.com.easypoint.dao.RegistroPontoDAO.java
public List<RegistroPonto> listarPorMes(int mes, Long idFuncionario) { try {/*from w w w . j av a 2 s. co m*/ session = HibernateUtil.getSessionFactory().openSession(); String jpql = "FROM br.com.easypoint.model.RegistroPonto WHERE funcionario.id = :func and MONTH(horaEntrada) = :mes"; Query query = session.createQuery(jpql); query.setParameter("mes", mes); query.setParameter("func", idFuncionario); return query.list(); } catch (Exception e) { throw e; } }
From source file:br.com.fatec.modelo.DAORepositorio.java
public T procurarPorUsuarioESenha(String login, String senha) { Query query = null; T result = null;//from w w w.j a v a2 s.co m try { query = session.createQuery("from Usuario where login = :login and senha = :senha"); query.setParameter("login", login); query.setParameter("senha", senha); result = (T) query.uniqueResult(); } catch (Exception ex) { ex.printStackTrace(); } finally { session.disconnect(); session.close(); } return result; }
From source file:br.com.fatecmogidascruzes.saph.dao.AlternativeDAO.java
@Override public List<EvaluatedItem> getEvaluatedItemsByAbility(Alternative alternative, Ability ability) { session = HSession.getSession();// w w w . j av a 2 s . co m String hql = "from EvaluatedItem ev WHERE ev IN (:evList) AND ev.ability.id = :abId"; Query q = session.createQuery(hql); q.setParameterList("evList", alternative.getEvaluatedItems()); q.setParameter("abId", ability.getId()); List entities = q.list(); session.close(); return entities; }
From source file:br.com.fatecmogidascruzes.saph.dao.AlternativeDAO.java
@Override public List<EvaluatedItem> getEvaluatedItemsByPerformance(Alternative alternative, Performance performance) { session = HSession.getSession();/* ww w . j a v a 2s. c o m*/ String hql = "from EvaluatedItem ev WHERE ev IN (:evList) AND ev.performance = :performance"; Query q = session.createQuery(hql); q.setParameterList("evList", alternative.getEvaluatedItems()); q.setParameter("performance", performance); List entities = q.list(); session.close(); return entities; }
From source file:br.com.fatecmogidascruzes.saph.dao.AlternativeDAO.java
@Override public List<Alternative> getAlternativesByKnowledgeArea(KnowledgeArea kArea) { session = HSession.getSession();/* ww w.j a v a2s . c o m*/ String hql = " SELECT alt FROM Alternative alt inner join alt.evaluatedItems ev inner join ev.ability.knowledgeAreas ka WHERE :kAreaId = ka.id"; Query q = session.createQuery(hql); q.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); q.setParameter("kAreaId", kArea.getId()); List entities = q.list(); session.close(); return entities; }
From source file:br.com.gvt.eng.vod.dao.AssetDAO.java
public List<OnDemandContentVO> findTop50() { StringBuilder aux = new StringBuilder( "select a.assetId, count(*) as total from IpvodPurchase p join p.ipvodAsset a group by a.assetId order by total desc"); Query query = getSession().createQuery(String.valueOf(aux)); query.setFirstResult(0);/*from www .j a va 2s. co m*/ query.setMaxResults(50); @SuppressWarnings("unchecked") List<Object[]> list = query.list(); List<OnDemandContentVO> vos = new ArrayList<OnDemandContentVO>(); for (Object[] obj : list) { StringBuilder hql = new StringBuilder("select "); hql.append("a.title as title, "); hql.append("a.originalTitle as originalTitle, "); hql.append("'UNKNOWN' as genre, "); hql.append("c.description as category, "); hql.append("a.subtitles as subtitle, "); hql.append("a.country as country, "); hql.append("sc.description as subCategory, "); hql.append("a.assetId as assetId, "); hql.append("a.creationDate as creationDate, "); hql.append("a.description as description, "); hql.append("a.director as director, "); hql.append("a.actors as actors, "); hql.append("a.episode as episode, "); hql.append("a.billingID as billingID, "); hql.append("a.episodeName as episodeName, "); hql.append("a.licenseWindowEnd as licenseWindowEnd, "); hql.append("a.licenseWindowStart as licenseWindowStart, "); hql.append("a.price as price, "); hql.append("a.releaseYear as releaseYear, "); hql.append("a.season as season, "); hql.append("a.languages as languages, "); hql.append("a.assetInfo as assetInfo, "); hql.append("r.rating as rating, "); hql.append("r.adult as isAdult, "); hql.append("a.totalTime as totalTime, "); hql.append("a.product as product, "); hql.append("a.screenFormat as screenFormat, "); hql.append("a.audioType as audioType, "); hql.append("a.canResume as canResume, "); hql.append("a.isHD as isHD, "); hql.append("a.isRevised as isRevised, "); hql.append("a.fileSize as fileSize, "); hql.append("a.checksum as checksum, "); hql.append("a.bitrate as bitrate, "); hql.append("a.titleAlternative as titleAlternative, "); hql.append("at.description as assetType, "); hql.append("cp.providerId as contentProvider "); hql.append( "from IpvodAsset as a left join a.ipvodCategory1 c left join a.ipvodCategory2 sc left join a.ipvodAssetType at left join a.ipvodContentProvider cp left join a.rating r "); hql.append("where a.assetId = :assetId order by a.title asc "); query = getSession().createQuery(String.valueOf(hql)); query.setParameter("assetId", obj[0]); query.setResultTransformer(new AliasToBeanResultTransformer(OnDemandContentVO.class)); OnDemandContentVO vo = (OnDemandContentVO) query.uniqueResult(); vo.setOrder(new Long(list.lastIndexOf(obj) + 1)); vos.add(list.lastIndexOf(obj), vo); } return vos; }
From source file:br.com.gvt.eng.vod.dao.AssetDAO.java
@SuppressWarnings("unchecked") public List<OnDemandContentVO> findByGenre(Long genreId) { StringBuilder hql = new StringBuilder("select "); hql.append("a.title as title, "); hql.append("a.originalTitle as originalTitle, "); hql.append("'UNKNOWN' as genre, "); hql.append("c.description as category, "); hql.append("a.subtitles as subtitle, "); hql.append("a.country as country, "); hql.append("sc.description as subCategory, "); hql.append("a.assetId as assetId, "); hql.append("a.creationDate as creationDate, "); hql.append("a.description as description, "); hql.append("a.director as director, "); hql.append("a.actors as actors, "); hql.append("a.episode as episode, "); hql.append("a.billingID as billingID, "); hql.append("a.episodeName as episodeName, "); hql.append("a.licenseWindowEnd as licenseWindowEnd, "); hql.append("a.licenseWindowStart as licenseWindowStart, "); hql.append("a.price as price, "); hql.append("a.releaseYear as releaseYear, "); hql.append("a.season as season, "); hql.append("a.languages as languages, "); hql.append("a.assetInfo as assetInfo, "); hql.append("r.rating as rating, "); hql.append("r.adult as isAdult, "); hql.append("a.totalTime as totalTime, "); hql.append("a.product as product, "); hql.append("a.screenFormat as screenFormat, "); hql.append("a.audioType as audioType, "); hql.append("a.canResume as canResume, "); hql.append("a.isHD as isHD, "); hql.append("a.isRevised as isRevised, "); hql.append("a.fileSize as fileSize, "); hql.append("a.checksum as checksum, "); hql.append("a.bitrate as bitrate, "); hql.append("a.titleAlternative as titleAlternative, "); hql.append("at.description as assetType, "); hql.append("cp.providerId as contentProvider "); hql.append(/*from w w w .j a v a 2 s.co m*/ "from IpvodAsset as a left join a.ipvodCategory1 c left join a.ipvodCategory2 sc left join a.ipvodAssetType at left join a.ipvodContentProvider cp left join a.rating r "); hql.append("where c.categoryId = :genre order by a.title asc "); Query query = getSession().createQuery(String.valueOf(hql)); query.setParameter("genre", genreId); query.setResultTransformer(new AliasToBeanResultTransformer(OnDemandContentVO.class)); return query.list(); }
From source file:br.com.gvt.eng.vod.dao.AssetDAO.java
public List<IpvodAsset> getMyContent(long userId, String assetWhere) { final int ASSET_ID = 0; final int TITLE = 1; final int DESCRIPTION = 2; final int PRICE = 3; final int RATING = 4; final int RATING_LEVEL = 5; final int LANGUAGES = 6; final int SUBTITLES = 7; final int AUDIO_TYPE = 8; final int HD_CONTENT = 9; final int PURCHASE_ID = 10; final int PURCHASE_DATE = 11; final int VALID_UNTIL = 12; final int MD1_URL = 13; final int MD2_URL = 14; final int MD3_URL = 15; final int COUNTRY = 16; final int TOTAL_TIME = 17; final int RELEASE_YEAR = 18; StringBuilder hql = new StringBuilder("select " + "unique a.asset_id, " + "a.title, " + "a.description, " + "least((select price from IPVOD_ASSET x where x.asset_id = a.asset_id),coalesce((select min(price) from IPVOD_ASSET_PACKAGE ap where ap.asset_id = a.asset_id and ap.package_id in (select package_id from IPVOD_PACKAGE_SUBSCRIPTION ps where ps.user_id = :userId)),9999)) as price, " + "r.rating, " + "r.rating_level, " + "a.languages, " + "a.subtitles, " + "a.audio_type, " + "a.hd_content, " + "p.purchase_id, " + "p.PURCHASE_DATE, " + "p.VALID_UNTIL, " + "md1.URL as md1URL, " + "md2.URL as md2URL, " + "md3.URL as md3URL, " + "a.country, " + "a.total_time, " + "a.release_year " + "from IPVOD_ASSET a " + "left join IPVOD_VISUAL_MENU_ASSET_INDEX ma on (ma.ASSET_ID = A.ASSET_ID) " + "left join IPVOD_PURCHASE p on (p.asset_id = a.asset_id and p.equipment_id in (select equipment_id from IPVOD_EQUIPMENT where user_id = :userId) and p.valid_until > sysdate) " + "left join IPVOD_MEDIA_ASSET md1 on (md1.asset_id = a.asset_id and md1.media_type_id = 1) " + "left join IPVOD_MEDIA_ASSET md2 on (md2.asset_id = a.asset_id and md2.media_type_id = 2) " + "left join IPVOD_MEDIA_ASSET md3 on (md3.asset_id = a.asset_id and md3.media_type_id = 3) " + "left join IPVOD_RATING r on (r.rating_level = a.rating_level)" + "where a.asset_id = ma.asset_id and a.license_window_end >= sysdate and a.license_window_start <= sysdate " + assetWhere);/*from www. j av a2s. co m*/ Query query = getSession().createSQLQuery(String.valueOf(hql)); query.setParameter("userId", userId); @SuppressWarnings("unchecked") List<Object[]> assets = (List<Object[]>) query.list(); List<IpvodAsset> ipvodAssets = new ArrayList<IpvodAsset>(); for (Object[] asset : assets) { IpvodAsset ipvodAsset = new IpvodAsset(); ipvodAsset.setAssetId(((BigDecimal) asset[ASSET_ID]).longValue()); ipvodAsset.setTitle((String) asset[TITLE]); ipvodAsset.setDescription((String) asset[DESCRIPTION]); ipvodAsset.setPrice(((BigDecimal) asset[PRICE]).doubleValue()); ipvodAsset.setRating(new IpvodRating()); if (asset[RATING_LEVEL] != null) { ipvodAsset.getRating().setRatingLevel(((BigDecimal) asset[RATING_LEVEL]).longValue()); ipvodAsset.getRating().setRating((String) asset[RATING]); ipvodAsset.getRating().setAdult(false); } ipvodAsset.setLanguages((String) asset[LANGUAGES]); ipvodAsset.setSubtitles((String) asset[SUBTITLES]); ipvodAsset.setAudioType((String) asset[AUDIO_TYPE]); if (((BigDecimal) asset[HD_CONTENT]).longValue() == 1) { ipvodAsset.setHD(true); } else { ipvodAsset.setHD(false); } if (asset[PURCHASE_ID] != null) { IpvodPurchase ipvodPurchase = new IpvodPurchase(); ipvodPurchase.setPurchaseId(((BigDecimal) asset[PURCHASE_ID]).longValue()); ipvodPurchase.setPurchaseDate((Date) asset[PURCHASE_DATE]); ipvodPurchase.setValidUntil((Date) asset[VALID_UNTIL]); ipvodAsset.setIpvodPurchases(new ArrayList<IpvodPurchase>()); ipvodAsset.getIpvodPurchases().add(ipvodPurchase); } ArrayList<IpvodMediaAsset> ipvodMediaAssets = new ArrayList<IpvodMediaAsset>(); if (asset[MD1_URL] != null) { IpvodMediaAsset mediaAsset = new IpvodMediaAsset(); mediaAsset.setUrl((String) asset[MD1_URL]); mediaAsset.setIpvodMediaType(new IpvodMediaType()); mediaAsset.getIpvodMediaType().setMediaTypeId(1l); ipvodMediaAssets.add(mediaAsset); } if (asset[MD2_URL] != null) { IpvodMediaAsset mediaAsset = new IpvodMediaAsset(); mediaAsset.setUrl((String) asset[MD2_URL]); mediaAsset.setIpvodMediaType(new IpvodMediaType()); mediaAsset.getIpvodMediaType().setMediaTypeId(2l); ipvodMediaAssets.add(mediaAsset); } if (asset[MD3_URL] != null) { IpvodMediaAsset mediaAsset = new IpvodMediaAsset(); mediaAsset.setUrl((String) asset[MD3_URL]); mediaAsset.setIpvodMediaType(new IpvodMediaType()); mediaAsset.getIpvodMediaType().setMediaTypeId(3l); ipvodMediaAssets.add(mediaAsset); } ipvodAsset.setIpvodMediaAssets(ipvodMediaAssets); ipvodAsset.setCountry((String) asset[COUNTRY]); ipvodAsset.setTotalTime(((BigDecimal) asset[TOTAL_TIME]).longValue()); if (asset[RELEASE_YEAR] != null) { ipvodAsset.setReleaseYear(((BigDecimal) asset[RELEASE_YEAR]).intValue()); } ipvodAsset.setIpvodAssetType(new IpvodAssetType()); ipvodAssets.add(ipvodAsset); } return ipvodAssets; }