List of usage examples for org.hibernate SQLQuery setParameter
@Override
NativeQuery<T> setParameter(int position, Date value, TemporalType temporalType);
From source file:com.dungnv.streetfood.business.ArticleBusiness.java
License:Open Source License
@Override public List<ArticleDTO> getListArticleDTOLess(String userName, String localeCode, String countryCode, String token, ArticleDTO dto, int rowStart, int maxRow, boolean isCount, String sortType, String sortFieldList) {//from www.j a v a 2 s .c o m StringBuilder sbQuery = new StringBuilder(); List<Object> listParam = new ArrayList<>(); List<Type> listType = new ArrayList<>(); if (isCount) { sbQuery.append(" select count(a.id) as id from article a where 1=1 "); } else { sbQuery.append(" select a.id"); sbQuery.append(" , a.title"); if (dto == null || !"1".equals(dto.getIsGetOnlyIdentified())) { sbQuery.append(" , a.short_content shortContent"); sbQuery.append(" , a.view_count viewCount"); sbQuery.append(" , g.id imageId"); sbQuery.append(" , g.url imageUrl"); } sbQuery.append(" from article a left outer join img g on a.id = g.article_id and g.orders = 1"); sbQuery.append(" where 1 = 1"); } if (dto != null) { StringUtils.trimString(dto, false); if (!StringUtils.isNullOrEmpty(dto.getId())) { sbQuery.append(" AND a.id = ?"); listParam.add(Long.valueOf(dto.getId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getRestaurantId())) { sbQuery.append( " AND a.id in ( select article_id from restaurant_article where restaurant_id = ? ) "); listParam.add(Long.valueOf(dto.getRestaurantId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getNotRestaurantId())) { sbQuery.append( " AND a.id not in ( select article_id from restaurant_article where restaurant_id = ? ) "); listParam.add(Long.valueOf(dto.getNotRestaurantId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getDishId())) { sbQuery.append(" AND a.id in ( select article_id from dish_article where dish_id = ? ) "); listParam.add(Long.valueOf(dto.getDishId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getNotDishId())) { sbQuery.append(" AND a.id not in ( select article_id from dish_article where dish_id = ? ) "); listParam.add(Long.valueOf(dto.getNotDishId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getTitle())) { sbQuery.append(" AND lower(a.title) like ? "); listParam.add("%" + dto.getTitle().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getShortContent())) { sbQuery.append(" AND lower(a.short_content) like ? "); listParam.add("%" + dto.getShortContent().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getContent())) { sbQuery.append(" AND lower(a.content) like ? "); listParam.add("%" + dto.getContent().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (dto.getListTag() != null && !dto.getListTag().isEmpty()) { sbQuery.append(" AND a.id in (select article_id from tag_article where tag_id in "); sbQuery.append(QueryUtil.getParameterHolderString(dto.getListTag().size())); sbQuery.append(" )"); List<String> listTag = dto.getListTag(); for (String tagId : listTag) { listParam.add(Long.valueOf(tagId)); listType.add(LongType.INSTANCE); } } } if (!isCount) { sbQuery.append(" order by a.title DESC"); if (maxRow != 0) { sbQuery.append(" limit ?, ?"); listParam.add(rowStart); listType.add(IntegerType.INSTANCE); listParam.add(maxRow); listType.add(IntegerType.INSTANCE); } } SQLQuery query = gettDAO().getSession().createSQLQuery(sbQuery.toString()); query.addScalar("id", StringType.INSTANCE); if (!isCount) { query.addScalar("title", StringType.INSTANCE); if (dto == null || !"1".equals(dto.getIsGetOnlyIdentified())) { query.addScalar("shortContent", StringType.INSTANCE); query.addScalar("viewCount", StringType.INSTANCE); query.addScalar("imageId", StringType.INSTANCE); query.addScalar("imageUrl", StringType.INSTANCE); } } query.setResultTransformer(Transformers.aliasToBean(ArticleDTO.class)); for (int i = 0; i < listParam.size(); i++) { query.setParameter(i, listParam.get(i), listType.get(i)); } List<ArticleDTO> list = query.list(); return list; }
From source file:com.dungnv.streetfood.business.DishBusiness.java
License:Open Source License
@Override public List<DishDTO> getListDishDTOLess(String userName, String localeCode, String countryCode, String token, DishDTO dto, int rowStart, int maxRow, boolean isCount, String sortType, String sortFieldList) { StringBuilder sbQuery = new StringBuilder(); List<Object> listParam = new ArrayList<>(); List<Type> listType = new ArrayList<>(); if (isCount) { sbQuery.append(" select count(c.id) as id from dish c where 1=1 "); } else {/*from www. j ava 2 s .co m*/ sbQuery.append(" select c.id , c.name"); if (dto == null || !"1".equals(dto.getIsGetOnlyIdentified())) { sbQuery.append(" , c.short_description shortDescription"); sbQuery.append(" , c.dish_status dishStatus"); sbQuery.append(" , c.view_count viewCount"); sbQuery.append(" , c.comment_count commentCount "); sbQuery.append(" , c.share_count shareCount"); sbQuery.append(" , c.rating "); sbQuery.append(" , g.id imageId"); sbQuery.append(" , g.url imageUrl"); } sbQuery.append(" from dish c left outer join img g on c.id = g.dish_id and g.orders = 1 "); sbQuery.append(" where 1=1"); } if (dto != null) { StringUtils.trimString(dto, false); if (!StringUtils.isNullOrEmpty(dto.getId())) { sbQuery.append(" AND c.id = ?"); listParam.add(Long.valueOf(dto.getId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getName())) { sbQuery.append(" AND lower(c.name) like ? "); listParam.add("%" + dto.getName().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getCategoryId())) { sbQuery.append(" AND c.id in ( select dish_id from category_dish where category_id = ? ) "); listParam.add(Long.valueOf(dto.getCategoryId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getNotCategoryId())) { sbQuery.append(" AND c.id not in ( select dish_id from category_dish where category_id = ? ) "); listParam.add(Long.valueOf(dto.getNotCategoryId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getArticleId())) { sbQuery.append(" AND c.id in ( select dish_id from dish_article where article_id = ? ) "); listParam.add(Long.valueOf(dto.getArticleId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getNotArticleId())) { sbQuery.append(" AND c.id not in ( select dish_id from dish_article where article_id = ? ) "); listParam.add(Long.valueOf(dto.getNotArticleId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getRestaurantId())) { sbQuery.append( " AND c.id in ( select dish_id from restaurant_dish_detail where restaurant_id = ? ) "); listParam.add(Long.valueOf(dto.getRestaurantId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getNotRestaurantId())) { sbQuery.append( " AND c.id not in ( select dish_id from restaurant_dish_detail where restaurant_id = ? ) "); listParam.add(Long.valueOf(dto.getNotRestaurantId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getDishStatus())) { sbQuery.append(" AND c.dish_status = ? "); listParam.add(Long.valueOf(dto.getDishStatus())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getShortDescription())) { sbQuery.append(" AND lower(c.description) like ? "); listParam.add("%" + dto.getShortDescription().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getLongDescription())) { sbQuery.append(" AND lower(c.long_description) like ? "); listParam.add("%" + dto.getLongDescription().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getViewCountFrom())) { sbQuery.append(" AND c.view_count >= ? "); listParam.add(Long.valueOf(dto.getViewCountFrom())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getViewCountTo())) { sbQuery.append(" AND c.view_count <= ? "); listParam.add(Long.valueOf(dto.getViewCountTo())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getCommentCountFrom())) { sbQuery.append(" AND c.comment_count >= ? "); listParam.add(Long.valueOf(dto.getCommentCountFrom())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getCommentCountTo())) { sbQuery.append(" AND c.comment_count <= ? "); listParam.add(Long.valueOf(dto.getCommentCountTo())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getShareCountFrom())) { sbQuery.append(" AND c.share_count >= ? "); listParam.add(Long.valueOf(dto.getShareCountFrom())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getShareCountTo())) { sbQuery.append(" AND c.share_count <= ? "); listParam.add(Long.valueOf(dto.getShareCountTo())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getRatingFrom())) { sbQuery.append(" AND c.rating >= ? "); listParam.add(Double.valueOf(dto.getRatingFrom())); listType.add(DoubleType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getRatingTo())) { sbQuery.append(" AND c.rating <= ? "); listParam.add(Double.valueOf(dto.getRatingTo())); listType.add(DoubleType.INSTANCE); } if (dto.getListTag() != null && !dto.getListTag().isEmpty()) { sbQuery.append(" AND c.id in (select dish_id from tag_dish where tag_id in "); sbQuery.append(QueryUtil.getParameterHolderString(dto.getListTag().size())); sbQuery.append(" )"); List<String> listTag = dto.getListTag(); for (String tagId : listTag) { listParam.add(Long.valueOf(tagId)); listType.add(LongType.INSTANCE); } } if (dto.getListNotLocale() != null && !dto.getListNotLocale().isEmpty()) { sbQuery.append(" AND not exists (select l.dish_id from dish_language l where l.language_code in "); sbQuery.append(QueryUtil.getParameterHolderString(dto.getListNotLocale().size())); sbQuery.append(" AND l.dish_id = c.id )"); List<String> listNotLocale = dto.getListNotLocale(); for (String notLocale : listNotLocale) { listParam.add(notLocale); listType.add(StringType.INSTANCE); } } if (dto.getListLocale() != null && !dto.getListLocale().isEmpty()) { for (String locale : dto.getListLocale()) { sbQuery.append(" AND exists (select l.dish_id from dish_language l where l.language_code = ? "); sbQuery.append(" AND l.dish_id = c.id )"); listParam.add(locale); listType.add(StringType.INSTANCE); } } } if (!isCount) { sbQuery.append(" order by c.name DESC"); if (maxRow != 0) { sbQuery.append(" limit ?, ?"); listParam.add(rowStart); listType.add(IntegerType.INSTANCE); listParam.add(maxRow); listType.add(IntegerType.INSTANCE); } } SQLQuery query = gettDAO().getSession().createSQLQuery(sbQuery.toString()); query.addScalar("id", StringType.INSTANCE); if (!isCount) { query.addScalar("name", StringType.INSTANCE); if (dto == null || !"1".equals(dto.getIsGetOnlyIdentified())) { query.addScalar("shortDescription", StringType.INSTANCE); query.addScalar("dishStatus", StringType.INSTANCE); query.addScalar("viewCount", StringType.INSTANCE); query.addScalar("commentCount", StringType.INSTANCE); query.addScalar("shareCount", StringType.INSTANCE); query.addScalar("rating", StringType.INSTANCE); query.addScalar("imageId", StringType.INSTANCE); query.addScalar("imageUrl", StringType.INSTANCE); } } query.setResultTransformer(Transformers.aliasToBean(DishDTO.class)); for (int i = 0; i < listParam.size(); i++) { query.setParameter(i, listParam.get(i), listType.get(i)); } List<DishDTO> list = query.list(); return list; }
From source file:com.dungnv.streetfood.business.RestaurantBusiness.java
License:Open Source License
@Override public List<RestaurantDTO> getListRestaurantDTOLess(String userName, String localeCode, String countryCode, String token, RestaurantDTO dto, int rowStart, int maxRow, boolean isCount, String sortType, String sortFieldList) {// w w w.j av a 2 s . co m StringBuilder sbQuery = new StringBuilder(); List<Object> listParam = new ArrayList<>(); List<Type> listType = new ArrayList<>(); if (isCount) { sbQuery.append(" select count(r.id) as id from restaurant r where 1=1 "); } else { sbQuery.append(" select "); sbQuery.append(" r.id"); sbQuery.append(" , r.name"); if (dto == null || !"1".equals(dto.getIsGetOnlyIdentified())) { sbQuery.append(" , r.address"); sbQuery.append(" , r.restaurant_status restaurantStatus"); sbQuery.append(" , r.view_count viewCount"); sbQuery.append(" , r.comment_count commentCount"); sbQuery.append(" , r.share_count shareCount"); sbQuery.append(" , r.rating"); sbQuery.append(" , g.id imageId"); sbQuery.append(" , g.url imageUrl"); } sbQuery.append(" from restaurant r left outer join img g on r.id = g.restaurant_id and g.orders = 1"); sbQuery.append(" where 1 = 1"); } if (dto != null) { StringUtils.trimString(dto, false); if (!StringUtils.isNullOrEmpty(dto.getId())) { sbQuery.append(" AND r.id = ?"); listParam.add(Long.valueOf(dto.getId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getArticleId())) { sbQuery.append( " AND r.id in ( select restaurant_id from restaurant_article where article_id = ? ) "); listParam.add(Long.valueOf(dto.getArticleId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getNotArticleId())) { sbQuery.append( " AND r.id not in ( select restaurant_id from restaurant_article where article_id = ? ) "); listParam.add(Long.valueOf(dto.getNotArticleId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getDishId())) { sbQuery.append( " AND r.id in ( select restaurant_id from restaurant_dish_detail where dish_id = ? ) "); listParam.add(Long.valueOf(dto.getDishId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getNotDishId())) { sbQuery.append( " AND r.id not in ( select restaurant_id from restaurant_dish_detail where dish_id = ? ) "); listParam.add(Long.valueOf(dto.getNotDishId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getName())) { sbQuery.append(" AND lower(r.name) like ? "); listParam.add("%" + dto.getName().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getAddress())) { sbQuery.append(" AND lower(r.address) like ? "); listParam.add("%" + dto.getAddress().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getIntroduce())) { sbQuery.append(" AND lower(r.introduce) like ? "); listParam.add("%" + dto.getIntroduce().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getPhoneNumber())) { sbQuery.append(" AND lower(r.phone_number) like ? "); listParam.add("%" + dto.getPhoneNumber().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getCapacity())) { sbQuery.append(" AND lower(r.capacity) like ? "); listParam.add("%" + dto.getCapacity().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getRestaurantStatus())) { sbQuery.append(" AND r.restaurant_status = ? "); listParam.add(Long.valueOf(dto.getRestaurantStatus())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getCarParking())) { sbQuery.append(" AND r.car_parking = ? "); listParam.add(Long.valueOf(dto.getCarParking())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getMotobikeParking())) { sbQuery.append(" AND r.motobike_parking = ? "); listParam.add(Long.valueOf(dto.getMotobikeParking())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getViewCountFrom())) { sbQuery.append(" AND r.view_count >= ? "); listParam.add(Long.valueOf(dto.getViewCountFrom())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getViewCountTo())) { sbQuery.append(" AND r.view_count <= ? "); listParam.add(Long.valueOf(dto.getViewCountTo())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getCommentCountFrom())) { sbQuery.append(" AND r.comment_count >= ? "); listParam.add(Long.valueOf(dto.getCommentCountFrom())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getCommentCountTo())) { sbQuery.append(" AND r.comment_count <= ? "); listParam.add(Long.valueOf(dto.getCommentCountTo())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getShareCountFrom())) { sbQuery.append(" AND r.share_count >= ? "); listParam.add(Long.valueOf(dto.getShareCountFrom())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getShareCountTo())) { sbQuery.append(" AND r.share_count <= ? "); listParam.add(Long.valueOf(dto.getShareCountTo())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getRatingFrom())) { sbQuery.append(" AND r.rating >= ? "); listParam.add(Double.valueOf(dto.getRatingFrom())); listType.add(DoubleType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getRatingTo())) { sbQuery.append(" AND r.rating <= ? "); listParam.add(Double.valueOf(dto.getRatingTo())); listType.add(DoubleType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getWaitingTimeFrom())) { sbQuery.append(" AND r.waiting_time >= ? "); listParam.add(Long.valueOf(dto.getWaitingTimeFrom())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getWaitingTimeTo())) { sbQuery.append(" AND r.waiting_time <= ? "); listParam.add(Long.valueOf(dto.getWaitingTimeTo())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getOperatingTimeStart())) { try { sbQuery.append(" AND r.operating_time_start >= ? "); listParam.add(DateTimeUtils.convertStringToTime(dto.getOperatingTimeStart(), ParamUtils.HHmm)); listType.add(TimeType.INSTANCE); } catch (Exception ex) { Logger.getLogger(RestaurantBusiness.class.getName()).log(Level.SEVERE, null, ex); } } if (!StringUtils.isNullOrEmpty(dto.getOperatingTimeEnd())) { try { sbQuery.append(" AND r.operating_time_end <= ? "); listParam.add(DateTimeUtils.convertStringToTime(dto.getOperatingTimeEnd(), ParamUtils.HHmm)); listType.add(TimeType.INSTANCE); } catch (Exception ex) { Logger.getLogger(RestaurantBusiness.class.getName()).log(Level.SEVERE, null, ex); } } if (dto.getListTag() != null && !dto.getListTag().isEmpty()) { sbQuery.append(" AND r.id in (select restaurant_id from tag_restaurant where tag_id in "); sbQuery.append(QueryUtil.getParameterHolderString(dto.getListTag().size())); sbQuery.append(" )"); List<String> listTag = dto.getListTag(); for (String tagId : listTag) { listParam.add(Long.valueOf(tagId)); listType.add(LongType.INSTANCE); } } if (dto.getListNotLocale() != null && !dto.getListNotLocale().isEmpty()) { sbQuery.append( " AND not exists (select l.restaurant_id from restaurant_language l where l.language_code in "); sbQuery.append(QueryUtil.getParameterHolderString(dto.getListNotLocale().size())); sbQuery.append(" AND l.restaurant_id = r.id )"); List<String> listNotLocale = dto.getListNotLocale(); for (String notLocale : listNotLocale) { listParam.add(notLocale); listType.add(StringType.INSTANCE); } } if (dto.getListLocale() != null && !dto.getListLocale().isEmpty()) { for (String locale : dto.getListLocale()) { sbQuery.append( " AND exists (select l.restaurant_id from restaurant_language l where l.language_code = ? "); sbQuery.append(" AND l.restaurant_id = r.id )"); listParam.add(locale); listType.add(StringType.INSTANCE); } } } if (!isCount) { sbQuery.append(" order by r.name DESC"); if (maxRow != 0) { sbQuery.append(" limit ?, ?"); listParam.add(rowStart); listType.add(IntegerType.INSTANCE); listParam.add(maxRow); listType.add(IntegerType.INSTANCE); } } SQLQuery query = gettDAO().getSession().createSQLQuery(sbQuery.toString()); query.addScalar("id", StringType.INSTANCE); if (!isCount) { query.addScalar("name", StringType.INSTANCE); if (dto == null || !"1".equals(dto.getIsGetOnlyIdentified())) { query.addScalar("address", StringType.INSTANCE); query.addScalar("restaurantStatus", StringType.INSTANCE); query.addScalar("viewCount", StringType.INSTANCE); query.addScalar("commentCount", StringType.INSTANCE); query.addScalar("shareCount", StringType.INSTANCE); query.addScalar("rating", StringType.INSTANCE); query.addScalar("imageId", StringType.INSTANCE); query.addScalar("imageUrl", StringType.INSTANCE); } } query.setResultTransformer(Transformers.aliasToBean(RestaurantDTO.class)); for (int i = 0; i < listParam.size(); i++) { query.setParameter(i, listParam.get(i), listType.get(i)); } List<RestaurantDTO> list = query.list(); return list; }
From source file:com.dungnv.streetfood.business.SlideShowBusiness.java
License:Open Source License
@Override public List<SlideShowDTO> getListSlideShowDTOLess(String userName, String localeCode, String countryCode, String token, SlideShowDTO dto, int rowStart, int maxRow, boolean isCount, String sortType, String sortFieldList) {//from w w w. j a v a 2s. c om StringBuilder sbQuery = new StringBuilder(); List<Object> listParam = new ArrayList<>(); List<Type> listType = new ArrayList<>(); if (isCount) { sbQuery.append(" select count(a.id) as id from slide_show a where 1=1 "); } else { sbQuery.append(" select a.id "); sbQuery.append(" , a.url"); sbQuery.append(" , a.name"); sbQuery.append(" , a.description"); sbQuery.append(" , a.orders as 'order'"); sbQuery.append(" , a.valid_from_gmt validFromGmt "); sbQuery.append(" , a.valid_to_gmt validToGmt"); sbQuery.append(" , g.id imageId"); sbQuery.append(" , g.url imageUrl"); sbQuery.append(" from slide_show a left outer join img g on a.id = g.slide_show_id and g.orders = 1 "); sbQuery.append(" where 1=1"); } if (dto != null) { StringUtils.trimString(dto, false); if (!StringUtils.isNullOrEmpty(dto.getId())) { sbQuery.append(" AND a.id = ?"); listParam.add(Long.valueOf(dto.getId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(dto.getName())) { sbQuery.append(" AND lower(a.name) like ? "); listParam.add("%" + dto.getName().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } } if (!isCount) { sbQuery.append(" order by a.orders DESC"); if (maxRow != 0) { sbQuery.append(" limit ?, ?"); listParam.add(rowStart); listType.add(IntegerType.INSTANCE); listParam.add(maxRow); listType.add(IntegerType.INSTANCE); } } SQLQuery query = gettDAO().getSession().createSQLQuery(sbQuery.toString()); query.addScalar("id", StringType.INSTANCE); if (!isCount) { query.addScalar("url", StringType.INSTANCE); query.addScalar("name", StringType.INSTANCE); query.addScalar("description", StringType.INSTANCE); query.addScalar("order", StringType.INSTANCE); query.addScalar("validFromGmt", StringType.INSTANCE); query.addScalar("validToGmt", StringType.INSTANCE); query.addScalar("imageId", StringType.INSTANCE); query.addScalar("imageUrl", StringType.INSTANCE); } query.setResultTransformer(Transformers.aliasToBean(SlideShowDTO.class)); for (int i = 0; i < listParam.size(); i++) { query.setParameter(i, listParam.get(i), listType.get(i)); } List<SlideShowDTO> list = query.list(); return list; }
From source file:com.dungnv.streetfood.dao.CategoryDAO.java
License:Open Source License
public List<CategoryDTO> getListCategoryDTOLess(CategoryDTO categoryDTO, int rowStart, int maxRow, boolean isCount, String sortType, String sortFieldList) { StringBuilder sbQuery = new StringBuilder(); List<Object> listParam = new ArrayList<>(); List<Type> listType = new ArrayList<>(); if (isCount) { sbQuery.append(" select count(c.id) as id from Category c where 1=1 "); } else {/*w w w . jav a 2 s.c o m*/ sbQuery.append(" select c.id "); sbQuery.append(" , c.name"); if (categoryDTO == null || !"1".equals(categoryDTO.getIsGetOnlyIdentified())) { sbQuery.append(" , c.description"); sbQuery.append(" , c.category_status categoryStatus"); sbQuery.append(" , g.id imageId"); sbQuery.append(" , g.url imageUrl"); } sbQuery.append(" from Category c "); sbQuery.append(" left outer join img g on c.id = g.dish_group_id and g.orders = 1 "); sbQuery.append(" where 1=1"); } if (categoryDTO != null) { StringUtils.trimString(categoryDTO, false); if (!StringUtils.isNullOrEmpty(categoryDTO.getId())) { sbQuery.append(" AND c.id = ?"); listParam.add(Long.valueOf(categoryDTO.getId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(categoryDTO.getDishId())) { sbQuery.append(" AND c.id in ( select category_id from category_dish where dish_id = ? ) "); listParam.add(Long.valueOf(categoryDTO.getDishId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(categoryDTO.getNotDishId())) { sbQuery.append(" AND c.id not in ( select category_id from category_dish where dish_id = ? ) "); listParam.add(Long.valueOf(categoryDTO.getNotDishId())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(categoryDTO.getName())) { sbQuery.append(" AND lower(c.name) like ? "); listParam.add("%" + categoryDTO.getName().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (!StringUtils.isNullOrEmpty(categoryDTO.getCategoryStatus())) { sbQuery.append(" AND c.category_status = ? "); listParam.add(Long.valueOf(categoryDTO.getCategoryStatus())); listType.add(LongType.INSTANCE); } if (!StringUtils.isNullOrEmpty(categoryDTO.getDescription())) { sbQuery.append(" AND lower(c.description) like ? "); listParam.add("%" + categoryDTO.getDescription().toLowerCase() + "%"); listType.add(StringType.INSTANCE); } if (categoryDTO.getListTag() != null && !categoryDTO.getListTag().isEmpty()) { sbQuery.append(" AND c.id in (select category_id from tag_category where tag_id in "); sbQuery.append(QueryUtil.getParameterHolderString(categoryDTO.getListTag().size())); sbQuery.append(" )"); List<String> listTag = categoryDTO.getListTag(); for (String tagId : listTag) { listParam.add(Long.valueOf(tagId)); listType.add(LongType.INSTANCE); } } if (categoryDTO.getListNotLocale() != null && !categoryDTO.getListNotLocale().isEmpty()) { sbQuery.append( " AND not exists (select l.dish_group_id from dish_group_langage l where l.language_code in "); sbQuery.append(QueryUtil.getParameterHolderString(categoryDTO.getListNotLocale().size())); sbQuery.append(" AND l.dish_group_id = c.id )"); List<String> listNotLocale = categoryDTO.getListNotLocale(); for (String notLocale : listNotLocale) { listParam.add(notLocale); listType.add(StringType.INSTANCE); } } if (categoryDTO.getListLocale() != null && !categoryDTO.getListLocale().isEmpty()) { for (String locale : categoryDTO.getListLocale()) { sbQuery.append( " AND exists (select l.dish_group_id from dish_group_langage l where l.language_code = ? "); sbQuery.append(" AND l.dish_group_id = c.id )"); listParam.add(locale); listType.add(StringType.INSTANCE); } } } if (!isCount) { sbQuery.append(" order by c.name DESC"); if (maxRow != 0) { sbQuery.append(" limit ?, ?"); listParam.add(rowStart); listType.add(IntegerType.INSTANCE); listParam.add(maxRow); listType.add(IntegerType.INSTANCE); } } SQLQuery query = getSession().createSQLQuery(sbQuery.toString()); query.addScalar("id", StringType.INSTANCE); if (!isCount) { query.addScalar("name", StringType.INSTANCE); if (categoryDTO == null || !"1".equals(categoryDTO.getIsGetOnlyIdentified())) { query.addScalar("description", StringType.INSTANCE); query.addScalar("categoryStatus", StringType.INSTANCE); query.addScalar("imageId", StringType.INSTANCE); query.addScalar("imageUrl", StringType.INSTANCE); } } query.setResultTransformer(Transformers.aliasToBean(CategoryDTO.class)); for (int i = 0; i < listParam.size(); i++) { query.setParameter(i, listParam.get(i), listType.get(i)); } List<CategoryDTO> list = query.list(); StringUtils.escapeHTMLString(list); return list; }
From source file:com.formkiq.core.dao.SystemDaoImpl.java
License:Apache License
@SuppressWarnings({ "unchecked", "resource" }) @Override/* w w w . j a v a 2 s. c om*/ public List<SystemPropertyDTO> getProperties(final User user, final String key) { String sql = "select p.key as key, p.value as value, " + "p.user_id as \"user.uuid\"," + "u.email as \"user.email\"" + " from system_properties p " + " left join users u on u.user_id=p.user_id"; if (user != null || StringUtils.hasText(key)) { sql += " where "; } if (user != null) { sql += " p.user_id=:user"; } if (StringUtils.hasText(key)) { sql += user != null ? " and " : " "; sql += "key=:key"; } sql += " order by p.key "; Session session = getEntityManager().unwrap(Session.class); SQLQuery q = session.createSQLQuery(sql).addScalar("key", StringType.INSTANCE) .addScalar("value", StringType.INSTANCE).addScalar("user.email", StringType.INSTANCE) .addScalar("user.uuid", PostgresUUIDType.INSTANCE); if (user != null) { q.setParameter("user", user.getUserid(), PostgresUUIDType.INSTANCE); } if (StringUtils.hasText(key)) { q.setParameter("key", key); } List<Map<String, Object>> maplist = q.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE) .list(); List<SystemPropertyDTO> list = transformMapListToObject(maplist, SystemPropertyDTO.class); return list; }
From source file:com.timesoft.kaitoo.ws.common.CoreContent.java
public static void fildHibernateParameter(final SQLQuery sqlQuery, final Map<String, Object> paramMap) throws HibernateException { Set<String> set = paramMap.keySet(); for (Iterator<String> iter = set.iterator(); iter.hasNext();) { String paramName = iter.next(); Object paramValue = paramMap.get(paramName); if (paramValue != null) { if (paramValue instanceof java.lang.String) { sqlQuery.setParameter(paramName, paramValue.toString().trim(), StringType.INSTANCE); } else if (paramValue instanceof java.lang.Character) { sqlQuery.setParameter(paramName, paramValue, CharacterType.INSTANCE); } else if (paramValue instanceof java.lang.Integer) { sqlQuery.setParameter(paramName, paramValue, IntegerType.INSTANCE); } else if (paramValue instanceof java.util.Date) { sqlQuery.setParameter(paramName, paramValue, DateType.INSTANCE); } else if (paramValue instanceof java.lang.Long) { sqlQuery.setParameter(paramName, paramValue, LongType.INSTANCE); } else if (paramValue instanceof java.sql.Timestamp) { sqlQuery.setParameter(paramName, paramValue, TimestampType.INSTANCE); } else if (paramValue instanceof java.lang.Boolean) { sqlQuery.setParameter(paramName, paramValue, BooleanType.INSTANCE); } else if (paramValue instanceof java.lang.Float) { sqlQuery.setParameter(paramName, paramValue, FloatType.INSTANCE); } else if (paramValue instanceof java.lang.Double) { sqlQuery.setParameter(paramName, paramValue, DoubleType.INSTANCE); } else if (paramValue instanceof java.lang.Byte) { sqlQuery.setParameter(paramName, paramValue, ByteType.INSTANCE); } else if (paramValue instanceof java.util.Calendar) { sqlQuery.setParameter(paramName, paramValue, CalendarType.INSTANCE); }// ww w. j a va2 s.c o m } } }
From source file:es.emergya.bbdd.dao.HistoricoGPSHome.java
License:Open Source License
@SuppressWarnings("unchecked") @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = true, rollbackFor = Throwable.class) private List<String> calculateRecursos(Date inicio, Date fin, String flotas, List<String> recursosYaEncontrados) { int i;//from w w w . j av a 2 s .c o m StringBuffer sb = new StringBuffer(); sb.append("select distinct(rec.recurso) as nombreRecurso from "); sb.append(" (select st_collect(geom) as geom, recurso from historico_gps where "); sb.append(flotas); if (recursosYaEncontrados.size() > 0) { if (flotas.length() > 0) { sb.append(" and "); } sb.append("recurso not in ('"); sb.append(recursosYaEncontrados.get(0)); for (i = 1; i < recursosYaEncontrados.size(); i++) { sb.append("', '").append(recursosYaEncontrados.get(i)); } sb.append("') "); } if (inicio != null) { sb.append(" and marca_temporal >= :FECHA_INICIO "); } if (fin != null) { sb.append(" and marca_temporal <= :FECHA_FIN "); } sb.append(" group by recurso) as rec"); SQLQuery q = getSession().createSQLQuery(sb.toString()); if (inicio != null) { q.setParameter("FECHA_INICIO", inicio, Hibernate.TIMESTAMP); } if (fin != null) { q.setParameter("FECHA_FIN", fin, Hibernate.TIMESTAMP); } q.addScalar("nombreRecurso", Hibernate.STRING); log.debug(sb.toString() + " => " + inicio + " " + fin); List<String> result = q.list(); return result; }