List of usage examples for org.hibernate SQLQuery addScalar
SQLQuery<T> addScalar(String columnAlias, Type type);
From source file:com.dungnv.streetfood.business.TagDishBusiness.java
License:Open Source License
@Override public List<String> getTagsListByDish(String userName, String localeCode, String countryCode, String token, String id) {//from w w w . j a v a 2s . c o m SQLQuery query = gettDAO().getSession().createSQLQuery("select t.name id from tags t " + "inner join tag_dish l on t.id =l.tag_id" + " where l.dish_id = ? "); query.addScalar("id", StringType.INSTANCE); query.setLong(0, Long.valueOf(id)); return query.list(); }
From source file:com.dungnv.streetfood.business.TagRestaurantBusiness.java
License:Open Source License
@Override public List<String> getTagsListByRestaurant(String userName, String localeCode, String countryCode, String token, String id) { SQLQuery query = gettDAO().getSession().createSQLQuery("select t.name id from tags t " + "inner join tag_restaurant l on t.id =l.tag_id" + " where l.restaurant_id = ? "); query.addScalar("id", StringType.INSTANCE); query.setLong(0, Long.valueOf(id)); return query.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.j ava2 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.ephesoft.dcma.core.hibernate.DynamicHibernateDao.java
License:Open Source License
/** * To create queries./*from w ww . j a va 2 s .co m*/ * * @param queryString String * @param aliasTypes List<AliasType> * @param params Object * @return SQLQuery */ public SQLQuery createQuery(String queryString, List<AliasType> aliasTypes, Object... params) { SQLQuery sqlQuery = createQuery(queryString, params); if (aliasTypes != null) { for (AliasType aliasType : aliasTypes) { sqlQuery.addScalar(aliasType.alias, aliasType.type); } } return sqlQuery; }
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 {//from w w w .j a v a 2 s.co 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; }//from w ww. j a va2 s . com 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 a va 2 s.c o 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;// w w w .j av a 2 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 {/*from w w w .j a v a 2 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; }
From source file:com.ett.self.print.biz.PrintBizImpl.java
protected void searchFlowFromSql(String sql, String idcard) { SessionFactory sessionFactory = this.getBaseDaoDrv().getHibernateSessionFactory(); Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); String queryStr = MessageFormat.format(sql, idcard); log.debug("?" + queryStr.toString()); SQLQuery query = session.createSQLQuery(queryStr.toString()); query.addScalar("ywlx", new org.hibernate.type.StringType()); query.addScalar("fee", new org.hibernate.type.StringType()); query.addScalar("ywyy", new org.hibernate.type.StringType()); query.addScalar("yyrq", new org.hibernate.type.TimestampType()); query.addScalar("ksrq", new org.hibernate.type.TimestampType()); query.addScalar("slrq", new org.hibernate.type.TimestampType()); query.addScalar("lsh", new org.hibernate.type.StringType()); query.addScalar("xm", new org.hibernate.type.StringType()); query.addScalar("hphm", new org.hibernate.type.StringType()); query.addScalar("jdsbh", new org.hibernate.type.StringType()); query.addScalar("sfzmhm", new org.hibernate.type.StringType()); query.addScalar("zjcx", new org.hibernate.type.StringType()); query.addScalar("dabh", new org.hibernate.type.StringType()); query.setResultTransformer(Transformers.aliasToBean(DrvPersonFlowObject.class)); try {//from w ww .j a v a 2 s . c o m tx.begin(); //query.uniqueResult() this.lists = query.list(); if (log.isInfoEnabled()) { log.info("?==" + lists.size()); } if (this.lists == null || this.lists.size() == 0) { this.lists = new ArrayList(); //this.lists.add(co); } session.flush(); tx.commit(); } catch (Exception e) { e.printStackTrace(); log.info(e); if (tx != null) { tx.rollback(); } } finally { session.close(); } //return null; }