List of usage examples for org.hibernate SQLQuery setResultTransformer
@Deprecated Query<R> setResultTransformer(ResultTransformer transformer);
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) {/*from www . j ava 2s . c o 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.RestaurantDishDetailBusiness.java
License:Open Source License
@Override public List<RestaurantDTO> getListRestaurantByDish(String userName, String localeCode, String countryCode, String token, String id) { SQLQuery query = gettDAO().getSession().createSQLQuery("select c.id, c.name from restaurant c " + " inner join restaurant_dish_detail l on c.id = l.restaurant_id" + " where l.dish_id = ? "); query.addScalar("id", StringType.INSTANCE); query.addScalar("name", StringType.INSTANCE); query.setLong(0, Long.valueOf(id)); query.setResultTransformer(Transformers.aliasToBean(RestaurantDTO.class)); return query.list(); }
From source file:com.dungnv.streetfood.business.RestaurantDishDetailBusiness.java
License:Open Source License
@Override public List<DishDTO> getListDishByRestaurant(String userName, String localeCode, String countryCode, String token, String id) { SQLQuery query = gettDAO().getSession().createSQLQuery("select c.id, c.name from dish c " + " inner join restaurant_dish_detail l on c.id =l.dish_id" + " where l.restaurant_id = ? "); query.addScalar("id", StringType.INSTANCE); query.addScalar("name", StringType.INSTANCE); query.setLong(0, Long.valueOf(id)); query.setResultTransformer(Transformers.aliasToBean(DishDTO.class)); return query.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 www . ja va 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 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 {//from w ww.j a v a 2 s .co 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.ett.drv.biz.DrvQueryHelperImp.java
public List<ComboxObject> getDict(String xtlb, String type) { List<ComboxObject> listTmp = new ArrayList<ComboxObject>(); SessionFactory sessionFactory = this.getBaseDaoDrv().getHibernateSessionFactory(); Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); String queryStr = MessageFormat.format(DictSql, xtlb, type); logger.debug("?" + queryStr.toString()); SQLQuery query = session.createSQLQuery(queryStr.toString()); query.addScalar("value", new org.hibernate.type.StringType()); query.addScalar("text", new org.hibernate.type.StringType()); query.setResultTransformer(Transformers.aliasToBean(ComboxObject.class)); try {// ww w .j a v a2 s . c o m tx.begin(); //query.uniqueResult() listTmp = query.list(); if (logger.isInfoEnabled()) { logger.info("==" + listTmp.size()); } if (listTmp.size() == 0) { throw new ObjectDontExistException("?"); } session.flush(); tx.commit(); } catch (Exception e) { e.printStackTrace(); logger.info(e); if (tx != null) { tx.rollback(); } throw new ObjectDontExistException(e); } finally { session.close(); } return listTmp; }
From source file:com.ett.drv.biz.DrvQueryHelperImp.java
public DrvUser getDrvUser(String idcard, String glbm) { //System.out.println("Dao"); logger.debug("DAO" + this.getBaseDaoDrv()); logger.debug("??" + this.user); if (this.user != null) { return user; }/* w w w.ja va 2 s .c om*/ logger.debug("???" + idcard + "??" + glbm + "??"); List lists = new ArrayList(); SessionFactory sessionFactory = this.getBaseDaoDrv().getHibernateSessionFactory(); Session session = sessionFactory.openSession(); logger.debug("baseDaoDrv?"); Transaction tx = session.beginTransaction(); logger.debug("Sessionsql?"); String queryStr = MessageFormat.format(getDrvUser, idcard, glbm); logger.debug("??" + queryStr.toString()); SQLQuery query = session.createSQLQuery(queryStr.toString()); query.addScalar("lsh", new org.hibernate.type.StringType()); query.addScalar("sfzmhm", new org.hibernate.type.StringType()); query.addScalar("xb", new org.hibernate.type.IntegerType()); query.addScalar("xm", new org.hibernate.type.StringType()); query.addScalar("csrq", new org.hibernate.type.DateType()); query.addScalar("lxzsxxdz", new org.hibernate.type.StringType()); query.addScalar("lxdh", new org.hibernate.type.StringType()); query.addScalar("sjhm", new org.hibernate.type.StringType()); query.setResultTransformer(Transformers.aliasToBean(DrvUser.class)); try { tx.begin(); //query.uniqueResult() lists = query.list(); if (logger.isInfoEnabled()) { logger.info("??==" + lists.size()); } if (lists.size() == 0) { return null; //throw new ObjectDontExistException("??"); } session.flush(); tx.commit(); } catch (Exception e) { e.printStackTrace(); logger.info(e); if (tx != null) { tx.rollback(); } throw new ObjectDontExistException(e); } finally { session.close(); } this.user = (DrvUser) lists.get(0); return this.user; }
From source file:com.ett.drv.biz.DrvQueryHelperImp.java
public DrvUser getUserWithExamCard(DrvUser user) { DrvUser tmpuser = user;/*from ww w . j av a2 s. co m*/ List lists = new ArrayList(); SessionFactory sessionFactory = this.getBaseDaoDrv().getHibernateSessionFactory(); Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); String queryStr = MessageFormat.format(getExamCard, tmpuser.getSfzmhm()); logger.debug("??" + queryStr.toString()); SQLQuery query = session.createSQLQuery(queryStr.toString()); query.addScalar("dabh", new org.hibernate.type.StringType()); query.addScalar("zkzmbh", new org.hibernate.type.StringType()); query.addScalar("zkcx", new org.hibernate.type.StringType()); query.addScalar("cclzrq", new org.hibernate.type.TimestampType()); query.addScalar("fzrq", new org.hibernate.type.TimestampType()); query.addScalar("jxdm", new org.hibernate.type.StringType()); //GregorianCalendar query.addScalar("yxqz", new org.hibernate.type.TimestampType()); query.addScalar("yxqs", new org.hibernate.type.TimestampType()); query.setResultTransformer(Transformers.aliasToBean(DrvUser.class)); try { tx.begin(); //query.uniqueResult() lists = query.list(); if (logger.isInfoEnabled()) { logger.info("getUserWithExamCard?==" + lists.size()); } if (lists.size() == 0) { return null; //throw new ObjectDontExistException("???"); } session.flush(); tx.commit(); } catch (Exception e) { e.printStackTrace(); logger.info(e); if (tx != null) { tx.rollback(); } throw new ObjectDontExistException(e); } finally { session.close(); } DrvUser tmp = (DrvUser) lists.get(0); tmpuser.setDabh(tmp.getDabh()); tmpuser.setZkzmbh(tmp.getZkzmbh()); tmpuser.setYxqs(tmp.getYxqs()); tmpuser.setYxqz(tmp.getYxqz()); tmpuser.setZkcx(tmp.getZkcx()); tmpuser.setCclzrq(tmp.getCclzrq()); tmpuser.setFzrq(tmp.getFzrq()); tmpuser.setJxdm(tmp.getJxdm()); return tmpuser; }
From source file:com.ett.drv.biz.DrvQueryHelperImp.java
public DrvUser getUserWithLicense(DrvUser user) { DrvUser tmpuser = user;/*from w w w . j a v a2 s. c om*/ List lists = new ArrayList(); SessionFactory sessionFactory = this.getBaseDaoDrv().getHibernateSessionFactory(); Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); String queryStr = MessageFormat.format(getLicense, tmpuser.getSfzmhm()); logger.debug("getUserWithLicense?" + queryStr.toString()); SQLQuery query = session.createSQLQuery(queryStr.toString()); query.addScalar("zkcx", new org.hibernate.type.StringType()); query.addScalar("dabh", new org.hibernate.type.StringType()); query.addScalar("yxqz", new org.hibernate.type.TimestampType()); query.addScalar("yxqs", new org.hibernate.type.TimestampType()); query.addScalar("cclzrq", new org.hibernate.type.TimestampType()); query.addScalar("syrq", new org.hibernate.type.TimestampType()); query.addScalar("qfrq", new org.hibernate.type.TimestampType()); query.addScalar("jxdm", new org.hibernate.type.StringType()); query.setResultTransformer(Transformers.aliasToBean(DrvUser.class)); try { tx.begin(); //query.uniqueResult() lists = query.list(); if (logger.isInfoEnabled()) { logger.info("getUserWithLicense==" + lists.size()); } if (lists.size() == 0) { return null; //throw new ObjectDontExistException("???"); } session.flush(); tx.commit(); } catch (Exception e) { e.printStackTrace(); logger.info(e); if (tx != null) { tx.rollback(); } throw new ObjectDontExistException(e); } finally { session.close(); } DrvUser tmp = (DrvUser) lists.get(0); tmpuser.setDabh(tmp.getDabh()); tmpuser.setYxqs(tmp.getYxqs()); tmpuser.setYxqz(tmp.getYxqz()); tmpuser.setCclzrq(tmp.getCclzrq()); tmpuser.setQfrq(tmp.getQfrq()); tmpuser.setSyrq(tmp.getSyrq()); tmpuser.setJxdm(tmp.getJxdm()); tmpuser.setZkcx(tmp.getZkcx()); return tmpuser; }
From source file:com.ett.drv.biz.DrvQueryHelperImp.java
public List<ComboxObject> getDict(String xtlb, String type, String glbm) { List<ComboxObject> listTmp = new ArrayList<ComboxObject>(); SessionFactory sessionFactory = this.getBaseDaoDrv().getHibernateSessionFactory(); Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); String queryStr = MessageFormat.format(DictSqlWithGlbm, xtlb, type, glbm); logger.debug("DictSqlWithGlbm?" + queryStr.toString()); SQLQuery query = session.createSQLQuery(queryStr.toString()); query.addScalar("value", new org.hibernate.type.StringType()); query.addScalar("text", new org.hibernate.type.StringType()); query.setResultTransformer(Transformers.aliasToBean(ComboxObject.class)); try {/*www .ja v a2 s . com*/ tx.begin(); //query.uniqueResult() listTmp = query.list(); if (logger.isInfoEnabled()) { logger.info("==" + listTmp.size()); } if (listTmp.size() == 0) { return null; //throw new ObjectDontExistException("?"); } session.flush(); tx.commit(); } catch (Exception e) { e.printStackTrace(); logger.info(e); if (tx != null) { tx.rollback(); } throw new ObjectDontExistException(e); } finally { session.close(); } return listTmp; }