List of usage examples for org.hibernate Query setParameterList
Query<R> setParameterList(int position, Object[] values);
From source file:com.letusgo.daoImp.DaoImpl.java
@Override public Query getQuery(String hql, Map<String, Object> map) { Query query = getSession().createQuery(hql); // TODO Auto-generated method stub if (map != null) { Set<String> keySet = map.keySet(); for (String string : keySet) { Object obj = map.get(string); //????? if (obj instanceof Collection<?>) { query.setParameterList(string, (Collection<?>) obj); } else if (obj instanceof Object[]) { query.setParameterList(string, (Object[]) obj); } else { query.setParameter(string, obj); }/*from w w w . j av a 2s .c om*/ } } return query; }
From source file:com.lushapp.modules.sys.service.UserManager.java
License:Apache License
/** * ?Id?????// w w w. j av a2 s . c om * @param inUserIds id? * @param loginNameOrName ???? * @param page * @param rows ? * @param sort ? * @param order ?? ?:'asc',??:'desc' * @return */ public Page<User> getUsersByQuery(List<Long> inUserIds, String loginNameOrName, int page, int rows, String sort, String order) { List<Object> params = Lists.newArrayList(); StringBuilder hql = new StringBuilder(); hql.append("from User u where 1=1 "); if (!Collections3.isEmpty(inUserIds)) { hql.append("and (u.id in (:ids) "); if (StringUtils.isNotBlank(loginNameOrName)) { hql.append("or u.loginName like ? or u.name like ? ) "); params.add("%" + loginNameOrName + "%"); params.add("%" + loginNameOrName + "%"); } } else { if (StringUtils.isNotBlank(loginNameOrName)) { hql.append("and (u.loginName like ? or u.name like ?) "); params.add("%" + loginNameOrName + "%"); params.add("%" + loginNameOrName + "%"); } } hql.append("and u.status = ? "); params.add(StatusState.normal.getValue()); // Page<User> p = new Page<User>(rows); p.setPageNo(page); if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) { p.setOrder(order); p.setOrderBy(sort); } else { p.setOrder(Page.ASC); p.setOrderBy("id"); } Query q = userDao.createQuery(hql.toString(), params.toArray()); if (!Collections3.isEmpty(inUserIds)) { q.setParameterList("ids", inUserIds); } if (p.isAutoCount()) { long totalCount = getEntityDao().countHqlResult(hql.toString(), params.toArray()); p.setTotalCount(totalCount); } getEntityDao().setPageParameterToQuery(q, p); List result = q.list(); p.setResult(result); return p; }
From source file:com.medigy.service.impl.person.PatientWorklistServiceImpl.java
License:Open Source License
private Map<Long, Float> getPatientBalance(final PatientWorklistParameters parameters) { // TODO: There is no claimType in INVOICE. Need to re-do the patient balance query final Query query = getSession().createQuery(PATIENT_BALANCE_HQL); final List<Long> idList = new ArrayList<Long>(); for (InvoiceStatusType.Cache cache : excludeStatusList) idList.add(cache.getEntity().getSystemId()); query.setParameterList("excludeStatusList", idList); query.setLong("selfpayClaimType", ClaimType.Cache.SELFPAY.getEntity().getClaimTypeId()); final Map<Long, Float> balanceMap = new HashMap<Long, Float>(); final List list = query.list(); for (Object rowObject : list) { if (rowObject instanceof Object[]) { final Object[] columnValues = (Object[]) rowObject; balanceMap.put((Long) columnValues[0], (Float) columnValues[1]); }/*from w w w . j ava 2 s .co m*/ } return balanceMap; }
From source file:com.medigy.service.impl.person.PatientWorklistServiceImpl.java
License:Open Source License
private Map<Long, Float> getAccountBalance(final PatientWorklistParameters parameters) { final Query query = getSession().createQuery(ACCOUNT_BALANCE_HQL); final List<Long> idList = new ArrayList<Long>(); for (InvoiceStatusType.Cache cache : excludeStatusList) idList.add(cache.getEntity().getSystemId()); query.setParameterList("excludeStatusList", idList); final Map<Long, Float> balanceMap = new HashMap<Long, Float>(); final List list = query.list(); for (Object rowObject : list) { if (rowObject instanceof Object[]) { final Object[] columnValues = (Object[]) rowObject; balanceMap.put((Long) columnValues[0], (Float) columnValues[1]); }/*from w ww . j a v a 2s. c o m*/ } return balanceMap; }
From source file:com.mg.framework.api.orm.OrmTemplate.java
License:Open Source License
/** * Apply the given name parameter to the given Query object. * * @param queryObject the Query object/*w ww .j av a 2s.c o m*/ * @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); } }
From source file:com.mg.jet.birt.report.data.oda.ejbql.Statement.java
License:Open Source License
@SuppressWarnings("unchecked") public IResultSet executeQuery() throws OdaException { Type[] qryReturnTypes = null; List<Object> rst = null; try {//from w w w .j ava 2 s. c om Session hibsession = HibernateUtil.currentSession(); String qryStr = this.query; qryStr = qryStr.replaceAll("[\\n\\r]+", " "); qryStr.trim(); // Create the Hibernate query, notice that we are using the query // prepared Query qry = hibsession.createQuery(qryStr); for (int i = 0; i < paramNames.size(); i++) { Object paramValue = convertParamValue(hibsession, paramNames.get(i), paramValues[i]); if (paramValue instanceof Object[]) qry.setParameterList(paramNames.get(i), (Object[]) paramValue); else qry.setParameter(paramNames.get(i), paramValue); } if (maxRows != 0) qry.setMaxResults(maxRows); // use the query list method to return the resuls in a List object rst = qry.list(); qryReturnTypes = qry.getReturnTypes(); } catch (Exception e) { throw new OdaException(e); } // create a new ResultSet Ojbect passing in the row set and the meta // data and the // Hibernate query return types return new ResultSet(rst, getMetaData(), qryReturnTypes); }
From source file:com.mobileman.projecth.persistence.impl.UserConnectionDaoImpl.java
License:Apache License
/** * {@inheritDoc}//from w w w . j a v a2s.c om * @see com.mobileman.projecth.persistence.UserConnectionDao#findInvitableUsers(String, Long, Collection) */ @SuppressWarnings("unchecked") @Override public List<User> findInvitableUsers(String filter, Long invitingUserId, Collection<UserType> includeUserTypes) { if (log.isDebugEnabled()) { log.debug( "findInvitableUsers(" + filter + ", " + invitingUserId + ", " + includeUserTypes + ") - start"); //$NON-NLS-1$ } if (filter == null) { throw new IllegalArgumentException("Login must not be null"); } if (filter.trim().length() == 0) { throw new IllegalArgumentException("Login must not be empty string"); } String encodedFilter = encoderService.encode(filter).trim(); Query query = getSession().createQuery("select u " + "from User u join u.userAccount ua " + "left join u.medicalInstitution.country country " + "where u.userAccount.id is not null " + "and u.id != :_iuid " + "and u.userType in (:_iut) " + "and not exists (select uc.id from UserConnection uc where ((uc.user.id=:_iuid and uc.owner.id=u.id) or (uc.owner.id=:_iuid and uc.user.id=u.id)) and uc.state!=:_ucs) " + "and (ua.loginEncoded=:_filt or u.name.nameEncoded=:_filt or u.name.surnameEncoded=:_filt " + "or u.medicalInstitution.nameEncoded=:_filt " + "or u.medicalInstitution.address.placeEncoded=:_filt " + "or u.medicalInstitution.address.numberEncoded=:_filt " + "or u.medicalInstitution.address.addressEncoded=:_filt " + "or u.medicalInstitution.address.postalCode.codeEncoded=:_filt " + // Location "or country.name=:_filtdec " + "or country.code=:_filtdec) "); query.setParameter("_filt", encodedFilter); query.setParameter("_filtdec", filter); query.setParameter("_iuid", invitingUserId); query.setParameterList("_iut", includeUserTypes); query.setParameter("_ucs", UserConnectionState.C); List<User> users = query.list(); if (log.isDebugEnabled()) { log.debug("findUsersByLoginNamePlace(String) - returns"); //$NON-NLS-1$ } return users; }
From source file:com.model.database.queries.EventManager.java
License:Open Source License
/** * returns stops within a circle for selected list of agencies */// w w w . j av a 2 s . com public static List<GeoStop> getstopswithincircle2(double d, double lat, double lon, int sessionindex, List<String> agencyList) throws FactoryException, TransformException { CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326"); CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:2993"); MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS); GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); Point point = geometryFactory.createPoint(new Coordinate(lat, lon)); Geometry targetGeometry = JTS.transform(point, transform); //point = geometryFactory.createPoint(targetGeometry.getCoordinate()); point = targetGeometry.getCentroid(); point.setSRID(2993); session[sessionindex].beginTransaction(); Query q = session[sessionindex].getNamedQuery("STOP_BY_COORDINATES_SEL_AGENCIES"); Type geomType = GeometryUserType.TYPE; q.setParameter("point", point, geomType); q.setParameter("radius", d); q.setParameterList("sa", agencyList); @SuppressWarnings("unchecked") List<GeoStop> results = (List<GeoStop>) q.list(); Hutil.getSessionFactory()[sessionindex].close(); return results; }
From source file:com.model.database.queries.EventManager.java
License:Open Source License
public static long getstopscountbycounty(String countyId, List<String> selectedAgencies, int sessionindex) throws FactoryException, TransformException { session[sessionindex].beginTransaction(); Query q = session[sessionindex].getNamedQuery("STOPS_BY_COUNTY_SEL_AGENCIES"); q.setParameter("id", countyId); q.setParameterList("sa", selectedAgencies); //@SuppressWarnings("unchecked") long result = (Long) q.list().get(0); Hutil.getSessionFactory()[sessionindex].close(); return result; }
From source file:com.model.database.queries.EventManager.java
License:Open Source License
public static long getstopscountbyregion(String regionId, List<String> selectedAgencies, int sessionindex) throws FactoryException, TransformException { session[sessionindex].beginTransaction(); Query q = session[sessionindex].getNamedQuery("STOPS_BY_REGION_SEL_AGENCIES"); q.setParameter("id", regionId); q.setParameterList("sa", selectedAgencies); //@SuppressWarnings("unchecked") long result = (Long) q.list().get(0); Hutil.getSessionFactory()[sessionindex].close(); return result; }