Java Code Examples for org.hibernate.Query.setParameterList()
The following are Jave code examples for showing how to use
setParameterList() of the
org.hibernate.Query
class.
You can vote up the examples you like. Your votes will be used in our system to get
more good examples.
+ Save this method
Example 1
Project: sjk File: AppHistory4IndexDaoImpl.java View Source Code | 11 votes |
/** * 更新 状态到数据库,仅针对 appStatus 为 1(add) 2(update) 更新索引 , */ @Override public int updateAppHistory4indeToIndexed(List<Integer> appIds) { String hql = "update AppHistory4Index set indexStatus=1,lastIndexTime=:lastIndexTime where (appStatus=1 or appStatus=2) and appId in (:appIds)"; Session session = null; try { session = this.sessions.openSession(); Query query = session.createQuery(hql); query.setParameterList("appIds", appIds); query.setTimestamp("lastIndexTime", new Date()); return query.executeUpdate(); } catch (Exception e) { logger.error("error:", e); return 0; } finally { if (session != null && session.isOpen()) { session.flush(); session.clear(); session.close(); } } }
Example 2
Project: jeesupport File: AbsSupportDao.java View Source Code | 8 votes |
@SuppressWarnings( "unchecked" ) @Override public < T > List< T > selectByHQL( String _db , String _hql , String[] _param , Object[] _value, Class< T > _cls ){ Session sess = _get_session( _db ); try { Query query = _get_session( _db ).createQuery( _hql ); if ( _param != null && _value != null ) { for( int i = 0; i < _param.length; i ++ ){ if( _value[i] instanceof Collection ) query.setParameterList( _param[i] , ( Collection<?> ) _value[i] ); else query.setParameter( _param[i] ,_value[i] ); } } return query.list(); } finally { _flush_session( sess ); } }
Example 3
Project: sjk File: UserDaoImpl.java View Source Code | 8 votes |
@Override public boolean deleteByIds(List<Integer> ids) { String hql = "delete User where id in (:ids)"; Query query = getSession().createQuery(hql); query.setParameterList("ids", ids); return query.executeUpdate() == ids.size(); }
Example 4
Project: sjk File: MarketAppDaoImpl.java View Source Code | 8 votes |
@Override public List<MarketApp> getByIds(Session session, List<Integer> ids) { StringBuilder queryString = new StringBuilder("from MarketApp where id in (:ids)"); Query q = session.createQuery(queryString.toString()); q.setParameterList("ids", ids); List<MarketApp> list = HibernateHelper.list(q); return list; }
Example 5
Project: sjk File: AppDaoImpl.java View Source Code | 8 votes |
@Override public int updateDownload(List<Integer> ids, Integer realDownload, int deltaDownload) { String hql = null; if (realDownload != null) { hql = "update App set realDownload = :realDownload , deltaDownload = :deltaDownload, downloadRank = :downloadRank where id in (:id)"; } else { hql = "update App set deltaDownload = :deltaDownload, downloadRank = realDownload + :deltaDownload where id in (:id)"; } Query query = getSession().createQuery(hql); if (realDownload != null) { query.setParameter("realDownload", realDownload); query.setParameter("downloadRank", realDownload.intValue() + deltaDownload); } query.setParameter("deltaDownload", deltaDownload); query.setParameterList("id", ids); return query.executeUpdate(); }
Example 6
Project: sjk File: AppDaoImpl.java View Source Code | 7 votes |
@Override public int deleteByIds(List<Integer> ids) { String hql = "delete App where id in (:ids)"; Query query = getSession().createQuery(hql); query.setParameterList("ids", ids); return query.executeUpdate(); }
Example 7
Project: sjk File: MoFeaturedDaoImpl.java View Source Code | 7 votes |
@Override public Boolean updateDeleted(List<Integer> ids, boolean deleted) { String hql = "update MoFeatured set Deleted =:deleted where id in (:ids)"; Query query = getSession().createQuery(hql); query.setBoolean("deleted", deleted); query.setParameterList("ids", ids); return query.executeUpdate() > 0; }
Example 8
Project: sjk File: TagDaoImpl.java View Source Code | 7 votes |
@Override public int deleteByIds(List<Integer> ids) { String hql = "delete Tag where id in (:ids)"; Query query = getSession().createQuery(hql); query.setParameterList("ids", ids); return query.executeUpdate(); }
Example 9
Project: sjk File: AppHistory4IndexDaoImpl.java View Source Code | 6 votes |
/** * 设置appStatus 状态 为可删除 状态 3,索引状态 indexStatus为 -1 */ @Override public int updateAppStatus2Del(List<Integer> ids) { Session session = null; try { session = this.sessions.openSession(); String hql = "update AppHistory4Index set appStatus=3,indexStatus=-1,lastOpTime=:lastOpTime where appId in (:appIds)"; Query query = session.createQuery(hql); query.setParameterList("appIds", ids); query.setTimestamp("lastOpTime", new Date()); return query.executeUpdate(); } catch (Exception e) { logger.error("error:", e); return 0; } finally { if (session != null && session.isOpen()) { session.flush(); session.clear(); session.close(); } } }
Example 10
Project: lams File: HibernateTemplate.java View Source Code | 6 votes |
/** * Apply the given name parameter to the given Query object. * @param queryObject the Query object * @param paramName the name of the parameter * @param value the value of the parameter * @throws HibernateException if thrown by the Query object */ protected void applyNamedParameterToQuery(Query queryObject, String paramName, Object value) throws HibernateException { if (value instanceof Collection) { queryObject.setParameterList(paramName, (Collection<?>) value); } else if (value instanceof Object[]) { queryObject.setParameterList(paramName, (Object[]) value); } else { queryObject.setParameter(paramName, value); } }
Example 11
Project: lams File: HibernateTemplate.java View Source Code | 6 votes |
/** * Apply the given name parameter to the given Query object. * @param queryObject the Query object * @param paramName the name of the parameter * @param value the value of the parameter * @throws HibernateException if thrown by the Query object */ protected void applyNamedParameterToQuery(Query queryObject, String paramName, Object value) throws HibernateException { if (value instanceof Collection) { queryObject.setParameterList(paramName, (Collection<?>) value); } else if (value instanceof Object[]) { queryObject.setParameterList(paramName, (Object[]) value); } else { queryObject.setParameter(paramName, value); } }
Example 12
Project: sjk File: AppDaoImpl.java View Source Code | 6 votes |
@Override public List<TopAppVo> getAppList(Set<String> pnames) { // String names = ""; // StringBuilder sb = new StringBuilder(); // for (String name : pnames) { // sb.append("'" + name + "'" + ","); // } // names = sb.toString().substring(0, sb.toString().length() - 1); // names = "'com.tencent.mobileqq'"; // // System.out.println("--> " + names); // return this.jdbcTemplate.query(this.top2000sql, // this.TopAppVoRowMapper, names); Query query = getSession().createSQLQuery(this.top2000sql); query.setParameterList("ids", pnames); List<Object[]> lists = HibernateHelper.list(query); List<TopAppVo> volist = new ArrayList<TopAppVo>(); for (Object[] obj : lists) { TopAppVo vo = new TopAppVo(); vo.setId((Integer) obj[0]); vo.setName((String) obj[1]); vo.setPkname((String) obj[2]); vo.setLastUpdateTime((Date)obj[3]); volist.add(vo); } return volist; }
Example 13
Project: sjk File: AppHistory4IndexDaoImpl.java View Source Code | 6 votes |
@Override public int delAppHistory4index(List<Integer> appIds) { // String hql = // "delete AppHistory4Index where appStatus=3 and indexStatus=-1 and appId in (:appIds)"; // 删除前一天生成索引的数据,避免数据过多 String hql = "delete AppHistory4Index where (indexStatus=-1 and appId in (:appIds) ) or lastIndexTime<:lastIndexTime"; Session session = null; try { session = this.sessions.openSession(); Query query = session.createQuery(hql); query.setParameterList("appIds", appIds); query.setTimestamp("lastIndexTime", DateUtils.addDays(new Date(), -1));// 删除前一天索引后的数据 return query.executeUpdate(); } catch (Exception e) { logger.error("error:", e); return 0; } finally { if (session != null && session.isOpen()) { session.flush(); session.clear(); session.close(); } } }
Example 14
Project: sjk File: AppDaoImpl.java View Source Code | 6 votes |
@Override public int deleteByMarketApps(Session session, List<Integer> marketAppIds) { String hql = "delete App where marketAppId in (:marketAppIds)"; Query query = session.createQuery(hql); query.setParameterList("marketAppIds", marketAppIds); return query.executeUpdate(); }
Example 15
Project: unitimes File: TimetableGridSolutionHelper.java View Source Code | 6 votes |
public static TimetableGridModel createModel(String solutionIdsStr, StudentGroupInfo g, org.hibernate.Session hibSession, TimetableGridContext context) { TimetableGridModel model = new TimetableGridModel(ResourceType.STUDENT_GROUP.ordinal(), g.getGroupId()); model.setName(g.getGroupName()); model.setFirstDay(context.getFirstDay()); model.setFirstSessionDay(context.getFirstSessionDay()); model.setFirstDate(context.getFirstDate()); List<Long> classIds = new ArrayList<Long>(); for (StudentGroupInfo.ClassInfo clazz: g.getGroupAssignments()) classIds.add(clazz.getClassId()); if (classIds.isEmpty()) return null; Query q = hibSession.createQuery( "select distinct a from Assignment a where a.solution.uniqueId in ("+solutionIdsStr+") and a.classId in (:classIds)"); q.setParameterList("classIds", classIds, new LongType()); q.setCacheable(true); List assignments = q.list(); model.setSize((int)Math.round(g.countStudentWeights())); for (Iterator i = assignments.iterator(); i.hasNext(); ) { Assignment assignment = (Assignment)i.next(); List<TimetableGridCell> cells = createCells(model, assignment, hibSession, context, false); StudentGroupInfo.ClassInfo ci = g.getGroupAssignment(assignment.getClassId()); if (ci != null) { int total = g.countStudentsOfOffering(assignment.getClazz().getSchedulingSubpart().getInstrOfferingConfig().getInstructionalOffering().getUniqueId()); for (TimetableGridCell cell: cells) { cell.setGroup("(" + Math.round(ci.countStudentsWeight()) + ")"); if (ci.getStudents() != null && !ci.getStudents().isEmpty() && total > 1) { int assigned = ci.getStudents().size(); int minLimit = assignment.getClazz().getExpectedCapacity(); int maxLimit = assignment.getClazz().getMaxExpectedCapacity(); int limit = maxLimit; if (minLimit < maxLimit) { int roomLimit = (int) Math.floor(assignment.getPlacement().getRoomSize() / (assignment.getClazz().getRoomRatio() == null ? 1.0f : assignment.getClazz().getRoomRatio())); // int roomLimit = Math.round((c.getRoomRatio() == null ? 1.0f : c.getRoomRatio()) * p.getRoomSize()); limit = Math.min(Math.max(minLimit, roomLimit), maxLimit); } if (assignment.getClazz().getSchedulingSubpart().getInstrOfferingConfig().isUnlimitedEnrollment() || limit >= 9999) limit = Integer.MAX_VALUE; int p = 100 * assigned / Math.min(limit, total); cell.setBackground(percentage2color(p)); cell.setPreference(assigned + " of " + total); } } } } model.setUtilization(g.getGroupValue()); return model; }
Example 16
Project: unitimes File: PdfWorksheet.java View Source Code | 5 votes |
public static boolean print(OutputStream out, Collection<SubjectArea> subjectAreas, String courseNumber) throws IOException, DocumentException { TreeSet courses = new TreeSet(new Comparator() { public int compare(Object o1, Object o2) { CourseOffering co1 = (CourseOffering)o1; CourseOffering co2 = (CourseOffering)o2; int cmp = co1.getCourseName().compareTo(co2.getCourseName()); if (cmp!=0) return cmp; return co1.getUniqueId().compareTo(co2.getUniqueId()); } }); List<Long> subjectIds = new ArrayList<Long>(); for (SubjectArea sa: subjectAreas) subjectIds.add(sa.getUniqueId()); String query = "select co from CourseOffering co where co.subjectArea.uniqueId in :subjectIds"; if (courseNumber != null && !courseNumber.trim().isEmpty()) { if (courseNumber.indexOf('*') >= 0) { query += " and co.courseNbr like :courseNbr "; } else { query += " and co.courseNbr = :courseNbr "; } } Query q = new SessionDAO().getSession().createQuery(query); q.setParameterList("subjectIds", subjectIds); if (courseNumber != null && !courseNumber.trim().isEmpty()) q.setParameter("courseNbr", ApplicationProperty.CourseOfferingNumberUpperCase.isTrue()? courseNumber.trim().replace('*', '%').toUpperCase() : courseNumber.trim().replace('*', '%')); courses.addAll(q.list()); if (courses.isEmpty()) return false; PdfWorksheet w = new PdfWorksheet(out, subjectAreas, courseNumber); for (Iterator i=courses.iterator();i.hasNext();) { w.print((CourseOffering)i.next()); } w.lastPage(); w.close(); return true; }
Example 17
Project: sjk File: MarketAppDaoImpl.java View Source Code | 5 votes |
@Override public int deleteByMarketApp(Session session, String marketName, List<Integer> appIdsOfMarket) { Query query = session .createQuery("delete from MarketApp where appId in ( :appIdsOfMarket) and marketName=:marketName"); query.setParameterList("appIdsOfMarket", appIdsOfMarket); query.setString("marketName", marketName); int rows = query.executeUpdate(); return rows; }
Example 18
Project: bdf2 File: HibernateDao.java View Source Code | 5 votes |
public void setQueryParameters(Query query,Map<String,Object> parameters){ if(parameters==null)return; for(String name:parameters.keySet()){ Object obj=parameters.get(name); if(obj instanceof Collection){ query.setParameterList(name, (Collection<?>)obj); }else if(obj instanceof Object[]){ query.setParameterList(name, (Object[])obj); }else{ query.setParameter(name, obj); } } }
Example 19
Project: sjk File: MetroDaoImpl.java View Source Code | 5 votes |
@Override public int updateHide(List<Integer> ids) { String hql = "update Metro set Hidden = 1 where id in (:ids)"; Query query = getSession().createQuery(hql); query.setParameterList("ids", ids); return query.executeUpdate(); }
Example 20
Project: sjk File: MarketAppDaoImpl.java View Source Code | 5 votes |
@Override public int deleteByIds(List<Integer> ids) { String hql = "delete MarketApp where id in (:ids)"; Query query = getSession().createQuery(hql); query.setParameterList("ids", ids); return query.executeUpdate(); }